CreateOrderViewController.m 167 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485
  1. //
  2. // CreateOrderViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/24/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CreateOrderViewController.h"
  9. #import "RANetwork.h"
  10. #import "MainViewController.h"
  11. #import "Singleton.h"
  12. #import "config.h"
  13. #import "CustomIOSAlertView.h"
  14. #import "AddressEditorViewController.h"
  15. #import "CreditCardEditorViewController.h"
  16. #import "JKTimerManager.h"
  17. #define SUBMIT_CONFIRM 123
  18. #define KEEP_TAIL 456
  19. #define CLOSE_ACTION 567
  20. @interface CreateOrderViewController ()
  21. // static const char associatedkey;
  22. @property (nonatomic,assign) BOOL isResume;///<恢复
  23. @property (nonatomic,assign) NSInteger userType;///<恢复使用
  24. @end
  25. @implementation CreateOrderViewController
  26. - (void)alertMessage:(NSString *)msg {
  27. if (notifyMe_switch) {
  28. if ([self.class_name isEqualToString:@"CreateOrderViewController"]) {
  29. NSString *err_msg = msg;
  30. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Attention!!" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
  31. __weak typeof(self) weakself = self;
  32. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  33. [weakself.navigationController popViewControllerAnimated:YES];
  34. }];
  35. [alertVC addAction:action];
  36. [self presentViewController:alertVC animated:YES completion:nil];
  37. } else {
  38. [RAUtils message_alert:msg title:nil controller:self] ;
  39. }
  40. } else {
  41. [RAUtils message_alert:msg title:nil controller:self] ;
  42. }
  43. }
  44. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  45. {
  46. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  47. if([value isEqualToString:@"new_addr"])
  48. {
  49. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  50. addressVC.url_type = URL_REMOTE;
  51. addressVC.request_url=URL_ADDRESS_EDOTOR;
  52. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  53. // NSString * string = [checked componentsJoinedByString:@","];
  54. // [params setValue:string forKey:@"cart2Checkbox"];
  55. addressVC.params = params;
  56. addressVC.delegate = self;
  57. addressVC.from = indexPath;
  58. // orderinfoVC.params = params;
  59. [self.navigationController pushViewController:addressVC animated:true];
  60. }else if([value isEqualToString:@"credit_card"])
  61. {
  62. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  63. NSDictionary *data = [item_json objectForKey:@"data"];
  64. if(data!=nil)
  65. {
  66. cardVC.content_data_download = [data mutableCopy];
  67. cardVC.url_type = URL_NONE;
  68. cardVC.request_url=nil;
  69. }
  70. else
  71. {
  72. cardVC.url_type = URL_REMOTE;
  73. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  74. }
  75. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  76. params[@"orderCode"]=appDelegate.order_code;
  77. cardVC.params = params;
  78. cardVC.delegate = self;
  79. cardVC.from = indexPath;
  80. // orderinfoVC.params = params;
  81. [self.navigationController pushViewController:cardVC animated:true];
  82. }
  83. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  84. {
  85. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  86. cvc.showNavibar = true;
  87. cvc.contact_type = value;
  88. __weak typeof(self) weakself = self;
  89. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  90. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  91. //
  92. // if(self.returnValue)
  93. // self.returnValue(value);
  94. };
  95. [self.navigationController pushViewController:cvc animated:true];
  96. }
  97. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  98. {
  99. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  100. cvc.showNavibar = true;
  101. cvc.contact_type = value;
  102. __weak typeof(self) weakself = self;
  103. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  104. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  105. //
  106. // if(self.returnValue)
  107. // self.returnValue(value);
  108. };
  109. [self.navigationController pushViewController:cvc animated:true];
  110. }
  111. else if([value isEqualToString:@"Sales_Order_Customer"])
  112. {
  113. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  114. cvc.contact_type = value;
  115. cvc.showNavibar = true;
  116. __weak typeof(self) weakself = self;
  117. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  118. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  119. //
  120. // if(self.returnValue)
  121. // self.returnValue(value);
  122. };
  123. [self.navigationController pushViewController:cvc animated:true];
  124. }
  125. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  126. {
  127. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  128. cvc.showNavibar = true;
  129. cvc.contact_type = value;
  130. __weak typeof(self) weakself = self;
  131. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  132. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  133. //
  134. // if(self.returnValue)
  135. // self.returnValue(value);
  136. };
  137. [self.navigationController pushViewController:cvc animated:true];
  138. }
  139. else if([value isEqualToString:@"Contact_Return_To"])
  140. {
  141. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  142. cvc.showNavibar = true;
  143. cvc.contact_type = value;
  144. __weak typeof(self) weakself = self;
  145. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  146. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  147. //
  148. // if(self.returnValue)
  149. // self.returnValue(value);
  150. };
  151. [self.navigationController pushViewController:cvc animated:true];
  152. }
  153. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  154. {
  155. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  156. cvc.showNavibar = true;
  157. cvc.contact_type = value;
  158. __weak typeof(self) weakself = self;
  159. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  160. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  161. //
  162. // if(self.returnValue)
  163. // self.returnValue(value);
  164. };
  165. [self.navigationController pushViewController:cvc animated:true];
  166. }
  167. }
  168. - (void)dealloc {
  169. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  170. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  171. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  172. if (self.isResume && self.userType == USER_ROLE_CUSTOMER) {
  173. [self releaseOrderAfterSave];
  174. }
  175. }
  176. -(void) viewWillAppear:(BOOL)animated
  177. {
  178. [super viewWillAppear:animated];
  179. [self start_urgency_timer];
  180. self.isResume = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_resume"] boolValue];
  181. self.userType = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_userType"] integerValue];
  182. BOOL canSubmit = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_submitOrder"] boolValue];
  183. // 检查权限
  184. NSMutableArray * items = [[NSMutableArray alloc]init];
  185. UIBarButtonItem *savebtn = nil;
  186. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  187. style:UIBarButtonItemStylePlain
  188. target:self
  189. action:@selector(onSaveClick:)];
  190. UIImage *submit_img = [[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
  191. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  192. submit_img = [[UIImage imageNamed:@"submit_red"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  193. #endif
  194. self.btnSubmitOrder = nil;
  195. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:submit_img
  196. style:UIBarButtonItemStylePlain
  197. target:self
  198. action:@selector(onCommitOrderClick:)];
  199. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  200. fixedItem.width = 20.0f;
  201. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  202. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  203. {
  204. [items addObject:savebtn];
  205. [items addObject:fixedItem];
  206. }
  207. if (!self.isResume) {
  208. // 正常情况
  209. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  210. // customer的订单必须是Sales Order并且有提交权限才能提交
  211. if ([Singleton sharedInstance].currentOrderIsMerged && [Singleton sharedInstance].permissions_submit_order) {
  212. [items addObject:self.btnSubmitOrder];
  213. }
  214. } else {
  215. [items addObject:self.btnSubmitOrder];
  216. }
  217. } else {
  218. // 恢复
  219. if (self.userType == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  220. // customer的订单必须是Sales Order并且有提交权限才能提交
  221. if (canSubmit) {
  222. [items addObject:self.btnSubmitOrder];
  223. }
  224. } else {
  225. [items addObject:self.btnSubmitOrder];
  226. }
  227. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_resume"];
  228. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_userType"];
  229. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_submitOrder"];
  230. }
  231. // [items addObject:item2];
  232. self.navigationItem.rightBarButtonItems=items;
  233. if(appDelegate.can_submit_order)
  234. {
  235. [self.btnSubmitOrder setImage:submit_img];
  236. self.btnSubmitOrder.enabled = true;
  237. }
  238. else
  239. {
  240. [self.btnSubmitOrder setImage:nil];
  241. self.btnSubmitOrder.enabled = false;
  242. }
  243. self.navigationController.navigationBarHidden=false;
  244. }
  245. -(void) download_success
  246. {
  247. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  248. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  249. NSString* order_customerid=[self getValue:@"customer_cid"];
  250. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  251. appDelegate.order_customer_id = order_customerid;
  252. }
  253. - (void)viewDidLoad {
  254. [super viewDidLoad];
  255. self.editable = YES;
  256. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  257. style:UIBarButtonItemStylePlain
  258. target:self
  259. action:@selector(onCloseClick:)];
  260. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  261. // closeButton.title = @"Close";
  262. self.navigationItem.leftBarButtonItem = closeButton;
  263. // self.navigationItem.backBarButtonItem = backButton;
  264. // Do any additional setup after loading the view.
  265. }
  266. - (void)onCommitOrderClick:(id)sender {
  267. // get customer info
  268. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  269. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  270. //
  271. // // 检查价格类型
  272. // // 提货价才能提交订单
  273. // /** 价格类型
  274. // * 0 提货价
  275. // * 1 统一价
  276. // * 2 计算价
  277. // */
  278. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  279. // if (priceType != 0) {
  280. //
  281. // NSString* pricename = nil;
  282. // switch (priceType) {
  283. // case 1:
  284. // pricename=flat_price;
  285. // break;
  286. // case 2:
  287. // pricename=given_price;
  288. // break;
  289. // default:
  290. // break;
  291. // }
  292. //
  293. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current price is %@, please change to %@ and try again.",pricename,[Singleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  294. //
  295. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  296. //
  297. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  298. //
  299. // }];
  300. //
  301. //
  302. // [alertVC addAction:cancelAction];
  303. //
  304. // [self presentViewController:alertVC animated:YES completion:nil];
  305. //
  306. // return;
  307. // }
  308. // }
  309. NSString* msg;
  310. #ifdef OFFLINE_MODE
  311. if(appDelegate.offline_mode)
  312. {
  313. msg=@"Are you sure to mark offline order as ready for submit?";
  314. }
  315. else
  316. #endif
  317. {
  318. msg=@"Submit order now?";
  319. // if(appDelegate.user_type == USER_ROLE_CUSTOMER) {
  320. //
  321. // NSString *specialInstuction = [Singleton sharedInstance].specialInstruction;
  322. // NSString * deliverprice=[Singleton sharedInstance].deliveryString;
  323. // msg = [NSString stringWithFormat:@"Are you sure to submit order?\n\n1. Your price type is %@, Order will sent to NPD with this price.",deliverprice];
  324. // if (specialInstuction.length) {
  325. // msg = [msg stringByAppendingFormat:@"\n2. Special Instruction: %@.",specialInstuction];
  326. // }
  327. //
  328. // }
  329. }
  330. // 2017-03-20 修改
  331. //
  332. // CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
  333. //
  334. //
  335. //
  336. //
  337. // // Add some custom content to the alert view
  338. // [alertView setContainerView:[self createDemoView:msg]];
  339. //
  340. // // Modify the parameters
  341. //
  342. //
  343. // NSArray *titleArr = [NSMutableArray arrayWithObjects:@"NO",@"YES", nil];
  344. // [alertView setButtonTitles:titleArr];
  345. // //[alertView setDelegate:self];
  346. //
  347. // // You may use a Block, rather than a delegate.
  348. // [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
  349. // // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
  350. // if(buttonIndex==0)
  351. // [alertView close];
  352. // else
  353. // {
  354. // // add params check here.
  355. // [self.lastedit endEditing:true];
  356. // [self.lasttextview endEditing:true];
  357. //
  358. //
  359. //
  360. // // self.cancommit=true;
  361. // // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  362. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  363. // // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  364. // // for(int i=0;i<section_count;i++)
  365. // // {
  366. // // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  367. // // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  368. // // for(int j=0;j<item_count;j++)
  369. // // {
  370. // // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  371. // // NSString* key = [itemjson valueForKey:@"name"];
  372. // // if(key==nil || key.length==0)
  373. // // continue;
  374. // // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  375. // // {
  376. // // NSString* single_select = [itemjson valueForKey:@"single_select"];
  377. // // if([single_select isEqualToString:@"true"])
  378. // // {
  379. // // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  380. // // int count = [[cadejson valueForKey:@"count"] intValue];
  381. // // bool setvalue = false;
  382. // // for(int cc=0;cc<count;cc++)
  383. // // {
  384. // // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  385. // // if([[valjson valueForKey:@"check"]intValue]==1)
  386. // // {
  387. // // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  388. // // setvalue=true;
  389. // // break;
  390. // // }
  391. // // }
  392. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  393. // // {
  394. // // self.cancommit = false;
  395. // // }
  396. // // }
  397. // // else
  398. // // {
  399. // // //not support multi select for now;
  400. // // }
  401. // // /*
  402. // // upparams setValue:itemjson forKey:<#(NSString *)#>
  403. // //
  404. // // */
  405. // // }else
  406. // // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  407. // // {
  408. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  409. // // self.cancommit = false;
  410. // // }
  411. // // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  412. // // {
  413. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  414. // // self.cancommit = false;
  415. // //
  416. // // NSString* valuestr = [itemjson valueForKey:@"value"];
  417. // // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  418. // // }
  419. // // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  420. // // {
  421. // // NSString* valuestr = [itemjson valueForKey:@"value"];
  422. // // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  423. // //
  424. // // NSString* value = [itemjson valueForKey:@"value"];
  425. // // NSMutableDictionary* boolitem=nil;
  426. // // NSMutableDictionary* subjson=nil;
  427. // // if([value isEqualToString:@"true"])
  428. // // {
  429. // // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  430. // //
  431. // // }
  432. // // else
  433. // // {
  434. // // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  435. // //
  436. // // }
  437. // // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  438. // // if( subjson!=nil /*&& !active*/)
  439. // // {
  440. // // int sub_count = [[subjson valueForKey:@"count"] intValue];
  441. // // for(int l=0;l<sub_count;l++)
  442. // // {
  443. // // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  444. // //
  445. // //
  446. // //
  447. // //
  448. // // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  449. // // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  450. // // else
  451. // // {
  452. // // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  453. // // self.cancommit = false;
  454. // // }
  455. // // }
  456. // //
  457. // //
  458. // //
  459. // // }
  460. // // }
  461. // // else
  462. // // {
  463. // // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  464. // // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  465. // // else
  466. // // {
  467. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  468. // // self.cancommit = false;
  469. // // }
  470. // // }
  471. // // upparams= [self subitem_param:itemjson addto:upparams ];
  472. // // }
  473. // // }
  474. // // if(self.cancommit==false)
  475. // // {
  476. // // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  477. // // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  478. // // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  479. // // //[self.editorTable reloadData ];
  480. // // [self.editorTable reloadData];
  481. // // // [waitalert dismissViewControllerAnimated:YES completion:nil];
  482. // // return;
  483. // // }
  484. //
  485. // NSMutableDictionary* upparams = [self check_cancommit:true];
  486. // if(self.cancommit==false)
  487. // return;
  488. //
  489. // if(upparams[@"shipping"]==nil)
  490. // goto commit_order;
  491. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  492. // {
  493. // upparams[@"shipping"] = nil;
  494. // goto commit_order;
  495. // }
  496. // else if([upparams[@"shipping"] doubleValue]==0)
  497. // {
  498. //
  499. //
  500. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  501. // //block代码块取代了delegate
  502. //
  503. //
  504. //
  505. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  506. // {
  507. //
  508. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  509. //
  510. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  511. // {
  512. //
  513. // if(/*!self.have_tail*/ true)
  514. // {UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  515. // [upparams setValue:@"false" forKey:@"isHold"];
  516. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  517. //
  518. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  519. //
  520. // dispatch_async(dispatch_get_main_queue(), ^{
  521. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  522. //
  523. //
  524. // if([[editor_json valueForKey:@"result"] intValue]==2)
  525. // {
  526. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  527. //
  528. // // debug aaa
  529. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  530. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  531. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  532. //
  533. // // appDelegate.customerInfo = customerInfo;
  534. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  535. // // appDelegate.order_code = nil;
  536. // [appDelegate closeOrder];
  537. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  538. //
  539. // NSString* title=nil;
  540. // NSString* msg=nil;
  541. // if(appDelegate.offline_mode)
  542. // {
  543. // title=TITLE_OFFLINE_SUBMIT;
  544. // msg=MSG_OFFLINE_SUBMIT;
  545. // }
  546. // else
  547. // {
  548. // title=@"Submit successful.";
  549. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  550. // }
  551. //
  552. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  553. //
  554. // [alert show];
  555. //
  556. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  557. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  558. // NSString* soid=[editor_json valueForKey:@"so#"];
  559. // // if(pdf_url.length>0)
  560. // // {
  561. // //
  562. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  563. // // //[self downloadpdf:pdf_url];
  564. // //
  565. // //
  566. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  567. // // {
  568. // // //bbb
  569. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  570. // // }
  571. // //
  572. // // [self prepareReturn:nil];
  573. // //
  574. // // [self.navigationController popViewControllerAnimated:true];
  575. // //
  576. // // [appDelegate printPdf:pdf_url];
  577. // //// if(self.printPdfCallback)
  578. // //// self.printPdfCallback(pdf_url);
  579. // // }
  580. // // else
  581. // {
  582. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  583. // {
  584. // //bbb
  585. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  586. // }
  587. // [self prepareReturn:nil];
  588. //
  589. // [self.navigationController popViewControllerAnimated:true];
  590. //
  591. // if(pdf_url.length>0)
  592. // {
  593. //
  594. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  595. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  596. // // [appDelegate printPdf:pdf_url];
  597. //
  598. // }
  599. // }
  600. //
  601. // }
  602. // else
  603. // {
  604. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  605. // }
  606. //
  607. //
  608. //
  609. //
  610. // });
  611. // });
  612. // }
  613. // else
  614. // {
  615. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  616. //
  617. //
  618. // alert.tag = KEEP_TAIL;
  619. //
  620. //
  621. // self.upparams = upparams;
  622. //
  623. // [alert show];
  624. // }
  625. //
  626. // }
  627. // else
  628. // { //USER_ROLE_CUSTOMER
  629. //
  630. // // if(self.have_tail)
  631. // // [upparams setValue:@"true" forKey:@"isHold"];
  632. // // else
  633. // // [upparams setValue:@"false" forKey:@"isHold"];
  634. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  635. //
  636. // [upparams setValue:@"true" forKey:@"isHold"];
  637. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  638. //
  639. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  640. //
  641. // dispatch_async(dispatch_get_main_queue(), ^{
  642. //
  643. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  644. //
  645. // if([[editor_json valueForKey:@"result"] intValue]==2)
  646. // {
  647. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  648. //
  649. //
  650. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  651. // // appDelegate.customerInfo = customerInfo;
  652. //
  653. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  654. // // appDelegate.order_code = orderCode;
  655. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  656. // [appDelegate closeOrder];
  657. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  658. //
  659. // NSString* title=nil;
  660. // NSString* msg=nil;
  661. // if(appDelegate.offline_mode)
  662. // {
  663. // title=TITLE_OFFLINE_SUBMIT;
  664. // msg=MSG_OFFLINE_SUBMIT;
  665. // }
  666. // else
  667. // {
  668. // title=@"Submit successful.";
  669. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  670. // }
  671. //
  672. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  673. //
  674. // [alert show];
  675. // // // self.labelContact.text=appDelegate.contact_name;
  676. // //
  677. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  678. // [self prepareReturn:nil];
  679. // [self.navigationController popViewControllerAnimated:true];
  680. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  681. // //
  682. // //
  683. // // ;
  684. // // }];
  685. //
  686. // }
  687. // else
  688. // {
  689. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  690. // }
  691. //
  692. //
  693. //
  694. //
  695. // });
  696. // });
  697. //
  698. // }
  699. //
  700. //
  701. //
  702. // }];
  703. //
  704. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  705. // //DebugLog(@"Cancel");
  706. //
  707. //
  708. // }];
  709. // [alertControl addAction:actionOne];
  710. //
  711. // [alertControl addAction:alertthree];
  712. //
  713. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  714. //
  715. //
  716. //
  717. //
  718. // [self presentViewController:alertControl animated:YES completion:nil];
  719. //
  720. //
  721. //
  722. // }
  723. // else
  724. // {
  725. // commit_order:
  726. //
  727. // {
  728. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  729. //
  730. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  731. // {
  732. //
  733. // if(/*!self.have_tail*/ true)
  734. // {UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  735. // [upparams setValue:@"false" forKey:@"isHold"];
  736. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  737. //
  738. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  739. //
  740. // dispatch_async(dispatch_get_main_queue(), ^{
  741. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  742. //
  743. //
  744. // if([[editor_json valueForKey:@"result"] intValue]==2)
  745. // {
  746. //
  747. // //debug bbb
  748. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  749. //
  750. //
  751. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  752. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  753. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  754. // // appDelegate.customerInfo = customerInfo;
  755. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  756. // // appDelegate.order_code = nil;
  757. // [appDelegate closeOrder];
  758. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  759. //
  760. // NSString* title=nil;
  761. // NSString* msg=nil;
  762. // if(appDelegate.offline_mode)
  763. // {
  764. // title=TITLE_OFFLINE_SUBMIT;
  765. // msg=MSG_OFFLINE_SUBMIT;
  766. // }
  767. // else
  768. // {
  769. // title=@"Submit successful.";
  770. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  771. // }
  772. //
  773. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  774. //
  775. // [alert show];
  776. //
  777. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  778. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  779. // NSString* soid=[editor_json valueForKey:@"so#"];
  780. // // if(pdf_url.length>0)
  781. // // {
  782. // //
  783. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  784. // //// [self downloadpdf:pdf_url];
  785. // //
  786. // //
  787. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  788. // // {
  789. // // //bbb
  790. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  791. // // }
  792. // //
  793. // // [self prepareReturn:nil];
  794. // //
  795. // // [self.navigationController popViewControllerAnimated:true];
  796. // //
  797. // // [appDelegate printPdf:pdf_url];
  798. // //
  799. // //// if(self.printPdfCallback)
  800. // //// self.printPdfCallback(pdf_url);
  801. // // }
  802. // // else
  803. // {
  804. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  805. // {
  806. // //bbb
  807. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  808. // }
  809. // [self prepareReturn:nil];
  810. //
  811. // [self.navigationController popViewControllerAnimated:true];
  812. //
  813. //
  814. // if(pdf_url.length>0)
  815. // {
  816. //
  817. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  818. //
  819. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  820. //
  821. //
  822. // }
  823. //
  824. //
  825. // }
  826. // // // self.labelContact.text=appDelegate.contact_name;
  827. // //
  828. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  829. //
  830. //
  831. //
  832. //
  833. //
  834. //
  835. // }
  836. // else
  837. // {
  838. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  839. // }
  840. //
  841. //
  842. //
  843. //
  844. // });
  845. // });
  846. // }
  847. // else
  848. // {
  849. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  850. //
  851. //
  852. // alert.tag = KEEP_TAIL;
  853. //
  854. //
  855. // self.upparams = upparams;
  856. //
  857. // [alert show];
  858. // }
  859. //
  860. // }
  861. // else
  862. // { //USER_ROLE_CUSTOMER
  863. //
  864. // // if(self.have_tail)
  865. // // [upparams setValue:@"true" forKey:@"isHold"];
  866. // // else
  867. // // [upparams setValue:@"false" forKey:@"isHold"];
  868. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  869. //
  870. // [upparams setValue:@"true" forKey:@"isHold"];
  871. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  872. //
  873. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  874. //
  875. // dispatch_async(dispatch_get_main_queue(), ^{
  876. //
  877. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  878. //
  879. // if([[editor_json valueForKey:@"result"] intValue]==2)
  880. // {
  881. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  882. //
  883. //
  884. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  885. // // appDelegate.customerInfo = customerInfo;
  886. //
  887. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  888. // // appDelegate.order_code = orderCode;
  889. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  890. // [appDelegate closeOrder];
  891. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  892. //
  893. // NSString* title=nil;
  894. // NSString* msg=nil;
  895. // if(appDelegate.offline_mode)
  896. // {
  897. // title=TITLE_OFFLINE_SUBMIT;
  898. // msg=MSG_OFFLINE_SUBMIT;
  899. // }
  900. // else
  901. // {
  902. // title=@"Submit successful.";
  903. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  904. // }
  905. //
  906. //
  907. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  908. //
  909. // [alert show];
  910. // // // self.labelContact.text=appDelegate.contact_name;
  911. // //
  912. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  913. // [self prepareReturn:nil];
  914. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  915. // //
  916. // //
  917. // // ;
  918. // // }];
  919. // [self.navigationController popViewControllerAnimated:true];
  920. //
  921. // }
  922. // else
  923. // {
  924. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  925. // }
  926. //
  927. //
  928. //
  929. //
  930. // });
  931. // });
  932. //
  933. // }
  934. // }
  935. //
  936. //
  937. //
  938. //
  939. // }
  940. //
  941. //
  942. //
  943. //
  944. //
  945. //
  946. //
  947. //
  948. //
  949. //
  950. //
  951. // }
  952. // }];
  953. //
  954. // // [alertView setUseMotionEffects:true];
  955. //
  956. //
  957. // // And launch the dialog
  958. //
  959. // [alertView sizeToFit];
  960. // [alertView show];
  961. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit Confirm.", nil) message:NSLocalizedString(msg, nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  962. //
  963. // alert.tag = SUBMIT_CONFIRM;
  964. // [alert show];
  965. //
  966. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Order Submission" message:msg preferredStyle:UIAlertControllerStyleAlert];
  967. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  968. {
  969. // add params check here.
  970. [self.lastedit endEditing:true];
  971. [self.lasttextview endEditing:true];
  972. NSMutableDictionary* upparams = [self check_cancommit:true];
  973. if(self.cancommit==false)
  974. return;
  975. // 2018-1-2 Modify
  976. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  977. {
  978. [self customer_commit_order:upparams];
  979. }
  980. else // USER_ROLE_EMPLOYEE
  981. {
  982. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  983. {
  984. upparams[@"shipping"] = nil;
  985. }
  986. if(upparams[@"shipping"]==nil || [upparams[@"shipping"] doubleValue]!=0)
  987. [self empolyee_commit_order:upparams];
  988. else
  989. {
  990. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  991. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  992. {
  993. //yes
  994. [self empolyee_commit_order:upparams];
  995. }];
  996. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  997. //DebugLog(@"Cancel");
  998. }];
  999. [alertControl addAction:actionOne];
  1000. [alertControl addAction:alertthree];
  1001. [self presentViewController:alertControl animated:YES completion:nil];
  1002. }
  1003. }
  1004. // if(upparams[@"shipping"]==nil)
  1005. // goto commit_order;
  1006. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1007. // {
  1008. // upparams[@"shipping"] = nil;
  1009. // goto commit_order;
  1010. // }
  1011. // else if([upparams[@"shipping"] doubleValue]==0)
  1012. // {
  1013. //
  1014. //
  1015. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1016. // //block代码块取代了delegate
  1017. //
  1018. //
  1019. //
  1020. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  1021. // {
  1022. //
  1023. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1024. //
  1025. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1026. // {
  1027. //
  1028. // if(/*!self.have_tail*/ true)
  1029. // {UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  1030. // [upparams setValue:@"false" forKey:@"isHold"];
  1031. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1032. //
  1033. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1034. //
  1035. // dispatch_async(dispatch_get_main_queue(), ^{
  1036. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1037. //
  1038. //
  1039. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1040. // {
  1041. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1042. //
  1043. // // debug aaa
  1044. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1045. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  1046. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1047. //
  1048. // // appDelegate.customerInfo = customerInfo;
  1049. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1050. // // appDelegate.order_code = nil;
  1051. // [appDelegate closeOrder];
  1052. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1053. //
  1054. // NSString* title=nil;
  1055. // NSString* msg=nil;
  1056. //#ifdef OFFLINE_MODE
  1057. // if(appDelegate.offline_mode)
  1058. // {
  1059. // title=TITLE_OFFLINE_SUBMIT;
  1060. // msg=MSG_OFFLINE_SUBMIT;
  1061. // }
  1062. // else
  1063. //#endif
  1064. // {
  1065. // title=@"Order submitted sucessfully";
  1066. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1067. // }
  1068. //
  1069. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1070. //
  1071. // [alert show];
  1072. //
  1073. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1074. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  1075. // NSString* soid=[editor_json valueForKey:@"so#"];
  1076. // // if(pdf_url.length>0)
  1077. // // {
  1078. // //
  1079. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1080. // // //[self downloadpdf:pdf_url];
  1081. // //
  1082. // //
  1083. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1084. // // {
  1085. // // //bbb
  1086. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1087. // // }
  1088. // //
  1089. // // [self prepareReturn:nil];
  1090. // //
  1091. // // [self.navigationController popViewControllerAnimated:true];
  1092. // //
  1093. // // [appDelegate printPdf:pdf_url];
  1094. // //// if(self.printPdfCallback)
  1095. // //// self.printPdfCallback(pdf_url);
  1096. // // }
  1097. // // else
  1098. // {
  1099. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1100. // {
  1101. // //bbb
  1102. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1103. // }
  1104. // [self prepareReturn:nil];
  1105. //
  1106. // [self.navigationController popViewControllerAnimated:true];
  1107. //
  1108. // if(pdf_url.length>0)
  1109. // {
  1110. //
  1111. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1112. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1113. // // [appDelegate printPdf:pdf_url];
  1114. //
  1115. // }
  1116. // }
  1117. //
  1118. // }
  1119. // else
  1120. // {
  1121. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1122. // }
  1123. //
  1124. //
  1125. //
  1126. //
  1127. // });
  1128. // });
  1129. // }
  1130. // else
  1131. // {
  1132. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1133. //
  1134. //
  1135. // alert.tag = KEEP_TAIL;
  1136. //
  1137. //
  1138. // self.upparams = upparams;
  1139. //
  1140. // [alert show];
  1141. // }
  1142. //
  1143. // }
  1144. // else
  1145. // { //USER_ROLE_CUSTOMER
  1146. //
  1147. // // if(self.have_tail)
  1148. // // [upparams setValue:@"true" forKey:@"isHold"];
  1149. // // else
  1150. // // [upparams setValue:@"false" forKey:@"isHold"];
  1151. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  1152. //
  1153. // [upparams setValue:@"true" forKey:@"isHold"];
  1154. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1155. //
  1156. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1157. //
  1158. // dispatch_async(dispatch_get_main_queue(), ^{
  1159. //
  1160. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1161. //
  1162. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1163. // {
  1164. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1165. //
  1166. //
  1167. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1168. // // appDelegate.customerInfo = customerInfo;
  1169. //
  1170. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1171. // // appDelegate.order_code = orderCode;
  1172. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1173. // [appDelegate closeOrder];
  1174. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1175. //
  1176. // NSString* title=nil;
  1177. // NSString* msg=nil;
  1178. //#ifdef OFFLINE_MODE
  1179. // if(appDelegate.offline_mode)
  1180. // {
  1181. // title=TITLE_OFFLINE_SUBMIT;
  1182. // msg=MSG_OFFLINE_SUBMIT;
  1183. // }
  1184. // else
  1185. //#endif
  1186. // {
  1187. // title=@"Order submitted sucessfully";
  1188. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1189. // }
  1190. //
  1191. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1192. //
  1193. // [alert show];
  1194. // // // self.labelContact.text=appDelegate.contact_name;
  1195. // //
  1196. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1197. // [self prepareReturn:nil];
  1198. // [self.navigationController popViewControllerAnimated:true];
  1199. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1200. // //
  1201. // //
  1202. // // ;
  1203. // // }];
  1204. //
  1205. // }
  1206. // else
  1207. // {
  1208. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1209. // }
  1210. //
  1211. //
  1212. //
  1213. //
  1214. // });
  1215. // });
  1216. //
  1217. // }
  1218. //
  1219. //
  1220. //
  1221. // }];
  1222. //
  1223. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1224. // //DebugLog(@"Cancel");
  1225. //
  1226. //
  1227. // }];
  1228. // [alertControl addAction:actionOne];
  1229. //
  1230. // [alertControl addAction:alertthree];
  1231. //
  1232. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1233. //
  1234. //
  1235. //
  1236. //
  1237. // [self presentViewController:alertControl animated:YES completion:nil];
  1238. //
  1239. //
  1240. //
  1241. // }
  1242. // else
  1243. // {
  1244. // commit_order:
  1245. //
  1246. // {
  1247. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1248. //
  1249. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1250. // {
  1251. //
  1252. // if(/*!self.have_tail*/ true)
  1253. // {UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  1254. // [upparams setValue:@"false" forKey:@"isHold"];
  1255. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1256. //
  1257. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1258. //
  1259. // dispatch_async(dispatch_get_main_queue(), ^{
  1260. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1261. //
  1262. //
  1263. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1264. // {
  1265. //
  1266. // //debug bbb
  1267. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1268. //
  1269. //
  1270. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1271. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  1272. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1273. // // appDelegate.customerInfo = customerInfo;
  1274. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1275. // // appDelegate.order_code = nil;
  1276. // [appDelegate closeOrder];
  1277. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1278. //
  1279. // NSString* title=nil;
  1280. // NSString* msg=nil;
  1281. //#ifdef OFFLINE_MODE
  1282. // if(appDelegate.offline_mode)
  1283. // {
  1284. // title=TITLE_OFFLINE_SUBMIT;
  1285. // msg=MSG_OFFLINE_SUBMIT;
  1286. // }
  1287. // else
  1288. //#endif
  1289. // {
  1290. // title=@"Order submitted sucessfully";
  1291. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1292. // }
  1293. //
  1294. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1295. //
  1296. // [alert show];
  1297. //
  1298. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1299. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  1300. // NSString* soid=[editor_json valueForKey:@"so#"];
  1301. // // if(pdf_url.length>0)
  1302. // // {
  1303. // //
  1304. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1305. // //// [self downloadpdf:pdf_url];
  1306. // //
  1307. // //
  1308. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1309. // // {
  1310. // // //bbb
  1311. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1312. // // }
  1313. // //
  1314. // // [self prepareReturn:nil];
  1315. // //
  1316. // // [self.navigationController popViewControllerAnimated:true];
  1317. // //
  1318. // // [appDelegate printPdf:pdf_url];
  1319. // //
  1320. // //// if(self.printPdfCallback)
  1321. // //// self.printPdfCallback(pdf_url);
  1322. // // }
  1323. // // else
  1324. // {
  1325. // NSMutableDictionary* value=[[NSMutableDictionary alloc]init];
  1326. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1327. // {
  1328. // //bbb
  1329. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1330. // value[@"commitorder_logout"]=@"true";
  1331. // }
  1332. //
  1333. //
  1334. // value[@"is_subaction"] = self.params[@"is_subaction"];
  1335. // value[@"subaction_tag"] = self.params[@"subaction_tag"];
  1336. //
  1337. // [self prepareReturn:value];
  1338. //
  1339. // [self.navigationController popViewControllerAnimated:true];
  1340. //
  1341. //
  1342. // if(pdf_url.length>0)
  1343. // {
  1344. //
  1345. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1346. //
  1347. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1348. //
  1349. //
  1350. // }
  1351. //
  1352. //
  1353. // }
  1354. // // // self.labelContact.text=appDelegate.contact_name;
  1355. // //
  1356. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1357. //
  1358. //
  1359. //
  1360. //
  1361. //
  1362. //
  1363. // }
  1364. // else
  1365. // {
  1366. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1367. // }
  1368. //
  1369. //
  1370. //
  1371. //
  1372. // });
  1373. // });
  1374. // }
  1375. // else
  1376. // {
  1377. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1378. //
  1379. //
  1380. // alert.tag = KEEP_TAIL;
  1381. //
  1382. //
  1383. // self.upparams = upparams;
  1384. //
  1385. // [alert show];
  1386. // }
  1387. //
  1388. // }
  1389. // else
  1390. // { //USER_ROLE_CUSTOMER
  1391. //
  1392. // // if(self.have_tail)
  1393. // // [upparams setValue:@"true" forKey:@"isHold"];
  1394. // // else
  1395. // // [upparams setValue:@"false" forKey:@"isHold"];
  1396. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  1397. //
  1398. // [upparams setValue:@"true" forKey:@"isHold"];
  1399. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1400. //
  1401. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1402. //
  1403. // dispatch_async(dispatch_get_main_queue(), ^{
  1404. //
  1405. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1406. //
  1407. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1408. // {
  1409. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1410. //
  1411. //
  1412. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1413. // // appDelegate.customerInfo = customerInfo;
  1414. //
  1415. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1416. // // appDelegate.order_code = orderCode;
  1417. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1418. // [appDelegate closeOrder];
  1419. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1420. //
  1421. // NSString* title=nil;
  1422. // NSString* msg=nil;
  1423. //#ifdef OFFLINE_MODE
  1424. // if(appDelegate.offline_mode)
  1425. // {
  1426. // title=TITLE_OFFLINE_SUBMIT;
  1427. // msg=MSG_OFFLINE_SUBMIT;
  1428. // }
  1429. // else
  1430. //#endif
  1431. // {
  1432. // title=@"Order submitted sucessfully";
  1433. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1434. // }
  1435. //
  1436. //
  1437. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1438. //
  1439. // [alert show];
  1440. // // // self.labelContact.text=appDelegate.contact_name;
  1441. // //
  1442. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1443. // [self prepareReturn:nil];
  1444. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1445. // //
  1446. // //
  1447. // // ;
  1448. // // }];
  1449. // [self.navigationController popViewControllerAnimated:true];
  1450. //
  1451. // }
  1452. // else
  1453. // {
  1454. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1455. // }
  1456. //
  1457. //
  1458. //
  1459. //
  1460. // });
  1461. // });
  1462. //
  1463. // }
  1464. // }
  1465. //
  1466. //
  1467. //
  1468. //
  1469. // }
  1470. }
  1471. }];
  1472. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1473. }];
  1474. [alertVC addAction:yesAction];
  1475. [alertVC addAction:cancelAction];
  1476. [self presentViewController:alertVC animated:yesAction completion:nil];
  1477. }
  1478. - (UIView *)createDemoView:(NSString*) msg
  1479. {
  1480. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  1481. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  1482. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  1483. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  1484. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  1485. titleLabel.text=@"Order Submission";
  1486. titleLabel.numberOfLines = 0;
  1487. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1488. // titleLabel.textAlignment = NSTextAlignmentRight;
  1489. titleLabel.textAlignment = NSTextAlignmentCenter;
  1490. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  1491. // CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1492. CGSize sizetitle = [RAUtils sizeWithFont:titleLabel.text=@"Order Submission" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1493. //[titleLabel sizeToFit];
  1494. // titleLabel.center.x = demoView.center.x;
  1495. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  1496. [demoView addSubview:titleLabel];
  1497. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  1498. lineLabel.font = [UIFont systemFontOfSize:17];
  1499. lineLabel.text=msg;
  1500. lineLabel.numberOfLines = 0;
  1501. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1502. // CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1503. CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1504. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  1505. //[lineLabel sizeToFit];
  1506. [demoView addSubview:lineLabel];
  1507. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  1508. return demoView;
  1509. }
  1510. - (void)onCloseClick:(UIButton *)sender {
  1511. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1512. if (self.resumeOrder) {
  1513. [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
  1514. return;
  1515. }
  1516. //
  1517. // NSRange range = [tempStr rangeOfString:@")\">"];//判断字符串是否包含
  1518. //
  1519. // //if (range.location ==NSNotFound)//不包含
  1520. // if (range.length >0)//包含
  1521. // {
  1522. //
  1523. //
  1524. //
  1525. // }
  1526. // else//不包含
  1527. // {
  1528. //
  1529. // }
  1530. // UIAlertView * alert = nil;
  1531. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Choose your action" preferredStyle:UIAlertControllerStyleAlert];
  1532. UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1533. [self.navigationController popViewControllerAnimated:true];
  1534. }];
  1535. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1536. [self.navigationController popViewControllerAnimated:false];
  1537. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1538. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1539. }];
  1540. NSString * a2Title=nil;
  1541. if(appDelegate.order_status==0)
  1542. a2Title=@"Close and cancel order";
  1543. else
  1544. a2Title=@"Close and release order";
  1545. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:a2Title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1546. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1547. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  1548. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
  1549. NSDictionary* order_json = result;
  1550. [waitalert dismissViewControllerAnimated:YES completion:^{
  1551. if([[order_json valueForKey:@"result"] intValue]==2)
  1552. {
  1553. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1554. // appDelegate.order_code = nil;
  1555. [appDelegate closeOrder];
  1556. #ifdef RA_NOTIFICATION
  1557. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1558. #else
  1559. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1560. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1561. #endif
  1562. [((MainViewController*)appDelegate.main_vc) switchToHome];
  1563. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1564. {
  1565. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1566. }
  1567. [self prepareReturn:nil];
  1568. [self.navigationController popViewControllerAnimated:true];
  1569. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1570. // ;
  1571. // }];
  1572. }
  1573. else
  1574. {
  1575. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  1576. }
  1577. }];
  1578. }];
  1579. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1580. //
  1581. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1582. //
  1583. // dispatch_async(dispatch_get_main_queue(), ^{
  1584. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1585. // if([[order_json valueForKey:@"result"] intValue]==2)
  1586. // {
  1587. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1588. // // appDelegate.order_code = nil;
  1589. //
  1590. // [appDelegate closeOrder];
  1591. //
  1592. //
  1593. //#ifdef RA_NOTIFICATION
  1594. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1595. //#else
  1596. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1597. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1598. //#endif
  1599. //
  1600. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  1601. //
  1602. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1603. // {
  1604. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1605. // }
  1606. //
  1607. // [self prepareReturn:nil];
  1608. //
  1609. //
  1610. // [self.navigationController popViewControllerAnimated:true];
  1611. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1612. // // ;
  1613. // // }];
  1614. //
  1615. // }
  1616. // else
  1617. // {
  1618. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  1619. // }
  1620. //
  1621. //
  1622. //
  1623. // });
  1624. // });
  1625. }];
  1626. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1627. }];
  1628. [alertController addAction:action_0];
  1629. [alertController addAction:action_1];
  1630. [alertController addAction:action_2];
  1631. [alertController addAction:action_3];
  1632. [self presentViewController:alertController animated:YES completion:nil];
  1633. // alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and cancel order", nil), nil];
  1634. // else
  1635. // {
  1636. //
  1637. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Choose your action" preferredStyle:UIAlertControllerStyleAlert];
  1638. //
  1639. //
  1640. // UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1641. //
  1642. //
  1643. //
  1644. // }];
  1645. //
  1646. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  1647. //
  1648. //
  1649. //
  1650. // }];
  1651. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Close and release order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1652. //
  1653. //
  1654. //
  1655. // }];
  1656. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1657. //
  1658. //
  1659. //
  1660. // }];
  1661. // [alertController addAction:action_0];
  1662. // [alertController addAction:action_1];
  1663. // [alertController addAction:action_2];
  1664. // [alertController addAction:action_3];
  1665. //
  1666. //
  1667. // [self presentViewController:alertController animated:YES completion:nil];
  1668. //
  1669. //
  1670. //// alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil];
  1671. //
  1672. // }
  1673. // alert.tag = CLOSE_ACTION;
  1674. // // alert.
  1675. // [alert show];
  1676. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1677. // appDelegate.order_code = nil;
  1678. //
  1679. // }
  1680. }
  1681. - (void)didReceiveMemoryWarning {
  1682. [super didReceiveMemoryWarning];
  1683. // Dispose of any resources that can be recreated.
  1684. }
  1685. - (IBAction)onSaveClick:(id)sender {
  1686. // id foo = nil;
  1687. // [[NSMutableArray array] addObject:foo];
  1688. // add params check here.
  1689. [self.lastedit endEditing:true];
  1690. [self.lasttextview endEditing:true];
  1691. NSMutableDictionary* upparams = [self check_cancommit:false];
  1692. // if(self.cancommit==false)
  1693. // return;
  1694. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1695. upparams[@"shipping"] = nil;
  1696. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order"];
  1697. [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
  1698. NSDictionary* editor_json =result;
  1699. [waitalert dismissViewControllerAnimated:YES completion:^{
  1700. if([[editor_json valueForKey:@"result"] intValue]==2)
  1701. {
  1702. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1703. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1704. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1705. {
  1706. appDelegate.customerInfo = customerInfo;
  1707. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1708. }
  1709. NSString *msg = nil;
  1710. if ([editor_json objectForKey:@"so#"]) {
  1711. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1712. }
  1713. [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1714. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1715. {
  1716. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1717. [self prepareReturn:nil];
  1718. [self.navigationController popViewControllerAnimated:true];
  1719. }
  1720. else{
  1721. #ifdef RA_NOTIFICATION
  1722. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1723. #else
  1724. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1725. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1726. #endif
  1727. }
  1728. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1729. if (![Singleton sharedInstance].currentOrderIsMerged) {
  1730. [self releaseOrderAfterSave];
  1731. }
  1732. }
  1733. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1734. // appDelegate.order_code = nil;
  1735. //
  1736. // }
  1737. // // self.labelContact.text=appDelegate.contact_name;
  1738. //
  1739. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1740. // [self prepareReturn:nil];
  1741. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1742. //
  1743. //
  1744. // ;
  1745. // }];
  1746. }
  1747. else
  1748. {
  1749. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1750. }
  1751. }];
  1752. }];
  1753. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1754. //
  1755. // NSDictionary* editor_json = [RANetwork save_Order:upparams];
  1756. //
  1757. // dispatch_async(dispatch_get_main_queue(), ^{
  1758. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1759. //
  1760. //
  1761. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1762. // {
  1763. //
  1764. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1765. //
  1766. //
  1767. //
  1768. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1769. //
  1770. //
  1771. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1772. // {
  1773. // appDelegate.customerInfo = customerInfo;
  1774. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1775. // }
  1776. // NSString *msg = nil;
  1777. // if ([editor_json objectForKey:@"so#"]) {
  1778. // msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1779. // }
  1780. // [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1781. //
  1782. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1783. // {
  1784. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1785. // [self prepareReturn:nil];
  1786. // [self.navigationController popViewControllerAnimated:true];
  1787. // }
  1788. // else{
  1789. //
  1790. //
  1791. //#ifdef RA_NOTIFICATION
  1792. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1793. //#else
  1794. //
  1795. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1796. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1797. //#endif
  1798. // }
  1799. //
  1800. // if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1801. //
  1802. // if (![Singleton sharedInstance].currentOrderIsMerged) {
  1803. // [self releaseOrderAfterSave];
  1804. // }
  1805. //
  1806. //
  1807. // }
  1808. //
  1809. //
  1810. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1811. // // appDelegate.order_code = nil;
  1812. // //
  1813. // // }
  1814. // // // self.labelContact.text=appDelegate.contact_name;
  1815. // //
  1816. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1817. // // [self prepareReturn:nil];
  1818. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1819. // //
  1820. // //
  1821. // // ;
  1822. // // }];
  1823. //
  1824. // }
  1825. // else
  1826. // {
  1827. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1828. // }
  1829. //
  1830. //
  1831. //
  1832. //
  1833. // });
  1834. // });
  1835. }
  1836. - (void)textFieldDidEndEditing:(UITextField *)textField
  1837. {
  1838. [super textFieldDidEndEditing:textField];
  1839. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  1840. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1841. NSMutableDictionary* section_json=nil;
  1842. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  1843. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1844. NSString* name = [item_json valueForKey:@"name"];
  1845. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  1846. {
  1847. float shipping = [self getprice:@"shipping" section:indexPath.section];
  1848. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  1849. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  1850. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  1851. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  1852. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  1853. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1854. int count=0;
  1855. count=[[section_json valueForKey:@"count"] intValue];
  1856. int total_row_idx=-1;
  1857. for(int i=0;i<count;i++)
  1858. {
  1859. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1860. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  1861. {
  1862. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  1863. [olditem setValue:@"true" forKey:@"dirty"];
  1864. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1865. total_row_idx=i;
  1866. }
  1867. }
  1868. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1869. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  1870. if(total_row_idx>=0)
  1871. {
  1872. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  1873. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  1874. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1875. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1876. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1877. // CGSize tablecontent =self.editorTable.contentSize;
  1878. // tablecontent.height=tablecontent.height+self.keyboard_h;
  1879. // self.editorTable.contentSize=tablecontent;
  1880. //
  1881. //
  1882. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  1883. }
  1884. // self.content_data = [editor_json mutableCopy];
  1885. // self.content_data = [self translate_json:editor_json];
  1886. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  1887. // [self.editorTable reloadData];
  1888. }
  1889. //
  1890. // [item_json setValue:@"true" forKey:@"dirty"];
  1891. // [item_json setValue:textField.text forKey:@"value"];
  1892. }
  1893. -(float) getprice:(NSString*) name section :(long) index
  1894. {
  1895. NSMutableDictionary* section_json=nil;
  1896. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  1897. int count=0;
  1898. count=[[section_json valueForKey:@"count"] intValue];
  1899. for(int i=0;i<count;i++)
  1900. {
  1901. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1902. if([[olditem valueForKey:@"name"] isEqualToString:name])
  1903. {
  1904. return [[olditem valueForKey:@"value"] floatValue];
  1905. }
  1906. }
  1907. return 0;
  1908. }
  1909. /*
  1910. #pragma mark - Navigation
  1911. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1912. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1913. // Get the new view controller using [segue destinationViewController].
  1914. // Pass the selected object to the new view controller.
  1915. }
  1916. */
  1917. //#pragma mark - UIAlertViewDelegate
  1918. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  1919. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1920. //{
  1921. //
  1922. // if(alertView.tag == CLOSE_ACTION)
  1923. // {
  1924. // if(buttonIndex==1)
  1925. // {
  1926. //
  1927. // [self.navigationController popViewControllerAnimated:true];
  1928. // // back to cart;
  1929. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1930. // // ;
  1931. // // }];
  1932. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1933. // // appDelegate.order_code = nil;
  1934. // //
  1935. // // }
  1936. // }
  1937. // if(buttonIndex==2)
  1938. // {
  1939. //
  1940. // [self.navigationController popViewControllerAnimated:false];
  1941. //
  1942. //
  1943. //
  1944. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1945. //
  1946. //
  1947. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1948. // // back to cart;
  1949. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1950. // // ;
  1951. // // }];
  1952. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1953. // // appDelegate.order_code = nil;
  1954. // //
  1955. // // }
  1956. // }
  1957. // else if(buttonIndex==3)
  1958. // {
  1959. // // close order;
  1960. //
  1961. //
  1962. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1963. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  1964. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1965. //
  1966. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1967. //
  1968. // dispatch_async(dispatch_get_main_queue(), ^{
  1969. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1970. // if([[order_json valueForKey:@"result"] intValue]==2)
  1971. // {
  1972. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1973. // // appDelegate.order_code = nil;
  1974. //
  1975. // [appDelegate closeOrder];
  1976. //
  1977. //
  1978. //#ifdef RA_NOTIFICATION
  1979. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1980. //#else
  1981. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1982. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1983. //#endif
  1984. //
  1985. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  1986. //
  1987. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1988. // {
  1989. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1990. // }
  1991. //
  1992. // [self prepareReturn:nil];
  1993. //
  1994. //
  1995. // [self.navigationController popViewControllerAnimated:true];
  1996. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1997. // // ;
  1998. // // }];
  1999. //
  2000. // }
  2001. // else
  2002. // {
  2003. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  2004. // }
  2005. //
  2006. //
  2007. //
  2008. // });
  2009. // });
  2010. //
  2011. //
  2012. //
  2013. //
  2014. //
  2015. // //
  2016. // // }
  2017. // }
  2018. // }
  2019. //}
  2020. //
  2021. //
  2022. //-(void) downloadpdf:(NSString* )url
  2023. //{
  2024. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Printing..."];
  2025. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2026. //
  2027. //
  2028. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  2029. //
  2030. // //设置请求方式为get
  2031. //
  2032. // [request setHTTPMethod:@"GET"];
  2033. //
  2034. // //添加用户会话id
  2035. //
  2036. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  2037. //
  2038. // //连接发送请求
  2039. //
  2040. //
  2041. // NSHTTPURLResponse* urlResponse = nil;
  2042. //
  2043. // NSError *error = [[NSError alloc] init];
  2044. //
  2045. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  2046. //
  2047. // // self.filename = [urlResponse suggestedFilename];
  2048. //
  2049. //
  2050. // dispatch_async(dispatch_get_main_queue(), ^{
  2051. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2052. // // self.navigationItem.title = self.save_name;
  2053. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  2054. // // self.content=nil;
  2055. // if(content!=nil&&content.length>0)
  2056. // {
  2057. //
  2058. //
  2059. // [self startAirPrintWithData:content];
  2060. //
  2061. //
  2062. // }
  2063. // else
  2064. // {
  2065. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  2066. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  2067. // }
  2068. //
  2069. // ;
  2070. // // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  2071. // //
  2072. //
  2073. //
  2074. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  2075. //
  2076. //
  2077. //
  2078. //
  2079. // });
  2080. // });
  2081. //}
  2082. //
  2083. //- (void)startAirPrintWithData:(id )data
  2084. //{
  2085. //
  2086. //
  2087. //
  2088. //
  2089. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  2090. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  2091. // printInfo.outputType = UIPrintInfoOutputGeneral;
  2092. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  2093. // printInfo.jobName = @"CoolVisitAirPrint";
  2094. // airPrinterController.printInfo = printInfo;
  2095. // airPrinterController.printingItem = data;
  2096. // airPrinterController.delegate = self;
  2097. //
  2098. //
  2099. // airPrinterController.showsNumberOfCopies=true;
  2100. // airPrinterController.showsPageRange = true;
  2101. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  2102. //
  2103. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  2104. // if(completed && error)
  2105. // DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
  2106. // };
  2107. //
  2108. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2109. //
  2110. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  2111. //
  2112. //
  2113. //
  2114. //
  2115. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  2116. // {
  2117. // if (available&& appDelegate.printerURL.length>0)
  2118. // {
  2119. //
  2120. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  2121. // DebugLog(@"AIRPRINTER AVAILABLE");
  2122. // }
  2123. // else
  2124. // {
  2125. //
  2126. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  2127. // //
  2128. // //
  2129. // //
  2130. // // // [printPicker presentAnimated:YES completionHandler:
  2131. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  2132. // // {
  2133. // // if (userDidSelect)
  2134. // // {
  2135. // // NSString* sid= printerController.printInfo.printerID;
  2136. // // UIPrintPaper*paper= printerController.printPaper;
  2137. // //
  2138. // // }
  2139. // // }];
  2140. //
  2141. //
  2142. // DebugLog(@"AIRPRINTER NOT AVAILABLE");
  2143. //
  2144. //
  2145. //
  2146. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  2147. // {
  2148. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  2149. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  2150. //
  2151. //
  2152. //
  2153. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  2154. //
  2155. //
  2156. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  2157. //
  2158. //
  2159. //
  2160. // // [printPicker presentAnimated:YES completionHandler:
  2161. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  2162. // {
  2163. // if (userDidSelect)
  2164. // {
  2165. // //User selected the item in the UIPrinterPickerController and got the printer details.
  2166. //
  2167. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  2168. //
  2169. // //Here you will get the printer and printer details.ie,
  2170. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  2171. //
  2172. //
  2173. //
  2174. //
  2175. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  2176. //
  2177. // [self startAirPrintWithData:data];
  2178. //
  2179. // }
  2180. // else
  2181. // {
  2182. //
  2183. //
  2184. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2185. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  2186. // {
  2187. //
  2188. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2189. // }
  2190. // [self prepareReturn:nil];
  2191. //
  2192. // [self.navigationController popViewControllerAnimated:true];
  2193. // }
  2194. // }];
  2195. // }
  2196. // }
  2197. // }];
  2198. //
  2199. //
  2200. //
  2201. //}
  2202. //
  2203. //#pragma mark - UIPrintInteractionControllerDelegate
  2204. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  2205. //{
  2206. //
  2207. // ;
  2208. //
  2209. // // (int) width = 29700
  2210. // // Printing description of (*( (int *)0x7caa3a40)):
  2211. // // (int) height = 42000
  2212. // //设置纸张大小
  2213. //
  2214. //
  2215. // for(UIPrintPaper* paper in paperList)
  2216. // {
  2217. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  2218. // return paper;
  2219. //
  2220. // }
  2221. // CGSize paperSize = CGSizeMake(612, 792);
  2222. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  2223. // return p;
  2224. //}
  2225. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  2226. //{
  2227. //
  2228. //}
  2229. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  2230. //{
  2231. //
  2232. //}
  2233. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  2234. //{
  2235. //
  2236. //}
  2237. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  2238. //{
  2239. //
  2240. //}
  2241. //
  2242. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  2243. //{
  2244. //
  2245. //}
  2246. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  2247. //{
  2248. //
  2249. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2250. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  2251. // {
  2252. //
  2253. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2254. // }
  2255. //
  2256. // [self prepareReturn:nil];
  2257. //
  2258. // [self.navigationController popViewControllerAnimated:true];
  2259. //}
  2260. //
  2261. //- (NSString *)currentPriceTypeName {
  2262. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  2263. //
  2264. // NSString* pricename = nil;
  2265. // switch (priceType) {
  2266. // case 0:
  2267. // pricename=[Singleton sharedInstance].deliveryString;
  2268. // break;
  2269. // case 1:
  2270. // pricename=flat_price;
  2271. // break;
  2272. // case 2:
  2273. // pricename=given_price;
  2274. // break;
  2275. // default:
  2276. // break;
  2277. // }
  2278. // return pricename;
  2279. //}
  2280. - (void)releaseOrderAfterSave {
  2281. dispatch_async(dispatch_get_main_queue(), ^{
  2282. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2283. // [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  2284. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:nil];
  2285. [appDelegate closeOrder];
  2286. [appDelegate SetSo:nil];
  2287. appDelegate.cart_count=0;
  2288. [appDelegate update_count_mark];
  2289. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2290. [self prepareReturn:nil];
  2291. [self.navigationController popToRootViewControllerAnimated:false];
  2292. });
  2293. }
  2294. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  2295. {
  2296. NSString* ret=nil;
  2297. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  2298. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  2299. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  2300. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  2301. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  2302. if(customer_address1.length>0)
  2303. [arraddr addObject:customer_address1];
  2304. if(customer_address2.length>0)
  2305. [arraddr addObject:customer_address2];
  2306. if(customer_address3.length>0)
  2307. [arraddr addObject:customer_address3];
  2308. if(customer_address4.length>0)
  2309. [arraddr addObject:customer_address4];
  2310. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  2311. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  2312. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  2313. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  2314. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  2315. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  2316. if(customer_city.length>0)
  2317. [arrcty addObject:customer_city];
  2318. if(customer_state.length>0)
  2319. [arrcty addObject:customer_state];
  2320. if(customer_zipcode.length>0)
  2321. [arrcty addObject:customer_zipcode];
  2322. if(customer_country.length>0)
  2323. [arrcty addObject:customer_country];
  2324. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  2325. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  2326. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  2327. //
  2328. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  2329. // if(customer_phone.length>0)
  2330. // {
  2331. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  2332. // [arrpho addObject:customer_phone];
  2333. // }
  2334. // if(customer_fax.length>0)
  2335. // {
  2336. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  2337. // [arrpho addObject:customer_fax];
  2338. // }
  2339. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  2340. //
  2341. //
  2342. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  2343. // if(customer_contact.length>0)
  2344. // {
  2345. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  2346. //
  2347. // }
  2348. // NSString *contact_string = customer_contact;
  2349. //
  2350. //
  2351. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  2352. // if(customer_email.length>0)
  2353. // {
  2354. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  2355. //
  2356. // }
  2357. // NSString *email_string = customer_email;
  2358. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  2359. if(addr_string.length>0)
  2360. [arrext addObject:addr_string];
  2361. if(cty_string.length>0)
  2362. [arrext addObject:cty_string];
  2363. // if(phone_string.length>0)
  2364. // [arrext addObject:phone_string];
  2365. // if(contact_string.length>0)
  2366. // [arrext addObject:contact_string];
  2367. // if(email_string.length>0)
  2368. // [arrext addObject:email_string];
  2369. ret = [arrext componentsJoinedByString:@"\r\n"];
  2370. // NSString *string = [array componentsJoinedByString:@" "];
  2371. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  2372. return ret;
  2373. }
  2374. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  2375. {
  2376. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  2377. NSArray *keys= [key_map allKeys];
  2378. //遍历keys
  2379. for(int i=0;i<[keys count];i++)
  2380. {
  2381. //得到当前key
  2382. NSString *key=[keys objectAtIndex:i];
  2383. //如果key不是pic,说明value是字符类型,比如name:Boris
  2384. NSString* valuefrom = [key_map valueForKey:key];
  2385. if(valuefrom.length==0)
  2386. continue;
  2387. NSString* value=[self getValue:valuefrom];
  2388. [ret setValue:value forKey:valuefrom];
  2389. }
  2390. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  2391. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  2392. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  2393. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  2394. return ret;
  2395. }
  2396. -(NSMutableDictionary*)create_cusromer_info_from_table
  2397. {
  2398. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2399. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  2400. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  2401. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  2402. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  2403. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  2404. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  2405. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  2406. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  2407. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  2408. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  2409. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  2410. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  2411. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  2412. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  2413. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  2414. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  2415. NSString * firstname =nil;
  2416. NSString* lastname = nil;
  2417. NSString* contact_name = [self getValue:@"customer_contact"];
  2418. if(contact_name!=nil)
  2419. {
  2420. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  2421. if(_arr.count>=1)
  2422. {
  2423. firstname =_arr[0];
  2424. if(_arr.count>1)
  2425. {
  2426. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  2427. }
  2428. }
  2429. }
  2430. [ret setValue:firstname forKey:@"customer_first_name"];
  2431. [ret setValue:lastname forKey:@"customer_last_name"];
  2432. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  2433. return ret;
  2434. }
  2435. #pragma mark - multi_action sub action clicked
  2436. - (void)MActionClicked:(UIButton *)sender {
  2437. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  2438. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  2439. int refresh =0;
  2440. NSMutableDictionary* section_json=nil;
  2441. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  2442. NSString* subid=[item_json valueForKey:@"subid"];
  2443. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  2444. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  2445. NSString* type = [sub_action valueForKey:@"type"];
  2446. if([type isEqualToString:@"pull"])
  2447. {
  2448. [self.lastedit endEditing:true];
  2449. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  2450. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  2451. NSMutableDictionary* value=[self create_value_map:keymap];
  2452. if(subid==nil)
  2453. {
  2454. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  2455. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  2456. int icount=[[section_json valueForKey:@"count"] intValue];
  2457. for (int ic=0;ic<icount;ic++)
  2458. {
  2459. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  2460. NSString* mapto = [modify_item valueForKey:@"name"];
  2461. if(mapto.length==0)
  2462. continue;
  2463. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  2464. if(valuefrom==nil)
  2465. continue;
  2466. NSString* valuestr=[value valueForKey:valuefrom];
  2467. // valuestr = [self getValue:valuefrom];
  2468. if(true)
  2469. {
  2470. if(valuestr.length>0)
  2471. [modify_item setValue:valuestr forKey:@"value"];
  2472. else
  2473. [modify_item setValue:@"" forKey:@"value"];
  2474. [modify_item setValue:@"true" forKey:@"dirty"];
  2475. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  2476. }
  2477. }
  2478. }
  2479. else
  2480. {
  2481. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  2482. int section = [(NSString*)idarr[0] intValue];
  2483. int item=[(NSString*)idarr[1] intValue];
  2484. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  2485. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  2486. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  2487. NSString* control_type = [olditem valueForKey:@"control"];
  2488. if([control_type isEqualToString:@"switch"])
  2489. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  2490. else if([control_type isEqualToString:@"enum"])
  2491. {
  2492. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  2493. }
  2494. else
  2495. {
  2496. [RAUtils message_alert:@"not impl" title:@"Sorry" controller:self];
  2497. // [RAUtils alert_view:@"" title:@"not impl"];
  2498. }
  2499. [olditem setValue:@"true" forKey:@"dirty"];
  2500. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  2501. }
  2502. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2503. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2504. if(refresh==1)
  2505. {
  2506. // if(restore_json!=nil)
  2507. // {
  2508. // int rc=[[restore_json valueForKey:@"count"] intValue];
  2509. // for(int ir=0;ir<rc;ir++)
  2510. // {
  2511. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  2512. //
  2513. //
  2514. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2515. // for(int i=0;i<section_count;i++)
  2516. // {
  2517. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2518. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2519. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2520. // for(int j=0;j<item_count;j++)
  2521. // {
  2522. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2523. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2524. //
  2525. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2526. // {
  2527. // [itemjson removeObjectForKey:@"dirty"];
  2528. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2529. // }
  2530. //
  2531. // }
  2532. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2533. // }
  2534. //
  2535. //
  2536. // }
  2537. //
  2538. // }
  2539. [self refresh:refresh_trigger] ;
  2540. return ;
  2541. }
  2542. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  2543. [self.editorTable reloadData ];
  2544. }
  2545. else
  2546. {
  2547. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2548. NSDictionary * item_json = sub_action;
  2549. NSString* value = [item_json valueForKey:@"value"];
  2550. if([value isEqualToString:@"new_addr"])
  2551. {
  2552. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2553. addressVC.url_type = URL_REMOTE;
  2554. addressVC.request_url=URL_ADDRESS_EDOTOR;
  2555. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2556. // NSString * string = [checked componentsJoinedByString:@","];
  2557. // [params setValue:string forKey:@"cart2Checkbox"];
  2558. params[@"is_subaction"]=@"true";
  2559. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2560. addressVC.params = params;
  2561. addressVC.delegate = self;
  2562. addressVC.from = indexPath;
  2563. // orderinfoVC.params = params;
  2564. [self.navigationController pushViewController:addressVC animated:true];
  2565. }else if([value isEqualToString:@"credit_card"])
  2566. {
  2567. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2568. NSDictionary *data = [item_json objectForKey:@"data"];
  2569. if(data!=nil)
  2570. {
  2571. cardVC.content_data_download = [data mutableCopy];
  2572. cardVC.url_type = URL_NONE;
  2573. cardVC.request_url=nil;
  2574. }
  2575. else
  2576. {
  2577. cardVC.url_type = URL_REMOTE;
  2578. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  2579. }
  2580. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2581. params[@"orderCode"]=appDelegate.order_code;
  2582. params[@"is_subaction"]=@"true";
  2583. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2584. cardVC.params = params;
  2585. cardVC.delegate = self;
  2586. cardVC.from = indexPath;
  2587. // orderinfoVC.params = params;
  2588. [self.navigationController pushViewController:cardVC animated:true];
  2589. }
  2590. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  2591. {
  2592. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2593. cvc.showNavibar = true;
  2594. cvc.contact_type = value;
  2595. cvc.is_subaction = @"true";
  2596. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2597. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2598. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2599. //
  2600. // if(self.returnValue)
  2601. // self.returnValue(value);
  2602. };
  2603. [self.navigationController pushViewController:cvc animated:true];
  2604. }
  2605. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  2606. {
  2607. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2608. cvc.showNavibar = true;
  2609. cvc.contact_type = value;
  2610. cvc.is_subaction = @"true";
  2611. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2612. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2613. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2614. //
  2615. // if(self.returnValue)
  2616. // self.returnValue(value);
  2617. };
  2618. [self.navigationController pushViewController:cvc animated:true];
  2619. }
  2620. else if([value isEqualToString:@"Sales_Order_Customer"])
  2621. {
  2622. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2623. cvc.is_subaction = @"true";
  2624. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2625. cvc.showNavibar = true;
  2626. cvc.contact_type = value;
  2627. __weak typeof(self) weakself = self;
  2628. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2629. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2630. //
  2631. // if(self.returnValue)
  2632. // self.returnValue(value);
  2633. };
  2634. [self.navigationController pushViewController:cvc animated:true];
  2635. }
  2636. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  2637. {
  2638. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2639. cvc.showNavibar = true;
  2640. cvc.contact_type = value;
  2641. cvc.is_subaction = @"true";
  2642. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2643. __weak typeof(self) weakself = self;
  2644. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2645. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2646. //
  2647. // if(self.returnValue)
  2648. // self.returnValue(value);
  2649. };
  2650. [self.navigationController pushViewController:cvc animated:true];
  2651. }
  2652. else if([value isEqualToString:@"Contact_Return_To"])
  2653. {
  2654. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2655. cvc.is_subaction = @"true";
  2656. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2657. cvc.showNavibar = true;
  2658. cvc.contact_type = value;
  2659. __weak typeof(self) weakself = self;
  2660. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2661. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2662. //
  2663. // if(self.returnValue)
  2664. // self.returnValue(value);
  2665. };
  2666. [self.navigationController pushViewController:cvc animated:true];
  2667. }
  2668. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  2669. {
  2670. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2671. cvc.is_subaction = @"true";
  2672. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2673. cvc.showNavibar = true;
  2674. cvc.contact_type = value;
  2675. __weak typeof(self) weakself = self;
  2676. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2677. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2678. //
  2679. // if(self.returnValue)
  2680. // self.returnValue(value);
  2681. };
  2682. [self.navigationController pushViewController:cvc animated:true];
  2683. }
  2684. }
  2685. }
  2686. #pragma mark - Urgency
  2687. -(void) viewWillDisappear:(BOOL)animated
  2688. {
  2689. [super viewWillDisappear:animated];
  2690. [self cancel_urgency_timer];
  2691. }
  2692. - (void)start_urgency_timer {
  2693. if (!self.editable) {
  2694. return;
  2695. }
  2696. __weak typeof(self) weakSelf = self;
  2697. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  2698. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  2699. #ifdef OFFLINE_MODE
  2700. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  2701. #endif
  2702. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  2703. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  2704. // DebugLog(@"timer start....");
  2705. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  2706. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  2707. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  2708. // CreateOrderViewController
  2709. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  2710. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  2711. NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  2712. [urgencyDic setValue:so forKey:@"order_so"];
  2713. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  2714. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  2715. }
  2716. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  2717. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  2718. }];
  2719. }
  2720. - (void)cancel_urgency_timer {
  2721. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  2722. }
  2723. #pragma mark - Submit Order
  2724. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  2725. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  2726. [upparams setValue:@"true" forKey:@"isHold"];
  2727. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  2728. NSDictionary* editor_json =result;
  2729. [waitalert dismissViewControllerAnimated:YES completion:^{
  2730. if([[editor_json valueForKey:@"result"] intValue]==2)
  2731. {
  2732. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2733. // appDelegate.customerInfo = customerInfo;
  2734. [appDelegate closeOrder];
  2735. #ifdef RA_NOTIFICATION
  2736. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2737. #else
  2738. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2739. #endif
  2740. NSString* title=nil;
  2741. NSString* msg=nil;
  2742. #ifdef OFFLINE_MODE
  2743. if(appDelegate.offline_mode)
  2744. {
  2745. title=TITLE_OFFLINE_SUBMIT;
  2746. msg=MSG_OFFLINE_SUBMIT;
  2747. }
  2748. else
  2749. #endif
  2750. {
  2751. title=@"Order submitted sucessfully";
  2752. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2753. }
  2754. [RAUtils message_alert:msg title:title controller:self];
  2755. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2756. // [alert show];
  2757. [self prepareReturn:nil];
  2758. [self.navigationController popToRootViewControllerAnimated:true];
  2759. }
  2760. else
  2761. {
  2762. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2763. }
  2764. }];
  2765. }];
  2766. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2767. //
  2768. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2769. //
  2770. // dispatch_async(dispatch_get_main_queue(), ^{
  2771. //
  2772. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2773. //
  2774. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2775. // {
  2776. //
  2777. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2778. // // appDelegate.customerInfo = customerInfo;
  2779. //
  2780. // [appDelegate closeOrder];
  2781. //
  2782. //
  2783. //#ifdef RA_NOTIFICATION
  2784. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2785. //#else
  2786. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2787. //#endif
  2788. //
  2789. // NSString* title=nil;
  2790. // NSString* msg=nil;
  2791. //#ifdef OFFLINE_MODE
  2792. // if(appDelegate.offline_mode)
  2793. // {
  2794. // title=TITLE_OFFLINE_SUBMIT;
  2795. // msg=MSG_OFFLINE_SUBMIT;
  2796. // }
  2797. // else
  2798. //#endif
  2799. // {
  2800. // title=@"Order submitted sucessfully";
  2801. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2802. // }
  2803. //
  2804. // [RAUtils message_alert:msg title:title controller:self];
  2805. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2806. //
  2807. //// [alert show];
  2808. //
  2809. // [self prepareReturn:nil];
  2810. // [self.navigationController popToRootViewControllerAnimated:true];
  2811. //
  2812. //
  2813. // }
  2814. // else
  2815. // {
  2816. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2817. // }
  2818. // });
  2819. // });
  2820. }
  2821. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  2822. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  2823. [upparams setValue:@"false" forKey:@"isHold"];
  2824. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  2825. NSDictionary* editor_json = result;
  2826. [waitalert dismissViewControllerAnimated:YES completion:^{
  2827. if([[editor_json valueForKey:@"result"] intValue]==2)
  2828. {
  2829. // debug aaa
  2830. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2831. NSString* company= appDelegate.customerInfo[@"customer_name"];
  2832. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  2833. [appDelegate closeOrder];
  2834. #ifdef RA_NOTIFICATION
  2835. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2836. #else
  2837. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2838. #endif
  2839. NSString* title=nil;
  2840. NSString* msg=nil;
  2841. #ifdef OFFLINE_MODE
  2842. if(appDelegate.offline_mode)
  2843. {
  2844. title=TITLE_OFFLINE_SUBMIT;
  2845. msg=MSG_OFFLINE_SUBMIT;
  2846. }
  2847. else
  2848. #endif
  2849. {
  2850. title=@"Order submitted sucessfully";
  2851. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2852. }
  2853. UIAlertController* message_alert=[RAUtils message_alert:msg title:title controller:self];
  2854. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2855. //
  2856. // [alert show];
  2857. //
  2858. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2859. NSString* email_content =[editor_json valueForKey:@"email_content"];
  2860. NSString* soid=[editor_json valueForKey:@"so#"];
  2861. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  2862. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2863. {
  2864. //bbb
  2865. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2866. value[@"commitorder_logout"]=@"true";
  2867. }
  2868. [self prepareReturn:value];
  2869. [self.navigationController popToRootViewControllerAnimated:true];
  2870. if(pdf_url.length>0)
  2871. {
  2872. [message_alert dismissViewControllerAnimated:YES completion:^{
  2873. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2874. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  2875. // [appDelegate printPdf:pdf_url];
  2876. }];
  2877. }
  2878. }
  2879. else
  2880. {
  2881. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2882. }
  2883. }];
  2884. }];
  2885. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2886. //
  2887. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2888. //
  2889. // dispatch_async(dispatch_get_main_queue(), ^{
  2890. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2891. //
  2892. //
  2893. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2894. // {
  2895. //
  2896. // // debug aaa
  2897. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2898. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  2899. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  2900. //
  2901. // [appDelegate closeOrder];
  2902. //
  2903. //
  2904. //#ifdef RA_NOTIFICATION
  2905. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2906. //#else
  2907. //
  2908. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2909. //#endif
  2910. //
  2911. // NSString* title=nil;
  2912. // NSString* msg=nil;
  2913. //#ifdef OFFLINE_MODE
  2914. // if(appDelegate.offline_mode)
  2915. // {
  2916. // title=TITLE_OFFLINE_SUBMIT;
  2917. // msg=MSG_OFFLINE_SUBMIT;
  2918. // }
  2919. // else
  2920. //#endif
  2921. // {
  2922. // title=@"Order submitted sucessfully";
  2923. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2924. // }
  2925. //
  2926. // UIAlertController* message_alert=[RAUtils message_alert:msg title:title controller:self];
  2927. //
  2928. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2929. ////
  2930. //// [alert show];
  2931. ////
  2932. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2933. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  2934. // NSString* soid=[editor_json valueForKey:@"so#"];
  2935. //
  2936. // NSMutableDictionary *value = [NSMutableDictionary dictionary];
  2937. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2938. // {
  2939. // //bbb
  2940. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2941. // value[@"commitorder_logout"]=@"true";
  2942. // }
  2943. // [self prepareReturn:value];
  2944. //
  2945. // [self.navigationController popToRootViewControllerAnimated:true];
  2946. //
  2947. // if(pdf_url.length>0)
  2948. // {
  2949. //
  2950. //
  2951. // [message_alert dismissViewControllerAnimated:YES completion:nil];
  2952. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2953. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  2954. // // [appDelegate printPdf:pdf_url];
  2955. //
  2956. // }
  2957. //
  2958. //
  2959. // }
  2960. // else
  2961. // {
  2962. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2963. // }
  2964. // });
  2965. // });
  2966. }
  2967. @end