RAOrderPreviewController.m 186 KB

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