CreateOrderViewController.m 127 KB

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