CreateOrderViewController.m 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514
  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. #define SUBMIT_CONFIRM 123
  12. #define KEEP_TAIL 456
  13. #define CLOSE_ACTION 567
  14. @interface CreateOrderViewController ()
  15. // static const char associatedkey;
  16. @end
  17. @implementation CreateOrderViewController
  18. -(void) viewWillAppear:(BOOL)animated
  19. {
  20. [super viewWillAppear:animated];
  21. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  22. if(appDelegate.can_submit_order)
  23. {
  24. [self.btnSubmitOrder setImage:[UIImage imageNamed:@"commit"]];
  25. self.btnSubmitOrder.enabled = true;
  26. }
  27. else
  28. {
  29. [self.btnSubmitOrder setImage:nil];
  30. self.btnSubmitOrder.enabled = false;
  31. }
  32. self.navigationController.navigationBarHidden=false;
  33. }
  34. -(void) download_success
  35. {
  36. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  37. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  38. NSString* order_customerid=[self getValue:@"customer_cid"];
  39. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  40. appDelegate.order_customer_id = order_customerid;
  41. }
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  45. style:UIBarButtonItemStylePlain
  46. target:self
  47. action:@selector(onCloseClick:)];
  48. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  49. // closeButton.title = @"Close";
  50. self.navigationItem.leftBarButtonItem = closeButton;
  51. NSMutableArray * items = [[NSMutableArray alloc]init];
  52. UIBarButtonItem *savebtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
  53. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  54. style:UIBarButtonItemStylePlain
  55. target:self
  56. action:@selector(onSaveClick:)];
  57. self.btnSubmitOrder = nil;
  58. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  59. style:UIBarButtonItemStylePlain
  60. target:self
  61. action:@selector(onCommitOrderClick:)];
  62. // self.btnSubmitOrder.tintColor= UIColorFromRGB(0x996633);
  63. //savebtn setBackgroundImage:(nullable UIImage *) forState:<#(UIControlState)#> style:<#(UIBarButtonItemStyle)#> barMetrics:<#(UIBarMetrics)#>
  64. //[savebtn setImage:[UIImage imageNamed:@"save"] ];
  65. /*
  66. UIBarMetricsDefault,
  67. UIBarMetricsCompact,
  68. UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar
  69. UIBarMetricsCompactPrompt
  70. */
  71. // [savebtn setBackgroundImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  72. // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
  73. // item1.title = @"item1";
  74. //// item1.image = [UIImage imageNamed:@"rect_setting"];
  75. // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
  76. //// item2.image = [UIImage imageNamed:@"rect_about"];
  77. // item2.title = @"item2";
  78. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  79. fixedItem.width = 20.0f;
  80. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  81. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  82. {
  83. [items addObject:savebtn];
  84. [items addObject:fixedItem];
  85. }
  86. [items addObject:self.btnSubmitOrder];
  87. // [items addObject:item2];
  88. self.navigationItem.rightBarButtonItems=items;
  89. // self.navigationItem.backBarButtonItem = backButton;
  90. // Do any additional setup after loading the view.
  91. }
  92. - (void)onCommitOrderClick:(id)sender {
  93. // get customer info
  94. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  95. NSString* msg;
  96. if(appDelegate.offline_mode)
  97. {
  98. msg=@"Are you sure to mark order as ready for submit?";
  99. }
  100. else
  101. {
  102. msg=@"Are you sure to submit order?";
  103. }
  104. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit Confirm.", nil) message:NSLocalizedString(msg, nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  105. alert.tag = SUBMIT_CONFIRM;
  106. [alert show];
  107. }
  108. - (void)onCloseClick:(UIButton *)sender {
  109. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  110. if (self.resumeOrder) {
  111. [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
  112. return;
  113. }
  114. //
  115. // NSRange range = [tempStr rangeOfString:@")\">"];//判断字符串是否包含
  116. //
  117. // //if (range.location ==NSNotFound)//不包含
  118. // if (range.length >0)//包含
  119. // {
  120. //
  121. //
  122. //
  123. // }
  124. // else//不包含
  125. // {
  126. //
  127. // }
  128. UIAlertView * alert = nil;
  129. if(appDelegate.order_status==0)
  130. {
  131. 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];
  132. }
  133. else
  134. {
  135. 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];
  136. }
  137. alert.tag = CLOSE_ACTION;
  138. // alert.
  139. [alert show];
  140. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  141. // appDelegate.order_code = nil;
  142. //
  143. // }
  144. }
  145. - (void)didReceiveMemoryWarning {
  146. [super didReceiveMemoryWarning];
  147. // Dispose of any resources that can be recreated.
  148. }
  149. - (IBAction)onSaveClick:(id)sender {
  150. // add params check here.
  151. [self.lastedit endEditing:true];
  152. [self.lasttextview endEditing:true];
  153. // self.cancommit=true;
  154. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  155. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  156. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  157. // for(int i=0;i<section_count;i++)
  158. // {
  159. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  160. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  161. // for(int j=0;j<item_count;j++)
  162. // {
  163. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  164. // NSString* key = [itemjson valueForKey:@"name"];
  165. // if(key==nil || key.length==0)
  166. // continue;
  167. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  168. // {
  169. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  170. // if([single_select isEqualToString:@"true"])
  171. // {
  172. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  173. // int count = [[cadejson valueForKey:@"count"] intValue];
  174. // bool setvalue = false;
  175. // for(int cc=0;cc<count;cc++)
  176. // {
  177. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  178. // if([[valjson valueForKey:@"check"]intValue]==1)
  179. // {
  180. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  181. // setvalue=true;
  182. // break;
  183. // }
  184. // }
  185. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  186. // {
  187. // self.cancommit = false;
  188. // }
  189. // }
  190. // else
  191. // {
  192. // //not support multi select for now;
  193. // }
  194. // /*
  195. // upparams setValue:itemjson forKey:<#(NSString *)#>
  196. //
  197. // */
  198. // }else
  199. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  200. // {
  201. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  202. // self.cancommit = false;
  203. // }
  204. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  205. // {
  206. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"]==nil)
  207. // self.cancommit = false;
  208. //
  209. // NSString* valuestr = [itemjson valueForKey:@"value"];
  210. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  211. // }
  212. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  213. // {
  214. // NSString* valuestr = [itemjson valueForKey:@"value"];
  215. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  216. //
  217. // NSString* value = [itemjson valueForKey:@"value"];
  218. // NSMutableDictionary* boolitem=nil;
  219. // NSMutableDictionary* subjson=nil;
  220. // if([value isEqualToString:@"true"])
  221. // {
  222. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  223. //
  224. // }
  225. // else
  226. // {
  227. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  228. //
  229. // }
  230. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  231. // if( subjson!=nil /*&& !active*/)
  232. // {
  233. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  234. // for(int l=0;l<sub_count;l++)
  235. // {
  236. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  237. //
  238. //
  239. //
  240. //
  241. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  242. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  243. // else
  244. // {
  245. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  246. // self.cancommit = false;
  247. // }
  248. // }
  249. //
  250. //
  251. //
  252. // }
  253. // }
  254. // else
  255. // {
  256. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  257. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  258. // else
  259. // {
  260. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  261. // self.cancommit = false;
  262. // }
  263. // }
  264. // upparams= [self subitem_param:itemjson addto:upparams ];
  265. // }
  266. // }
  267. // // save order 不检查必填项;
  268. // self.cancommit=true;
  269. // if(self.cancommit==false)
  270. // {
  271. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  272. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  273. // //NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  274. // //[self.editorTable reloadData ];
  275. // [self.editorTable reloadData];
  276. // return;
  277. // }
  278. NSMutableDictionary* upparams = [self check_cancommit:false];
  279. // if(self.cancommit==false)
  280. // return;
  281. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"])
  282. upparams[@"shipping"] = nil;
  283. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving Order"];
  284. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  285. NSDictionary* editor_json = [iSalesNetwork save_Order:upparams];
  286. dispatch_async(dispatch_get_main_queue(), ^{
  287. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  288. if([[editor_json valueForKey:@"result"] intValue]==2)
  289. {
  290. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  291. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  292. appDelegate.customerInfo = customerInfo;
  293. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  294. [RAUtils message_alert:nil title:@"Order Saved" controller:self] ;
  295. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  296. {
  297. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  298. [self prepareReturn:nil];
  299. [self.navigationController popViewControllerAnimated:true];
  300. }
  301. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  302. // appDelegate.order_code = nil;
  303. //
  304. // }
  305. // // self.labelContact.text=appDelegate.contact_name;
  306. //
  307. // NSDictionary * customerinfo = appDelegate.customerInfo;
  308. // [self prepareReturn:nil];
  309. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  310. //
  311. //
  312. // ;
  313. // }];
  314. }
  315. else
  316. {
  317. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  318. }
  319. });
  320. });
  321. }
  322. - (void)textFieldDidEndEditing:(UITextField *)textField
  323. {
  324. [super textFieldDidEndEditing:textField];
  325. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  326. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  327. NSMutableDictionary* section_json=nil;
  328. // NSLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  329. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  330. NSString* name = [item_json valueForKey:@"name"];
  331. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"])
  332. {
  333. float shipping = [self getprice:@"shipping" section:indexPath.section];
  334. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  335. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  336. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  337. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate;
  338. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  339. int count=0;
  340. count=[[section_json valueForKey:@"count"] intValue];
  341. int total_row_idx=-1;
  342. for(int i=0;i<count;i++)
  343. {
  344. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  345. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  346. {
  347. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  348. [olditem setValue:@"true" forKey:@"dirty"];
  349. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  350. total_row_idx=i;
  351. }
  352. }
  353. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  354. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  355. if(total_row_idx>=0)
  356. {
  357. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  358. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  359. // NSLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  360. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  361. // NSLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  362. // CGSize tablecontent =self.editorTable.contentSize;
  363. // tablecontent.height=tablecontent.height+self.keyboard_h;
  364. // self.editorTable.contentSize=tablecontent;
  365. //
  366. //
  367. // NSLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  368. }
  369. // self.content_data = [editor_json mutableCopy];
  370. // self.content_data = [self translate_json:editor_json];
  371. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  372. // [self.editorTable reloadData];
  373. }
  374. //
  375. // [item_json setValue:@"true" forKey:@"dirty"];
  376. // [item_json setValue:textField.text forKey:@"value"];
  377. }
  378. -(float) getprice:(NSString*) name section :(long) index
  379. {
  380. NSMutableDictionary* section_json=nil;
  381. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  382. int count=0;
  383. count=[[section_json valueForKey:@"count"] intValue];
  384. for(int i=0;i<count;i++)
  385. {
  386. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  387. if([[olditem valueForKey:@"name"] isEqualToString:name])
  388. {
  389. return [[olditem valueForKey:@"value"] floatValue];
  390. }
  391. }
  392. return 0;
  393. }
  394. /*
  395. #pragma mark - Navigation
  396. // In a storyboard-based application, you will often want to do a little preparation before navigation
  397. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  398. // Get the new view controller using [segue destinationViewController].
  399. // Pass the selected object to the new view controller.
  400. }
  401. */
  402. #pragma mark - UIAlertViewDelegate
  403. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  404. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  405. {
  406. if(buttonIndex!=alertView.cancelButtonIndex && alertView.tag == SUBMIT_CONFIRM)
  407. {
  408. // add params check here.
  409. [self.lastedit endEditing:true];
  410. [self.lasttextview endEditing:true];
  411. // self.cancommit=true;
  412. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  413. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  414. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  415. // for(int i=0;i<section_count;i++)
  416. // {
  417. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  418. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  419. // for(int j=0;j<item_count;j++)
  420. // {
  421. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  422. // NSString* key = [itemjson valueForKey:@"name"];
  423. // if(key==nil || key.length==0)
  424. // continue;
  425. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  426. // {
  427. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  428. // if([single_select isEqualToString:@"true"])
  429. // {
  430. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  431. // int count = [[cadejson valueForKey:@"count"] intValue];
  432. // bool setvalue = false;
  433. // for(int cc=0;cc<count;cc++)
  434. // {
  435. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  436. // if([[valjson valueForKey:@"check"]intValue]==1)
  437. // {
  438. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  439. // setvalue=true;
  440. // break;
  441. // }
  442. // }
  443. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  444. // {
  445. // self.cancommit = false;
  446. // }
  447. // }
  448. // else
  449. // {
  450. // //not support multi select for now;
  451. // }
  452. // /*
  453. // upparams setValue:itemjson forKey:<#(NSString *)#>
  454. //
  455. // */
  456. // }else
  457. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  458. // {
  459. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  460. // self.cancommit = false;
  461. // }
  462. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  463. // {
  464. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  465. // self.cancommit = false;
  466. //
  467. // NSString* valuestr = [itemjson valueForKey:@"value"];
  468. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  469. // }
  470. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  471. // {
  472. // NSString* valuestr = [itemjson valueForKey:@"value"];
  473. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  474. //
  475. // NSString* value = [itemjson valueForKey:@"value"];
  476. // NSMutableDictionary* boolitem=nil;
  477. // NSMutableDictionary* subjson=nil;
  478. // if([value isEqualToString:@"true"])
  479. // {
  480. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  481. //
  482. // }
  483. // else
  484. // {
  485. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  486. //
  487. // }
  488. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  489. // if( subjson!=nil /*&& !active*/)
  490. // {
  491. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  492. // for(int l=0;l<sub_count;l++)
  493. // {
  494. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  495. //
  496. //
  497. //
  498. //
  499. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  500. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  501. // else
  502. // {
  503. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  504. // self.cancommit = false;
  505. // }
  506. // }
  507. //
  508. //
  509. //
  510. // }
  511. // }
  512. // else
  513. // {
  514. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  515. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  516. // else
  517. // {
  518. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  519. // self.cancommit = false;
  520. // }
  521. // }
  522. // upparams= [self subitem_param:itemjson addto:upparams ];
  523. // }
  524. // }
  525. // if(self.cancommit==false)
  526. // {
  527. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  528. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  529. // //NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  530. // //[self.editorTable reloadData ];
  531. // [self.editorTable reloadData];
  532. // // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  533. // return;
  534. // }
  535. NSMutableDictionary* upparams = [self check_cancommit:true];
  536. if(self.cancommit==false)
  537. return;
  538. if(upparams[@"shipping"]==nil)
  539. goto commit_order;
  540. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"])
  541. {
  542. upparams[@"shipping"] = nil;
  543. goto commit_order;
  544. }
  545. else if([upparams[@"shipping"] doubleValue]==0)
  546. {
  547. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  548. //block代码块取代了delegate
  549. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  550. {
  551. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  552. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  553. {
  554. if(/*!self.have_tail*/ true)
  555. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  556. [upparams setValue:@"false" forKey:@"isHold"];
  557. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  558. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  559. dispatch_async(dispatch_get_main_queue(), ^{
  560. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  561. if([[editor_json valueForKey:@"result"] intValue]==2)
  562. {
  563. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  564. // debug aaa
  565. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  566. NSString* company= appDelegate.customerInfo[@"customer_name"];
  567. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  568. // appDelegate.customerInfo = customerInfo;
  569. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  570. // appDelegate.order_code = nil;
  571. [appDelegate closeOrder];
  572. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  573. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  574. [alert show];
  575. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  576. NSString* email_content =[editor_json valueForKey:@"email_content"];
  577. NSString* soid=[editor_json valueForKey:@"so#"];
  578. // if(pdf_url.length>0)
  579. // {
  580. //
  581. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  582. // //[self downloadpdf:pdf_url];
  583. //
  584. //
  585. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  586. // {
  587. // //bbb
  588. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  589. // }
  590. //
  591. // [self prepareReturn:nil];
  592. //
  593. // [self.navigationController popViewControllerAnimated:true];
  594. //
  595. // [appDelegate printPdf:pdf_url];
  596. //// if(self.printPdfCallback)
  597. //// self.printPdfCallback(pdf_url);
  598. // }
  599. // else
  600. {
  601. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  602. {
  603. //bbb
  604. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  605. }
  606. [self prepareReturn:nil];
  607. [self.navigationController popViewControllerAnimated:true];
  608. if(pdf_url.length>0)
  609. {
  610. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  611. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  612. // [appDelegate printPdf:pdf_url];
  613. }
  614. }
  615. }
  616. else
  617. {
  618. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  619. }
  620. });
  621. });
  622. }
  623. else
  624. {
  625. 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];
  626. alert.tag = KEEP_TAIL;
  627. self.upparams = upparams;
  628. [alert show];
  629. }
  630. }
  631. else
  632. { //USER_ROLE_CUSTOMER
  633. // if(self.have_tail)
  634. // [upparams setValue:@"true" forKey:@"isHold"];
  635. // else
  636. // [upparams setValue:@"false" forKey:@"isHold"];
  637. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  638. [upparams setValue:@"true" forKey:@"isHold"];
  639. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  640. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  641. dispatch_async(dispatch_get_main_queue(), ^{
  642. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  643. if([[editor_json valueForKey:@"result"] intValue]==2)
  644. {
  645. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  646. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  647. // appDelegate.customerInfo = customerInfo;
  648. NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  649. appDelegate.order_code = orderCode;
  650. appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  651. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  652. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  653. [alert show];
  654. // // self.labelContact.text=appDelegate.contact_name;
  655. //
  656. // NSDictionary * customerinfo = appDelegate.customerInfo;
  657. [self prepareReturn:nil];
  658. [self.navigationController popViewControllerAnimated:true];
  659. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  660. //
  661. //
  662. // ;
  663. // }];
  664. }
  665. else
  666. {
  667. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  668. }
  669. });
  670. });
  671. }
  672. }];
  673. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  674. //NSLog(@"Cancel");
  675. }];
  676. [alertControl addAction:actionOne];
  677. [alertControl addAction:alertthree];
  678. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  679. [self presentViewController:alertControl animated:YES completion:nil];
  680. }
  681. else
  682. {
  683. commit_order:
  684. {
  685. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  686. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  687. {
  688. if(/*!self.have_tail*/ true)
  689. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  690. [upparams setValue:@"false" forKey:@"isHold"];
  691. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  692. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  693. dispatch_async(dispatch_get_main_queue(), ^{
  694. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  695. if([[editor_json valueForKey:@"result"] intValue]==2)
  696. {
  697. //debug bbb
  698. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  699. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  700. NSString* company= appDelegate.customerInfo[@"customer_name"];
  701. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  702. // appDelegate.customerInfo = customerInfo;
  703. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  704. // appDelegate.order_code = nil;
  705. [appDelegate closeOrder];
  706. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  707. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  708. [alert show];
  709. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  710. NSString* email_content =[editor_json valueForKey:@"email_content"];
  711. NSString* soid=[editor_json valueForKey:@"so#"];
  712. // if(pdf_url.length>0)
  713. // {
  714. //
  715. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  716. //// [self downloadpdf:pdf_url];
  717. //
  718. //
  719. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  720. // {
  721. // //bbb
  722. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  723. // }
  724. //
  725. // [self prepareReturn:nil];
  726. //
  727. // [self.navigationController popViewControllerAnimated:true];
  728. //
  729. // [appDelegate printPdf:pdf_url];
  730. //
  731. //// if(self.printPdfCallback)
  732. //// self.printPdfCallback(pdf_url);
  733. // }
  734. // else
  735. {
  736. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  737. {
  738. //bbb
  739. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  740. }
  741. [self prepareReturn:nil];
  742. [self.navigationController popViewControllerAnimated:true];
  743. if(pdf_url.length>0)
  744. {
  745. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  746. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  747. }
  748. }
  749. // // self.labelContact.text=appDelegate.contact_name;
  750. //
  751. // NSDictionary * customerinfo = appDelegate.customerInfo;
  752. }
  753. else
  754. {
  755. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  756. }
  757. });
  758. });
  759. }
  760. else
  761. {
  762. 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];
  763. alert.tag = KEEP_TAIL;
  764. self.upparams = upparams;
  765. [alert show];
  766. }
  767. }
  768. else
  769. { //USER_ROLE_CUSTOMER
  770. // if(self.have_tail)
  771. // [upparams setValue:@"true" forKey:@"isHold"];
  772. // else
  773. // [upparams setValue:@"false" forKey:@"isHold"];
  774. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  775. [upparams setValue:@"true" forKey:@"isHold"];
  776. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  777. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  778. dispatch_async(dispatch_get_main_queue(), ^{
  779. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  780. if([[editor_json valueForKey:@"result"] intValue]==2)
  781. {
  782. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  783. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  784. // appDelegate.customerInfo = customerInfo;
  785. NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  786. appDelegate.order_code = orderCode;
  787. appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  788. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  789. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  790. [alert show];
  791. // // self.labelContact.text=appDelegate.contact_name;
  792. //
  793. // NSDictionary * customerinfo = appDelegate.customerInfo;
  794. [self prepareReturn:nil];
  795. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  796. //
  797. //
  798. // ;
  799. // }];
  800. [self.navigationController popViewControllerAnimated:true];
  801. }
  802. else
  803. {
  804. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  805. }
  806. });
  807. });
  808. }
  809. }
  810. }
  811. }
  812. // else if( alertView.tag == KEEP_TAIL)
  813. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  814. // if(buttonIndex!=alertView.cancelButtonIndex)
  815. // {//keep tail;
  816. //
  817. // [self.upparams setValue:@"true" forKey:@"isHold"];
  818. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  819. //
  820. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  821. //
  822. // dispatch_async(dispatch_get_main_queue(), ^{
  823. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  824. //
  825. //
  826. // if([[editor_json valueForKey:@"result"] intValue]==2)
  827. // {
  828. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  829. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  830. //
  831. // [alert show];
  832. //
  833. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  834. // appDelegate.customerInfo = customerInfo;
  835. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  836. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  837. // appDelegate.order_code = orderCode;
  838. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  839. // // // self.labelContact.text=appDelegate.contact_name;
  840. // //
  841. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  842. // [self prepareReturn:nil];
  843. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  844. ////
  845. ////
  846. //// ;
  847. //// }];
  848. // [self.navigationController popViewControllerAnimated:true];
  849. //
  850. // }
  851. // else
  852. // {
  853. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  854. // }
  855. //
  856. //
  857. //
  858. //
  859. // });
  860. // });
  861. // }
  862. // else
  863. // {// not keep tail;
  864. // [self.upparams setValue:@"false" forKey:@"isHold"];
  865. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  866. //
  867. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  868. //
  869. // dispatch_async(dispatch_get_main_queue(), ^{
  870. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  871. //
  872. //
  873. // if([[editor_json valueForKey:@"result"] intValue]==2)
  874. // {
  875. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  876. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  877. //
  878. // [alert show];
  879. //
  880. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  881. // // appDelegate.customerInfo = customerInfo;
  882. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  883. // // appDelegate.order_code = nil;
  884. // [appDelegate closeOrder];
  885. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  886. // // // self.labelContact.text=appDelegate.contact_name;
  887. // //
  888. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  889. // [self prepareReturn:nil];
  890. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  891. ////
  892. ////
  893. //// ;
  894. //// }];
  895. // [self.navigationController popViewControllerAnimated:true];
  896. //
  897. // }
  898. // else
  899. // {
  900. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  901. // }
  902. //
  903. //
  904. //
  905. //
  906. // });
  907. // });
  908. // }
  909. // }
  910. else if(alertView.tag == CLOSE_ACTION)
  911. {
  912. if(buttonIndex==1)
  913. {
  914. [self.navigationController popViewControllerAnimated:true];
  915. // back to cart;
  916. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  917. // ;
  918. // }];
  919. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  920. // appDelegate.order_code = nil;
  921. //
  922. // }
  923. }
  924. if(buttonIndex==2)
  925. {
  926. [self.navigationController popViewControllerAnimated:true];
  927. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  928. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  929. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  930. // back to cart;
  931. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  932. // ;
  933. // }];
  934. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  935. // appDelegate.order_code = nil;
  936. //
  937. // }
  938. }
  939. else if(buttonIndex==3)
  940. {
  941. // close order;
  942. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  943. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  944. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  945. NSDictionary* order_json = [iSalesNetwork release_Order:appDelegate.order_code];
  946. dispatch_async(dispatch_get_main_queue(), ^{
  947. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  948. if([[order_json valueForKey:@"result"] intValue]==2)
  949. {
  950. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  951. // appDelegate.order_code = nil;
  952. [appDelegate closeOrder];
  953. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  954. [((MainViewController*)appDelegate.main_vc) switchToHome];
  955. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  956. {
  957. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  958. }
  959. [self prepareReturn:nil];
  960. [self.navigationController popViewControllerAnimated:true];
  961. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  962. // ;
  963. // }];
  964. }
  965. else
  966. {
  967. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  968. }
  969. });
  970. });
  971. //
  972. // }
  973. }
  974. }
  975. }
  976. //
  977. //
  978. //-(void) downloadpdf:(NSString* )url
  979. //{
  980. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Printing..."];
  981. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  982. //
  983. //
  984. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  985. //
  986. // //设置请求方式为get
  987. //
  988. // [request setHTTPMethod:@"GET"];
  989. //
  990. // //添加用户会话id
  991. //
  992. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  993. //
  994. // //连接发送请求
  995. //
  996. //
  997. // NSHTTPURLResponse* urlResponse = nil;
  998. //
  999. // NSError *error = [[NSError alloc] init];
  1000. //
  1001. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  1002. //
  1003. // // self.filename = [urlResponse suggestedFilename];
  1004. //
  1005. //
  1006. // dispatch_async(dispatch_get_main_queue(), ^{
  1007. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1008. // // self.navigationItem.title = self.save_name;
  1009. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  1010. // // self.content=nil;
  1011. // if(content!=nil&&content.length>0)
  1012. // {
  1013. //
  1014. //
  1015. // [self startAirPrintWithData:content];
  1016. //
  1017. //
  1018. // }
  1019. // else
  1020. // {
  1021. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  1022. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  1023. // }
  1024. //
  1025. // ;
  1026. // // NSLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  1027. // //
  1028. //
  1029. //
  1030. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  1031. //
  1032. //
  1033. //
  1034. //
  1035. // });
  1036. // });
  1037. //}
  1038. //
  1039. //- (void)startAirPrintWithData:(id )data
  1040. //{
  1041. //
  1042. //
  1043. //
  1044. //
  1045. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  1046. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  1047. // printInfo.outputType = UIPrintInfoOutputGeneral;
  1048. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  1049. // printInfo.jobName = @"CoolVisitAirPrint";
  1050. // airPrinterController.printInfo = printInfo;
  1051. // airPrinterController.printingItem = data;
  1052. // airPrinterController.delegate = self;
  1053. //
  1054. //
  1055. // airPrinterController.showsNumberOfCopies=true;
  1056. // airPrinterController.showsPageRange = true;
  1057. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  1058. //
  1059. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  1060. // if(completed && error)
  1061. // NSLog(@"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);
  1062. // };
  1063. //
  1064. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1065. //
  1066. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  1067. //
  1068. //
  1069. //
  1070. //
  1071. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  1072. // {
  1073. // if (available&& appDelegate.printerURL.length>0)
  1074. // {
  1075. //
  1076. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  1077. // NSLog(@"AIRPRINTER AVAILABLE");
  1078. // }
  1079. // else
  1080. // {
  1081. //
  1082. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1083. // //
  1084. // //
  1085. // //
  1086. // // // [printPicker presentAnimated:YES completionHandler:
  1087. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  1088. // // {
  1089. // // if (userDidSelect)
  1090. // // {
  1091. // // NSString* sid= printerController.printInfo.printerID;
  1092. // // UIPrintPaper*paper= printerController.printPaper;
  1093. // //
  1094. // // }
  1095. // // }];
  1096. //
  1097. //
  1098. // NSLog(@"AIRPRINTER NOT AVAILABLE");
  1099. //
  1100. //
  1101. //
  1102. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  1103. // {
  1104. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  1105. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  1106. //
  1107. //
  1108. //
  1109. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  1110. //
  1111. //
  1112. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1113. //
  1114. //
  1115. //
  1116. // // [printPicker presentAnimated:YES completionHandler:
  1117. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  1118. // {
  1119. // if (userDidSelect)
  1120. // {
  1121. // //User selected the item in the UIPrinterPickerController and got the printer details.
  1122. //
  1123. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  1124. //
  1125. // //Here you will get the printer and printer details.ie,
  1126. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  1127. //
  1128. //
  1129. //
  1130. //
  1131. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  1132. //
  1133. // [self startAirPrintWithData:data];
  1134. //
  1135. // }
  1136. // else
  1137. // {
  1138. //
  1139. //
  1140. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1141. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1142. // {
  1143. //
  1144. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1145. // }
  1146. // [self prepareReturn:nil];
  1147. //
  1148. // [self.navigationController popViewControllerAnimated:true];
  1149. // }
  1150. // }];
  1151. // }
  1152. // }
  1153. // }];
  1154. //
  1155. //
  1156. //
  1157. //}
  1158. //
  1159. //#pragma mark - UIPrintInteractionControllerDelegate
  1160. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  1161. //{
  1162. //
  1163. // ;
  1164. //
  1165. // // (int) width = 29700
  1166. // // Printing description of (*( (int *)0x7caa3a40)):
  1167. // // (int) height = 42000
  1168. // //设置纸张大小
  1169. //
  1170. //
  1171. // for(UIPrintPaper* paper in paperList)
  1172. // {
  1173. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  1174. // return paper;
  1175. //
  1176. // }
  1177. // CGSize paperSize = CGSizeMake(612, 792);
  1178. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  1179. // return p;
  1180. //}
  1181. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1182. //{
  1183. //
  1184. //}
  1185. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1186. //{
  1187. //
  1188. //}
  1189. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1190. //{
  1191. //
  1192. //}
  1193. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1194. //{
  1195. //
  1196. //}
  1197. //
  1198. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  1199. //{
  1200. //
  1201. //}
  1202. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  1203. //{
  1204. //
  1205. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1206. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1207. // {
  1208. //
  1209. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1210. // }
  1211. //
  1212. // [self prepareReturn:nil];
  1213. //
  1214. // [self.navigationController popViewControllerAnimated:true];
  1215. //}
  1216. @end