RAOrderPreviewController.m 180 KB

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