CreateOrderViewController.m 164 KB

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