CreateOrderViewController.m 181 KB

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