CreateOrderViewController.m 126 KB

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