CreateOrderViewController.m 79 KB

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