CreateOrderViewController.m 77 KB

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