CreateOrderViewController.m 164 KB

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