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"]||[name isEqualToString:@"tax_percentage"])
  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 tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  921. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  922. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  923. int count=0;
  924. count=[[section_json valueForKey:@"count"] intValue];
  925. int total_row_idx=-1;
  926. for(int i=0;i<count;i++)
  927. {
  928. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  929. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  930. {
  931. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  932. [olditem setValue:@"true" forKey:@"dirty"];
  933. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  934. total_row_idx=i;
  935. }
  936. }
  937. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  938. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  939. if(total_row_idx>=0)
  940. {
  941. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  942. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  943. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  944. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  945. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  946. // CGSize tablecontent =self.editorTable.contentSize;
  947. // tablecontent.height=tablecontent.height+self.keyboard_h;
  948. // self.editorTable.contentSize=tablecontent;
  949. //
  950. //
  951. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  952. }
  953. // self.content_data = [editor_json mutableCopy];
  954. // self.content_data = [self translate_json:editor_json];
  955. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  956. // [self.editorTable reloadData];
  957. }
  958. //
  959. // [item_json setValue:@"true" forKey:@"dirty"];
  960. // [item_json setValue:textField.text forKey:@"value"];
  961. }
  962. -(float) getprice:(NSString*) name section :(long) index
  963. {
  964. NSMutableDictionary* section_json=nil;
  965. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  966. int count=0;
  967. count=[[section_json valueForKey:@"count"] intValue];
  968. for(int i=0;i<count;i++)
  969. {
  970. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  971. if([[olditem valueForKey:@"name"] isEqualToString:name])
  972. {
  973. return [[olditem valueForKey:@"value"] floatValue];
  974. }
  975. }
  976. return 0;
  977. }
  978. /*
  979. #pragma mark - Navigation
  980. // In a storyboard-based application, you will often want to do a little preparation before navigation
  981. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  982. // Get the new view controller using [segue destinationViewController].
  983. // Pass the selected object to the new view controller.
  984. }
  985. */
  986. #pragma mark - UIAlertViewDelegate
  987. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  988. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  989. {
  990. if(buttonIndex!=alertView.cancelButtonIndex && alertView.tag == SUBMIT_CONFIRM)
  991. {
  992. // add params check here.
  993. [self.lastedit endEditing:true];
  994. [self.lasttextview endEditing:true];
  995. // self.cancommit=true;
  996. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  997. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  998. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  999. // for(int i=0;i<section_count;i++)
  1000. // {
  1001. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1002. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1003. // for(int j=0;j<item_count;j++)
  1004. // {
  1005. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1006. // NSString* key = [itemjson valueForKey:@"name"];
  1007. // if(key==nil || key.length==0)
  1008. // continue;
  1009. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  1010. // {
  1011. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  1012. // if([single_select isEqualToString:@"true"])
  1013. // {
  1014. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  1015. // int count = [[cadejson valueForKey:@"count"] intValue];
  1016. // bool setvalue = false;
  1017. // for(int cc=0;cc<count;cc++)
  1018. // {
  1019. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1020. // if([[valjson valueForKey:@"check"]intValue]==1)
  1021. // {
  1022. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  1023. // setvalue=true;
  1024. // break;
  1025. // }
  1026. // }
  1027. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  1028. // {
  1029. // self.cancommit = false;
  1030. // }
  1031. // }
  1032. // else
  1033. // {
  1034. // //not support multi select for now;
  1035. // }
  1036. // /*
  1037. // upparams setValue:itemjson forKey:<#(NSString *)#>
  1038. //
  1039. // */
  1040. // }else
  1041. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  1042. // {
  1043. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  1044. // self.cancommit = false;
  1045. // }
  1046. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  1047. // {
  1048. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  1049. // self.cancommit = false;
  1050. //
  1051. // NSString* valuestr = [itemjson valueForKey:@"value"];
  1052. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1053. // }
  1054. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  1055. // {
  1056. // NSString* valuestr = [itemjson valueForKey:@"value"];
  1057. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1058. //
  1059. // NSString* value = [itemjson valueForKey:@"value"];
  1060. // NSMutableDictionary* boolitem=nil;
  1061. // NSMutableDictionary* subjson=nil;
  1062. // if([value isEqualToString:@"true"])
  1063. // {
  1064. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  1065. //
  1066. // }
  1067. // else
  1068. // {
  1069. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  1070. //
  1071. // }
  1072. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  1073. // if( subjson!=nil /*&& !active*/)
  1074. // {
  1075. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  1076. // for(int l=0;l<sub_count;l++)
  1077. // {
  1078. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1079. //
  1080. //
  1081. //
  1082. //
  1083. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  1084. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  1085. // else
  1086. // {
  1087. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  1088. // self.cancommit = false;
  1089. // }
  1090. // }
  1091. //
  1092. //
  1093. //
  1094. // }
  1095. // }
  1096. // else
  1097. // {
  1098. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  1099. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  1100. // else
  1101. // {
  1102. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  1103. // self.cancommit = false;
  1104. // }
  1105. // }
  1106. // upparams= [self subitem_param:itemjson addto:upparams ];
  1107. // }
  1108. // }
  1109. // if(self.cancommit==false)
  1110. // {
  1111. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  1112. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1113. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1114. // //[self.editorTable reloadData ];
  1115. // [self.editorTable reloadData];
  1116. // // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1117. // return;
  1118. // }
  1119. NSMutableDictionary* upparams = [self check_cancommit:true];
  1120. if(self.cancommit==false)
  1121. return;
  1122. if(upparams[@"shipping"]==nil)
  1123. goto commit_order;
  1124. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"])
  1125. {
  1126. upparams[@"shipping"] = nil;
  1127. goto commit_order;
  1128. }
  1129. else if([upparams[@"shipping"] doubleValue]==0)
  1130. {
  1131. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1132. //block代码块取代了delegate
  1133. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  1134. {
  1135. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1136. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1137. {
  1138. if(/*!self.have_tail*/ true)
  1139. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1140. [upparams setValue:@"false" forKey:@"isHold"];
  1141. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1142. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  1143. dispatch_async(dispatch_get_main_queue(), ^{
  1144. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1145. if([[editor_json valueForKey:@"result"] intValue]==2)
  1146. {
  1147. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1148. // debug aaa
  1149. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1150. NSString* company= appDelegate.customerInfo[@"customer_name"];
  1151. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1152. // appDelegate.customerInfo = customerInfo;
  1153. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1154. // appDelegate.order_code = nil;
  1155. [appDelegate closeOrder];
  1156. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1157. NSString* title=nil;
  1158. NSString* msg=nil;
  1159. if(appDelegate.offline_mode)
  1160. {
  1161. title=TITLE_OFFLINE_SUBMIT;
  1162. msg=MSG_OFFLINE_SUBMIT;
  1163. }
  1164. else
  1165. {
  1166. title=@"Submit successful.";
  1167. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  1168. }
  1169. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1170. [alert show];
  1171. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1172. NSString* email_content =[editor_json valueForKey:@"email_content"];
  1173. NSString* soid=[editor_json valueForKey:@"so#"];
  1174. // if(pdf_url.length>0)
  1175. // {
  1176. //
  1177. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1178. // //[self downloadpdf:pdf_url];
  1179. //
  1180. //
  1181. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1182. // {
  1183. // //bbb
  1184. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1185. // }
  1186. //
  1187. // [self prepareReturn:nil];
  1188. //
  1189. // [self.navigationController popViewControllerAnimated:true];
  1190. //
  1191. // [appDelegate printPdf:pdf_url];
  1192. //// if(self.printPdfCallback)
  1193. //// self.printPdfCallback(pdf_url);
  1194. // }
  1195. // else
  1196. {
  1197. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1198. {
  1199. //bbb
  1200. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1201. }
  1202. [self prepareReturn:nil];
  1203. [self.navigationController popViewControllerAnimated:true];
  1204. if(pdf_url.length>0)
  1205. {
  1206. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1207. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1208. // [appDelegate printPdf:pdf_url];
  1209. }
  1210. }
  1211. }
  1212. else
  1213. {
  1214. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1215. }
  1216. });
  1217. });
  1218. }
  1219. else
  1220. {
  1221. 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];
  1222. alert.tag = KEEP_TAIL;
  1223. self.upparams = upparams;
  1224. [alert show];
  1225. }
  1226. }
  1227. else
  1228. { //USER_ROLE_CUSTOMER
  1229. // if(self.have_tail)
  1230. // [upparams setValue:@"true" forKey:@"isHold"];
  1231. // else
  1232. // [upparams setValue:@"false" forKey:@"isHold"];
  1233. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1234. [upparams setValue:@"true" forKey:@"isHold"];
  1235. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1236. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  1237. dispatch_async(dispatch_get_main_queue(), ^{
  1238. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1239. if([[editor_json valueForKey:@"result"] intValue]==2)
  1240. {
  1241. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1242. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1243. // appDelegate.customerInfo = customerInfo;
  1244. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1245. // appDelegate.order_code = orderCode;
  1246. // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1247. [appDelegate closeOrder];
  1248. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1249. NSString* title=nil;
  1250. NSString* msg=nil;
  1251. if(appDelegate.offline_mode)
  1252. {
  1253. title=TITLE_OFFLINE_SUBMIT;
  1254. msg=MSG_OFFLINE_SUBMIT;
  1255. }
  1256. else
  1257. {
  1258. title=@"Submit successful.";
  1259. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  1260. }
  1261. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1262. [alert show];
  1263. // // self.labelContact.text=appDelegate.contact_name;
  1264. //
  1265. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1266. [self prepareReturn:nil];
  1267. [self.navigationController popViewControllerAnimated:true];
  1268. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1269. //
  1270. //
  1271. // ;
  1272. // }];
  1273. }
  1274. else
  1275. {
  1276. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1277. }
  1278. });
  1279. });
  1280. }
  1281. }];
  1282. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1283. //DebugLog(@"Cancel");
  1284. }];
  1285. [alertControl addAction:actionOne];
  1286. [alertControl addAction:alertthree];
  1287. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1288. [self presentViewController:alertControl animated:YES completion:nil];
  1289. }
  1290. else
  1291. {
  1292. commit_order:
  1293. {
  1294. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1295. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1296. {
  1297. if(/*!self.have_tail*/ true)
  1298. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1299. [upparams setValue:@"false" forKey:@"isHold"];
  1300. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1301. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  1302. dispatch_async(dispatch_get_main_queue(), ^{
  1303. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1304. if([[editor_json valueForKey:@"result"] intValue]==2)
  1305. {
  1306. //debug bbb
  1307. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1308. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1309. NSString* company= appDelegate.customerInfo[@"customer_name"];
  1310. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1311. // appDelegate.customerInfo = customerInfo;
  1312. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1313. // appDelegate.order_code = nil;
  1314. [appDelegate closeOrder];
  1315. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1316. NSString* title=nil;
  1317. NSString* msg=nil;
  1318. if(appDelegate.offline_mode)
  1319. {
  1320. title=TITLE_OFFLINE_SUBMIT;
  1321. msg=MSG_OFFLINE_SUBMIT;
  1322. }
  1323. else
  1324. {
  1325. title=@"Submit successful.";
  1326. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  1327. }
  1328. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1329. [alert show];
  1330. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1331. NSString* email_content =[editor_json valueForKey:@"email_content"];
  1332. NSString* soid=[editor_json valueForKey:@"so#"];
  1333. // if(pdf_url.length>0)
  1334. // {
  1335. //
  1336. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1337. //// [self downloadpdf:pdf_url];
  1338. //
  1339. //
  1340. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1341. // {
  1342. // //bbb
  1343. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1344. // }
  1345. //
  1346. // [self prepareReturn:nil];
  1347. //
  1348. // [self.navigationController popViewControllerAnimated:true];
  1349. //
  1350. // [appDelegate printPdf:pdf_url];
  1351. //
  1352. //// if(self.printPdfCallback)
  1353. //// self.printPdfCallback(pdf_url);
  1354. // }
  1355. // else
  1356. {
  1357. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1358. {
  1359. //bbb
  1360. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1361. }
  1362. [self prepareReturn:nil];
  1363. [self.navigationController popViewControllerAnimated:true];
  1364. if(pdf_url.length>0)
  1365. {
  1366. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1367. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1368. }
  1369. }
  1370. // // self.labelContact.text=appDelegate.contact_name;
  1371. //
  1372. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1373. }
  1374. else
  1375. {
  1376. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1377. }
  1378. });
  1379. });
  1380. }
  1381. else
  1382. {
  1383. 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];
  1384. alert.tag = KEEP_TAIL;
  1385. self.upparams = upparams;
  1386. [alert show];
  1387. }
  1388. }
  1389. else
  1390. { //USER_ROLE_CUSTOMER
  1391. // if(self.have_tail)
  1392. // [upparams setValue:@"true" forKey:@"isHold"];
  1393. // else
  1394. // [upparams setValue:@"false" forKey:@"isHold"];
  1395. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1396. [upparams setValue:@"true" forKey:@"isHold"];
  1397. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1398. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  1399. dispatch_async(dispatch_get_main_queue(), ^{
  1400. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1401. if([[editor_json valueForKey:@"result"] intValue]==2)
  1402. {
  1403. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1404. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1405. // appDelegate.customerInfo = customerInfo;
  1406. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1407. // appDelegate.order_code = orderCode;
  1408. // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1409. [appDelegate closeOrder];
  1410. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1411. NSString* title=nil;
  1412. NSString* msg=nil;
  1413. if(appDelegate.offline_mode)
  1414. {
  1415. title=TITLE_OFFLINE_SUBMIT;
  1416. msg=MSG_OFFLINE_SUBMIT;
  1417. }
  1418. else
  1419. {
  1420. title=@"Submit successful.";
  1421. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  1422. }
  1423. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1424. [alert show];
  1425. // // self.labelContact.text=appDelegate.contact_name;
  1426. //
  1427. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1428. [self prepareReturn:nil];
  1429. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1430. //
  1431. //
  1432. // ;
  1433. // }];
  1434. [self.navigationController popViewControllerAnimated:true];
  1435. }
  1436. else
  1437. {
  1438. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1439. }
  1440. });
  1441. });
  1442. }
  1443. }
  1444. }
  1445. }
  1446. // else if( alertView.tag == KEEP_TAIL)
  1447. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1448. // if(buttonIndex!=alertView.cancelButtonIndex)
  1449. // {//keep tail;
  1450. //
  1451. // [self.upparams setValue:@"true" forKey:@"isHold"];
  1452. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1453. //
  1454. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  1455. //
  1456. // dispatch_async(dispatch_get_main_queue(), ^{
  1457. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1458. //
  1459. //
  1460. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1461. // {
  1462. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1463. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1464. //
  1465. // [alert show];
  1466. //
  1467. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1468. // appDelegate.customerInfo = customerInfo;
  1469. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1470. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1471. // appDelegate.order_code = orderCode;
  1472. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1473. // // // self.labelContact.text=appDelegate.contact_name;
  1474. // //
  1475. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1476. // [self prepareReturn:nil];
  1477. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  1478. ////
  1479. ////
  1480. //// ;
  1481. //// }];
  1482. // [self.navigationController popViewControllerAnimated:true];
  1483. //
  1484. // }
  1485. // else
  1486. // {
  1487. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1488. // }
  1489. //
  1490. //
  1491. //
  1492. //
  1493. // });
  1494. // });
  1495. // }
  1496. // else
  1497. // {// not keep tail;
  1498. // [self.upparams setValue:@"false" forKey:@"isHold"];
  1499. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1500. //
  1501. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  1502. //
  1503. // dispatch_async(dispatch_get_main_queue(), ^{
  1504. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1505. //
  1506. //
  1507. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1508. // {
  1509. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1510. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1511. //
  1512. // [alert show];
  1513. //
  1514. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1515. // // appDelegate.customerInfo = customerInfo;
  1516. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1517. // // appDelegate.order_code = nil;
  1518. // [appDelegate closeOrder];
  1519. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1520. // // // self.labelContact.text=appDelegate.contact_name;
  1521. // //
  1522. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1523. // [self prepareReturn:nil];
  1524. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  1525. ////
  1526. ////
  1527. //// ;
  1528. //// }];
  1529. // [self.navigationController popViewControllerAnimated:true];
  1530. //
  1531. // }
  1532. // else
  1533. // {
  1534. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1535. // }
  1536. //
  1537. //
  1538. //
  1539. //
  1540. // });
  1541. // });
  1542. // }
  1543. // }
  1544. else if(alertView.tag == CLOSE_ACTION)
  1545. {
  1546. if(buttonIndex==1)
  1547. {
  1548. [self.navigationController popViewControllerAnimated:true];
  1549. // back to cart;
  1550. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1551. // ;
  1552. // }];
  1553. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1554. // appDelegate.order_code = nil;
  1555. //
  1556. // }
  1557. }
  1558. if(buttonIndex==2)
  1559. {
  1560. [self.navigationController popViewControllerAnimated:true];
  1561. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1562. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1563. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1564. // back to cart;
  1565. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1566. // ;
  1567. // }];
  1568. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1569. // appDelegate.order_code = nil;
  1570. //
  1571. // }
  1572. }
  1573. else if(buttonIndex==3)
  1574. {
  1575. // close order;
  1576. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1577. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  1578. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1579. NSDictionary* order_json = [iSalesNetwork release_Order:appDelegate.order_code];
  1580. dispatch_async(dispatch_get_main_queue(), ^{
  1581. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1582. if([[order_json valueForKey:@"result"] intValue]==2)
  1583. {
  1584. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1585. // appDelegate.order_code = nil;
  1586. [appDelegate closeOrder];
  1587. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1588. [((MainViewController*)appDelegate.main_vc) switchToHome];
  1589. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1590. {
  1591. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1592. }
  1593. [self prepareReturn:nil];
  1594. [self.navigationController popViewControllerAnimated:true];
  1595. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1596. // ;
  1597. // }];
  1598. }
  1599. else
  1600. {
  1601. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  1602. }
  1603. });
  1604. });
  1605. //
  1606. // }
  1607. }
  1608. }
  1609. }
  1610. //
  1611. //
  1612. //-(void) downloadpdf:(NSString* )url
  1613. //{
  1614. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Printing..."];
  1615. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1616. //
  1617. //
  1618. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  1619. //
  1620. // //设置请求方式为get
  1621. //
  1622. // [request setHTTPMethod:@"GET"];
  1623. //
  1624. // //添加用户会话id
  1625. //
  1626. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  1627. //
  1628. // //连接发送请求
  1629. //
  1630. //
  1631. // NSHTTPURLResponse* urlResponse = nil;
  1632. //
  1633. // NSError *error = [[NSError alloc] init];
  1634. //
  1635. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  1636. //
  1637. // // self.filename = [urlResponse suggestedFilename];
  1638. //
  1639. //
  1640. // dispatch_async(dispatch_get_main_queue(), ^{
  1641. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1642. // // self.navigationItem.title = self.save_name;
  1643. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  1644. // // self.content=nil;
  1645. // if(content!=nil&&content.length>0)
  1646. // {
  1647. //
  1648. //
  1649. // [self startAirPrintWithData:content];
  1650. //
  1651. //
  1652. // }
  1653. // else
  1654. // {
  1655. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  1656. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  1657. // }
  1658. //
  1659. // ;
  1660. // // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  1661. // //
  1662. //
  1663. //
  1664. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  1665. //
  1666. //
  1667. //
  1668. //
  1669. // });
  1670. // });
  1671. //}
  1672. //
  1673. //- (void)startAirPrintWithData:(id )data
  1674. //{
  1675. //
  1676. //
  1677. //
  1678. //
  1679. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  1680. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  1681. // printInfo.outputType = UIPrintInfoOutputGeneral;
  1682. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  1683. // printInfo.jobName = @"CoolVisitAirPrint";
  1684. // airPrinterController.printInfo = printInfo;
  1685. // airPrinterController.printingItem = data;
  1686. // airPrinterController.delegate = self;
  1687. //
  1688. //
  1689. // airPrinterController.showsNumberOfCopies=true;
  1690. // airPrinterController.showsPageRange = true;
  1691. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  1692. //
  1693. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  1694. // if(completed && error)
  1695. // 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);
  1696. // };
  1697. //
  1698. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1699. //
  1700. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  1701. //
  1702. //
  1703. //
  1704. //
  1705. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  1706. // {
  1707. // if (available&& appDelegate.printerURL.length>0)
  1708. // {
  1709. //
  1710. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  1711. // DebugLog(@"AIRPRINTER AVAILABLE");
  1712. // }
  1713. // else
  1714. // {
  1715. //
  1716. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1717. // //
  1718. // //
  1719. // //
  1720. // // // [printPicker presentAnimated:YES completionHandler:
  1721. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  1722. // // {
  1723. // // if (userDidSelect)
  1724. // // {
  1725. // // NSString* sid= printerController.printInfo.printerID;
  1726. // // UIPrintPaper*paper= printerController.printPaper;
  1727. // //
  1728. // // }
  1729. // // }];
  1730. //
  1731. //
  1732. // DebugLog(@"AIRPRINTER NOT AVAILABLE");
  1733. //
  1734. //
  1735. //
  1736. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  1737. // {
  1738. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  1739. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  1740. //
  1741. //
  1742. //
  1743. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  1744. //
  1745. //
  1746. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1747. //
  1748. //
  1749. //
  1750. // // [printPicker presentAnimated:YES completionHandler:
  1751. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  1752. // {
  1753. // if (userDidSelect)
  1754. // {
  1755. // //User selected the item in the UIPrinterPickerController and got the printer details.
  1756. //
  1757. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  1758. //
  1759. // //Here you will get the printer and printer details.ie,
  1760. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  1761. //
  1762. //
  1763. //
  1764. //
  1765. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  1766. //
  1767. // [self startAirPrintWithData:data];
  1768. //
  1769. // }
  1770. // else
  1771. // {
  1772. //
  1773. //
  1774. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1775. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1776. // {
  1777. //
  1778. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1779. // }
  1780. // [self prepareReturn:nil];
  1781. //
  1782. // [self.navigationController popViewControllerAnimated:true];
  1783. // }
  1784. // }];
  1785. // }
  1786. // }
  1787. // }];
  1788. //
  1789. //
  1790. //
  1791. //}
  1792. //
  1793. //#pragma mark - UIPrintInteractionControllerDelegate
  1794. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  1795. //{
  1796. //
  1797. // ;
  1798. //
  1799. // // (int) width = 29700
  1800. // // Printing description of (*( (int *)0x7caa3a40)):
  1801. // // (int) height = 42000
  1802. // //设置纸张大小
  1803. //
  1804. //
  1805. // for(UIPrintPaper* paper in paperList)
  1806. // {
  1807. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  1808. // return paper;
  1809. //
  1810. // }
  1811. // CGSize paperSize = CGSizeMake(612, 792);
  1812. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  1813. // return p;
  1814. //}
  1815. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1816. //{
  1817. //
  1818. //}
  1819. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1820. //{
  1821. //
  1822. //}
  1823. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1824. //{
  1825. //
  1826. //}
  1827. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1828. //{
  1829. //
  1830. //}
  1831. //
  1832. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  1833. //{
  1834. //
  1835. //}
  1836. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  1837. //{
  1838. //
  1839. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1840. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1841. // {
  1842. //
  1843. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1844. // }
  1845. //
  1846. // [self prepareReturn:nil];
  1847. //
  1848. // [self.navigationController popViewControllerAnimated:true];
  1849. //}
  1850. //
  1851. //- (NSString *)currentPriceTypeName {
  1852. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  1853. //
  1854. // NSString* pricename = nil;
  1855. // switch (priceType) {
  1856. // case 0:
  1857. // pricename=[Singleton sharedInstance].deliveryString;
  1858. // break;
  1859. // case 1:
  1860. // pricename=flat_price;
  1861. // break;
  1862. // case 2:
  1863. // pricename=given_price;
  1864. // break;
  1865. // default:
  1866. // break;
  1867. // }
  1868. // return pricename;
  1869. //}
  1870. - (void)releaseOrderAfterSave {
  1871. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1872. [iSalesNetwork release_Order:appDelegate.order_code];
  1873. [appDelegate closeOrder];
  1874. [appDelegate SetSo:nil];
  1875. appDelegate.cart_count=0;
  1876. [appDelegate update_count_mark];
  1877. [((MainViewController*)appDelegate.main_vc) switchToHome];
  1878. [self prepareReturn:nil];
  1879. [self.navigationController popToRootViewControllerAnimated:false];
  1880. }
  1881. @end