CartUtils.m 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. //
  2. // CartUtils.m
  3. // iSales-NPD
  4. //
  5. // Created by Ray on 12/26/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CartUtils.h"
  9. #import "RAUtils.h"
  10. #import "AppDelegate.h"
  11. #import "RANetwork.h"
  12. #import "LoginViewController.h"
  13. #import "MainViewController.h"
  14. @implementation CartUtils
  15. +(void) neworder:(UIViewController*) vc selectorholder:(id)holder selector:(SEL)addtocart
  16. {
  17. __block UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Create Order" completion:^{
  18. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  19. NSMutableDictionary* return_json = result;
  20. [waitalert dismissViewControllerAnimated:YES completion:^{
  21. if([[return_json valueForKey:@"result"] intValue]==2)
  22. {
  23. int resulti=[[return_json valueForKey:@"result"] intValue];
  24. if(resulti==2)
  25. {
  26. //successed.
  27. NSString* order_code = [return_json valueForKey:@"orderCode"];
  28. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  29. appDelegate.order_code = order_code;
  30. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  31. IMP imp = [holder methodForSelector:addtocart];
  32. void (*func)(id, SEL) = (void *)imp;
  33. func(holder, addtocart);
  34. // [holder performSelector:addtocart];
  35. }
  36. }
  37. else
  38. {
  39. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:vc] ;
  40. }
  41. }];
  42. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  43. }];
  44. }];
  45. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  46. //
  47. // NSDictionary* return_json = [RANetwork new_Order];
  48. //
  49. // dispatch_async(dispatch_get_main_queue(), ^{
  50. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  51. //
  52. //
  53. // if([[return_json valueForKey:@"result"] intValue]==2)
  54. // {
  55. // int result=[[return_json valueForKey:@"result"] intValue];
  56. // if(result==2)
  57. // {
  58. // //successed.
  59. //
  60. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  61. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  62. // appDelegate.order_code = order_code;
  63. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  64. //
  65. // [holder performSelector:addtocart];
  66. //
  67. //
  68. //
  69. //
  70. // }
  71. // }
  72. // else
  73. // {
  74. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:vc] ;
  75. // }
  76. //
  77. //
  78. //
  79. //
  80. // });
  81. // });
  82. }
  83. +(void) add_to_cart:(UIViewController*) vc selectorholder:(id)holder selector:(SEL)addtocart
  84. {
  85. UIApplication * app = [UIApplication sharedApplication];
  86. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  87. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  88. if(appDelegate.bLogin==false)
  89. {
  90. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  91. loginvc.returnValue = ^(bool blogin){
  92. if(blogin)
  93. {
  94. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  95. if(true)
  96. {
  97. [main_vc checklogin:YES];
  98. NSString* msg =@"";
  99. // if(appDelegate.contact_id.length>0)
  100. // {
  101. // msg = [msg stringByAppendingString:@"Customer:"];
  102. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  103. //
  104. // }
  105. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  106. //block代码块取代了delegate
  107. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  108. // vc.disable_refresh = true;
  109. OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  110. ovc.showNavibar = true;
  111. //ovc.customer_id = appDelegate.contact_id;
  112. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  113. IMP imp = [holder methodForSelector:addtocart];
  114. void (*func)(id, SEL) = (void *)imp;
  115. func(holder, addtocart);
  116. // [holder performSelector:addtocart];
  117. };
  118. ovc.init_style = OL_OPEN;
  119. ovc.onCancel = ^(){
  120. // self.disable_refresh = false;
  121. };
  122. [vc.navigationController pushViewController:ovc animated:true];
  123. }];
  124. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  125. {
  126. //create new;
  127. // self.disable_refresh = true;
  128. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  129. {
  130. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  131. cvc.showNavibar = true;
  132. cvc.contact_type = @"Sales_Order_Customer";
  133. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  134. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  135. appDelegate.customerInfo = value;
  136. if(appDelegate.order_code==nil)
  137. [self neworder:vc selectorholder:holder selector:addtocart];
  138. // neworder();
  139. // [main_vc checklogin:true];
  140. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  141. //
  142. // if(self.returnValue)
  143. // self.returnValue(value);
  144. };
  145. cvc.onCancel = ^(){
  146. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
  147. // self.disable_refresh = false;
  148. };
  149. cvc.onReset = ^(){
  150. // [main_vc checklogin:true];
  151. };
  152. [vc.navigationController pushViewController:cvc animated:true];
  153. }
  154. else
  155. {
  156. [self neworder:vc selectorholder:holder selector:addtocart];
  157. }
  158. }
  159. DebugLog(@"No");
  160. }];
  161. [alertControl addAction:actionOne];
  162. [alertControl addAction:alertthree];
  163. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  164. }];
  165. [alertControl addAction:alertcancel];
  166. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  167. [vc presentViewController:alertControl animated:YES completion:nil];
  168. }
  169. // else
  170. // {
  171. //
  172. // //customer login;
  173. // [main_vc checklogin:false];
  174. // //[self addtocart];
  175. // [holder performSelector:addtocart];
  176. // }
  177. }
  178. };
  179. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  180. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  181. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  182. [vc presentViewController:navi animated:YES completion:^{
  183. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  184. DebugLog(@"LoginViewController present.........");
  185. // self.btop = false;
  186. // <#code#>
  187. }];
  188. }
  189. else
  190. {
  191. //if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&appDelegate.order_code==nil)
  192. if(appDelegate.order_code==nil)
  193. {
  194. if(appDelegate.contact_id.length==0)
  195. {
  196. NSString* msg =@"";
  197. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  198. //block代码块取代了delegate
  199. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  200. // vc.disable_refresh = true;
  201. OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  202. ovc.showNavibar = true;
  203. //ovc.customer_id = appDelegate.contact_id;
  204. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  205. IMP imp = [holder methodForSelector:addtocart];
  206. void (*func)(id, SEL) = (void *)imp;
  207. func(holder, addtocart);
  208. // [holder performSelector:addtocart];
  209. };
  210. ovc.init_style = OL_OPEN;
  211. ovc.onCancel = ^(){
  212. // self.disable_refresh = false;
  213. };
  214. [vc.navigationController pushViewController:ovc animated:true];
  215. }];
  216. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  217. {
  218. //create new;
  219. // self.disable_refresh = true;
  220. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  221. {
  222. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  223. cvc.showNavibar = true;
  224. cvc.contact_type = @"Sales_Order_Customer";
  225. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  226. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  227. appDelegate.customerInfo = value;
  228. if(appDelegate.order_code==nil)
  229. [self neworder:vc selectorholder:holder selector:addtocart];
  230. // neworder();
  231. // [main_vc checklogin:true];
  232. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  233. //
  234. // if(self.returnValue)
  235. // self.returnValue(value);
  236. };
  237. cvc.onCancel = ^(){
  238. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
  239. // self.disable_refresh = false;
  240. };
  241. cvc.onReset = ^(){
  242. // [main_vc checklogin:true];
  243. };
  244. [vc.navigationController pushViewController:cvc animated:true];
  245. }
  246. else
  247. {
  248. [self neworder:vc selectorholder:holder selector:addtocart];
  249. }
  250. }
  251. DebugLog(@"No");
  252. }];
  253. [alertControl addAction:actionOne];
  254. [alertControl addAction:alertthree];
  255. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  256. }];
  257. [alertControl addAction:alertcancel];
  258. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  259. [vc presentViewController:alertControl animated:YES completion:nil];
  260. }
  261. else
  262. {
  263. __block UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Checking Pending Order" completion:^{
  264. [RANetwork request_pendingorder:appDelegate.contact_id completionHandler:^(NSMutableDictionary *result) {
  265. NSMutableDictionary* return_json =result;
  266. [waitalert dismissViewControllerAnimated:YES completion:^{
  267. if([[return_json valueForKey:@"result"] intValue]==2)
  268. {
  269. bool openPendingOrder= [[return_json valueForKey:@"hasPending"] boolValue];
  270. bool createNewOrder=appDelegate.can_create_order;
  271. if(openPendingOrder&&createNewOrder)
  272. {
  273. NSString* msg =@"";
  274. if(appDelegate.contact_id.length>0)
  275. {
  276. msg = [msg stringByAppendingString:@"Customer:"];
  277. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  278. }
  279. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  280. //block代码块取代了delegate
  281. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  282. // vc.disable_refresh = true;
  283. OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  284. ovc.showNavibar = true;
  285. ovc.customer_id = appDelegate.contact_id;
  286. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  287. IMP imp = [holder methodForSelector:addtocart];
  288. void (*func)(id, SEL) = (void *)imp;
  289. func(holder, addtocart);
  290. // [holder performSelector:addtocart];
  291. };
  292. ovc.init_style = OL_OPEN;
  293. ovc.onCancel = ^(){
  294. // self.disable_refresh = false;
  295. };
  296. [vc.navigationController pushViewController:ovc animated:true];
  297. }];
  298. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  299. {
  300. //create new;
  301. // self.disable_refresh = true;
  302. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  303. {
  304. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  305. cvc.showNavibar = true;
  306. cvc.contact_type = @"Sales_Order_Customer";
  307. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  308. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  309. appDelegate.customerInfo = value;
  310. if(appDelegate.order_code==nil)
  311. [self neworder:vc selectorholder:holder selector:addtocart];
  312. // neworder();
  313. // [main_vc checklogin:true];
  314. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  315. //
  316. // if(self.returnValue)
  317. // self.returnValue(value);
  318. };
  319. cvc.onCancel = ^(){
  320. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
  321. // self.disable_refresh = false;
  322. };
  323. cvc.onReset = ^(){
  324. // [main_vc checklogin:true];
  325. };
  326. [vc.navigationController pushViewController:cvc animated:true];
  327. }
  328. else
  329. {
  330. [self neworder:vc selectorholder:holder selector:addtocart];
  331. }
  332. }
  333. DebugLog(@"No");
  334. }];
  335. [alertControl addAction:actionOne];
  336. [alertControl addAction:alertthree];
  337. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  338. }];
  339. [alertControl addAction:alertcancel];
  340. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  341. [vc presentViewController:alertControl animated:YES completion:nil];
  342. }
  343. else
  344. {
  345. if(openPendingOrder)
  346. {
  347. NSString* msg =@"";
  348. if(appDelegate.contact_id.length>0)
  349. {
  350. msg = [msg stringByAppendingString:@"Customer:"];
  351. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  352. }
  353. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  354. //block代码块取代了delegate
  355. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  356. // vc.disable_refresh = true;
  357. OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  358. ovc.showNavibar = true;
  359. ovc.customer_id = appDelegate.contact_id;
  360. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  361. IMP imp = [holder methodForSelector:addtocart];
  362. void (*func)(id, SEL) = (void *)imp;
  363. func(holder, addtocart);
  364. // [holder performSelector:addtocart];
  365. };
  366. ovc.init_style = OL_OPEN;
  367. ovc.onCancel = ^(){
  368. // self.disable_refresh = false;
  369. };
  370. [vc.navigationController pushViewController:ovc animated:true];
  371. }];
  372. [alertControl addAction:actionOne];
  373. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  374. }];
  375. [alertControl addAction:alertcancel];
  376. // [alertControl addAction:alertthree];
  377. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  378. [vc presentViewController:alertControl animated:YES completion:nil];
  379. }
  380. else if(createNewOrder)
  381. {
  382. NSString* msg =@"";
  383. if(appDelegate.contact_id.length>0)
  384. {
  385. msg = [msg stringByAppendingString:@"Customer:"];
  386. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  387. }
  388. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  389. //block代码块取代了delegate
  390. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  391. {
  392. //create new;
  393. // self.disable_refresh = true;
  394. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  395. {
  396. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  397. cvc.showNavibar = true;
  398. cvc.contact_type = @"Sales_Order_Customer";
  399. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  400. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  401. appDelegate.customerInfo = value;
  402. if(appDelegate.order_code==nil)
  403. [self neworder:vc selectorholder:holder selector:addtocart];
  404. // neworder();
  405. // [main_vc checklogin:true];
  406. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  407. //
  408. // if(self.returnValue)
  409. // self.returnValue(value);
  410. };
  411. cvc.onCancel = ^(){
  412. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
  413. // self.disable_refresh = false;
  414. };
  415. cvc.onReset = ^(){
  416. // [main_vc checklogin:true];
  417. };
  418. [vc.navigationController pushViewController:cvc animated:true];
  419. }
  420. else
  421. {
  422. [self neworder:vc selectorholder:holder selector:addtocart];
  423. }
  424. }
  425. DebugLog(@"No");
  426. }];
  427. // [alertControl addAction:actionOne];
  428. [alertControl addAction:alertthree];
  429. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  430. }];
  431. [alertControl addAction:alertcancel];
  432. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  433. [vc presentViewController:alertControl animated:YES completion:nil];
  434. }
  435. else
  436. {
  437. [RAUtils message_alert:[return_json valueForKey:@"You donot have permission to access order"] title:@"Add To Cart" controller:vc];
  438. }
  439. }
  440. }
  441. else
  442. {
  443. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Check Pending Order" controller:vc] ;
  444. }
  445. }];
  446. }];
  447. }];
  448. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  449. //
  450. // NSDictionary* return_json = [RANetwork request_PendingOrder:appDelegate.contact_id];
  451. //
  452. // dispatch_async(dispatch_get_main_queue(), ^{
  453. //
  454. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  455. //
  456. // if([[return_json valueForKey:@"result"] intValue]==2)
  457. // {
  458. //
  459. // bool openPendingOrder= [[return_json valueForKey:@"hasPending"] boolValue];
  460. // bool createNewOrder=appDelegate.can_create_order;
  461. //
  462. // if(openPendingOrder&&createNewOrder)
  463. // {
  464. //
  465. // NSString* msg =@"";
  466. // if(appDelegate.contact_id.length>0)
  467. // {
  468. // msg = [msg stringByAppendingString:@"Customer:"];
  469. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  470. //
  471. // }
  472. //
  473. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  474. // //block代码块取代了delegate
  475. //
  476. //
  477. //
  478. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  479. //
  480. //
  481. // // vc.disable_refresh = true;
  482. // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  483. // ovc.showNavibar = true;
  484. // ovc.customer_id = appDelegate.contact_id;
  485. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  486. //
  487. // [holder performSelector:addtocart];
  488. //
  489. //
  490. // };
  491. // ovc.init_style = OL_OPEN;
  492. //
  493. // ovc.onCancel = ^(){
  494. //
  495. // // self.disable_refresh = false;
  496. //
  497. //
  498. //
  499. // };
  500. //
  501. // [vc.navigationController pushViewController:ovc animated:true];
  502. //
  503. //
  504. //
  505. //
  506. //
  507. // }];
  508. //
  509. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  510. //
  511. //
  512. // {
  513. // //create new;
  514. // // self.disable_refresh = true;
  515. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  516. // {
  517. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  518. // cvc.showNavibar = true;
  519. // cvc.contact_type = @"Sales_Order_Customer";
  520. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  521. //
  522. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  523. // appDelegate.customerInfo = value;
  524. //
  525. //
  526. // if(appDelegate.order_code==nil)
  527. // [self neworder:vc selectorholder:holder selector:addtocart];
  528. // // neworder();
  529. //
  530. // // [main_vc checklogin:true];
  531. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  532. //
  533. // //
  534. // // if(self.returnValue)
  535. // // self.returnValue(value);
  536. // };
  537. //
  538. // cvc.onCancel = ^(){
  539. //
  540. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
  541. //
  542. // // self.disable_refresh = false;
  543. //
  544. // };
  545. // cvc.onReset = ^(){
  546. // // [main_vc checklogin:true];
  547. // };
  548. //
  549. // [vc.navigationController pushViewController:cvc animated:true];
  550. // }
  551. // else
  552. // {
  553. // [self neworder:vc selectorholder:holder selector:addtocart];
  554. // }
  555. //
  556. // }
  557. //
  558. //
  559. // DebugLog(@"No");
  560. // }];
  561. // [alertControl addAction:actionOne];
  562. //
  563. // [alertControl addAction:alertthree];
  564. //
  565. // UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  566. // }];
  567. // [alertControl addAction:alertcancel];
  568. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  569. //
  570. //
  571. // [vc presentViewController:alertControl animated:YES completion:nil];
  572. //
  573. //
  574. //
  575. //
  576. //
  577. //
  578. // }
  579. // else
  580. // {
  581. // if(openPendingOrder)
  582. // {
  583. // NSString* msg =@"";
  584. // if(appDelegate.contact_id.length>0)
  585. // {
  586. // msg = [msg stringByAppendingString:@"Customer:"];
  587. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  588. //
  589. // }
  590. //
  591. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  592. // //block代码块取代了delegate
  593. //
  594. //
  595. //
  596. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  597. //
  598. //
  599. // // vc.disable_refresh = true;
  600. // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  601. // ovc.showNavibar = true;
  602. // ovc.customer_id = appDelegate.contact_id;
  603. // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  604. //
  605. // [holder performSelector:addtocart];
  606. //
  607. //
  608. // };
  609. // ovc.init_style = OL_OPEN;
  610. //
  611. // ovc.onCancel = ^(){
  612. //
  613. // // self.disable_refresh = false;
  614. //
  615. //
  616. //
  617. // };
  618. //
  619. // [vc.navigationController pushViewController:ovc animated:true];
  620. //
  621. //
  622. //
  623. //
  624. //
  625. // }];
  626. //
  627. //
  628. // [alertControl addAction:actionOne];
  629. // UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  630. // }];
  631. // [alertControl addAction:alertcancel];
  632. //
  633. // // [alertControl addAction:alertthree];
  634. //
  635. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  636. //
  637. //
  638. // [vc presentViewController:alertControl animated:YES completion:nil];
  639. //
  640. //
  641. //
  642. //
  643. //
  644. //
  645. //
  646. // }
  647. // else if(createNewOrder)
  648. // {
  649. // NSString* msg =@"";
  650. // if(appDelegate.contact_id.length>0)
  651. // {
  652. // msg = [msg stringByAppendingString:@"Customer:"];
  653. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  654. //
  655. // }
  656. //
  657. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
  658. // //block代码块取代了delegate
  659. //
  660. //
  661. //
  662. //
  663. //
  664. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  665. //
  666. //
  667. // {
  668. // //create new;
  669. // // self.disable_refresh = true;
  670. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  671. // {
  672. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  673. // cvc.showNavibar = true;
  674. // cvc.contact_type = @"Sales_Order_Customer";
  675. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  676. //
  677. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  678. // appDelegate.customerInfo = value;
  679. //
  680. //
  681. // if(appDelegate.order_code==nil)
  682. // [self neworder:vc selectorholder:holder selector:addtocart];
  683. // // neworder();
  684. //
  685. // // [main_vc checklogin:true];
  686. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  687. //
  688. // //
  689. // // if(self.returnValue)
  690. // // self.returnValue(value);
  691. // };
  692. //
  693. // cvc.onCancel = ^(){
  694. //
  695. // [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
  696. //
  697. // // self.disable_refresh = false;
  698. //
  699. // };
  700. // cvc.onReset = ^(){
  701. // // [main_vc checklogin:true];
  702. // };
  703. //
  704. // [vc.navigationController pushViewController:cvc animated:true];
  705. // }
  706. // else
  707. // {
  708. // [self neworder:vc selectorholder:holder selector:addtocart];
  709. // }
  710. //
  711. // }
  712. //
  713. //
  714. // DebugLog(@"No");
  715. // }];
  716. // // [alertControl addAction:actionOne];
  717. //
  718. // [alertControl addAction:alertthree];
  719. //
  720. // UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  721. // }];
  722. // [alertControl addAction:alertcancel];
  723. //
  724. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  725. //
  726. //
  727. // [vc presentViewController:alertControl animated:YES completion:nil];
  728. //
  729. //
  730. //
  731. //
  732. //
  733. // }
  734. // else
  735. // {
  736. // [RAUtils message_alert:[return_json valueForKey:@"You donot have permission to access order"] title:@"Add To Cart" controller:vc];
  737. // }
  738. //
  739. // }
  740. //
  741. //
  742. // }
  743. // else
  744. // {
  745. //
  746. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Check Pending Order" controller:vc] ;
  747. // }
  748. //
  749. //
  750. //
  751. //
  752. // });
  753. // });
  754. }
  755. // // [main_vc checklogin:false];
  756. //
  757. // if(appDelegate.can_create_order)
  758. // {
  759. // NSString* msg =@"";
  760. // if(appDelegate.contact_id.length>0)
  761. // {
  762. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  763. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  764. //
  765. // }
  766. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
  767. //
  768. // // alert.
  769. // [alert show];
  770. // }
  771. // else
  772. // {
  773. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil), nil];
  774. //
  775. // // alert.
  776. // [alert show];
  777. // }
  778. }
  779. else
  780. {
  781. // if(appDelegate.order_code==nil)
  782. // [ self neworder];
  783. // else
  784. IMP imp = [holder methodForSelector:addtocart];
  785. void (*func)(id, SEL) = (void *)imp;
  786. func(holder, addtocart);
  787. // [holder performSelector:addtocart];
  788. }
  789. }
  790. }
  791. +(void) add_recent_model:(NSDictionary*) model
  792. {
  793. NSMutableDictionary * newdict = [[NSMutableDictionary alloc]init];
  794. [newdict setObject:model forKey:@"item_0"];
  795. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  796. int count=[appDelegate.recent_model[@"count"] intValue];
  797. for(int i=0;i<count;i++)
  798. {
  799. NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
  800. NSString *mitemProductID = [NSString stringWithFormat:@"%@",mitem[@"product_id"]];
  801. NSString *modelProductID = [NSString stringWithFormat:@"%@",model[@"product_id"]];
  802. if([mitemProductID isEqualToString:modelProductID])
  803. continue;
  804. [newdict setObject:mitem forKey:[NSString stringWithFormat:@"item_%lu",(unsigned long)newdict.allKeys.count]];
  805. }
  806. newdict[@"count"]=[NSString stringWithFormat:@"%lu",(unsigned long)newdict.allKeys.count];
  807. appDelegate.recent_model = newdict;
  808. //
  809. //
  810. // if(!bexist)
  811. // {
  812. // [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
  813. // appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
  814. // }
  815. }
  816. @end