RAOrderPreviewController.m 163 KB

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