CreateOrderViewController.m 77 KB

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