CreateOrderViewController.m 78 KB

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