CreateOrderViewController.m 77 KB

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