CreateOrderViewController.m 78 KB

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