CreateOrderViewController.m 77 KB

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