CreateOrderViewController.m 188 KB

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