RAOrderPreviewController.m 180 KB

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