CartUtils.m 54 KB

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