CreateOrderViewController.m 163 KB

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