CreateOrderViewController.m 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976
  1. //
  2. // CreateOrderViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/24/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CreateOrderViewController.h"
  9. #import "RANetwork.h"
  10. #import "MainViewController.h"
  11. #import "RASingleton.h"
  12. #import "config.h"
  13. #import "CustomIOSAlertView.h"
  14. #import "AddressEditorViewController.h"
  15. #import "CreditCardEditorViewController.h"
  16. #import "JKTimerManager.h"
  17. #import "ZipArchive.h"
  18. #define SUBMIT_CONFIRM 123
  19. #define KEEP_TAIL 456
  20. #define CLOSE_ACTION 567
  21. @interface CreateOrderViewController ()
  22. // static const char associatedkey;
  23. @property (nonatomic,assign) BOOL isResume;///<恢复
  24. @property (nonatomic,assign) NSInteger userType;///<恢复使用
  25. @end
  26. @implementation CreateOrderViewController
  27. - (void)alertMessage:(NSString *)msg {
  28. if (notifyMe_switch) {
  29. if ([self.class_name isEqualToString:@"CreateOrderViewController"]) {
  30. NSString *err_msg = msg;
  31. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Attention!!" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
  32. __weak typeof(self) weakself = self;
  33. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  34. [weakself.navigationController popViewControllerAnimated:YES];
  35. }];
  36. [alertVC addAction:action];
  37. [self presentViewController:alertVC animated:YES completion:nil];
  38. } else {
  39. [RAUtils message_alert:msg title:nil controller:self] ;
  40. }
  41. } else {
  42. [RAUtils message_alert:msg title:nil controller:self] ;
  43. }
  44. }
  45. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  46. {
  47. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  48. if([value isEqualToString:@"new_addr"])
  49. {
  50. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  51. addressVC.url_type = URL_REMOTE;
  52. addressVC.request_url=URL_ADDRESS_EDOTOR;
  53. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  54. // NSString * string = [checked componentsJoinedByString:@","];
  55. // [params setValue:string forKey:@"cart2Checkbox"];
  56. addressVC.params = params;
  57. addressVC.delegate = self;
  58. addressVC.from = indexPath;
  59. // orderinfoVC.params = params;
  60. [self.navigationController pushViewController:addressVC animated:true];
  61. }else if([value isEqualToString:@"credit_card"])
  62. {
  63. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  64. NSDictionary *data = [item_json objectForKey:@"data"];
  65. if(data!=nil)
  66. {
  67. cardVC.content_data_download = [data mutableCopy];
  68. cardVC.url_type = URL_NONE;
  69. cardVC.request_url=nil;
  70. }
  71. else
  72. {
  73. cardVC.url_type = URL_REMOTE;
  74. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  75. }
  76. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  77. params[@"orderCode"]=appDelegate.order_code;
  78. cardVC.params = params;
  79. cardVC.delegate = self;
  80. cardVC.from = indexPath;
  81. // orderinfoVC.params = params;
  82. [self.navigationController pushViewController:cardVC animated:true];
  83. }
  84. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  85. {
  86. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  87. cvc.showNavibar = true;
  88. cvc.contact_type = value;
  89. __weak typeof(self) weakself = self;
  90. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  91. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  92. //
  93. // if(self.returnValue)
  94. // self.returnValue(value);
  95. };
  96. [self.navigationController pushViewController:cvc animated:true];
  97. }
  98. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  99. {
  100. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  101. cvc.showNavibar = true;
  102. cvc.contact_type = value;
  103. __weak typeof(self) weakself = self;
  104. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  105. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  106. //
  107. // if(self.returnValue)
  108. // self.returnValue(value);
  109. };
  110. [self.navigationController pushViewController:cvc animated:true];
  111. }
  112. else if([value isEqualToString:@"Sales_Order_Customer"])
  113. {
  114. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  115. cvc.contact_type = value;
  116. cvc.showNavibar = true;
  117. __weak typeof(self) weakself = self;
  118. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  119. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  120. //
  121. // if(self.returnValue)
  122. // self.returnValue(value);
  123. };
  124. [self.navigationController pushViewController:cvc animated:true];
  125. }
  126. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  127. {
  128. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  129. cvc.showNavibar = true;
  130. cvc.contact_type = value;
  131. __weak typeof(self) weakself = self;
  132. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  133. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  134. //
  135. // if(self.returnValue)
  136. // self.returnValue(value);
  137. };
  138. [self.navigationController pushViewController:cvc animated:true];
  139. }
  140. else if([value isEqualToString:@"Contact_Return_To"])
  141. {
  142. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  143. cvc.showNavibar = true;
  144. cvc.contact_type = value;
  145. __weak typeof(self) weakself = self;
  146. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  147. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  148. //
  149. // if(self.returnValue)
  150. // self.returnValue(value);
  151. };
  152. [self.navigationController pushViewController:cvc animated:true];
  153. }
  154. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  155. {
  156. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  157. cvc.showNavibar = true;
  158. cvc.contact_type = value;
  159. __weak typeof(self) weakself = self;
  160. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  161. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  162. //
  163. // if(self.returnValue)
  164. // self.returnValue(value);
  165. };
  166. [self.navigationController pushViewController:cvc animated:true];
  167. }
  168. }
  169. - (void)dealloc {
  170. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  171. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  172. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  173. if (self.isResume && self.userType == USER_ROLE_CUSTOMER) {
  174. [self releaseOrderAfterSave];
  175. }
  176. }
  177. -(void) viewWillAppear:(BOOL)animated
  178. {
  179. [super viewWillAppear:animated];
  180. [self start_urgency_timer];
  181. self.isResume = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_resume"] boolValue];
  182. self.userType = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_userType"] integerValue];
  183. BOOL canSubmit = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_submitOrder"] boolValue];
  184. // 检查权限
  185. NSMutableArray * items = [[NSMutableArray alloc]init];
  186. UIBarButtonItem *savebtn = nil;
  187. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  188. style:UIBarButtonItemStylePlain
  189. target:self
  190. action:@selector(onSaveClick:)];
  191. UIImage *submit_img = [[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
  192. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  193. submit_img = [[UIImage imageNamed:@"submit_red"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  194. #endif
  195. self.btnSubmitOrder = nil;
  196. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:submit_img
  197. style:UIBarButtonItemStylePlain
  198. target:self
  199. action:@selector(onCommitOrderClick:)];
  200. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  201. fixedItem.width = 20.0f;
  202. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  203. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  204. {
  205. [items addObject:savebtn];
  206. [items addObject:fixedItem];
  207. }
  208. if (!self.isResume) {
  209. // 正常情况
  210. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  211. // customer的订单必须是Sales Order并且有提交权限才能提交
  212. if ([RASingleton sharedInstance].currentOrderIsMerged && [RASingleton sharedInstance].permissions_submit_order) {
  213. [items addObject:self.btnSubmitOrder];
  214. }
  215. } else {
  216. [items addObject:self.btnSubmitOrder];
  217. }
  218. } else {
  219. // 恢复
  220. if (self.userType == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  221. // customer的订单必须是Sales Order并且有提交权限才能提交
  222. if (canSubmit) {
  223. [items addObject:self.btnSubmitOrder];
  224. }
  225. } else {
  226. [items addObject:self.btnSubmitOrder];
  227. }
  228. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_resume"];
  229. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_userType"];
  230. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_submitOrder"];
  231. }
  232. // [items addObject:item2];
  233. self.navigationItem.rightBarButtonItems=items;
  234. if(appDelegate.can_submit_order)
  235. {
  236. [self.btnSubmitOrder setImage:submit_img];
  237. self.btnSubmitOrder.enabled = true;
  238. }
  239. else
  240. {
  241. [self.btnSubmitOrder setImage:nil];
  242. self.btnSubmitOrder.enabled = false;
  243. }
  244. self.navigationController.navigationBarHidden=false;
  245. }
  246. -(void) download_success
  247. {
  248. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  249. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  250. NSString* order_customerid=[self getValue:@"customer_cid"];
  251. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  252. appDelegate.order_customer_id = order_customerid;
  253. }
  254. - (void)viewDidLoad {
  255. [super viewDidLoad];
  256. self.editable = YES;
  257. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  258. style:UIBarButtonItemStylePlain
  259. target:self
  260. action:@selector(onCloseClick:)];
  261. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  262. // closeButton.title = @"Close";
  263. self.navigationItem.leftBarButtonItem = closeButton;
  264. // self.navigationItem.backBarButtonItem = backButton;
  265. // Do any additional setup after loading the view.
  266. }
  267. - (void)onCommitOrderClick:(id)sender {
  268. // get customer info
  269. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  270. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  271. //
  272. // // 检查价格类型
  273. // // 提货价才能提交订单
  274. // /** 价格类型
  275. // * 0 提货价
  276. // * 1 统一价
  277. // * 2 计算价
  278. // */
  279. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  280. // if (priceType != 0) {
  281. //
  282. // NSString* pricename = nil;
  283. // switch (priceType) {
  284. // case 1:
  285. // pricename=flat_price;
  286. // break;
  287. // case 2:
  288. // pricename=given_price;
  289. // break;
  290. // default:
  291. // break;
  292. // }
  293. //
  294. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current price is %@, please change to %@ and try again.",pricename,[Singleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  295. //
  296. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  297. //
  298. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  299. //
  300. // }];
  301. //
  302. //
  303. // [alertVC addAction:cancelAction];
  304. //
  305. // [self presentViewController:alertVC animated:YES completion:nil];
  306. //
  307. // return;
  308. // }
  309. // }
  310. NSString* msg;
  311. #ifdef OFFLINE_MODE
  312. if(appDelegate.offline_mode)
  313. {
  314. msg=@"Are you sure to mark offline order as ready for submit?";
  315. }
  316. else
  317. #endif
  318. {
  319. msg=@"Submit order now?";
  320. }
  321. //
  322. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Order Submission" message:msg preferredStyle:UIAlertControllerStyleAlert];
  323. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  324. {
  325. // add params check here.
  326. [self.lastedit endEditing:true];
  327. [self.lasttextview endEditing:true];
  328. NSMutableDictionary* upparams = [self check_cancommit:true];
  329. if(self.cancommit==false)
  330. return;
  331. // 2018-1-2 Modify
  332. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  333. {
  334. [self customer_commit_order:upparams];
  335. }
  336. else // USER_ROLE_EMPLOYEE
  337. {
  338. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  339. {
  340. upparams[@"shipping"] = nil;
  341. }
  342. if(upparams[@"shipping"]==nil || [upparams[@"shipping"] doubleValue]!=0)
  343. [self empolyee_commit_order:upparams];
  344. else
  345. {
  346. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  347. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  348. {
  349. //yes
  350. [self empolyee_commit_order:upparams];
  351. }];
  352. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  353. //DebugLog(@"Cancel");
  354. }];
  355. [alertControl addAction:actionOne];
  356. [alertControl addAction:alertthree];
  357. [self presentViewController:alertControl animated:YES completion:nil];
  358. }
  359. }
  360. }
  361. }];
  362. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  363. }];
  364. [alertVC addAction:yesAction];
  365. [alertVC addAction:cancelAction];
  366. [self presentViewController:alertVC animated:yesAction completion:nil];
  367. }
  368. - (UIView *)createDemoView:(NSString*) msg
  369. {
  370. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  371. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  372. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  373. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  374. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  375. titleLabel.text=@"Order Submission";
  376. titleLabel.numberOfLines = 0;
  377. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  378. // titleLabel.textAlignment = NSTextAlignmentRight;
  379. titleLabel.textAlignment = NSTextAlignmentCenter;
  380. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  381. // CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  382. CGSize sizetitle = [RAUtils sizeWithFont:titleLabel.text=@"Order Submission" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  383. //[titleLabel sizeToFit];
  384. // titleLabel.center.x = demoView.center.x;
  385. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  386. [demoView addSubview:titleLabel];
  387. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  388. lineLabel.font = [UIFont systemFontOfSize:17];
  389. lineLabel.text=msg;
  390. lineLabel.numberOfLines = 0;
  391. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  392. // CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  393. CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  394. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  395. //[lineLabel sizeToFit];
  396. [demoView addSubview:lineLabel];
  397. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  398. return demoView;
  399. }
  400. - (void)onCloseClick:(UIButton *)sender {
  401. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  402. if (self.resumeOrder) {
  403. [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
  404. return;
  405. }
  406. //
  407. // NSRange range = [tempStr rangeOfString:@")\">"];//判断字符串是否包含
  408. //
  409. // //if (range.location ==NSNotFound)//不包含
  410. // if (range.length >0)//包含
  411. // {
  412. //
  413. //
  414. //
  415. // }
  416. // else//不包含
  417. // {
  418. //
  419. // }
  420. // UIAlertView * alert = nil;
  421. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Choose your action" preferredStyle:UIAlertControllerStyleAlert];
  422. UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  423. [((MainViewController*)appDelegate.main_vc) switchToCart];
  424. [self.navigationController popViewControllerAnimated:true];
  425. }];
  426. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  427. [self.navigationController popViewControllerAnimated:false];
  428. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  429. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  430. }];
  431. NSString * a2Title=nil;
  432. if(appDelegate.order_status==0)
  433. a2Title=@"Close and cancel order";
  434. else
  435. a2Title=@"Close and release order";
  436. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:a2Title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  437. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  438. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
  439. #ifdef SCANNER_ORDER
  440. if(RASingleton.sharedInstance.enable_OfflineOrder)
  441. {
  442. [waitalert dismissViewControllerAnimated:YES completion:^{
  443. [OLDataProvider deleteScanOrder:appDelegate.order_code];
  444. [appDelegate closeOrder];
  445. //
  446. [self prepareReturn:nil];
  447. [self.navigationController popViewControllerAnimated:true];
  448. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  449. }];
  450. return;
  451. }
  452. #endif
  453. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
  454. NSDictionary* order_json = result;
  455. [waitalert dismissViewControllerAnimated:YES completion:^{
  456. if([[order_json valueForKey:@"result"] intValue]==2)
  457. {
  458. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  459. // appDelegate.order_code = nil;
  460. [appDelegate closeOrder];
  461. #ifdef RA_NOTIFICATION
  462. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  463. #else
  464. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  465. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  466. #endif
  467. [((MainViewController*)appDelegate.main_vc) switchToHome];
  468. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  469. {
  470. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  471. }
  472. [self prepareReturn:nil];
  473. [self.navigationController popViewControllerAnimated:true];
  474. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  475. // ;
  476. // }];
  477. }
  478. else
  479. {
  480. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  481. }
  482. }];
  483. }];
  484. }];
  485. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  486. //
  487. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  488. //
  489. // dispatch_async(dispatch_get_main_queue(), ^{
  490. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  491. // if([[order_json valueForKey:@"result"] intValue]==2)
  492. // {
  493. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  494. // // appDelegate.order_code = nil;
  495. //
  496. // [appDelegate closeOrder];
  497. //
  498. //
  499. //#ifdef RA_NOTIFICATION
  500. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  501. //#else
  502. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  503. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  504. //#endif
  505. //
  506. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  507. //
  508. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  509. // {
  510. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  511. // }
  512. //
  513. // [self prepareReturn:nil];
  514. //
  515. //
  516. // [self.navigationController popViewControllerAnimated:true];
  517. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  518. // // ;
  519. // // }];
  520. //
  521. // }
  522. // else
  523. // {
  524. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  525. // }
  526. //
  527. //
  528. //
  529. // });
  530. // });
  531. }];
  532. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  533. }];
  534. [alertController addAction:action_0];
  535. [alertController addAction:action_1];
  536. [alertController addAction:action_2];
  537. [alertController addAction:action_3];
  538. [self presentViewController:alertController animated:YES completion:nil];
  539. // alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and cancel order", nil), nil];
  540. // else
  541. // {
  542. //
  543. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Choose your action" preferredStyle:UIAlertControllerStyleAlert];
  544. //
  545. //
  546. // UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  547. //
  548. //
  549. //
  550. // }];
  551. //
  552. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  553. //
  554. //
  555. //
  556. // }];
  557. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Close and release order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  558. //
  559. //
  560. //
  561. // }];
  562. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  563. //
  564. //
  565. //
  566. // }];
  567. // [alertController addAction:action_0];
  568. // [alertController addAction:action_1];
  569. // [alertController addAction:action_2];
  570. // [alertController addAction:action_3];
  571. //
  572. //
  573. // [self presentViewController:alertController animated:YES completion:nil];
  574. //
  575. //
  576. //// alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil];
  577. //
  578. // }
  579. // alert.tag = CLOSE_ACTION;
  580. // // alert.
  581. // [alert show];
  582. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  583. // appDelegate.order_code = nil;
  584. //
  585. // }
  586. }
  587. - (void)didReceiveMemoryWarning {
  588. [super didReceiveMemoryWarning];
  589. // Dispose of any resources that can be recreated.
  590. }
  591. - (IBAction)onSaveClick:(id)sender {
  592. // id foo = nil;
  593. // [[NSMutableArray array] addObject:foo];
  594. // add params check here.
  595. [self.lastedit endEditing:true];
  596. [self.lasttextview endEditing:true];
  597. NSMutableDictionary* upparams = [self check_cancommit:false];
  598. // if(self.cancommit==false)
  599. // return;
  600. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  601. upparams[@"shipping"] = nil;
  602. if(RASingleton.sharedInstance.enable_OfflineOrder)
  603. {
  604. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  605. NSString *documents = [paths objectAtIndex:0];
  606. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  607. NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  608. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  609. [RAUtils dicttofile:orderPath dict:self.content_data_download];
  610. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  611. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  612. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  613. [RAUtils dicttofile:cartpath dict:RASingleton.sharedInstance.scan_cart];
  614. NSMutableDictionary* orderlist = nil;
  615. NSString *orderlistPath = [documents stringByAppendingPathComponent:@"orderlist.json"];
  616. if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
  617. orderlist = [NSMutableDictionary new];
  618. // [orderlist addObject:appDelegate.order_code];
  619. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  620. }
  621. else
  622. {
  623. orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
  624. // [orderlist insertObject:appDelegate.order_code atIndex:0];
  625. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  626. }
  627. NSMutableDictionary* orderitem = [NSMutableDictionary new];
  628. orderitem[@"create_by"] = appDelegate.user;
  629. orderitem[@"price"] = upparams[@"total_price"];
  630. orderitem[@"customer_name"] = upparams[@"customer_contact"];
  631. orderitem[@"purchase_time"] = [RAUtils current_date_time];
  632. orderitem[@"order_status"] = @"Saved Order";
  633. orderitem[@"order_code"] = appDelegate.order_code;
  634. orderitem[@"model_count"] =[ NSString stringWithFormat:@"%@",RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] ];
  635. int count = [orderlist[@"count"] intValue];
  636. NSMutableDictionary* newlist = [NSMutableDictionary new];
  637. newlist[@"item_0"]=orderitem;
  638. int newcount = 1;
  639. for(int i=0;i<count;i++)
  640. {
  641. NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
  642. if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
  643. continue;
  644. else
  645. {
  646. newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  647. newcount++;
  648. }
  649. }
  650. newlist[@"count"] = @(newcount);
  651. [RAUtils dicttofile:orderlistPath dict:newlist];
  652. #ifdef RA_NOTIFICATION
  653. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  654. #else
  655. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  656. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  657. #endif
  658. return;
  659. }
  660. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order" completion:^{
  661. [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
  662. NSDictionary* editor_json =result;
  663. [waitalert dismissViewControllerAnimated:YES completion:^{
  664. if([[editor_json valueForKey:@"result"] intValue]==2)
  665. {
  666. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  667. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  668. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  669. {
  670. appDelegate.customerInfo = customerInfo;
  671. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  672. }
  673. NSString *msg = nil;
  674. if ([editor_json objectForKey:@"so#"]) {
  675. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  676. }
  677. [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  678. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  679. {
  680. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  681. [self prepareReturn:nil];
  682. [self.navigationController popViewControllerAnimated:true];
  683. }
  684. else{
  685. #ifdef RA_NOTIFICATION
  686. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  687. #else
  688. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  689. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  690. #endif
  691. }
  692. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  693. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  694. [self releaseOrderAfterSave];
  695. }
  696. }
  697. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  698. // appDelegate.order_code = nil;
  699. //
  700. // }
  701. // // self.labelContact.text=appDelegate.contact_name;
  702. //
  703. // NSDictionary * customerinfo = appDelegate.customerInfo;
  704. // [self prepareReturn:nil];
  705. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  706. //
  707. //
  708. // ;
  709. // }];
  710. }
  711. else
  712. {
  713. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  714. }
  715. }];
  716. }];
  717. }];
  718. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  719. //
  720. // NSDictionary* editor_json = [RANetwork save_Order:upparams];
  721. //
  722. // dispatch_async(dispatch_get_main_queue(), ^{
  723. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  724. //
  725. //
  726. // if([[editor_json valueForKey:@"result"] intValue]==2)
  727. // {
  728. //
  729. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  730. //
  731. //
  732. //
  733. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  734. //
  735. //
  736. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  737. // {
  738. // appDelegate.customerInfo = customerInfo;
  739. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  740. // }
  741. // NSString *msg = nil;
  742. // if ([editor_json objectForKey:@"so#"]) {
  743. // msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  744. // }
  745. // [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  746. //
  747. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  748. // {
  749. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  750. // [self prepareReturn:nil];
  751. // [self.navigationController popViewControllerAnimated:true];
  752. // }
  753. // else{
  754. //
  755. //
  756. //#ifdef RA_NOTIFICATION
  757. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  758. //#else
  759. //
  760. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  761. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  762. //#endif
  763. // }
  764. //
  765. // if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  766. //
  767. // if (![Singleton sharedInstance].currentOrderIsMerged) {
  768. // [self releaseOrderAfterSave];
  769. // }
  770. //
  771. //
  772. // }
  773. //
  774. //
  775. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  776. // // appDelegate.order_code = nil;
  777. // //
  778. // // }
  779. // // // self.labelContact.text=appDelegate.contact_name;
  780. // //
  781. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  782. // // [self prepareReturn:nil];
  783. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  784. // //
  785. // //
  786. // // ;
  787. // // }];
  788. //
  789. // }
  790. // else
  791. // {
  792. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  793. // }
  794. //
  795. //
  796. //
  797. //
  798. // });
  799. // });
  800. }
  801. - (void)textFieldDidEndEditing:(UITextField *)textField
  802. {
  803. [super textFieldDidEndEditing:textField];
  804. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  805. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  806. NSMutableDictionary* section_json=nil;
  807. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  808. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  809. NSString* name = [item_json valueForKey:@"name"];
  810. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  811. {
  812. float shipping = [self getprice:@"shipping" section:indexPath.section];
  813. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  814. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  815. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  816. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  817. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  818. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  819. int count=0;
  820. count=[[section_json valueForKey:@"count"] intValue];
  821. int total_row_idx=-1;
  822. for(int i=0;i<count;i++)
  823. {
  824. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  825. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  826. {
  827. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  828. [olditem setValue:@"true" forKey:@"dirty"];
  829. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  830. total_row_idx=i;
  831. }
  832. }
  833. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  834. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  835. if(total_row_idx>=0)
  836. {
  837. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  838. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  839. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  840. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  841. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  842. // CGSize tablecontent =self.editorTable.contentSize;
  843. // tablecontent.height=tablecontent.height+self.keyboard_h;
  844. // self.editorTable.contentSize=tablecontent;
  845. //
  846. //
  847. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  848. }
  849. // self.content_data = [editor_json mutableCopy];
  850. // self.content_data = [self translate_json:editor_json];
  851. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  852. // [self.editorTable reloadData];
  853. }
  854. //
  855. // [item_json setValue:@"true" forKey:@"dirty"];
  856. // [item_json setValue:textField.text forKey:@"value"];
  857. }
  858. -(float) getprice:(NSString*) name section :(long) index
  859. {
  860. NSMutableDictionary* section_json=nil;
  861. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  862. int count=0;
  863. count=[[section_json valueForKey:@"count"] intValue];
  864. for(int i=0;i<count;i++)
  865. {
  866. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  867. if([[olditem valueForKey:@"name"] isEqualToString:name])
  868. {
  869. return [[olditem valueForKey:@"value"] floatValue];
  870. }
  871. }
  872. return 0;
  873. }
  874. /*
  875. #pragma mark - Navigation
  876. // In a storyboard-based application, you will often want to do a little preparation before navigation
  877. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  878. // Get the new view controller using [segue destinationViewController].
  879. // Pass the selected object to the new view controller.
  880. }
  881. */
  882. //#pragma mark - UIAlertViewDelegate
  883. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  884. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  885. //{
  886. //
  887. // if(alertView.tag == CLOSE_ACTION)
  888. // {
  889. // if(buttonIndex==1)
  890. // {
  891. //
  892. // [self.navigationController popViewControllerAnimated:true];
  893. // // back to cart;
  894. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  895. // // ;
  896. // // }];
  897. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  898. // // appDelegate.order_code = nil;
  899. // //
  900. // // }
  901. // }
  902. // if(buttonIndex==2)
  903. // {
  904. //
  905. // [self.navigationController popViewControllerAnimated:false];
  906. //
  907. //
  908. //
  909. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  910. //
  911. //
  912. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  913. // // back to cart;
  914. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  915. // // ;
  916. // // }];
  917. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  918. // // appDelegate.order_code = nil;
  919. // //
  920. // // }
  921. // }
  922. // else if(buttonIndex==3)
  923. // {
  924. // // close order;
  925. //
  926. //
  927. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  928. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  929. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  930. //
  931. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  932. //
  933. // dispatch_async(dispatch_get_main_queue(), ^{
  934. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  935. // if([[order_json valueForKey:@"result"] intValue]==2)
  936. // {
  937. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  938. // // appDelegate.order_code = nil;
  939. //
  940. // [appDelegate closeOrder];
  941. //
  942. //
  943. //#ifdef RA_NOTIFICATION
  944. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  945. //#else
  946. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  947. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  948. //#endif
  949. //
  950. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  951. //
  952. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  953. // {
  954. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  955. // }
  956. //
  957. // [self prepareReturn:nil];
  958. //
  959. //
  960. // [self.navigationController popViewControllerAnimated:true];
  961. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  962. // // ;
  963. // // }];
  964. //
  965. // }
  966. // else
  967. // {
  968. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  969. // }
  970. //
  971. //
  972. //
  973. // });
  974. // });
  975. //
  976. //
  977. //
  978. //
  979. //
  980. // //
  981. // // }
  982. // }
  983. // }
  984. //}
  985. //
  986. //
  987. //-(void) downloadpdf:(NSString* )url
  988. //{
  989. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Printing..."];
  990. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  991. //
  992. //
  993. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  994. //
  995. // //设置请求方式为get
  996. //
  997. // [request setHTTPMethod:@"GET"];
  998. //
  999. // //添加用户会话id
  1000. //
  1001. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  1002. //
  1003. // //连接发送请求
  1004. //
  1005. //
  1006. // NSHTTPURLResponse* urlResponse = nil;
  1007. //
  1008. // NSError *error = [[NSError alloc] init];
  1009. //
  1010. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  1011. //
  1012. // // self.filename = [urlResponse suggestedFilename];
  1013. //
  1014. //
  1015. // dispatch_async(dispatch_get_main_queue(), ^{
  1016. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1017. // // self.navigationItem.title = self.save_name;
  1018. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  1019. // // self.content=nil;
  1020. // if(content!=nil&&content.length>0)
  1021. // {
  1022. //
  1023. //
  1024. // [self startAirPrintWithData:content];
  1025. //
  1026. //
  1027. // }
  1028. // else
  1029. // {
  1030. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  1031. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  1032. // }
  1033. //
  1034. // ;
  1035. // // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  1036. // //
  1037. //
  1038. //
  1039. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  1040. //
  1041. //
  1042. //
  1043. //
  1044. // });
  1045. // });
  1046. //}
  1047. //
  1048. //- (void)startAirPrintWithData:(id )data
  1049. //{
  1050. //
  1051. //
  1052. //
  1053. //
  1054. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  1055. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  1056. // printInfo.outputType = UIPrintInfoOutputGeneral;
  1057. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  1058. // printInfo.jobName = @"CoolVisitAirPrint";
  1059. // airPrinterController.printInfo = printInfo;
  1060. // airPrinterController.printingItem = data;
  1061. // airPrinterController.delegate = self;
  1062. //
  1063. //
  1064. // airPrinterController.showsNumberOfCopies=true;
  1065. // airPrinterController.showsPageRange = true;
  1066. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  1067. //
  1068. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  1069. // if(completed && error)
  1070. // DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
  1071. // };
  1072. //
  1073. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1074. //
  1075. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  1076. //
  1077. //
  1078. //
  1079. //
  1080. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  1081. // {
  1082. // if (available&& appDelegate.printerURL.length>0)
  1083. // {
  1084. //
  1085. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  1086. // DebugLog(@"AIRPRINTER AVAILABLE");
  1087. // }
  1088. // else
  1089. // {
  1090. //
  1091. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1092. // //
  1093. // //
  1094. // //
  1095. // // // [printPicker presentAnimated:YES completionHandler:
  1096. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  1097. // // {
  1098. // // if (userDidSelect)
  1099. // // {
  1100. // // NSString* sid= printerController.printInfo.printerID;
  1101. // // UIPrintPaper*paper= printerController.printPaper;
  1102. // //
  1103. // // }
  1104. // // }];
  1105. //
  1106. //
  1107. // DebugLog(@"AIRPRINTER NOT AVAILABLE");
  1108. //
  1109. //
  1110. //
  1111. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  1112. // {
  1113. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  1114. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  1115. //
  1116. //
  1117. //
  1118. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  1119. //
  1120. //
  1121. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1122. //
  1123. //
  1124. //
  1125. // // [printPicker presentAnimated:YES completionHandler:
  1126. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  1127. // {
  1128. // if (userDidSelect)
  1129. // {
  1130. // //User selected the item in the UIPrinterPickerController and got the printer details.
  1131. //
  1132. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  1133. //
  1134. // //Here you will get the printer and printer details.ie,
  1135. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  1136. //
  1137. //
  1138. //
  1139. //
  1140. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  1141. //
  1142. // [self startAirPrintWithData:data];
  1143. //
  1144. // }
  1145. // else
  1146. // {
  1147. //
  1148. //
  1149. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1150. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1151. // {
  1152. //
  1153. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1154. // }
  1155. // [self prepareReturn:nil];
  1156. //
  1157. // [self.navigationController popViewControllerAnimated:true];
  1158. // }
  1159. // }];
  1160. // }
  1161. // }
  1162. // }];
  1163. //
  1164. //
  1165. //
  1166. //}
  1167. //
  1168. //#pragma mark - UIPrintInteractionControllerDelegate
  1169. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  1170. //{
  1171. //
  1172. // ;
  1173. //
  1174. // // (int) width = 29700
  1175. // // Printing description of (*( (int *)0x7caa3a40)):
  1176. // // (int) height = 42000
  1177. // //设置纸张大小
  1178. //
  1179. //
  1180. // for(UIPrintPaper* paper in paperList)
  1181. // {
  1182. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  1183. // return paper;
  1184. //
  1185. // }
  1186. // CGSize paperSize = CGSizeMake(612, 792);
  1187. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  1188. // return p;
  1189. //}
  1190. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1191. //{
  1192. //
  1193. //}
  1194. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1195. //{
  1196. //
  1197. //}
  1198. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1199. //{
  1200. //
  1201. //}
  1202. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1203. //{
  1204. //
  1205. //}
  1206. //
  1207. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  1208. //{
  1209. //
  1210. //}
  1211. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  1212. //{
  1213. //
  1214. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1215. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1216. // {
  1217. //
  1218. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1219. // }
  1220. //
  1221. // [self prepareReturn:nil];
  1222. //
  1223. // [self.navigationController popViewControllerAnimated:true];
  1224. //}
  1225. //
  1226. //- (NSString *)currentPriceTypeName {
  1227. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  1228. //
  1229. // NSString* pricename = nil;
  1230. // switch (priceType) {
  1231. // case 0:
  1232. // pricename=[Singleton sharedInstance].deliveryString;
  1233. // break;
  1234. // case 1:
  1235. // pricename=flat_price;
  1236. // break;
  1237. // case 2:
  1238. // pricename=given_price;
  1239. // break;
  1240. // default:
  1241. // break;
  1242. // }
  1243. // return pricename;
  1244. //}
  1245. - (void)releaseOrderAfterSave {
  1246. dispatch_async(dispatch_get_main_queue(), ^{
  1247. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1248. // [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1249. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:nil];
  1250. [appDelegate closeOrder];
  1251. [appDelegate SetSo:nil];
  1252. appDelegate.cart_count=0;
  1253. [appDelegate update_count_mark];
  1254. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1255. [self prepareReturn:nil];
  1256. [self.navigationController popToRootViewControllerAnimated:false];
  1257. });
  1258. }
  1259. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  1260. {
  1261. NSString* ret=nil;
  1262. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  1263. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  1264. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  1265. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  1266. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  1267. if(customer_address1.length>0)
  1268. [arraddr addObject:customer_address1];
  1269. if(customer_address2.length>0)
  1270. [arraddr addObject:customer_address2];
  1271. if(customer_address3.length>0)
  1272. [arraddr addObject:customer_address3];
  1273. if(customer_address4.length>0)
  1274. [arraddr addObject:customer_address4];
  1275. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  1276. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  1277. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  1278. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  1279. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  1280. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  1281. if(customer_city.length>0)
  1282. [arrcty addObject:customer_city];
  1283. if(customer_state.length>0)
  1284. [arrcty addObject:customer_state];
  1285. if(customer_zipcode.length>0)
  1286. [arrcty addObject:customer_zipcode];
  1287. if(customer_country.length>0)
  1288. [arrcty addObject:customer_country];
  1289. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  1290. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  1291. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  1292. //
  1293. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  1294. // if(customer_phone.length>0)
  1295. // {
  1296. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  1297. // [arrpho addObject:customer_phone];
  1298. // }
  1299. // if(customer_fax.length>0)
  1300. // {
  1301. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  1302. // [arrpho addObject:customer_fax];
  1303. // }
  1304. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  1305. //
  1306. //
  1307. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  1308. // if(customer_contact.length>0)
  1309. // {
  1310. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  1311. //
  1312. // }
  1313. // NSString *contact_string = customer_contact;
  1314. //
  1315. //
  1316. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  1317. // if(customer_email.length>0)
  1318. // {
  1319. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  1320. //
  1321. // }
  1322. // NSString *email_string = customer_email;
  1323. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  1324. if(addr_string.length>0)
  1325. [arrext addObject:addr_string];
  1326. if(cty_string.length>0)
  1327. [arrext addObject:cty_string];
  1328. // if(phone_string.length>0)
  1329. // [arrext addObject:phone_string];
  1330. // if(contact_string.length>0)
  1331. // [arrext addObject:contact_string];
  1332. // if(email_string.length>0)
  1333. // [arrext addObject:email_string];
  1334. ret = [arrext componentsJoinedByString:@"\r\n"];
  1335. // NSString *string = [array componentsJoinedByString:@" "];
  1336. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  1337. return ret;
  1338. }
  1339. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  1340. {
  1341. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  1342. NSArray *keys= [key_map allKeys];
  1343. //遍历keys
  1344. for(int i=0;i<[keys count];i++)
  1345. {
  1346. //得到当前key
  1347. NSString *key=[keys objectAtIndex:i];
  1348. //如果key不是pic,说明value是字符类型,比如name:Boris
  1349. NSString* valuefrom = [key_map valueForKey:key];
  1350. if(valuefrom.length==0)
  1351. continue;
  1352. NSString* value=[self getValue:valuefrom];
  1353. [ret setValue:value forKey:valuefrom];
  1354. }
  1355. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  1356. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  1357. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  1358. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  1359. return ret;
  1360. }
  1361. -(NSMutableDictionary*)create_cusromer_info_from_table
  1362. {
  1363. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1364. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  1365. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  1366. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  1367. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  1368. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  1369. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  1370. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  1371. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  1372. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  1373. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  1374. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  1375. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1376. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  1377. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1378. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  1379. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  1380. NSString * firstname =nil;
  1381. NSString* lastname = nil;
  1382. NSString* contact_name = [self getValue:@"customer_contact"];
  1383. if(contact_name!=nil)
  1384. {
  1385. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  1386. if(_arr.count>=1)
  1387. {
  1388. firstname =_arr[0];
  1389. if(_arr.count>1)
  1390. {
  1391. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  1392. }
  1393. }
  1394. }
  1395. [ret setValue:firstname forKey:@"customer_first_name"];
  1396. [ret setValue:lastname forKey:@"customer_last_name"];
  1397. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  1398. return ret;
  1399. }
  1400. #pragma mark - multi_action sub action clicked
  1401. - (void)MActionClicked:(UIButton *)sender {
  1402. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  1403. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1404. int refresh =0;
  1405. NSMutableDictionary* section_json=nil;
  1406. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1407. NSString* subid=[item_json valueForKey:@"subid"];
  1408. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1409. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  1410. NSString* type = [sub_action valueForKey:@"type"];
  1411. bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
  1412. if([type isEqualToString:@"pull"])
  1413. {
  1414. [self.lastedit endEditing:true];
  1415. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  1416. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  1417. NSMutableDictionary* value=[self create_value_map:keymap];
  1418. if(subid==nil)
  1419. {
  1420. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1421. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1422. int icount=[[section_json valueForKey:@"count"] intValue];
  1423. for (int ic=0;ic<icount;ic++)
  1424. {
  1425. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1426. NSString* mapto = [modify_item valueForKey:@"name"];
  1427. if(mapto.length==0)
  1428. continue;
  1429. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1430. if(valuefrom==nil)
  1431. continue;
  1432. NSString* valuestr=[value valueForKey:valuefrom];
  1433. // valuestr = [self getValue:valuefrom];
  1434. if(true)
  1435. {
  1436. if(valuestr.length>0)
  1437. [modify_item setValue:valuestr forKey:@"value"];
  1438. else
  1439. [modify_item setValue:@"" forKey:@"value"];
  1440. [modify_item setValue:@"true" forKey:@"dirty"];
  1441. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1442. }
  1443. }
  1444. }
  1445. else
  1446. {
  1447. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1448. int section = [(NSString*)idarr[0] intValue];
  1449. int item=[(NSString*)idarr[1] intValue];
  1450. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1451. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1452. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1453. NSString* control_type = [olditem valueForKey:@"control"];
  1454. if([control_type isEqualToString:@"switch"])
  1455. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1456. else if([control_type isEqualToString:@"enum"])
  1457. {
  1458. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1459. }
  1460. else
  1461. {
  1462. [RAUtils message_alert:@"not impl" title:@"Sorry" controller:self];
  1463. // [RAUtils alert_view:@"" title:@"not impl"];
  1464. }
  1465. [olditem setValue:@"true" forKey:@"dirty"];
  1466. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1467. }
  1468. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1469. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1470. if(refresh==1)
  1471. {
  1472. // if(restore_json!=nil)
  1473. // {
  1474. // int rc=[[restore_json valueForKey:@"count"] intValue];
  1475. // for(int ir=0;ir<rc;ir++)
  1476. // {
  1477. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1478. //
  1479. //
  1480. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1481. // for(int i=0;i<section_count;i++)
  1482. // {
  1483. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1484. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1485. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1486. // for(int j=0;j<item_count;j++)
  1487. // {
  1488. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1489. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1490. //
  1491. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  1492. // {
  1493. // [itemjson removeObjectForKey:@"dirty"];
  1494. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  1495. // }
  1496. //
  1497. // }
  1498. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1499. // }
  1500. //
  1501. //
  1502. // }
  1503. //
  1504. // }
  1505. [self refresh:refresh_trigger discardDirty:discardDirty] ;
  1506. return ;
  1507. }
  1508. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1509. [self.editorTable reloadData ];
  1510. }
  1511. else
  1512. {
  1513. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1514. NSDictionary * item_json = sub_action;
  1515. NSString* value = [item_json valueForKey:@"value"];
  1516. if([value isEqualToString:@"new_addr"])
  1517. {
  1518. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1519. addressVC.url_type = URL_REMOTE;
  1520. addressVC.request_url=URL_ADDRESS_EDOTOR;
  1521. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1522. // NSString * string = [checked componentsJoinedByString:@","];
  1523. // [params setValue:string forKey:@"cart2Checkbox"];
  1524. params[@"is_subaction"]=@"true";
  1525. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  1526. addressVC.params = params;
  1527. addressVC.delegate = self;
  1528. addressVC.from = indexPath;
  1529. // orderinfoVC.params = params;
  1530. [self.navigationController pushViewController:addressVC animated:true];
  1531. }else if([value isEqualToString:@"credit_card"])
  1532. {
  1533. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1534. NSDictionary *data = [item_json objectForKey:@"data"];
  1535. if(data!=nil)
  1536. {
  1537. cardVC.content_data_download = [data mutableCopy];
  1538. cardVC.url_type = URL_NONE;
  1539. cardVC.request_url=nil;
  1540. }
  1541. else
  1542. {
  1543. cardVC.url_type = URL_REMOTE;
  1544. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  1545. }
  1546. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1547. params[@"orderCode"]=appDelegate.order_code;
  1548. params[@"is_subaction"]=@"true";
  1549. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  1550. cardVC.params = params;
  1551. cardVC.delegate = self;
  1552. cardVC.from = indexPath;
  1553. // orderinfoVC.params = params;
  1554. [self.navigationController pushViewController:cardVC animated:true];
  1555. }
  1556. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  1557. {
  1558. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1559. cvc.showNavibar = true;
  1560. cvc.contact_type = value;
  1561. cvc.is_subaction = @"true";
  1562. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1563. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1564. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1565. //
  1566. // if(self.returnValue)
  1567. // self.returnValue(value);
  1568. };
  1569. [self.navigationController pushViewController:cvc animated:true];
  1570. }
  1571. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  1572. {
  1573. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1574. cvc.showNavibar = true;
  1575. cvc.contact_type = value;
  1576. cvc.is_subaction = @"true";
  1577. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1578. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1579. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1580. //
  1581. // if(self.returnValue)
  1582. // self.returnValue(value);
  1583. };
  1584. [self.navigationController pushViewController:cvc animated:true];
  1585. }
  1586. else if([value isEqualToString:@"Sales_Order_Customer"])
  1587. {
  1588. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1589. cvc.is_subaction = @"true";
  1590. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1591. cvc.showNavibar = true;
  1592. cvc.contact_type = value;
  1593. __weak typeof(self) weakself = self;
  1594. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1595. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1596. //
  1597. // if(self.returnValue)
  1598. // self.returnValue(value);
  1599. };
  1600. [self.navigationController pushViewController:cvc animated:true];
  1601. }
  1602. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  1603. {
  1604. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1605. cvc.showNavibar = true;
  1606. cvc.contact_type = value;
  1607. cvc.is_subaction = @"true";
  1608. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1609. __weak typeof(self) weakself = self;
  1610. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1611. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1612. //
  1613. // if(self.returnValue)
  1614. // self.returnValue(value);
  1615. };
  1616. [self.navigationController pushViewController:cvc animated:true];
  1617. }
  1618. else if([value isEqualToString:@"Contact_Return_To"])
  1619. {
  1620. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1621. cvc.is_subaction = @"true";
  1622. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1623. cvc.showNavibar = true;
  1624. cvc.contact_type = value;
  1625. __weak typeof(self) weakself = self;
  1626. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1627. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1628. //
  1629. // if(self.returnValue)
  1630. // self.returnValue(value);
  1631. };
  1632. [self.navigationController pushViewController:cvc animated:true];
  1633. }
  1634. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  1635. {
  1636. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1637. cvc.is_subaction = @"true";
  1638. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1639. cvc.showNavibar = true;
  1640. cvc.contact_type = value;
  1641. __weak typeof(self) weakself = self;
  1642. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1643. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1644. //
  1645. // if(self.returnValue)
  1646. // self.returnValue(value);
  1647. };
  1648. [self.navigationController pushViewController:cvc animated:true];
  1649. }
  1650. }
  1651. }
  1652. #pragma mark - Urgency
  1653. -(void) viewWillDisappear:(BOOL)animated
  1654. {
  1655. [super viewWillDisappear:animated];
  1656. [self cancel_urgency_timer];
  1657. }
  1658. - (void)start_urgency_timer {
  1659. return;
  1660. if (!self.editable) {
  1661. return;
  1662. }
  1663. __weak typeof(self) weakSelf = self;
  1664. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1665. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  1666. #ifdef OFFLINE_MODE
  1667. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  1668. #endif
  1669. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  1670. __block NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  1671. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  1672. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  1673. // DebugLog(@"timer start....");
  1674. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  1675. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  1676. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  1677. // CreateOrderViewController
  1678. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  1679. [urgencyDic setValue:so forKey:@"order_so"];
  1680. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  1681. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  1682. }
  1683. dispatch_async(dispatch_get_main_queue(), ^{
  1684. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  1685. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  1686. });
  1687. }];
  1688. }
  1689. - (void)cancel_urgency_timer {
  1690. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  1691. }
  1692. #pragma mark - Submit Order
  1693. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  1694. [upparams setValue:@"true" forKey:@"isHold"];
  1695. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  1696. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  1697. NSDictionary* editor_json =result;
  1698. [waitalert dismissViewControllerAnimated:YES completion:^{
  1699. if([[editor_json valueForKey:@"result"] intValue]==2)
  1700. {
  1701. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1702. // appDelegate.customerInfo = customerInfo;
  1703. [appDelegate closeOrder];
  1704. #ifdef RA_NOTIFICATION
  1705. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1706. #else
  1707. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1708. #endif
  1709. NSString* title=nil;
  1710. NSString* msg=nil;
  1711. #ifdef OFFLINE_MODE
  1712. if(appDelegate.offline_mode)
  1713. {
  1714. title=TITLE_OFFLINE_SUBMIT;
  1715. msg=MSG_OFFLINE_SUBMIT;
  1716. }
  1717. else
  1718. #endif
  1719. {
  1720. title=@"Order submitted sucessfully";
  1721. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1722. }
  1723. [RAUtils message_alert:msg title:title controller:self];
  1724. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1725. // [alert show];
  1726. [self prepareReturn:nil];
  1727. [self.navigationController popToRootViewControllerAnimated:true];
  1728. }
  1729. else
  1730. {
  1731. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1732. }
  1733. }];
  1734. }];
  1735. }];
  1736. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1737. //
  1738. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1739. //
  1740. // dispatch_async(dispatch_get_main_queue(), ^{
  1741. //
  1742. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1743. //
  1744. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1745. // {
  1746. //
  1747. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1748. // // appDelegate.customerInfo = customerInfo;
  1749. //
  1750. // [appDelegate closeOrder];
  1751. //
  1752. //
  1753. //#ifdef RA_NOTIFICATION
  1754. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1755. //#else
  1756. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1757. //#endif
  1758. //
  1759. // NSString* title=nil;
  1760. // NSString* msg=nil;
  1761. //#ifdef OFFLINE_MODE
  1762. // if(appDelegate.offline_mode)
  1763. // {
  1764. // title=TITLE_OFFLINE_SUBMIT;
  1765. // msg=MSG_OFFLINE_SUBMIT;
  1766. // }
  1767. // else
  1768. //#endif
  1769. // {
  1770. // title=@"Order submitted sucessfully";
  1771. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1772. // }
  1773. //
  1774. // [RAUtils message_alert:msg title:title controller:self];
  1775. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1776. //
  1777. //// [alert show];
  1778. //
  1779. // [self prepareReturn:nil];
  1780. // [self.navigationController popToRootViewControllerAnimated:true];
  1781. //
  1782. //
  1783. // }
  1784. // else
  1785. // {
  1786. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1787. // }
  1788. // });
  1789. // });
  1790. }
  1791. -(void)addTasks: (NSString*)filename md5:(NSString*) md5
  1792. {
  1793. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1794. // if (![self shouldUploadWithCurrentNerworkStatus]) {
  1795. // [self.view makeToast:@"Current network is not WiFi,you can upload it manually when wifi connected." duration:3.0 position:CSToastPositionCenter];
  1796. // }
  1797. //prepare upload
  1798. // NSMutableArray* tasks = [NSMutableArray new];
  1799. // for(NSMutableDictionary* photo in self.photos)
  1800. NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
  1801. // task[@"path"]=path;
  1802. task[@"file"]=filename;
  1803. task[@"url"]=Appdelegate.uploadurl;
  1804. NSDictionary* params = @{
  1805. @"password" : @"usai2010",
  1806. @"md5":md5
  1807. };
  1808. task[@"params"]=params;
  1809. // NSString *file = photo[@"file"];
  1810. // [self moveTmpImageToCache:file];
  1811. // [tasks addObject:task];
  1812. // Signature
  1813. // NSDictionary *signatureTask = [self prepareSignatureTask];
  1814. // // add upload tasks;
  1815. [Appdelegate.uploadManager addTask:task];
  1816. // [self clear];
  1817. }
  1818. -(NSMutableDictionary*) convertScanitem :(NSMutableDictionary*) itemjson
  1819. {
  1820. // NSMutableArray* fields=[[NSMutableArray alloc] init];
  1821. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  1822. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  1823. {
  1824. NSString* single_select = [itemjson valueForKey:@"single_select"];
  1825. if([single_select isEqualToString:@"true"])
  1826. {
  1827. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  1828. int count = [[cadejson valueForKey:@"count"] intValue];
  1829. upparams[[itemjson valueForKey:@"name"]]=@"";
  1830. for(int cc=0;cc<count;cc++)
  1831. {
  1832. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1833. if([[valjson valueForKey:@"check"]intValue]==1)
  1834. {
  1835. // NSString* vid = [valjson valueForKey:@"value_id"] ;
  1836. // if(vid.length==0)
  1837. // vid=@"";
  1838. [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  1839. NSMutableDictionary* subitem = valjson[@"sub_item"];
  1840. if(subitem!=nil)
  1841. {
  1842. int scount = [subitem[@"count"]intValue];
  1843. for(int si=0;si<scount;si++)
  1844. {
  1845. NSMutableDictionary* sitem = subitem[[NSString stringWithFormat:@"item_%d",si]];
  1846. NSMutableDictionary* convertitem = [self convertScanitem:sitem];
  1847. [upparams addEntriesFromDictionary:convertitem];
  1848. }
  1849. }
  1850. break;
  1851. }
  1852. }
  1853. return upparams;
  1854. }
  1855. else //multiple select
  1856. {
  1857. NSMutableArray* checked = [[NSMutableArray alloc] init];
  1858. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  1859. int count = [[cadejson valueForKey:@"count"] intValue];
  1860. upparams[[itemjson valueForKey:@"name"]]=@"";
  1861. for(int cc=0;cc<count;cc++)
  1862. {
  1863. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1864. if([[valjson valueForKey:@"check"]intValue]==1)
  1865. {
  1866. // NSString* vid = [valjson valueForKey:@"value_id"] ;
  1867. // if(vid.length==0)
  1868. // vid=@"";
  1869. // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
  1870. [checked addObject:[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]]];
  1871. }
  1872. }
  1873. {
  1874. NSString * string = [checked componentsJoinedByString:@","];
  1875. [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
  1876. }
  1877. return upparams;
  1878. }
  1879. /*
  1880. upparams setValue:itemjson forKey:<#(NSString *)#>
  1881. */
  1882. }
  1883. else
  1884. if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  1885. {
  1886. return nil;
  1887. }
  1888. else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  1889. {
  1890. NSString* valuestr = [itemjson valueForKey:@"value"];
  1891. if(valuestr.length==0)
  1892. valuestr=@"";
  1893. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1894. return upparams;
  1895. }
  1896. else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  1897. {
  1898. NSString* valuestr = [itemjson valueForKey:@"value"];
  1899. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1900. NSString* value = [itemjson valueForKey:@"value"];
  1901. // NSMutableDictionary* boolitem=nil;
  1902. // NSMutableDictionary* subjson=nil;
  1903. if([value isEqualToString:@"true"])
  1904. {
  1905. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  1906. NSMutableDictionary* subitem = itemjson[@"sub_item"];
  1907. if(subitem!=nil)
  1908. {
  1909. int scount = [subitem[@"count"]intValue];
  1910. for(int si=0;si<scount;si++)
  1911. {
  1912. NSMutableDictionary* sitem = subitem[[NSString stringWithFormat:@"item_%d",si]];
  1913. NSMutableDictionary* convertitem = [self convertScanitem:sitem];
  1914. [upparams addEntriesFromDictionary:convertitem];
  1915. }
  1916. }
  1917. }
  1918. else
  1919. {
  1920. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  1921. }
  1922. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  1923. // if( subjson!=nil /*&& !active*/)
  1924. // {
  1925. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  1926. // for(int l=0;l<sub_count;l++)
  1927. // {
  1928. //// NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1929. //// if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  1930. //// [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  1931. //
  1932. // }
  1933. // }
  1934. return upparams;
  1935. }
  1936. else if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
  1937. {
  1938. NSString* avalue = [itemjson valueForKey:@"avalue"];
  1939. if(avalue.length==0)
  1940. avalue=@"";
  1941. [upparams setValue:avalue forKey:[itemjson valueForKey:@"name"]];
  1942. return upparams;
  1943. }
  1944. else if([[itemjson valueForKey:@"control"] isEqualToString:@"edit"])
  1945. {
  1946. // int min_length = [[itemjson valueForKey:@"min_length"] intValue];
  1947. // NSString* check_len_val =itemjson[@"value"];
  1948. NSString* valuestr= [itemjson valueForKey:@"value"];
  1949. if(valuestr.length==0)
  1950. valuestr=@"";
  1951. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1952. // {
  1953. // NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
  1954. // BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
  1955. // BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
  1956. // if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
  1957. // // 检查最大值最小值
  1958. // int max_type = [[itemjson objectForKey:@"max_type"] intValue];
  1959. // int min_type = [[itemjson objectForKey:@"min_type"] intValue];
  1960. //
  1961. // float max_value = MAXFLOAT;
  1962. // float min_value = 0;
  1963. //
  1964. // NSString *mfield = nil;
  1965. // float f_value = [check_len_val floatValue];
  1966. //
  1967. // if (check_max) {
  1968. //
  1969. // if (max_type > 0) {
  1970. // // key
  1971. // NSString *max_key = [itemjson objectForKey:@"max"];
  1972. // id max_obj = [self downloadValueForKey:max_key];
  1973. // if (max_obj) {
  1974. // max_value = [max_obj floatValue];
  1975. // }
  1976. //
  1977. // } else {
  1978. // // value
  1979. // id max_obj = [itemjson objectForKey:@"max"];
  1980. // if (max_obj != nil) {
  1981. // max_value = [max_obj floatValue];
  1982. // }
  1983. //
  1984. // }
  1985. //
  1986. // if (max_value < f_value) {
  1987. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
  1988. // }
  1989. // }
  1990. //
  1991. // if (check_min) {
  1992. //
  1993. // if (min_type > 0) {
  1994. // // key
  1995. // NSString *min_key = [itemjson objectForKey:@"min"];
  1996. // id min_obj = [self downloadValueForKey:min_key];
  1997. // if (min_obj) {
  1998. // min_value = [min_obj floatValue];
  1999. // }
  2000. // } else {
  2001. // // value
  2002. // id min_obj = [itemjson objectForKey:@"min"];
  2003. // if (min_obj != nil) {
  2004. // min_value = [min_obj floatValue];
  2005. // }
  2006. // }
  2007. //
  2008. // if (min_value > f_value) {
  2009. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
  2010. // }
  2011. // }
  2012. //
  2013. //
  2014. // if (check_min && check_max) {
  2015. // if (f_value < min_value || f_value > max_value) {
  2016. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
  2017. // }
  2018. // }
  2019. //
  2020. //
  2021. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2022. //
  2023. //
  2024. // } else {
  2025. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2026. // }
  2027. //
  2028. // }
  2029. return upparams;
  2030. }
  2031. else
  2032. {
  2033. NSString* value = [itemjson valueForKey:@"value"];
  2034. if(value.length==0)
  2035. value=@"";
  2036. [upparams setValue:value forKey:[itemjson valueForKey:@"name"]];
  2037. return upparams;
  2038. }
  2039. return upparams;
  2040. }
  2041. -(NSMutableDictionary*) convertScanOrder :(NSMutableDictionary*) dict
  2042. {
  2043. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  2044. // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)];
  2045. [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
  2046. // self.first_miss_pos = nil;
  2047. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  2048. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  2049. int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue];
  2050. // NSString* aaa = [RAUtils dict2string:self.content_data_control];
  2051. for(int i=0;i<section_count;i++)
  2052. {
  2053. DebugLog(@"debug...section:%d",i);
  2054. NSDictionary * sectionjson = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] ;
  2055. int item_count = [sectionjson[@"count"] intValue];
  2056. for(int j=0;j<item_count;j++)
  2057. {
  2058. NSMutableDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]];
  2059. NSString* key = [itemjson valueForKey:@"name"];
  2060. if(key==nil || key.length==0)
  2061. continue;
  2062. NSMutableDictionary* convertitem=[self convertScanitem:itemjson];
  2063. [upparams addEntriesFromDictionary:convertitem];
  2064. // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert];
  2065. // upparams= data.params;
  2066. // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy];
  2067. }
  2068. }
  2069. return upparams;
  2070. }
  2071. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  2072. if(RASingleton.sharedInstance.enable_OfflineOrder)
  2073. {
  2074. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  2075. NSString *documents = [paths objectAtIndex:0];
  2076. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2077. NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  2078. //
  2079. // NSArray *cachepaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2080. // NSString *cachefolder = [paths objectAtIndex:0];
  2081. //
  2082. // NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
  2083. // NSString* str=[RAConvertor dict2string:upparams];
  2084. // NSString *ordercontrol = [orderdir stringByAppendingPathComponent:@"order_control.json"];
  2085. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2086. // [RAUtils dicttofile:ordercontrol dict:self.content_data_control];
  2087. [RAUtils dicttofile:orderPath dict:self.content_data_download];
  2088. for(int os=0;os<[self.content_data_download[@"section_count"] intValue];os++)
  2089. {
  2090. NSDictionary* section = self.content_data_download[[NSString stringWithFormat:@"section_%d",os]];
  2091. for(int oi=0;oi<[section[@"count"] intValue];oi++)
  2092. {
  2093. NSDictionary* item = section [[NSString stringWithFormat:@"item_%d",oi]];
  2094. if([item[@"control"] isEqualToString:@"img"])
  2095. {
  2096. // 复制图片到打包目录
  2097. NSString* img_url_0=item[@"img_url_0"];
  2098. NSString* img_url_1=item[@"img_url_1"];
  2099. NSString* img_url_2=item[@"img_url_2"];
  2100. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2101. NSString *cachefolder = [paths objectAtIndex:0];
  2102. // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
  2103. NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
  2104. NSFileManager* fileManager=[NSFileManager defaultManager];
  2105. if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]])
  2106. {
  2107. NSError* err;
  2108. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err];
  2109. int i=0;
  2110. }
  2111. if(img_url_1.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_1]])
  2112. {
  2113. NSError* err;
  2114. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_1]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_1]] error:&err];
  2115. }
  2116. if(img_url_2.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_2]])
  2117. {
  2118. NSError* err;
  2119. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_2]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_2]] error:&err];
  2120. }
  2121. }
  2122. else if([item[@"control"] isEqualToString:@"signature"])
  2123. {
  2124. // 复制图片到打包目录
  2125. NSString* img_url_0=item[@"value"];
  2126. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2127. NSString *cachefolder = [paths objectAtIndex:0];
  2128. // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
  2129. NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
  2130. NSFileManager* fileManager=[NSFileManager defaultManager];
  2131. if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]])
  2132. {
  2133. NSError* err;
  2134. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err];
  2135. }
  2136. }
  2137. }
  2138. }
  2139. NSString * parampath= [orderdir stringByAppendingPathComponent:@"param.json"];
  2140. NSDictionary* param=[self convertScanOrder:self.content_data_download];
  2141. [RAUtils dicttofile:parampath dict:param];
  2142. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2143. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2144. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  2145. [RAUtils dicttofile:cartpath dict:RASingleton.sharedInstance.scan_cart];
  2146. NSString * zippath= [orderdir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2147. // NSError *error=nil;
  2148. //
  2149. // [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
  2150. NSArray* arr_files=[RAUtils allFilesAtPath:orderdir];
  2151. ZipArchive* zip = [[ZipArchive alloc] init];
  2152. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2153. //
  2154. //
  2155. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2156. //
  2157. //
  2158. // }
  2159. BOOL r = [zip CreateZipFile2:zippath Password:@"usai2010"];
  2160. for(int i=0;i<arr_files.count;i++)
  2161. {
  2162. NSString* file=arr_files[i];
  2163. r = [zip addFileToZip:file newname:[file lastPathComponent]];
  2164. }
  2165. NSString * filepath= [appDelegate.order_code stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2166. if( ![zip CloseZipFile2] )
  2167. {
  2168. zippath = @"";
  2169. filepath =@"";
  2170. }
  2171. NSString *md5 = [RAUtils md5WithFile:zippath];
  2172. [self addTasks:filepath md5:md5];
  2173. [OLDataProvider save2submitScanOrder];
  2174. [appDelegate closeOrder];
  2175. //
  2176. [self prepareReturn:nil];
  2177. [self.navigationController popViewControllerAnimated:true];
  2178. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2179. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  2180. // ret[@"result"]=@2;
  2181. // ret[@"file"]=zippath;
  2182. // result(ret);
  2183. return;
  2184. }
  2185. [upparams setValue:@"false" forKey:@"isHold"];
  2186. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  2187. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  2188. NSDictionary* editor_json = result;
  2189. [waitalert dismissViewControllerAnimated:YES completion:^{
  2190. if([[editor_json valueForKey:@"result"] intValue]==2)
  2191. {
  2192. // debug aaa
  2193. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2194. NSString* company= appDelegate.customerInfo[@"customer_name"];
  2195. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  2196. [appDelegate closeOrder];
  2197. #ifdef RA_NOTIFICATION
  2198. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2199. #else
  2200. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2201. #endif
  2202. __block NSString* title=nil;
  2203. __block NSString* msg=nil;
  2204. #ifdef OFFLINE_MODE
  2205. if(appDelegate.offline_mode)
  2206. {
  2207. title=TITLE_OFFLINE_SUBMIT;
  2208. msg=MSG_OFFLINE_SUBMIT;
  2209. }
  2210. else
  2211. #endif
  2212. {
  2213. title=@"Order submitted sucessfully";
  2214. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2215. }
  2216. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2217. NSString* email_content =[editor_json valueForKey:@"email_content"];
  2218. NSString* soid=[editor_json valueForKey:@"so#"];
  2219. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  2220. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2221. {
  2222. //bbb
  2223. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2224. value[@"commitorder_logout"]=@"true";
  2225. }
  2226. [self prepareReturn:value];
  2227. __block UIViewController* message_parent = self.navigationController.topViewController;
  2228. [self.navigationController popToRootViewControllerAnimated:true];
  2229. if(pdf_url.length>0)
  2230. {
  2231. // [message_alert dismissViewControllerAnimated:YES completion:^{
  2232. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2233. // [self.navigationController popToRootViewControllerAnimated:true];
  2234. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  2235. // [appDelegate printPdf:pdf_url];
  2236. // }];
  2237. }
  2238. else
  2239. dispatch_async(dispatch_get_main_queue(), ^{
  2240. // UIAlertController* message_alert=
  2241. [RAUtils message_alert:msg title:title controller:message_parent];
  2242. });
  2243. // __block UIAlertController* message_alert=[RAUtils message_alert:msg title:title controller:self.parentViewController action_handler:^(UIAlertAction * _Nonnull action) {
  2244. //
  2245. //
  2246. //
  2247. //
  2248. //// [self.navigationController popToRootViewControllerAnimated:true];
  2249. //
  2250. //
  2251. // } completion:^{
  2252. //
  2253. // }];
  2254. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2255. //
  2256. // [alert show];
  2257. //
  2258. }
  2259. else
  2260. {
  2261. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2262. }
  2263. }];
  2264. }];
  2265. }];
  2266. }
  2267. @end