CreateOrderViewController.m 78 KB

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