CreateOrderViewController.m 216 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317
  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 =[ self.storyboard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
  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 =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreditCardEditorViewController"];
  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 = [self.storyboard 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 = [self.storyboard 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 = [self.storyboard 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 = [self.storyboard 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 = [self.storyboard 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 = [self.storyboard 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. self.btnSubmitOrder = nil;
  191. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  192. style:UIBarButtonItemStylePlain
  193. target:self
  194. action:@selector(onCommitOrderClick:)];
  195. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  196. fixedItem.width = 20.0f;
  197. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  198. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  199. {
  200. [items addObject:savebtn];
  201. [items addObject:fixedItem];
  202. }
  203. if (!self.isResume) {
  204. // 正常情况
  205. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  206. // customer的订单必须是Sales Order并且有提交权限才能提交
  207. if ([Singleton sharedInstance].currentOrderIsMerged && [Singleton sharedInstance].permissions_submit_order) {
  208. [items addObject:self.btnSubmitOrder];
  209. }
  210. } else {
  211. [items addObject:self.btnSubmitOrder];
  212. }
  213. } else {
  214. // 恢复
  215. if (self.userType == USER_ROLE_CUSTOMER) {
  216. // customer的订单必须是Sales Order并且有提交权限才能提交
  217. if (canSubmit) {
  218. [items addObject:self.btnSubmitOrder];
  219. }
  220. } else {
  221. [items addObject:self.btnSubmitOrder];
  222. }
  223. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_resume"];
  224. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_userType"];
  225. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_submitOrder"];
  226. }
  227. // [items addObject:item2];
  228. self.navigationItem.rightBarButtonItems=items;
  229. if(appDelegate.can_submit_order)
  230. {
  231. [self.btnSubmitOrder setImage:[UIImage imageNamed:@"commit"]];
  232. self.btnSubmitOrder.enabled = true;
  233. }
  234. else
  235. {
  236. [self.btnSubmitOrder setImage:nil];
  237. self.btnSubmitOrder.enabled = false;
  238. }
  239. self.navigationController.navigationBarHidden=false;
  240. }
  241. -(void) download_success
  242. {
  243. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  244. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  245. NSString* order_customerid=[self getValue:@"customer_cid"];
  246. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  247. appDelegate.order_customer_id = order_customerid;
  248. }
  249. - (void)viewDidLoad {
  250. [super viewDidLoad];
  251. self.editable = YES;
  252. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  253. style:UIBarButtonItemStylePlain
  254. target:self
  255. action:@selector(onCloseClick:)];
  256. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  257. // closeButton.title = @"Close";
  258. self.navigationItem.leftBarButtonItem = closeButton;
  259. // self.navigationItem.backBarButtonItem = backButton;
  260. // Do any additional setup after loading the view.
  261. }
  262. - (void)onCommitOrderClick:(id)sender {
  263. // get customer info
  264. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  265. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  266. //
  267. // // 检查价格类型
  268. // // 提货价才能提交订单
  269. // /** 价格类型
  270. // * 0 提货价
  271. // * 1 统一价
  272. // * 2 计算价
  273. // */
  274. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  275. // if (priceType != 0) {
  276. //
  277. // NSString* pricename = nil;
  278. // switch (priceType) {
  279. // case 1:
  280. // pricename=flat_price;
  281. // break;
  282. // case 2:
  283. // pricename=given_price;
  284. // break;
  285. // default:
  286. // break;
  287. // }
  288. //
  289. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current price is %@, please change to %@ and try again.",pricename,[Singleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  290. //
  291. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  292. //
  293. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  294. //
  295. // }];
  296. //
  297. //
  298. // [alertVC addAction:cancelAction];
  299. //
  300. // [self presentViewController:alertVC animated:YES completion:nil];
  301. //
  302. // return;
  303. // }
  304. // }
  305. NSString* msg;
  306. #ifdef OFFLINE_MODE
  307. if(appDelegate.offline_mode)
  308. {
  309. msg=@"Are you sure to mark offline order as ready for submit?";
  310. }
  311. else
  312. #endif
  313. {
  314. msg=@"Submit order now?";
  315. // if(appDelegate.user_type == USER_ROLE_CUSTOMER) {
  316. //
  317. // NSString *specialInstuction = [Singleton sharedInstance].specialInstruction;
  318. // NSString * deliverprice=[Singleton sharedInstance].deliveryString;
  319. // msg = [NSString stringWithFormat:@"Are you sure to submit order?\n\n1. Your price type is %@, Order will sent to NPD with this price.",deliverprice];
  320. // if (specialInstuction.length) {
  321. // msg = [msg stringByAppendingFormat:@"\n2. Special Instruction: %@.",specialInstuction];
  322. // }
  323. //
  324. // }
  325. }
  326. // 2017-03-20 修改
  327. //
  328. // CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
  329. //
  330. //
  331. //
  332. //
  333. // // Add some custom content to the alert view
  334. // [alertView setContainerView:[self createDemoView:msg]];
  335. //
  336. // // Modify the parameters
  337. //
  338. //
  339. // NSArray *titleArr = [NSMutableArray arrayWithObjects:@"NO",@"YES", nil];
  340. // [alertView setButtonTitles:titleArr];
  341. // //[alertView setDelegate:self];
  342. //
  343. // // You may use a Block, rather than a delegate.
  344. // [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
  345. // // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
  346. // if(buttonIndex==0)
  347. // [alertView close];
  348. // else
  349. // {
  350. // // add params check here.
  351. // [self.lastedit endEditing:true];
  352. // [self.lasttextview endEditing:true];
  353. //
  354. //
  355. //
  356. // // self.cancommit=true;
  357. // // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  358. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  359. // // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  360. // // for(int i=0;i<section_count;i++)
  361. // // {
  362. // // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  363. // // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  364. // // for(int j=0;j<item_count;j++)
  365. // // {
  366. // // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  367. // // NSString* key = [itemjson valueForKey:@"name"];
  368. // // if(key==nil || key.length==0)
  369. // // continue;
  370. // // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  371. // // {
  372. // // NSString* single_select = [itemjson valueForKey:@"single_select"];
  373. // // if([single_select isEqualToString:@"true"])
  374. // // {
  375. // // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  376. // // int count = [[cadejson valueForKey:@"count"] intValue];
  377. // // bool setvalue = false;
  378. // // for(int cc=0;cc<count;cc++)
  379. // // {
  380. // // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  381. // // if([[valjson valueForKey:@"check"]intValue]==1)
  382. // // {
  383. // // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  384. // // setvalue=true;
  385. // // break;
  386. // // }
  387. // // }
  388. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  389. // // {
  390. // // self.cancommit = false;
  391. // // }
  392. // // }
  393. // // else
  394. // // {
  395. // // //not support multi select for now;
  396. // // }
  397. // // /*
  398. // // upparams setValue:itemjson forKey:<#(NSString *)#>
  399. // //
  400. // // */
  401. // // }else
  402. // // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  403. // // {
  404. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  405. // // self.cancommit = false;
  406. // // }
  407. // // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  408. // // {
  409. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  410. // // self.cancommit = false;
  411. // //
  412. // // NSString* valuestr = [itemjson valueForKey:@"value"];
  413. // // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  414. // // }
  415. // // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  416. // // {
  417. // // NSString* valuestr = [itemjson valueForKey:@"value"];
  418. // // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  419. // //
  420. // // NSString* value = [itemjson valueForKey:@"value"];
  421. // // NSMutableDictionary* boolitem=nil;
  422. // // NSMutableDictionary* subjson=nil;
  423. // // if([value isEqualToString:@"true"])
  424. // // {
  425. // // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  426. // //
  427. // // }
  428. // // else
  429. // // {
  430. // // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  431. // //
  432. // // }
  433. // // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  434. // // if( subjson!=nil /*&& !active*/)
  435. // // {
  436. // // int sub_count = [[subjson valueForKey:@"count"] intValue];
  437. // // for(int l=0;l<sub_count;l++)
  438. // // {
  439. // // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  440. // //
  441. // //
  442. // //
  443. // //
  444. // // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  445. // // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  446. // // else
  447. // // {
  448. // // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  449. // // self.cancommit = false;
  450. // // }
  451. // // }
  452. // //
  453. // //
  454. // //
  455. // // }
  456. // // }
  457. // // else
  458. // // {
  459. // // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  460. // // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  461. // // else
  462. // // {
  463. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  464. // // self.cancommit = false;
  465. // // }
  466. // // }
  467. // // upparams= [self subitem_param:itemjson addto:upparams ];
  468. // // }
  469. // // }
  470. // // if(self.cancommit==false)
  471. // // {
  472. // // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  473. // // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  474. // // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  475. // // //[self.editorTable reloadData ];
  476. // // [self.editorTable reloadData];
  477. // // // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  478. // // return;
  479. // // }
  480. //
  481. // NSMutableDictionary* upparams = [self check_cancommit:true];
  482. // if(self.cancommit==false)
  483. // return;
  484. //
  485. // if(upparams[@"shipping"]==nil)
  486. // goto commit_order;
  487. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  488. // {
  489. // upparams[@"shipping"] = nil;
  490. // goto commit_order;
  491. // }
  492. // else if([upparams[@"shipping"] doubleValue]==0)
  493. // {
  494. //
  495. //
  496. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  497. // //block代码块取代了delegate
  498. //
  499. //
  500. //
  501. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  502. // {
  503. //
  504. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  505. //
  506. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  507. // {
  508. //
  509. // if(/*!self.have_tail*/ true)
  510. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  511. // [upparams setValue:@"false" forKey:@"isHold"];
  512. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  513. //
  514. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  515. //
  516. // dispatch_async(dispatch_get_main_queue(), ^{
  517. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  518. //
  519. //
  520. // if([[editor_json valueForKey:@"result"] intValue]==2)
  521. // {
  522. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  523. //
  524. // // debug aaa
  525. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  526. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  527. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  528. //
  529. // // appDelegate.customerInfo = customerInfo;
  530. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  531. // // appDelegate.order_code = nil;
  532. // [appDelegate closeOrder];
  533. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  534. //
  535. // NSString* title=nil;
  536. // NSString* msg=nil;
  537. // if(appDelegate.offline_mode)
  538. // {
  539. // title=TITLE_OFFLINE_SUBMIT;
  540. // msg=MSG_OFFLINE_SUBMIT;
  541. // }
  542. // else
  543. // {
  544. // title=@"Submit successful.";
  545. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  546. // }
  547. //
  548. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  549. //
  550. // [alert show];
  551. //
  552. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  553. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  554. // NSString* soid=[editor_json valueForKey:@"so#"];
  555. // // if(pdf_url.length>0)
  556. // // {
  557. // //
  558. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  559. // // //[self downloadpdf:pdf_url];
  560. // //
  561. // //
  562. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  563. // // {
  564. // // //bbb
  565. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  566. // // }
  567. // //
  568. // // [self prepareReturn:nil];
  569. // //
  570. // // [self.navigationController popViewControllerAnimated:true];
  571. // //
  572. // // [appDelegate printPdf:pdf_url];
  573. // //// if(self.printPdfCallback)
  574. // //// self.printPdfCallback(pdf_url);
  575. // // }
  576. // // else
  577. // {
  578. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  579. // {
  580. // //bbb
  581. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  582. // }
  583. // [self prepareReturn:nil];
  584. //
  585. // [self.navigationController popViewControllerAnimated:true];
  586. //
  587. // if(pdf_url.length>0)
  588. // {
  589. //
  590. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  591. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  592. // // [appDelegate printPdf:pdf_url];
  593. //
  594. // }
  595. // }
  596. //
  597. // }
  598. // else
  599. // {
  600. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  601. // }
  602. //
  603. //
  604. //
  605. //
  606. // });
  607. // });
  608. // }
  609. // else
  610. // {
  611. // 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];
  612. //
  613. //
  614. // alert.tag = KEEP_TAIL;
  615. //
  616. //
  617. // self.upparams = upparams;
  618. //
  619. // [alert show];
  620. // }
  621. //
  622. // }
  623. // else
  624. // { //USER_ROLE_CUSTOMER
  625. //
  626. // // if(self.have_tail)
  627. // // [upparams setValue:@"true" forKey:@"isHold"];
  628. // // else
  629. // // [upparams setValue:@"false" forKey:@"isHold"];
  630. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  631. //
  632. // [upparams setValue:@"true" forKey:@"isHold"];
  633. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  634. //
  635. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  636. //
  637. // dispatch_async(dispatch_get_main_queue(), ^{
  638. //
  639. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  640. //
  641. // if([[editor_json valueForKey:@"result"] intValue]==2)
  642. // {
  643. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  644. //
  645. //
  646. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  647. // // appDelegate.customerInfo = customerInfo;
  648. //
  649. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  650. // // appDelegate.order_code = orderCode;
  651. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  652. // [appDelegate closeOrder];
  653. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  654. //
  655. // NSString* title=nil;
  656. // NSString* msg=nil;
  657. // if(appDelegate.offline_mode)
  658. // {
  659. // title=TITLE_OFFLINE_SUBMIT;
  660. // msg=MSG_OFFLINE_SUBMIT;
  661. // }
  662. // else
  663. // {
  664. // title=@"Submit successful.";
  665. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  666. // }
  667. //
  668. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  669. //
  670. // [alert show];
  671. // // // self.labelContact.text=appDelegate.contact_name;
  672. // //
  673. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  674. // [self prepareReturn:nil];
  675. // [self.navigationController popViewControllerAnimated:true];
  676. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  677. // //
  678. // //
  679. // // ;
  680. // // }];
  681. //
  682. // }
  683. // else
  684. // {
  685. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  686. // }
  687. //
  688. //
  689. //
  690. //
  691. // });
  692. // });
  693. //
  694. // }
  695. //
  696. //
  697. //
  698. // }];
  699. //
  700. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  701. // //DebugLog(@"Cancel");
  702. //
  703. //
  704. // }];
  705. // [alertControl addAction:actionOne];
  706. //
  707. // [alertControl addAction:alertthree];
  708. //
  709. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  710. //
  711. //
  712. //
  713. //
  714. // [self presentViewController:alertControl animated:YES completion:nil];
  715. //
  716. //
  717. //
  718. // }
  719. // else
  720. // {
  721. // commit_order:
  722. //
  723. // {
  724. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  725. //
  726. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  727. // {
  728. //
  729. // if(/*!self.have_tail*/ true)
  730. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  731. // [upparams setValue:@"false" forKey:@"isHold"];
  732. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  733. //
  734. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  735. //
  736. // dispatch_async(dispatch_get_main_queue(), ^{
  737. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  738. //
  739. //
  740. // if([[editor_json valueForKey:@"result"] intValue]==2)
  741. // {
  742. //
  743. // //debug bbb
  744. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  745. //
  746. //
  747. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  748. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  749. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  750. // // appDelegate.customerInfo = customerInfo;
  751. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  752. // // appDelegate.order_code = nil;
  753. // [appDelegate closeOrder];
  754. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  755. //
  756. // NSString* title=nil;
  757. // NSString* msg=nil;
  758. // if(appDelegate.offline_mode)
  759. // {
  760. // title=TITLE_OFFLINE_SUBMIT;
  761. // msg=MSG_OFFLINE_SUBMIT;
  762. // }
  763. // else
  764. // {
  765. // title=@"Submit successful.";
  766. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  767. // }
  768. //
  769. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  770. //
  771. // [alert show];
  772. //
  773. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  774. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  775. // NSString* soid=[editor_json valueForKey:@"so#"];
  776. // // if(pdf_url.length>0)
  777. // // {
  778. // //
  779. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  780. // //// [self downloadpdf:pdf_url];
  781. // //
  782. // //
  783. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  784. // // {
  785. // // //bbb
  786. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  787. // // }
  788. // //
  789. // // [self prepareReturn:nil];
  790. // //
  791. // // [self.navigationController popViewControllerAnimated:true];
  792. // //
  793. // // [appDelegate printPdf:pdf_url];
  794. // //
  795. // //// if(self.printPdfCallback)
  796. // //// self.printPdfCallback(pdf_url);
  797. // // }
  798. // // else
  799. // {
  800. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  801. // {
  802. // //bbb
  803. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  804. // }
  805. // [self prepareReturn:nil];
  806. //
  807. // [self.navigationController popViewControllerAnimated:true];
  808. //
  809. //
  810. // if(pdf_url.length>0)
  811. // {
  812. //
  813. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  814. //
  815. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  816. //
  817. //
  818. // }
  819. //
  820. //
  821. // }
  822. // // // self.labelContact.text=appDelegate.contact_name;
  823. // //
  824. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  825. //
  826. //
  827. //
  828. //
  829. //
  830. //
  831. // }
  832. // else
  833. // {
  834. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  835. // }
  836. //
  837. //
  838. //
  839. //
  840. // });
  841. // });
  842. // }
  843. // else
  844. // {
  845. // 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];
  846. //
  847. //
  848. // alert.tag = KEEP_TAIL;
  849. //
  850. //
  851. // self.upparams = upparams;
  852. //
  853. // [alert show];
  854. // }
  855. //
  856. // }
  857. // else
  858. // { //USER_ROLE_CUSTOMER
  859. //
  860. // // if(self.have_tail)
  861. // // [upparams setValue:@"true" forKey:@"isHold"];
  862. // // else
  863. // // [upparams setValue:@"false" forKey:@"isHold"];
  864. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  865. //
  866. // [upparams setValue:@"true" forKey:@"isHold"];
  867. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  868. //
  869. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  870. //
  871. // dispatch_async(dispatch_get_main_queue(), ^{
  872. //
  873. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  874. //
  875. // if([[editor_json valueForKey:@"result"] intValue]==2)
  876. // {
  877. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  878. //
  879. //
  880. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  881. // // appDelegate.customerInfo = customerInfo;
  882. //
  883. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  884. // // appDelegate.order_code = orderCode;
  885. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  886. // [appDelegate closeOrder];
  887. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  888. //
  889. // NSString* title=nil;
  890. // NSString* msg=nil;
  891. // if(appDelegate.offline_mode)
  892. // {
  893. // title=TITLE_OFFLINE_SUBMIT;
  894. // msg=MSG_OFFLINE_SUBMIT;
  895. // }
  896. // else
  897. // {
  898. // title=@"Submit successful.";
  899. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  900. // }
  901. //
  902. //
  903. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  904. //
  905. // [alert show];
  906. // // // self.labelContact.text=appDelegate.contact_name;
  907. // //
  908. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  909. // [self prepareReturn:nil];
  910. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  911. // //
  912. // //
  913. // // ;
  914. // // }];
  915. // [self.navigationController popViewControllerAnimated:true];
  916. //
  917. // }
  918. // else
  919. // {
  920. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  921. // }
  922. //
  923. //
  924. //
  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. // // [alertView setUseMotionEffects:true];
  951. //
  952. //
  953. // // And launch the dialog
  954. //
  955. // [alertView sizeToFit];
  956. // [alertView show];
  957. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit Confirm.", nil) message:NSLocalizedString(msg, nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  958. //
  959. // alert.tag = SUBMIT_CONFIRM;
  960. // [alert show];
  961. //
  962. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Order Submission" message:msg preferredStyle:UIAlertControllerStyleAlert];
  963. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  964. {
  965. // add params check here.
  966. [self.lastedit endEditing:true];
  967. [self.lasttextview endEditing:true];
  968. NSMutableDictionary* upparams = [self check_cancommit:true];
  969. if(self.cancommit==false)
  970. return;
  971. // 2018-1-2 Modify
  972. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  973. {
  974. [self customer_commit_order:upparams];
  975. }
  976. else // USER_ROLE_EMPLOYEE
  977. {
  978. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  979. {
  980. upparams[@"shipping"] = nil;
  981. }
  982. if(upparams[@"shipping"]==nil || [upparams[@"shipping"] doubleValue]!=0)
  983. [self empolyee_commit_order:upparams];
  984. else
  985. {
  986. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  987. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  988. {
  989. //yes
  990. [self empolyee_commit_order:upparams];
  991. }];
  992. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  993. //DebugLog(@"Cancel");
  994. }];
  995. [alertControl addAction:actionOne];
  996. [alertControl addAction:alertthree];
  997. [self presentViewController:alertControl animated:YES completion:nil];
  998. }
  999. }
  1000. // if(upparams[@"shipping"]==nil)
  1001. // goto commit_order;
  1002. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1003. // {
  1004. // upparams[@"shipping"] = nil;
  1005. // goto commit_order;
  1006. // }
  1007. // else if([upparams[@"shipping"] doubleValue]==0)
  1008. // {
  1009. //
  1010. //
  1011. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1012. // //block代码块取代了delegate
  1013. //
  1014. //
  1015. //
  1016. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  1017. // {
  1018. //
  1019. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1020. //
  1021. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1022. // {
  1023. //
  1024. // if(/*!self.have_tail*/ true)
  1025. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  1026. // [upparams setValue:@"false" forKey:@"isHold"];
  1027. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1028. //
  1029. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1030. //
  1031. // dispatch_async(dispatch_get_main_queue(), ^{
  1032. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1033. //
  1034. //
  1035. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1036. // {
  1037. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1038. //
  1039. // // debug aaa
  1040. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1041. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  1042. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1043. //
  1044. // // appDelegate.customerInfo = customerInfo;
  1045. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1046. // // appDelegate.order_code = nil;
  1047. // [appDelegate closeOrder];
  1048. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1049. //
  1050. // NSString* title=nil;
  1051. // NSString* msg=nil;
  1052. //#ifdef OFFLINE_MODE
  1053. // if(appDelegate.offline_mode)
  1054. // {
  1055. // title=TITLE_OFFLINE_SUBMIT;
  1056. // msg=MSG_OFFLINE_SUBMIT;
  1057. // }
  1058. // else
  1059. //#endif
  1060. // {
  1061. // title=@"Order submitted sucessfully";
  1062. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1063. // }
  1064. //
  1065. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1066. //
  1067. // [alert show];
  1068. //
  1069. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1070. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  1071. // NSString* soid=[editor_json valueForKey:@"so#"];
  1072. // // if(pdf_url.length>0)
  1073. // // {
  1074. // //
  1075. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1076. // // //[self downloadpdf:pdf_url];
  1077. // //
  1078. // //
  1079. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1080. // // {
  1081. // // //bbb
  1082. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1083. // // }
  1084. // //
  1085. // // [self prepareReturn:nil];
  1086. // //
  1087. // // [self.navigationController popViewControllerAnimated:true];
  1088. // //
  1089. // // [appDelegate printPdf:pdf_url];
  1090. // //// if(self.printPdfCallback)
  1091. // //// self.printPdfCallback(pdf_url);
  1092. // // }
  1093. // // else
  1094. // {
  1095. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1096. // {
  1097. // //bbb
  1098. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1099. // }
  1100. // [self prepareReturn:nil];
  1101. //
  1102. // [self.navigationController popViewControllerAnimated:true];
  1103. //
  1104. // if(pdf_url.length>0)
  1105. // {
  1106. //
  1107. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1108. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1109. // // [appDelegate printPdf:pdf_url];
  1110. //
  1111. // }
  1112. // }
  1113. //
  1114. // }
  1115. // else
  1116. // {
  1117. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1118. // }
  1119. //
  1120. //
  1121. //
  1122. //
  1123. // });
  1124. // });
  1125. // }
  1126. // else
  1127. // {
  1128. // 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];
  1129. //
  1130. //
  1131. // alert.tag = KEEP_TAIL;
  1132. //
  1133. //
  1134. // self.upparams = upparams;
  1135. //
  1136. // [alert show];
  1137. // }
  1138. //
  1139. // }
  1140. // else
  1141. // { //USER_ROLE_CUSTOMER
  1142. //
  1143. // // if(self.have_tail)
  1144. // // [upparams setValue:@"true" forKey:@"isHold"];
  1145. // // else
  1146. // // [upparams setValue:@"false" forKey:@"isHold"];
  1147. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  1148. //
  1149. // [upparams setValue:@"true" forKey:@"isHold"];
  1150. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1151. //
  1152. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1153. //
  1154. // dispatch_async(dispatch_get_main_queue(), ^{
  1155. //
  1156. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1157. //
  1158. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1159. // {
  1160. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1161. //
  1162. //
  1163. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1164. // // appDelegate.customerInfo = customerInfo;
  1165. //
  1166. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1167. // // appDelegate.order_code = orderCode;
  1168. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1169. // [appDelegate closeOrder];
  1170. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1171. //
  1172. // NSString* title=nil;
  1173. // NSString* msg=nil;
  1174. //#ifdef OFFLINE_MODE
  1175. // if(appDelegate.offline_mode)
  1176. // {
  1177. // title=TITLE_OFFLINE_SUBMIT;
  1178. // msg=MSG_OFFLINE_SUBMIT;
  1179. // }
  1180. // else
  1181. //#endif
  1182. // {
  1183. // title=@"Order submitted sucessfully";
  1184. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1185. // }
  1186. //
  1187. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1188. //
  1189. // [alert show];
  1190. // // // self.labelContact.text=appDelegate.contact_name;
  1191. // //
  1192. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1193. // [self prepareReturn:nil];
  1194. // [self.navigationController popViewControllerAnimated:true];
  1195. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1196. // //
  1197. // //
  1198. // // ;
  1199. // // }];
  1200. //
  1201. // }
  1202. // else
  1203. // {
  1204. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1205. // }
  1206. //
  1207. //
  1208. //
  1209. //
  1210. // });
  1211. // });
  1212. //
  1213. // }
  1214. //
  1215. //
  1216. //
  1217. // }];
  1218. //
  1219. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1220. // //DebugLog(@"Cancel");
  1221. //
  1222. //
  1223. // }];
  1224. // [alertControl addAction:actionOne];
  1225. //
  1226. // [alertControl addAction:alertthree];
  1227. //
  1228. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1229. //
  1230. //
  1231. //
  1232. //
  1233. // [self presentViewController:alertControl animated:YES completion:nil];
  1234. //
  1235. //
  1236. //
  1237. // }
  1238. // else
  1239. // {
  1240. // commit_order:
  1241. //
  1242. // {
  1243. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1244. //
  1245. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1246. // {
  1247. //
  1248. // if(/*!self.have_tail*/ true)
  1249. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  1250. // [upparams setValue:@"false" forKey:@"isHold"];
  1251. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1252. //
  1253. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1254. //
  1255. // dispatch_async(dispatch_get_main_queue(), ^{
  1256. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1257. //
  1258. //
  1259. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1260. // {
  1261. //
  1262. // //debug bbb
  1263. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1264. //
  1265. //
  1266. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1267. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  1268. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1269. // // appDelegate.customerInfo = customerInfo;
  1270. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1271. // // appDelegate.order_code = nil;
  1272. // [appDelegate closeOrder];
  1273. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1274. //
  1275. // NSString* title=nil;
  1276. // NSString* msg=nil;
  1277. //#ifdef OFFLINE_MODE
  1278. // if(appDelegate.offline_mode)
  1279. // {
  1280. // title=TITLE_OFFLINE_SUBMIT;
  1281. // msg=MSG_OFFLINE_SUBMIT;
  1282. // }
  1283. // else
  1284. //#endif
  1285. // {
  1286. // title=@"Order submitted sucessfully";
  1287. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1288. // }
  1289. //
  1290. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1291. //
  1292. // [alert show];
  1293. //
  1294. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1295. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  1296. // NSString* soid=[editor_json valueForKey:@"so#"];
  1297. // // if(pdf_url.length>0)
  1298. // // {
  1299. // //
  1300. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1301. // //// [self downloadpdf:pdf_url];
  1302. // //
  1303. // //
  1304. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1305. // // {
  1306. // // //bbb
  1307. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1308. // // }
  1309. // //
  1310. // // [self prepareReturn:nil];
  1311. // //
  1312. // // [self.navigationController popViewControllerAnimated:true];
  1313. // //
  1314. // // [appDelegate printPdf:pdf_url];
  1315. // //
  1316. // //// if(self.printPdfCallback)
  1317. // //// self.printPdfCallback(pdf_url);
  1318. // // }
  1319. // // else
  1320. // {
  1321. // NSMutableDictionary* value=[[NSMutableDictionary alloc]init];
  1322. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1323. // {
  1324. // //bbb
  1325. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1326. // value[@"commitorder_logout"]=@"true";
  1327. // }
  1328. //
  1329. //
  1330. // value[@"is_subaction"] = self.params[@"is_subaction"];
  1331. // value[@"subaction_tag"] = self.params[@"subaction_tag"];
  1332. //
  1333. // [self prepareReturn:value];
  1334. //
  1335. // [self.navigationController popViewControllerAnimated:true];
  1336. //
  1337. //
  1338. // if(pdf_url.length>0)
  1339. // {
  1340. //
  1341. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1342. //
  1343. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1344. //
  1345. //
  1346. // }
  1347. //
  1348. //
  1349. // }
  1350. // // // self.labelContact.text=appDelegate.contact_name;
  1351. // //
  1352. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1353. //
  1354. //
  1355. //
  1356. //
  1357. //
  1358. //
  1359. // }
  1360. // else
  1361. // {
  1362. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1363. // }
  1364. //
  1365. //
  1366. //
  1367. //
  1368. // });
  1369. // });
  1370. // }
  1371. // else
  1372. // {
  1373. // 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];
  1374. //
  1375. //
  1376. // alert.tag = KEEP_TAIL;
  1377. //
  1378. //
  1379. // self.upparams = upparams;
  1380. //
  1381. // [alert show];
  1382. // }
  1383. //
  1384. // }
  1385. // else
  1386. // { //USER_ROLE_CUSTOMER
  1387. //
  1388. // // if(self.have_tail)
  1389. // // [upparams setValue:@"true" forKey:@"isHold"];
  1390. // // else
  1391. // // [upparams setValue:@"false" forKey:@"isHold"];
  1392. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  1393. //
  1394. // [upparams setValue:@"true" forKey:@"isHold"];
  1395. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1396. //
  1397. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1398. //
  1399. // dispatch_async(dispatch_get_main_queue(), ^{
  1400. //
  1401. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1402. //
  1403. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1404. // {
  1405. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1406. //
  1407. //
  1408. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1409. // // appDelegate.customerInfo = customerInfo;
  1410. //
  1411. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1412. // // appDelegate.order_code = orderCode;
  1413. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1414. // [appDelegate closeOrder];
  1415. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1416. //
  1417. // NSString* title=nil;
  1418. // NSString* msg=nil;
  1419. //#ifdef OFFLINE_MODE
  1420. // if(appDelegate.offline_mode)
  1421. // {
  1422. // title=TITLE_OFFLINE_SUBMIT;
  1423. // msg=MSG_OFFLINE_SUBMIT;
  1424. // }
  1425. // else
  1426. //#endif
  1427. // {
  1428. // title=@"Order submitted sucessfully";
  1429. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1430. // }
  1431. //
  1432. //
  1433. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1434. //
  1435. // [alert show];
  1436. // // // self.labelContact.text=appDelegate.contact_name;
  1437. // //
  1438. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1439. // [self prepareReturn:nil];
  1440. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1441. // //
  1442. // //
  1443. // // ;
  1444. // // }];
  1445. // [self.navigationController popViewControllerAnimated:true];
  1446. //
  1447. // }
  1448. // else
  1449. // {
  1450. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1451. // }
  1452. //
  1453. //
  1454. //
  1455. //
  1456. // });
  1457. // });
  1458. //
  1459. // }
  1460. // }
  1461. //
  1462. //
  1463. //
  1464. //
  1465. // }
  1466. }
  1467. }];
  1468. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1469. }];
  1470. [alertVC addAction:yesAction];
  1471. [alertVC addAction:cancelAction];
  1472. [self presentViewController:alertVC animated:yesAction completion:nil];
  1473. }
  1474. - (UIView *)createDemoView:(NSString*) msg
  1475. {
  1476. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  1477. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  1478. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  1479. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  1480. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  1481. titleLabel.text=@"Order Submission";
  1482. titleLabel.numberOfLines = 0;
  1483. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1484. // titleLabel.textAlignment = NSTextAlignmentRight;
  1485. titleLabel.textAlignment = NSTextAlignmentCenter;
  1486. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  1487. CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1488. //[titleLabel sizeToFit];
  1489. // titleLabel.center.x = demoView.center.x;
  1490. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  1491. [demoView addSubview:titleLabel];
  1492. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  1493. lineLabel.font = [UIFont systemFontOfSize:17];
  1494. lineLabel.text=msg;
  1495. lineLabel.numberOfLines = 0;
  1496. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1497. CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1498. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  1499. //[lineLabel sizeToFit];
  1500. [demoView addSubview:lineLabel];
  1501. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  1502. return demoView;
  1503. }
  1504. - (void)onCloseClick:(UIButton *)sender {
  1505. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1506. if (self.resumeOrder) {
  1507. [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
  1508. return;
  1509. }
  1510. //
  1511. // NSRange range = [tempStr rangeOfString:@")\">"];//判断字符串是否包含
  1512. //
  1513. // //if (range.location ==NSNotFound)//不包含
  1514. // if (range.length >0)//包含
  1515. // {
  1516. //
  1517. //
  1518. //
  1519. // }
  1520. // else//不包含
  1521. // {
  1522. //
  1523. // }
  1524. UIAlertView * alert = nil;
  1525. if(appDelegate.order_status==0)
  1526. {
  1527. 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];
  1528. }
  1529. else
  1530. {
  1531. 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];
  1532. }
  1533. alert.tag = CLOSE_ACTION;
  1534. // alert.
  1535. [alert show];
  1536. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1537. // appDelegate.order_code = nil;
  1538. //
  1539. // }
  1540. }
  1541. - (void)didReceiveMemoryWarning {
  1542. [super didReceiveMemoryWarning];
  1543. // Dispose of any resources that can be recreated.
  1544. }
  1545. - (IBAction)onSaveClick:(id)sender {
  1546. // id foo = nil;
  1547. // [[NSMutableArray array] addObject:foo];
  1548. // add params check here.
  1549. [self.lastedit endEditing:true];
  1550. [self.lasttextview endEditing:true];
  1551. // self.cancommit=true;
  1552. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  1553. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  1554. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1555. // for(int i=0;i<section_count;i++)
  1556. // {
  1557. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1558. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1559. // for(int j=0;j<item_count;j++)
  1560. // {
  1561. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1562. // NSString* key = [itemjson valueForKey:@"name"];
  1563. // if(key==nil || key.length==0)
  1564. // continue;
  1565. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  1566. // {
  1567. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  1568. // if([single_select isEqualToString:@"true"])
  1569. // {
  1570. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  1571. // int count = [[cadejson valueForKey:@"count"] intValue];
  1572. // bool setvalue = false;
  1573. // for(int cc=0;cc<count;cc++)
  1574. // {
  1575. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1576. // if([[valjson valueForKey:@"check"]intValue]==1)
  1577. // {
  1578. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  1579. // setvalue=true;
  1580. // break;
  1581. // }
  1582. // }
  1583. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  1584. // {
  1585. // self.cancommit = false;
  1586. // }
  1587. // }
  1588. // else
  1589. // {
  1590. // //not support multi select for now;
  1591. // }
  1592. // /*
  1593. // upparams setValue:itemjson forKey:<#(NSString *)#>
  1594. //
  1595. // */
  1596. // }else
  1597. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  1598. // {
  1599. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  1600. // self.cancommit = false;
  1601. // }
  1602. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  1603. // {
  1604. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"]==nil)
  1605. // self.cancommit = false;
  1606. //
  1607. // NSString* valuestr = [itemjson valueForKey:@"value"];
  1608. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1609. // }
  1610. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  1611. // {
  1612. // NSString* valuestr = [itemjson valueForKey:@"value"];
  1613. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1614. //
  1615. // NSString* value = [itemjson valueForKey:@"value"];
  1616. // NSMutableDictionary* boolitem=nil;
  1617. // NSMutableDictionary* subjson=nil;
  1618. // if([value isEqualToString:@"true"])
  1619. // {
  1620. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  1621. //
  1622. // }
  1623. // else
  1624. // {
  1625. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  1626. //
  1627. // }
  1628. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  1629. // if( subjson!=nil /*&& !active*/)
  1630. // {
  1631. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  1632. // for(int l=0;l<sub_count;l++)
  1633. // {
  1634. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1635. //
  1636. //
  1637. //
  1638. //
  1639. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  1640. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  1641. // else
  1642. // {
  1643. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  1644. // self.cancommit = false;
  1645. // }
  1646. // }
  1647. //
  1648. //
  1649. //
  1650. // }
  1651. // }
  1652. // else
  1653. // {
  1654. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  1655. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  1656. // else
  1657. // {
  1658. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  1659. // self.cancommit = false;
  1660. // }
  1661. // }
  1662. // upparams= [self subitem_param:itemjson addto:upparams ];
  1663. // }
  1664. // }
  1665. // // save order 不检查必填项;
  1666. // self.cancommit=true;
  1667. // if(self.cancommit==false)
  1668. // {
  1669. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  1670. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1671. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1672. // //[self.editorTable reloadData ];
  1673. // [self.editorTable reloadData];
  1674. // return;
  1675. // }
  1676. NSMutableDictionary* upparams = [self check_cancommit:false];
  1677. // if(self.cancommit==false)
  1678. // return;
  1679. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1680. upparams[@"shipping"] = nil;
  1681. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving Order"];
  1682. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1683. NSDictionary* editor_json = [RANetwork save_Order:upparams];
  1684. dispatch_async(dispatch_get_main_queue(), ^{
  1685. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1686. if([[editor_json valueForKey:@"result"] intValue]==2)
  1687. {
  1688. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1689. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1690. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1691. {
  1692. appDelegate.customerInfo = customerInfo;
  1693. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1694. }
  1695. NSString *msg = nil;
  1696. if ([editor_json objectForKey:@"so#"]) {
  1697. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1698. }
  1699. [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1700. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1701. {
  1702. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1703. [self prepareReturn:nil];
  1704. [self.navigationController popViewControllerAnimated:true];
  1705. }
  1706. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1707. if (![Singleton sharedInstance].currentOrderIsMerged) {
  1708. [self releaseOrderAfterSave];
  1709. }
  1710. }
  1711. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1712. // appDelegate.order_code = nil;
  1713. //
  1714. // }
  1715. // // self.labelContact.text=appDelegate.contact_name;
  1716. //
  1717. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1718. // [self prepareReturn:nil];
  1719. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1720. //
  1721. //
  1722. // ;
  1723. // }];
  1724. }
  1725. else
  1726. {
  1727. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1728. }
  1729. });
  1730. });
  1731. }
  1732. - (void)textFieldDidEndEditing:(UITextField *)textField
  1733. {
  1734. [super textFieldDidEndEditing:textField];
  1735. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  1736. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1737. NSMutableDictionary* section_json=nil;
  1738. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  1739. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1740. NSString* name = [item_json valueForKey:@"name"];
  1741. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  1742. {
  1743. float shipping = [self getprice:@"shipping" section:indexPath.section];
  1744. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  1745. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  1746. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  1747. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  1748. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  1749. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1750. int count=0;
  1751. count=[[section_json valueForKey:@"count"] intValue];
  1752. int total_row_idx=-1;
  1753. for(int i=0;i<count;i++)
  1754. {
  1755. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1756. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  1757. {
  1758. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  1759. [olditem setValue:@"true" forKey:@"dirty"];
  1760. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1761. total_row_idx=i;
  1762. }
  1763. }
  1764. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1765. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  1766. if(total_row_idx>=0)
  1767. {
  1768. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  1769. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  1770. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1771. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1772. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1773. // CGSize tablecontent =self.editorTable.contentSize;
  1774. // tablecontent.height=tablecontent.height+self.keyboard_h;
  1775. // self.editorTable.contentSize=tablecontent;
  1776. //
  1777. //
  1778. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  1779. }
  1780. // self.content_data = [editor_json mutableCopy];
  1781. // self.content_data = [self translate_json:editor_json];
  1782. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  1783. // [self.editorTable reloadData];
  1784. }
  1785. //
  1786. // [item_json setValue:@"true" forKey:@"dirty"];
  1787. // [item_json setValue:textField.text forKey:@"value"];
  1788. }
  1789. -(float) getprice:(NSString*) name section :(long) index
  1790. {
  1791. NSMutableDictionary* section_json=nil;
  1792. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  1793. int count=0;
  1794. count=[[section_json valueForKey:@"count"] intValue];
  1795. for(int i=0;i<count;i++)
  1796. {
  1797. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1798. if([[olditem valueForKey:@"name"] isEqualToString:name])
  1799. {
  1800. return [[olditem valueForKey:@"value"] floatValue];
  1801. }
  1802. }
  1803. return 0;
  1804. }
  1805. /*
  1806. #pragma mark - Navigation
  1807. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1808. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1809. // Get the new view controller using [segue destinationViewController].
  1810. // Pass the selected object to the new view controller.
  1811. }
  1812. */
  1813. #pragma mark - UIAlertViewDelegate
  1814. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1815. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1816. {
  1817. if(buttonIndex!=alertView.cancelButtonIndex && alertView.tag == SUBMIT_CONFIRM)
  1818. {
  1819. // // add params check here.
  1820. // [self.lastedit endEditing:true];
  1821. // [self.lasttextview endEditing:true];
  1822. //
  1823. //
  1824. //
  1825. //// self.cancommit=true;
  1826. //// NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  1827. //// [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  1828. //// int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1829. //// for(int i=0;i<section_count;i++)
  1830. //// {
  1831. //// NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1832. //// int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1833. //// for(int j=0;j<item_count;j++)
  1834. //// {
  1835. //// NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1836. //// NSString* key = [itemjson valueForKey:@"name"];
  1837. //// if(key==nil || key.length==0)
  1838. //// continue;
  1839. //// if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  1840. //// {
  1841. //// NSString* single_select = [itemjson valueForKey:@"single_select"];
  1842. //// if([single_select isEqualToString:@"true"])
  1843. //// {
  1844. //// NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  1845. //// int count = [[cadejson valueForKey:@"count"] intValue];
  1846. //// bool setvalue = false;
  1847. //// for(int cc=0;cc<count;cc++)
  1848. //// {
  1849. //// NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1850. //// if([[valjson valueForKey:@"check"]intValue]==1)
  1851. //// {
  1852. //// [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  1853. //// setvalue=true;
  1854. //// break;
  1855. //// }
  1856. //// }
  1857. //// if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  1858. //// {
  1859. //// self.cancommit = false;
  1860. //// }
  1861. //// }
  1862. //// else
  1863. //// {
  1864. //// //not support multi select for now;
  1865. //// }
  1866. //// /*
  1867. //// upparams setValue:itemjson forKey:<#(NSString *)#>
  1868. ////
  1869. //// */
  1870. //// }else
  1871. //// if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  1872. //// {
  1873. //// if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  1874. //// self.cancommit = false;
  1875. //// }
  1876. //// else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  1877. //// {
  1878. //// if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  1879. //// self.cancommit = false;
  1880. ////
  1881. //// NSString* valuestr = [itemjson valueForKey:@"value"];
  1882. //// [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1883. //// }
  1884. //// else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  1885. //// {
  1886. //// NSString* valuestr = [itemjson valueForKey:@"value"];
  1887. //// [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1888. ////
  1889. //// NSString* value = [itemjson valueForKey:@"value"];
  1890. //// NSMutableDictionary* boolitem=nil;
  1891. //// NSMutableDictionary* subjson=nil;
  1892. //// if([value isEqualToString:@"true"])
  1893. //// {
  1894. //// boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  1895. ////
  1896. //// }
  1897. //// else
  1898. //// {
  1899. //// boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  1900. ////
  1901. //// }
  1902. //// subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  1903. //// if( subjson!=nil /*&& !active*/)
  1904. //// {
  1905. //// int sub_count = [[subjson valueForKey:@"count"] intValue];
  1906. //// for(int l=0;l<sub_count;l++)
  1907. //// {
  1908. //// NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1909. ////
  1910. ////
  1911. ////
  1912. ////
  1913. //// if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  1914. //// [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  1915. //// else
  1916. //// {
  1917. //// if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  1918. //// self.cancommit = false;
  1919. //// }
  1920. //// }
  1921. ////
  1922. ////
  1923. ////
  1924. //// }
  1925. //// }
  1926. //// else
  1927. //// {
  1928. //// if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  1929. //// [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  1930. //// else
  1931. //// {
  1932. //// if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  1933. //// self.cancommit = false;
  1934. //// }
  1935. //// }
  1936. //// upparams= [self subitem_param:itemjson addto:upparams ];
  1937. //// }
  1938. //// }
  1939. //// if(self.cancommit==false)
  1940. //// {
  1941. //// [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  1942. //// self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1943. //// //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1944. //// //[self.editorTable reloadData ];
  1945. //// [self.editorTable reloadData];
  1946. //// // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1947. //// return;
  1948. //// }
  1949. //
  1950. // NSMutableDictionary* upparams = [self check_cancommit:true];
  1951. // if(self.cancommit==false)
  1952. // return;
  1953. //
  1954. // if(upparams[@"shipping"]==nil)
  1955. // goto commit_order;
  1956. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1957. // {
  1958. // upparams[@"shipping"] = nil;
  1959. // goto commit_order;
  1960. // }
  1961. // else if([upparams[@"shipping"] doubleValue]==0)
  1962. // {
  1963. //
  1964. //
  1965. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1966. // //block代码块取代了delegate
  1967. //
  1968. //
  1969. //
  1970. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  1971. // {
  1972. //
  1973. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1974. //
  1975. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1976. // {
  1977. //
  1978. // if(/*!self.have_tail*/ true)
  1979. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  1980. // [upparams setValue:@"false" forKey:@"isHold"];
  1981. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1982. //
  1983. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1984. //
  1985. // dispatch_async(dispatch_get_main_queue(), ^{
  1986. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1987. //
  1988. //
  1989. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1990. // {
  1991. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1992. //
  1993. // // debug aaa
  1994. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1995. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  1996. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1997. //
  1998. // // appDelegate.customerInfo = customerInfo;
  1999. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  2000. // // appDelegate.order_code = nil;
  2001. // [appDelegate closeOrder];
  2002. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2003. //
  2004. // NSString* title=nil;
  2005. // NSString* msg=nil;
  2006. //#ifdef OFFLINE_MODE
  2007. // if(appDelegate.offline_mode)
  2008. // {
  2009. // title=TITLE_OFFLINE_SUBMIT;
  2010. // msg=MSG_OFFLINE_SUBMIT;
  2011. // }
  2012. // else
  2013. //#endif
  2014. // {
  2015. // title=@"Order submitted sucessfully";
  2016. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2017. // }
  2018. //
  2019. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2020. //
  2021. // [alert show];
  2022. //
  2023. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2024. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  2025. // NSString* soid=[editor_json valueForKey:@"so#"];
  2026. //// if(pdf_url.length>0)
  2027. //// {
  2028. ////
  2029. //// [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2030. //// //[self downloadpdf:pdf_url];
  2031. ////
  2032. ////
  2033. //// if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  2034. //// {
  2035. //// //bbb
  2036. //// [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2037. //// }
  2038. ////
  2039. //// [self prepareReturn:nil];
  2040. ////
  2041. //// [self.navigationController popViewControllerAnimated:true];
  2042. ////
  2043. //// [appDelegate printPdf:pdf_url];
  2044. ////// if(self.printPdfCallback)
  2045. ////// self.printPdfCallback(pdf_url);
  2046. //// }
  2047. //// else
  2048. // {
  2049. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2050. // {
  2051. // //bbb
  2052. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2053. // }
  2054. // [self prepareReturn:nil];
  2055. //
  2056. // [self.navigationController popViewControllerAnimated:true];
  2057. //
  2058. // if(pdf_url.length>0)
  2059. // {
  2060. //
  2061. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2062. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  2063. // // [appDelegate printPdf:pdf_url];
  2064. //
  2065. // }
  2066. // }
  2067. //
  2068. // }
  2069. // else
  2070. // {
  2071. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2072. // }
  2073. //
  2074. //
  2075. //
  2076. //
  2077. // });
  2078. // });
  2079. // }
  2080. // else
  2081. // {
  2082. // 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];
  2083. //
  2084. //
  2085. // alert.tag = KEEP_TAIL;
  2086. //
  2087. //
  2088. // self.upparams = upparams;
  2089. //
  2090. // [alert show];
  2091. // }
  2092. //
  2093. // }
  2094. // else
  2095. // { //USER_ROLE_CUSTOMER
  2096. //
  2097. // // if(self.have_tail)
  2098. // // [upparams setValue:@"true" forKey:@"isHold"];
  2099. // // else
  2100. // // [upparams setValue:@"false" forKey:@"isHold"];
  2101. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  2102. //
  2103. // [upparams setValue:@"true" forKey:@"isHold"];
  2104. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2105. //
  2106. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2107. //
  2108. // dispatch_async(dispatch_get_main_queue(), ^{
  2109. //
  2110. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2111. //
  2112. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2113. // {
  2114. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  2115. //
  2116. //
  2117. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2118. // // appDelegate.customerInfo = customerInfo;
  2119. //
  2120. //// NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  2121. //// appDelegate.order_code = orderCode;
  2122. //// appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  2123. // [appDelegate closeOrder];
  2124. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2125. //
  2126. // NSString* title=nil;
  2127. // NSString* msg=nil;
  2128. //#ifdef OFFLINE_MODE
  2129. // if(appDelegate.offline_mode)
  2130. // {
  2131. // title=TITLE_OFFLINE_SUBMIT;
  2132. // msg=MSG_OFFLINE_SUBMIT;
  2133. // }
  2134. // else
  2135. //#endif
  2136. // {
  2137. // title=@"Order submitted sucessfully";
  2138. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2139. // }
  2140. //
  2141. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2142. //
  2143. // [alert show];
  2144. // // // self.labelContact.text=appDelegate.contact_name;
  2145. // //
  2146. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  2147. // [self prepareReturn:nil];
  2148. // [self.navigationController popViewControllerAnimated:true];
  2149. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  2150. // //
  2151. // //
  2152. // // ;
  2153. // // }];
  2154. //
  2155. // }
  2156. // else
  2157. // {
  2158. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2159. // }
  2160. //
  2161. //
  2162. //
  2163. //
  2164. // });
  2165. // });
  2166. //
  2167. // }
  2168. //
  2169. //
  2170. //
  2171. // }];
  2172. //
  2173. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2174. // //DebugLog(@"Cancel");
  2175. //
  2176. //
  2177. // }];
  2178. // [alertControl addAction:actionOne];
  2179. //
  2180. // [alertControl addAction:alertthree];
  2181. //
  2182. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2183. //
  2184. //
  2185. //
  2186. //
  2187. // [self presentViewController:alertControl animated:YES completion:nil];
  2188. //
  2189. //
  2190. //
  2191. // }
  2192. // else
  2193. // {
  2194. // commit_order:
  2195. //
  2196. // {
  2197. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2198. //
  2199. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  2200. // {
  2201. //
  2202. // if(/*!self.have_tail*/ true)
  2203. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  2204. // [upparams setValue:@"false" forKey:@"isHold"];
  2205. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2206. //
  2207. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2208. //
  2209. // dispatch_async(dispatch_get_main_queue(), ^{
  2210. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2211. //
  2212. //
  2213. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2214. // {
  2215. //
  2216. // //debug bbb
  2217. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  2218. //
  2219. //
  2220. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2221. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  2222. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  2223. // // appDelegate.customerInfo = customerInfo;
  2224. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  2225. // // appDelegate.order_code = nil;
  2226. // [appDelegate closeOrder];
  2227. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2228. //
  2229. // NSString* title=nil;
  2230. // NSString* msg=nil;
  2231. //#ifdef OFFLINE_MODE
  2232. // if(appDelegate.offline_mode)
  2233. // {
  2234. // title=TITLE_OFFLINE_SUBMIT;
  2235. // msg=MSG_OFFLINE_SUBMIT;
  2236. // }
  2237. // else
  2238. //#endif
  2239. // {
  2240. // title=@"Order submitted sucessfully";
  2241. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2242. // }
  2243. //
  2244. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2245. //
  2246. // [alert show];
  2247. //
  2248. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2249. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  2250. // NSString* soid=[editor_json valueForKey:@"so#"];
  2251. //// if(pdf_url.length>0)
  2252. //// {
  2253. ////
  2254. //// [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2255. ////// [self downloadpdf:pdf_url];
  2256. ////
  2257. ////
  2258. //// if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  2259. //// {
  2260. //// //bbb
  2261. //// [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2262. //// }
  2263. ////
  2264. //// [self prepareReturn:nil];
  2265. ////
  2266. //// [self.navigationController popViewControllerAnimated:true];
  2267. ////
  2268. //// [appDelegate printPdf:pdf_url];
  2269. ////
  2270. ////// if(self.printPdfCallback)
  2271. ////// self.printPdfCallback(pdf_url);
  2272. //// }
  2273. //// else
  2274. // {
  2275. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2276. // {
  2277. // //bbb
  2278. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2279. // }
  2280. // [self prepareReturn:nil];
  2281. //
  2282. // [self.navigationController popViewControllerAnimated:true];
  2283. //
  2284. //
  2285. // if(pdf_url.length>0)
  2286. // {
  2287. //
  2288. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2289. //
  2290. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  2291. //
  2292. //
  2293. // }
  2294. //
  2295. //
  2296. // }
  2297. // // // self.labelContact.text=appDelegate.contact_name;
  2298. // //
  2299. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  2300. //
  2301. //
  2302. //
  2303. //
  2304. //
  2305. //
  2306. // }
  2307. // else
  2308. // {
  2309. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2310. // }
  2311. //
  2312. //
  2313. //
  2314. //
  2315. // });
  2316. // });
  2317. // }
  2318. // else
  2319. // {
  2320. // 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];
  2321. //
  2322. //
  2323. // alert.tag = KEEP_TAIL;
  2324. //
  2325. //
  2326. // self.upparams = upparams;
  2327. //
  2328. // [alert show];
  2329. // }
  2330. //
  2331. // }
  2332. // else
  2333. // { //USER_ROLE_CUSTOMER
  2334. //
  2335. // // if(self.have_tail)
  2336. // // [upparams setValue:@"true" forKey:@"isHold"];
  2337. // // else
  2338. // // [upparams setValue:@"false" forKey:@"isHold"];
  2339. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  2340. //
  2341. // [upparams setValue:@"true" forKey:@"isHold"];
  2342. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2343. //
  2344. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2345. //
  2346. // dispatch_async(dispatch_get_main_queue(), ^{
  2347. //
  2348. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2349. //
  2350. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2351. // {
  2352. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  2353. //
  2354. //
  2355. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2356. // // appDelegate.customerInfo = customerInfo;
  2357. //
  2358. //// NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  2359. //// appDelegate.order_code = orderCode;
  2360. //// appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  2361. // [appDelegate closeOrder];
  2362. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2363. //
  2364. // NSString* title=nil;
  2365. // NSString* msg=nil;
  2366. //#ifdef OFFLINE_MODE
  2367. // if(appDelegate.offline_mode)
  2368. // {
  2369. // title=TITLE_OFFLINE_SUBMIT;
  2370. // msg=MSG_OFFLINE_SUBMIT;
  2371. // }
  2372. // else
  2373. //#endif
  2374. // {
  2375. // title=@"Order submitted sucessfully";
  2376. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2377. // }
  2378. //
  2379. //
  2380. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2381. //
  2382. // [alert show];
  2383. // // // self.labelContact.text=appDelegate.contact_name;
  2384. // //
  2385. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  2386. // [self prepareReturn:nil];
  2387. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  2388. // //
  2389. // //
  2390. // // ;
  2391. // // }];
  2392. // [self.navigationController popViewControllerAnimated:true];
  2393. //
  2394. // }
  2395. // else
  2396. // {
  2397. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2398. // }
  2399. //
  2400. //
  2401. //
  2402. //
  2403. // });
  2404. // });
  2405. //
  2406. // }
  2407. // }
  2408. //
  2409. //
  2410. //
  2411. //
  2412. // }
  2413. //
  2414. }
  2415. // else if( alertView.tag == KEEP_TAIL)
  2416. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  2417. // if(buttonIndex!=alertView.cancelButtonIndex)
  2418. // {//keep tail;
  2419. //
  2420. // [self.upparams setValue:@"true" forKey:@"isHold"];
  2421. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2422. //
  2423. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  2424. //
  2425. // dispatch_async(dispatch_get_main_queue(), ^{
  2426. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2427. //
  2428. //
  2429. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2430. // {
  2431. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  2432. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2433. //
  2434. // [alert show];
  2435. //
  2436. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2437. // appDelegate.customerInfo = customerInfo;
  2438. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  2439. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  2440. // appDelegate.order_code = orderCode;
  2441. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2442. // // // self.labelContact.text=appDelegate.contact_name;
  2443. // //
  2444. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  2445. // [self prepareReturn:nil];
  2446. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  2447. ////
  2448. ////
  2449. //// ;
  2450. //// }];
  2451. // [self.navigationController popViewControllerAnimated:true];
  2452. //
  2453. // }
  2454. // else
  2455. // {
  2456. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  2457. // }
  2458. //
  2459. //
  2460. //
  2461. //
  2462. // });
  2463. // });
  2464. // }
  2465. // else
  2466. // {// not keep tail;
  2467. // [self.upparams setValue:@"false" forKey:@"isHold"];
  2468. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2469. //
  2470. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  2471. //
  2472. // dispatch_async(dispatch_get_main_queue(), ^{
  2473. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2474. //
  2475. //
  2476. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2477. // {
  2478. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  2479. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2480. //
  2481. // [alert show];
  2482. //
  2483. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2484. // // appDelegate.customerInfo = customerInfo;
  2485. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  2486. // // appDelegate.order_code = nil;
  2487. // [appDelegate closeOrder];
  2488. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2489. // // // self.labelContact.text=appDelegate.contact_name;
  2490. // //
  2491. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  2492. // [self prepareReturn:nil];
  2493. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  2494. ////
  2495. ////
  2496. //// ;
  2497. //// }];
  2498. // [self.navigationController popViewControllerAnimated:true];
  2499. //
  2500. // }
  2501. // else
  2502. // {
  2503. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  2504. // }
  2505. //
  2506. //
  2507. //
  2508. //
  2509. // });
  2510. // });
  2511. // }
  2512. // }
  2513. else if(alertView.tag == CLOSE_ACTION)
  2514. {
  2515. if(buttonIndex==1)
  2516. {
  2517. [self.navigationController popViewControllerAnimated:true];
  2518. // back to cart;
  2519. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  2520. // ;
  2521. // }];
  2522. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  2523. // appDelegate.order_code = nil;
  2524. //
  2525. // }
  2526. }
  2527. if(buttonIndex==2)
  2528. {
  2529. [self.navigationController popViewControllerAnimated:false];
  2530. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2531. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2532. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2533. // back to cart;
  2534. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  2535. // ;
  2536. // }];
  2537. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  2538. // appDelegate.order_code = nil;
  2539. //
  2540. // }
  2541. }
  2542. else if(buttonIndex==3)
  2543. {
  2544. // close order;
  2545. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2546. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  2547. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2548. NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  2549. dispatch_async(dispatch_get_main_queue(), ^{
  2550. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2551. if([[order_json valueForKey:@"result"] intValue]==2)
  2552. {
  2553. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2554. // appDelegate.order_code = nil;
  2555. [appDelegate closeOrder];
  2556. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2557. [((MainViewController*)appDelegate.main_vc) switchToHome];
  2558. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2559. {
  2560. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2561. }
  2562. [self prepareReturn:nil];
  2563. [self.navigationController popViewControllerAnimated:true];
  2564. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  2565. // ;
  2566. // }];
  2567. }
  2568. else
  2569. {
  2570. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  2571. }
  2572. });
  2573. });
  2574. //
  2575. // }
  2576. }
  2577. }
  2578. }
  2579. //
  2580. //
  2581. //-(void) downloadpdf:(NSString* )url
  2582. //{
  2583. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Printing..."];
  2584. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2585. //
  2586. //
  2587. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  2588. //
  2589. // //设置请求方式为get
  2590. //
  2591. // [request setHTTPMethod:@"GET"];
  2592. //
  2593. // //添加用户会话id
  2594. //
  2595. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  2596. //
  2597. // //连接发送请求
  2598. //
  2599. //
  2600. // NSHTTPURLResponse* urlResponse = nil;
  2601. //
  2602. // NSError *error = [[NSError alloc] init];
  2603. //
  2604. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  2605. //
  2606. // // self.filename = [urlResponse suggestedFilename];
  2607. //
  2608. //
  2609. // dispatch_async(dispatch_get_main_queue(), ^{
  2610. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2611. // // self.navigationItem.title = self.save_name;
  2612. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  2613. // // self.content=nil;
  2614. // if(content!=nil&&content.length>0)
  2615. // {
  2616. //
  2617. //
  2618. // [self startAirPrintWithData:content];
  2619. //
  2620. //
  2621. // }
  2622. // else
  2623. // {
  2624. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  2625. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  2626. // }
  2627. //
  2628. // ;
  2629. // // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  2630. // //
  2631. //
  2632. //
  2633. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  2634. //
  2635. //
  2636. //
  2637. //
  2638. // });
  2639. // });
  2640. //}
  2641. //
  2642. //- (void)startAirPrintWithData:(id )data
  2643. //{
  2644. //
  2645. //
  2646. //
  2647. //
  2648. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  2649. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  2650. // printInfo.outputType = UIPrintInfoOutputGeneral;
  2651. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  2652. // printInfo.jobName = @"CoolVisitAirPrint";
  2653. // airPrinterController.printInfo = printInfo;
  2654. // airPrinterController.printingItem = data;
  2655. // airPrinterController.delegate = self;
  2656. //
  2657. //
  2658. // airPrinterController.showsNumberOfCopies=true;
  2659. // airPrinterController.showsPageRange = true;
  2660. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  2661. //
  2662. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  2663. // if(completed && error)
  2664. // 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);
  2665. // };
  2666. //
  2667. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2668. //
  2669. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  2670. //
  2671. //
  2672. //
  2673. //
  2674. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  2675. // {
  2676. // if (available&& appDelegate.printerURL.length>0)
  2677. // {
  2678. //
  2679. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  2680. // DebugLog(@"AIRPRINTER AVAILABLE");
  2681. // }
  2682. // else
  2683. // {
  2684. //
  2685. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  2686. // //
  2687. // //
  2688. // //
  2689. // // // [printPicker presentAnimated:YES completionHandler:
  2690. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  2691. // // {
  2692. // // if (userDidSelect)
  2693. // // {
  2694. // // NSString* sid= printerController.printInfo.printerID;
  2695. // // UIPrintPaper*paper= printerController.printPaper;
  2696. // //
  2697. // // }
  2698. // // }];
  2699. //
  2700. //
  2701. // DebugLog(@"AIRPRINTER NOT AVAILABLE");
  2702. //
  2703. //
  2704. //
  2705. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  2706. // {
  2707. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  2708. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  2709. //
  2710. //
  2711. //
  2712. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  2713. //
  2714. //
  2715. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  2716. //
  2717. //
  2718. //
  2719. // // [printPicker presentAnimated:YES completionHandler:
  2720. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  2721. // {
  2722. // if (userDidSelect)
  2723. // {
  2724. // //User selected the item in the UIPrinterPickerController and got the printer details.
  2725. //
  2726. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  2727. //
  2728. // //Here you will get the printer and printer details.ie,
  2729. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  2730. //
  2731. //
  2732. //
  2733. //
  2734. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  2735. //
  2736. // [self startAirPrintWithData:data];
  2737. //
  2738. // }
  2739. // else
  2740. // {
  2741. //
  2742. //
  2743. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2744. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  2745. // {
  2746. //
  2747. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2748. // }
  2749. // [self prepareReturn:nil];
  2750. //
  2751. // [self.navigationController popViewControllerAnimated:true];
  2752. // }
  2753. // }];
  2754. // }
  2755. // }
  2756. // }];
  2757. //
  2758. //
  2759. //
  2760. //}
  2761. //
  2762. //#pragma mark - UIPrintInteractionControllerDelegate
  2763. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  2764. //{
  2765. //
  2766. // ;
  2767. //
  2768. // // (int) width = 29700
  2769. // // Printing description of (*( (int *)0x7caa3a40)):
  2770. // // (int) height = 42000
  2771. // //设置纸张大小
  2772. //
  2773. //
  2774. // for(UIPrintPaper* paper in paperList)
  2775. // {
  2776. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  2777. // return paper;
  2778. //
  2779. // }
  2780. // CGSize paperSize = CGSizeMake(612, 792);
  2781. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  2782. // return p;
  2783. //}
  2784. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  2785. //{
  2786. //
  2787. //}
  2788. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  2789. //{
  2790. //
  2791. //}
  2792. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  2793. //{
  2794. //
  2795. //}
  2796. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  2797. //{
  2798. //
  2799. //}
  2800. //
  2801. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  2802. //{
  2803. //
  2804. //}
  2805. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  2806. //{
  2807. //
  2808. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2809. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  2810. // {
  2811. //
  2812. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2813. // }
  2814. //
  2815. // [self prepareReturn:nil];
  2816. //
  2817. // [self.navigationController popViewControllerAnimated:true];
  2818. //}
  2819. //
  2820. //- (NSString *)currentPriceTypeName {
  2821. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  2822. //
  2823. // NSString* pricename = nil;
  2824. // switch (priceType) {
  2825. // case 0:
  2826. // pricename=[Singleton sharedInstance].deliveryString;
  2827. // break;
  2828. // case 1:
  2829. // pricename=flat_price;
  2830. // break;
  2831. // case 2:
  2832. // pricename=given_price;
  2833. // break;
  2834. // default:
  2835. // break;
  2836. // }
  2837. // return pricename;
  2838. //}
  2839. - (void)releaseOrderAfterSave {
  2840. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2841. [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  2842. [appDelegate closeOrder];
  2843. [appDelegate SetSo:nil];
  2844. appDelegate.cart_count=0;
  2845. [appDelegate update_count_mark];
  2846. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2847. [self prepareReturn:nil];
  2848. [self.navigationController popToRootViewControllerAnimated:false];
  2849. }
  2850. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  2851. {
  2852. NSString* ret=nil;
  2853. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  2854. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  2855. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  2856. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  2857. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  2858. if(customer_address1.length>0)
  2859. [arraddr addObject:customer_address1];
  2860. if(customer_address2.length>0)
  2861. [arraddr addObject:customer_address2];
  2862. if(customer_address3.length>0)
  2863. [arraddr addObject:customer_address3];
  2864. if(customer_address4.length>0)
  2865. [arraddr addObject:customer_address4];
  2866. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  2867. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  2868. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  2869. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  2870. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  2871. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  2872. if(customer_city.length>0)
  2873. [arrcty addObject:customer_city];
  2874. if(customer_state.length>0)
  2875. [arrcty addObject:customer_state];
  2876. if(customer_zipcode.length>0)
  2877. [arrcty addObject:customer_zipcode];
  2878. if(customer_country.length>0)
  2879. [arrcty addObject:customer_country];
  2880. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  2881. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  2882. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  2883. //
  2884. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  2885. // if(customer_phone.length>0)
  2886. // {
  2887. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  2888. // [arrpho addObject:customer_phone];
  2889. // }
  2890. // if(customer_fax.length>0)
  2891. // {
  2892. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  2893. // [arrpho addObject:customer_fax];
  2894. // }
  2895. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  2896. //
  2897. //
  2898. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  2899. // if(customer_contact.length>0)
  2900. // {
  2901. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  2902. //
  2903. // }
  2904. // NSString *contact_string = customer_contact;
  2905. //
  2906. //
  2907. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  2908. // if(customer_email.length>0)
  2909. // {
  2910. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  2911. //
  2912. // }
  2913. // NSString *email_string = customer_email;
  2914. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  2915. if(addr_string.length>0)
  2916. [arrext addObject:addr_string];
  2917. if(cty_string.length>0)
  2918. [arrext addObject:cty_string];
  2919. // if(phone_string.length>0)
  2920. // [arrext addObject:phone_string];
  2921. // if(contact_string.length>0)
  2922. // [arrext addObject:contact_string];
  2923. // if(email_string.length>0)
  2924. // [arrext addObject:email_string];
  2925. ret = [arrext componentsJoinedByString:@"\r\n"];
  2926. // NSString *string = [array componentsJoinedByString:@" "];
  2927. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  2928. return ret;
  2929. }
  2930. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  2931. {
  2932. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  2933. NSArray *keys= [key_map allKeys];
  2934. //遍历keys
  2935. for(int i=0;i<[keys count];i++)
  2936. {
  2937. //得到当前key
  2938. NSString *key=[keys objectAtIndex:i];
  2939. //如果key不是pic,说明value是字符类型,比如name:Boris
  2940. NSString* valuefrom = [key_map valueForKey:key];
  2941. if(valuefrom.length==0)
  2942. continue;
  2943. NSString* value=[self getValue:valuefrom];
  2944. [ret setValue:value forKey:valuefrom];
  2945. }
  2946. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  2947. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  2948. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  2949. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  2950. return ret;
  2951. }
  2952. -(NSMutableDictionary*)create_cusromer_info_from_table
  2953. {
  2954. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2955. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  2956. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  2957. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  2958. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  2959. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  2960. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  2961. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  2962. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  2963. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  2964. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  2965. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  2966. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  2967. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  2968. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  2969. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  2970. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  2971. NSString * firstname =nil;
  2972. NSString* lastname = nil;
  2973. NSString* contact_name = [self getValue:@"customer_contact"];
  2974. if(contact_name!=nil)
  2975. {
  2976. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  2977. if(_arr.count>=1)
  2978. {
  2979. firstname =_arr[0];
  2980. if(_arr.count>1)
  2981. {
  2982. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  2983. }
  2984. }
  2985. }
  2986. [ret setValue:firstname forKey:@"customer_first_name"];
  2987. [ret setValue:lastname forKey:@"customer_last_name"];
  2988. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  2989. return ret;
  2990. }
  2991. #pragma mark - multi_action sub action clicked
  2992. - (void)MActionClicked:(UIButton *)sender {
  2993. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  2994. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  2995. int refresh =0;
  2996. NSMutableDictionary* section_json=nil;
  2997. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  2998. NSString* subid=[item_json valueForKey:@"subid"];
  2999. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  3000. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  3001. NSString* type = [sub_action valueForKey:@"type"];
  3002. if([type isEqualToString:@"pull"])
  3003. {
  3004. [self.lastedit endEditing:true];
  3005. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  3006. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  3007. NSMutableDictionary* value=[self create_value_map:keymap];
  3008. if(subid==nil)
  3009. {
  3010. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  3011. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3012. int icount=[[section_json valueForKey:@"count"] intValue];
  3013. for (int ic=0;ic<icount;ic++)
  3014. {
  3015. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  3016. NSString* mapto = [modify_item valueForKey:@"name"];
  3017. if(mapto.length==0)
  3018. continue;
  3019. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  3020. if(valuefrom==nil)
  3021. continue;
  3022. NSString* valuestr=[value valueForKey:valuefrom];
  3023. // valuestr = [self getValue:valuefrom];
  3024. if(true)
  3025. {
  3026. if(valuestr.length>0) {
  3027. NSString *control = [modify_item objectForKey:@"control"];
  3028. if ([control isEqualToString:@"enum"]) {
  3029. NSMutableDictionary *cadedate = [[modify_item objectForKey:@"cadedate"] mutableCopy];
  3030. int count = [[cadedate objectForKey:@"count"] intValue];
  3031. for (int i = 0; i < count; i++) {
  3032. NSString *key = [NSString stringWithFormat:@"val_%d",i];
  3033. NSMutableDictionary *val = [[cadedate objectForKey:key] mutableCopy];
  3034. int check = [[val objectForKey:@"check"] intValue];
  3035. NSString *val_id = [val objectForKey:@"value_id"];
  3036. NSString *val_value = [val objectForKey:@"value"];
  3037. // state 通过id判断, country 通过value判断
  3038. if (check == 1 && (![val_id isEqualToString:valuestr] && ![val_value isEqualToString:valuestr])) {
  3039. check = 0;
  3040. [val setObject:@(check) forKey:@"check"];
  3041. [cadedate setObject:val forKey:key];
  3042. }
  3043. if ([val_id isEqualToString:valuestr] || [val_value isEqualToString:valuestr]) {
  3044. check = 1;
  3045. [val setObject:@(check) forKey:@"check"];
  3046. [cadedate setObject:val forKey:key];
  3047. }
  3048. }
  3049. [modify_item setObject:cadedate forKey:@"cadedate"];
  3050. } else {
  3051. [modify_item setValue:valuestr forKey:@"value"];
  3052. }
  3053. }
  3054. else {
  3055. [modify_item setValue:@"" forKey:@"value"];
  3056. }
  3057. [modify_item setValue:@"true" forKey:@"dirty"];
  3058. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  3059. }
  3060. }
  3061. }
  3062. else
  3063. {
  3064. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3065. int section = [(NSString*)idarr[0] intValue];
  3066. int item=[(NSString*)idarr[1] intValue];
  3067. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  3068. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3069. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  3070. NSString* control_type = [olditem valueForKey:@"control"];
  3071. if([control_type isEqualToString:@"switch"])
  3072. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  3073. else if([control_type isEqualToString:@"enum"])
  3074. {
  3075. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  3076. }
  3077. else
  3078. {
  3079. [RAUtils alert_view:@"" title:@"not impl"];
  3080. }
  3081. [olditem setValue:@"true" forKey:@"dirty"];
  3082. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3083. }
  3084. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3085. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  3086. if(refresh==1)
  3087. {
  3088. // if(restore_json!=nil)
  3089. // {
  3090. // int rc=[[restore_json valueForKey:@"count"] intValue];
  3091. // for(int ir=0;ir<rc;ir++)
  3092. // {
  3093. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  3094. //
  3095. //
  3096. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  3097. // for(int i=0;i<section_count;i++)
  3098. // {
  3099. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  3100. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  3101. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  3102. // for(int j=0;j<item_count;j++)
  3103. // {
  3104. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  3105. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  3106. //
  3107. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  3108. // {
  3109. // [itemjson removeObjectForKey:@"dirty"];
  3110. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  3111. // }
  3112. //
  3113. // }
  3114. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  3115. // }
  3116. //
  3117. //
  3118. // }
  3119. //
  3120. // }
  3121. [self refresh:refresh_trigger] ;
  3122. return ;
  3123. }
  3124. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  3125. [self.editorTable reloadData ];
  3126. }
  3127. else
  3128. {
  3129. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3130. NSDictionary * item_json = sub_action;
  3131. NSString* value = [item_json valueForKey:@"value"];
  3132. if([value isEqualToString:@"new_addr"])
  3133. {
  3134. AddressEditorViewController * addressVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
  3135. addressVC.url_type = URL_REMOTE;
  3136. addressVC.request_url=URL_ADDRESS_EDOTOR;
  3137. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  3138. // NSString * string = [checked componentsJoinedByString:@","];
  3139. // [params setValue:string forKey:@"cart2Checkbox"];
  3140. params[@"is_subaction"]=@"true";
  3141. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  3142. addressVC.params = params;
  3143. addressVC.delegate = self;
  3144. addressVC.from = indexPath;
  3145. // orderinfoVC.params = params;
  3146. [self.navigationController pushViewController:addressVC animated:true];
  3147. }else if([value isEqualToString:@"credit_card"])
  3148. {
  3149. CreditCardEditorViewController * cardVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreditCardEditorViewController"];
  3150. NSDictionary *data = [item_json objectForKey:@"data"];
  3151. if(data!=nil)
  3152. {
  3153. cardVC.content_data_download = [data mutableCopy];
  3154. cardVC.url_type = URL_NONE;
  3155. cardVC.request_url=nil;
  3156. }
  3157. else
  3158. {
  3159. cardVC.url_type = URL_REMOTE;
  3160. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  3161. }
  3162. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  3163. params[@"orderCode"]=appDelegate.order_code;
  3164. params[@"is_subaction"]=@"true";
  3165. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  3166. cardVC.params = params;
  3167. cardVC.delegate = self;
  3168. cardVC.from = indexPath;
  3169. // orderinfoVC.params = params;
  3170. [self.navigationController pushViewController:cardVC animated:true];
  3171. }
  3172. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  3173. {
  3174. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  3175. cvc.showNavibar = true;
  3176. cvc.contact_type = value;
  3177. cvc.is_subaction = @"true";
  3178. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  3179. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  3180. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  3181. //
  3182. // if(self.returnValue)
  3183. // self.returnValue(value);
  3184. };
  3185. [self.navigationController pushViewController:cvc animated:true];
  3186. }
  3187. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  3188. {
  3189. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  3190. cvc.showNavibar = true;
  3191. cvc.contact_type = value;
  3192. cvc.is_subaction = @"true";
  3193. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  3194. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  3195. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  3196. //
  3197. // if(self.returnValue)
  3198. // self.returnValue(value);
  3199. };
  3200. [self.navigationController pushViewController:cvc animated:true];
  3201. }
  3202. else if([value isEqualToString:@"Sales_Order_Customer"])
  3203. {
  3204. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  3205. cvc.is_subaction = @"true";
  3206. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  3207. cvc.showNavibar = true;
  3208. cvc.contact_type = value;
  3209. __weak typeof(self) weakself = self;
  3210. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  3211. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  3212. //
  3213. // if(self.returnValue)
  3214. // self.returnValue(value);
  3215. };
  3216. [self.navigationController pushViewController:cvc animated:true];
  3217. }
  3218. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  3219. {
  3220. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  3221. cvc.showNavibar = true;
  3222. cvc.contact_type = value;
  3223. cvc.is_subaction = @"true";
  3224. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  3225. __weak typeof(self) weakself = self;
  3226. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  3227. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  3228. //
  3229. // if(self.returnValue)
  3230. // self.returnValue(value);
  3231. };
  3232. [self.navigationController pushViewController:cvc animated:true];
  3233. }
  3234. else if([value isEqualToString:@"Contact_Return_To"])
  3235. {
  3236. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  3237. cvc.is_subaction = @"true";
  3238. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  3239. cvc.showNavibar = true;
  3240. cvc.contact_type = value;
  3241. __weak typeof(self) weakself = self;
  3242. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  3243. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  3244. //
  3245. // if(self.returnValue)
  3246. // self.returnValue(value);
  3247. };
  3248. [self.navigationController pushViewController:cvc animated:true];
  3249. }
  3250. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  3251. {
  3252. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  3253. cvc.is_subaction = @"true";
  3254. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  3255. cvc.showNavibar = true;
  3256. cvc.contact_type = value;
  3257. __weak typeof(self) weakself = self;
  3258. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  3259. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  3260. //
  3261. // if(self.returnValue)
  3262. // self.returnValue(value);
  3263. };
  3264. [self.navigationController pushViewController:cvc animated:true];
  3265. }
  3266. }
  3267. }
  3268. #pragma mark - Urgency
  3269. -(void) viewWillDisappear:(BOOL)animated
  3270. {
  3271. [super viewWillDisappear:animated];
  3272. [self cancel_urgency_timer];
  3273. }
  3274. - (void)start_urgency_timer {
  3275. if (!self.editable) {
  3276. return;
  3277. }
  3278. __weak typeof(self) weakSelf = self;
  3279. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  3280. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  3281. #ifdef OFFLINE_MODE
  3282. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  3283. #endif
  3284. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  3285. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  3286. // DebugLog(@"timer start....");
  3287. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  3288. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  3289. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  3290. // CreateOrderViewController
  3291. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  3292. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  3293. NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  3294. [urgencyDic setValue:so forKey:@"order_so"];
  3295. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  3296. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  3297. }
  3298. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  3299. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  3300. }];
  3301. }
  3302. - (void)cancel_urgency_timer {
  3303. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  3304. }
  3305. #pragma mark - Submit Order
  3306. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  3307. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  3308. [upparams setValue:@"true" forKey:@"isHold"];
  3309. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3310. NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  3311. dispatch_async(dispatch_get_main_queue(), ^{
  3312. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  3313. if([[editor_json valueForKey:@"result"] intValue]==2)
  3314. {
  3315. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3316. // appDelegate.customerInfo = customerInfo;
  3317. [appDelegate closeOrder];
  3318. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3319. NSString* title=nil;
  3320. NSString* msg=nil;
  3321. #ifdef OFFLINE_MODE
  3322. if(appDelegate.offline_mode)
  3323. {
  3324. title=TITLE_OFFLINE_SUBMIT;
  3325. msg=MSG_OFFLINE_SUBMIT;
  3326. }
  3327. else
  3328. #endif
  3329. {
  3330. title=@"Order submitted sucessfully";
  3331. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  3332. }
  3333. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  3334. [alert show];
  3335. [self prepareReturn:nil];
  3336. [self.navigationController popToRootViewControllerAnimated:true];
  3337. }
  3338. else
  3339. {
  3340. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  3341. }
  3342. });
  3343. });
  3344. }
  3345. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  3346. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  3347. [upparams setValue:@"false" forKey:@"isHold"];
  3348. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3349. NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  3350. dispatch_async(dispatch_get_main_queue(), ^{
  3351. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  3352. if([[editor_json valueForKey:@"result"] intValue]==2)
  3353. {
  3354. // debug aaa
  3355. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3356. NSString* company= appDelegate.customerInfo[@"customer_name"];
  3357. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  3358. [appDelegate closeOrder];
  3359. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3360. NSString* title=nil;
  3361. NSString* msg=nil;
  3362. #ifdef OFFLINE_MODE
  3363. if(appDelegate.offline_mode)
  3364. {
  3365. title=TITLE_OFFLINE_SUBMIT;
  3366. msg=MSG_OFFLINE_SUBMIT;
  3367. }
  3368. else
  3369. #endif
  3370. {
  3371. title=@"Order submitted sucessfully";
  3372. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  3373. }
  3374. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  3375. [alert show];
  3376. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  3377. NSString* email_content =[editor_json valueForKey:@"email_content"];
  3378. NSString* soid=[editor_json valueForKey:@"so#"];
  3379. {
  3380. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  3381. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  3382. {
  3383. //bbb
  3384. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  3385. value[@"commitorder_logout"]=@"true";
  3386. }
  3387. [self prepareReturn:value];
  3388. [self.navigationController popToRootViewControllerAnimated:true];
  3389. if(pdf_url.length>0)
  3390. {
  3391. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  3392. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  3393. // [appDelegate printPdf:pdf_url];
  3394. }
  3395. }
  3396. }
  3397. else
  3398. {
  3399. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  3400. }
  3401. });
  3402. });
  3403. }
  3404. -(void) handle_action_return:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath action:(int) action_code
  3405. {
  3406. DebugLog(@"commoneditor return %ld_%ld",(long)indexPath.section,(long)indexPath.row);
  3407. NSMutableDictionary* section_json=nil;
  3408. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  3409. bool is_subaction = [value[@"is_subaction"] boolValue];
  3410. int subaction_tag= [value[@"subaction_tag"] intValue];
  3411. [value removeObjectForKey:@"is_subaction"];
  3412. [value removeObjectForKey:@"subaction_tag"];
  3413. if(is_subaction)
  3414. {
  3415. NSMutableDictionary* sub_action = [[item_json objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
  3416. int refresh = [[sub_action valueForKey:@"refresh"] intValue];
  3417. NSString* refresh_trigger = [sub_action valueForKey:@"name"];
  3418. NSDictionary * restore_json=[sub_action objectForKeyedSubscript:@"restore"];
  3419. NSString* subid=[sub_action valueForKey:@"subid"];
  3420. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  3421. NSString* required = [sub_action valueForKey:@"required"];
  3422. if([required isEqualToString:@"true"] && value.count==0)
  3423. {
  3424. CALayer *layer = [cell.contentView layer];
  3425. // layer.borderColor = [[UIColor redColor] CGColor];
  3426. // layer.borderWidth = 1.0;
  3427. layer.shadowColor = [UIColor redColor].CGColor;
  3428. layer.shadowOffset = CGSizeMake(0, 0);
  3429. layer.shadowOpacity = 1;
  3430. layer.shadowRadius = 2.0;
  3431. }
  3432. else
  3433. {
  3434. CALayer *layer = [cell.contentView layer];
  3435. // layer.borderColor = [[UIColor redColor] CGColor];
  3436. // layer.borderWidth = 1.0;
  3437. layer.shadowColor = [UIColor clearColor].CGColor;
  3438. layer.shadowOffset = CGSizeMake(0, 0);
  3439. layer.shadowOpacity = 1;
  3440. layer.shadowRadius = 2.0;
  3441. }
  3442. if(value.count!=0)
  3443. {
  3444. if(action_code==ACTION_SAVE_DATA)
  3445. {
  3446. [sub_action setObject:value forKey:@"data"];
  3447. if(subid==nil)
  3448. {
  3449. [sub_action setValue:@"true" forKey:@"dirty"];
  3450. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3451. int count=0;
  3452. count=[[section_json valueForKey:@"count"] intValue];
  3453. for(int i=0;i<count;i++)
  3454. {
  3455. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  3456. if([[olditem valueForKey:@"name"] isEqualToString:[sub_action valueForKey:@"name" ]])
  3457. {
  3458. // sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  3459. [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  3460. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  3461. }
  3462. }
  3463. }
  3464. else
  3465. {
  3466. assert(@"not impl");
  3467. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3468. int section = [(NSString*)idarr[0] intValue];
  3469. int item=[(NSString*)idarr[1] intValue];
  3470. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3471. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  3472. sub_action= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:sub_action step:2];
  3473. [sub_action setValue:@"true" forKey:@"dirty"];
  3474. [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  3475. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3476. }
  3477. }
  3478. else if(action_code==ACTION_FILL_SECTION)
  3479. {
  3480. if(subid==nil)
  3481. {
  3482. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  3483. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3484. int icount=[[section_json valueForKey:@"count"] intValue];
  3485. for (int ic=0;ic<icount;ic++)
  3486. {
  3487. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  3488. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  3489. NSString* valuestr= [value valueForKey:valuefrom];
  3490. if(valuestr !=nil)
  3491. {
  3492. // 2018-01-19 Place Order Select Ship To未刷新State Enum
  3493. NSString *control = [modify_item objectForKey:@"control"];
  3494. if ([control isEqualToString:@"enum"]) {
  3495. NSMutableDictionary *cadedate = [[modify_item objectForKey:@"cadedate"] mutableCopy];
  3496. int count = [[cadedate objectForKey:@"count"] intValue];
  3497. for (int i = 0; i < count; i++) {
  3498. NSString *key = [NSString stringWithFormat:@"val_%d",i];
  3499. NSMutableDictionary *val = [[cadedate objectForKey:key] mutableCopy];
  3500. int check = [[val objectForKey:@"check"] intValue];
  3501. NSString *val_id = [val objectForKey:@"value_id"];
  3502. NSString *val_value = [val objectForKey:@"value"];
  3503. // state 通过id判断, country 通过value判断
  3504. if (check == 1 && (![val_id isEqualToString:valuestr] && ![val_value isEqualToString:valuestr])) {
  3505. check = 0;
  3506. [val setObject:@(check) forKey:@"check"];
  3507. [cadedate setObject:val forKey:key];
  3508. }
  3509. if ([val_id isEqualToString:valuestr] || [val_value isEqualToString:valuestr]) {
  3510. check = 1;
  3511. [val setObject:@(check) forKey:@"check"];
  3512. [cadedate setObject:val forKey:key];
  3513. }
  3514. }
  3515. [modify_item setObject:cadedate forKey:@"cadedate"];
  3516. } else {
  3517. [modify_item setValue:valuestr forKey:@"value"];
  3518. }
  3519. // [modify_item setValue:valuestr forKey:@"value"];
  3520. [modify_item setValue:@"true" forKey:@"dirty"];
  3521. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  3522. }
  3523. }
  3524. }
  3525. else
  3526. {
  3527. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3528. int section = [(NSString*)idarr[0] intValue];
  3529. int item=[(NSString*)idarr[1] intValue];
  3530. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  3531. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3532. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  3533. NSMutableDictionary* olditem_sub_action = [[olditem objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
  3534. olditem_sub_action= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  3535. [olditem_sub_action setValue:@"true" forKey:@"dirty"];
  3536. [olditem setObject:olditem_sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  3537. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3538. }
  3539. }
  3540. // [section_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  3541. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3542. }
  3543. DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
  3544. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  3545. if(refresh==1)
  3546. {
  3547. if(restore_json!=nil)
  3548. {
  3549. int rc=[[restore_json valueForKey:@"count"] intValue];
  3550. for(int ir=0;ir<rc;ir++)
  3551. {
  3552. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  3553. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  3554. for(int i=0;i<section_count;i++)
  3555. {
  3556. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  3557. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  3558. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  3559. for(int j=0;j<item_count;j++)
  3560. {
  3561. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  3562. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  3563. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  3564. {
  3565. [itemjson removeObjectForKey:@"dirty"];
  3566. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  3567. }
  3568. }
  3569. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  3570. }
  3571. }
  3572. }
  3573. [self refresh:refresh_trigger] ;
  3574. return ;
  3575. }
  3576. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  3577. [self.editorTable reloadData ];
  3578. }
  3579. else
  3580. {
  3581. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  3582. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  3583. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  3584. NSString* subid=[item_json valueForKey:@"subid"];
  3585. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  3586. NSString* required = [item_json valueForKey:@"required"];
  3587. if([required isEqualToString:@"true"] && value.count==0)
  3588. {
  3589. CALayer *layer = [cell.contentView layer];
  3590. // layer.borderColor = [[UIColor redColor] CGColor];
  3591. // layer.borderWidth = 1.0;
  3592. layer.shadowColor = [UIColor redColor].CGColor;
  3593. layer.shadowOffset = CGSizeMake(0, 0);
  3594. layer.shadowOpacity = 1;
  3595. layer.shadowRadius = 2.0;
  3596. }
  3597. else
  3598. {
  3599. CALayer *layer = [cell.contentView layer];
  3600. // layer.borderColor = [[UIColor redColor] CGColor];
  3601. // layer.borderWidth = 1.0;
  3602. layer.shadowColor = [UIColor clearColor].CGColor;
  3603. layer.shadowOffset = CGSizeMake(0, 0);
  3604. layer.shadowOpacity = 1;
  3605. layer.shadowRadius = 2.0;
  3606. }
  3607. if(value.count!=0)
  3608. {
  3609. if(action_code==ACTION_SAVE_DATA)
  3610. {
  3611. [item_json setObject:value forKey:@"data"];
  3612. if(subid==nil)
  3613. {
  3614. [item_json setValue:@"true" forKey:@"dirty"];
  3615. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3616. int count=0;
  3617. count=[[section_json valueForKey:@"count"] intValue];
  3618. for(int i=0;i<count;i++)
  3619. {
  3620. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  3621. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  3622. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  3623. }
  3624. }
  3625. else
  3626. {
  3627. assert(@"not impl");
  3628. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3629. int section = [(NSString*)idarr[0] intValue];
  3630. int item=[(NSString*)idarr[1] intValue];
  3631. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3632. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  3633. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  3634. [item_json setValue:@"true" forKey:@"dirty"];
  3635. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3636. }
  3637. }
  3638. else if(action_code==ACTION_FILL_SECTION)
  3639. {
  3640. if(subid==nil)
  3641. {
  3642. NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
  3643. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  3644. int icount=[[section_json valueForKey:@"count"] intValue];
  3645. for (int ic=0;ic<icount;ic++)
  3646. {
  3647. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  3648. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  3649. NSString* valuestr= [value valueForKey:valuefrom];
  3650. if(valuestr !=nil)
  3651. {
  3652. [modify_item setValue:valuestr forKey:@"value"];
  3653. [modify_item setValue:@"true" forKey:@"dirty"];
  3654. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  3655. }
  3656. }
  3657. }
  3658. else
  3659. {
  3660. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  3661. int section = [(NSString*)idarr[0] intValue];
  3662. int item=[(NSString*)idarr[1] intValue];
  3663. NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
  3664. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  3665. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  3666. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  3667. [olditem setValue:@"true" forKey:@"dirty"];
  3668. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  3669. }
  3670. }
  3671. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  3672. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  3673. }
  3674. DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
  3675. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  3676. if(refresh==1)
  3677. {
  3678. if(restore_json!=nil)
  3679. {
  3680. int rc=[[restore_json valueForKey:@"count"] intValue];
  3681. for(int ir=0;ir<rc;ir++)
  3682. {
  3683. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  3684. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  3685. for(int i=0;i<section_count;i++)
  3686. {
  3687. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  3688. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  3689. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  3690. for(int j=0;j<item_count;j++)
  3691. {
  3692. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  3693. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  3694. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  3695. {
  3696. [itemjson removeObjectForKey:@"dirty"];
  3697. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  3698. }
  3699. }
  3700. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  3701. }
  3702. }
  3703. }
  3704. [self refresh:refresh_trigger] ;
  3705. return ;
  3706. }
  3707. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  3708. [self.editorTable reloadData ];
  3709. }
  3710. }
  3711. @end