RAOrderPreviewController.m 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748
  1. //
  2. // RAOrderPreviewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Jack on 2017/11/16.
  6. // Copyright © 2017年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RAOrderPreviewController.h"
  9. #import "RANetwork.h"
  10. #import "MainViewController.h"
  11. #import "RASingleton.h"
  12. #import "config.h"
  13. //#import "CustomIOSAlertView.h"
  14. #import "AddressEditorViewController.h"
  15. #import "CreditCardEditorViewController.h"
  16. #import "JKTimerManager.h"
  17. #import "CommonEditorCellModel.h"
  18. #import "RABackOrderSubmitAlertController.h"
  19. #import "ActiveViewController.h"
  20. #define SUBMIT_CONFIRM 123
  21. #define KEEP_TAIL 456
  22. //#define CLOSE_ACTION 567
  23. @interface RAOrderPreviewController ()
  24. @property (nonatomic,assign) BOOL isResume;///<恢复
  25. @property (nonatomic,assign) NSInteger userType;///<恢复使用
  26. @end
  27. @implementation RAOrderPreviewController
  28. - (void)alertMessage:(NSString *)msg {
  29. if (notifyMe_switch) {
  30. if ([self.class_name isEqualToString:@"CreateOrderViewController"]) {
  31. NSString *err_msg = msg;
  32. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Attention!!" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
  33. // __weak typeof(self) weakself = self;
  34. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  35. [self.navigationController popToRootViewControllerAnimated:true];
  36. }];
  37. [alertVC addAction:action];
  38. [self presentViewController:alertVC animated:YES completion:nil];
  39. } else {
  40. // [RAUtils message_box:nil message:msg completion:nil] ;
  41. [RAUtils message_box:nil message:msg completion:nil];
  42. }
  43. } else {
  44. // [RAUtils message_box:nil message:msg completion:nil] ;
  45. [RAUtils message_box:nil message:msg completion:nil];
  46. }
  47. }
  48. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  49. {
  50. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  51. if([value isEqualToString:@"new_addr"])
  52. {
  53. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  54. addressVC.url_type = URL_REMOTE;
  55. addressVC.request_url=URL_ADDRESS_EDOTOR;
  56. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  57. // NSString * string = [checked componentsJoinedByString:@","];
  58. // [params setValue:string forKey:@"cart2Checkbox"];
  59. addressVC.params = params;
  60. addressVC.delegate = self;
  61. addressVC.from = indexPath;
  62. // orderinfoVC.params = params;
  63. [self.navigationController pushViewController:addressVC animated:true];
  64. }else if([value isEqualToString:@"credit_card"])
  65. {
  66. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  67. NSDictionary *data = [item_json objectForKey:@"data"];
  68. if(data!=nil)
  69. {
  70. cardVC.content_data_download = [data mutableCopy];
  71. cardVC.url_type = URL_NONE;
  72. cardVC.request_url=nil;
  73. }
  74. else
  75. {
  76. cardVC.url_type = URL_REMOTE;
  77. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  78. }
  79. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  80. params[@"orderCode"]=appDelegate.order_code;
  81. cardVC.params = params;
  82. cardVC.delegate = self;
  83. cardVC.from = indexPath;
  84. // orderinfoVC.params = params;
  85. [self.navigationController pushViewController:cardVC animated:true];
  86. }
  87. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  88. {
  89. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  90. cvc.showNavibar = true;
  91. cvc.contact_type = value;
  92. __weak typeof(self) weakself = self;
  93. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  94. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  95. //
  96. // if(self.returnValue)
  97. // self.returnValue(value);
  98. };
  99. [self.navigationController pushViewController:cvc animated:true];
  100. }
  101. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  102. {
  103. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  104. cvc.showNavibar = true;
  105. cvc.contact_type = value;
  106. __weak typeof(self) weakself = self;
  107. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  108. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  109. //
  110. // if(self.returnValue)
  111. // self.returnValue(value);
  112. };
  113. [self.navigationController pushViewController:cvc animated:true];
  114. }
  115. else if([value isEqualToString:@"Sales_Order_Customer"])
  116. {
  117. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  118. cvc.contact_type = value;
  119. cvc.showNavibar = true;
  120. __weak typeof(self) weakself = self;
  121. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  122. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  123. //
  124. // if(self.returnValue)
  125. // self.returnValue(value);
  126. };
  127. [self.navigationController pushViewController:cvc animated:true];
  128. }
  129. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  130. {
  131. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  132. cvc.showNavibar = true;
  133. cvc.contact_type = value;
  134. __weak typeof(self) weakself = self;
  135. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  136. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  137. //
  138. // if(self.returnValue)
  139. // self.returnValue(value);
  140. };
  141. [self.navigationController pushViewController:cvc animated:true];
  142. }
  143. else if([value isEqualToString:@"Contact_Return_To"])
  144. {
  145. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  146. cvc.showNavibar = true;
  147. cvc.contact_type = value;
  148. __weak typeof(self) weakself = self;
  149. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  150. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  151. //
  152. // if(self.returnValue)
  153. // self.returnValue(value);
  154. };
  155. [self.navigationController pushViewController:cvc animated:true];
  156. }
  157. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  158. {
  159. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  160. cvc.showNavibar = true;
  161. cvc.contact_type = value;
  162. __weak typeof(self) weakself = self;
  163. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  164. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  165. //
  166. // if(self.returnValue)
  167. // self.returnValue(value);
  168. };
  169. [self.navigationController pushViewController:cvc animated:true];
  170. }
  171. }
  172. - (void)dealloc {
  173. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  174. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  175. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  176. if (self.isResume && self.userType == USER_ROLE_CUSTOMER) {
  177. [self releaseOrderAfterSave];
  178. }
  179. }
  180. -(void) viewWillAppear:(BOOL)animated
  181. {
  182. [super viewWillAppear:animated];
  183. // [self start_urgency_timer];
  184. self.isResume = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_resume"] boolValue];
  185. self.userType = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_userType"] integerValue];
  186. BOOL canSubmit = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_submitOrder"] boolValue];
  187. // 检查权限
  188. NSMutableArray * items = [[NSMutableArray alloc]init];
  189. UIBarButtonItem *savebtn = nil;
  190. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  191. style:UIBarButtonItemStylePlain
  192. target:self
  193. action:@selector(onSaveClick:)];
  194. #if defined(BUILD_NPD) || defined (BUILD_CONTRAST)
  195. UIImage *submit_img = [[UIImage imageNamed:@"submit_red"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  196. self.btnSubmitOrder = nil;
  197. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:submit_img
  198. style:UIBarButtonItemStylePlain
  199. target:self
  200. action:@selector(onCommitOrderClick:)];
  201. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  202. fixedItem.width = 20.0f;
  203. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  204. {
  205. [items addObject:savebtn];
  206. [items addObject:fixedItem];
  207. }
  208. #else
  209. UIImage *submit_img = [UIImage imageNamed:@"submit_red"];
  210. self.btnSubmitOrder = nil;
  211. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:submit_img
  212. style:UIBarButtonItemStylePlain
  213. target:self
  214. action:@selector(onCommitOrderClick:)];
  215. [items addObject:savebtn];
  216. #endif
  217. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  218. if (!self.isResume) {
  219. // 正常情况
  220. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  221. // customer的订单必须是Sales Order并且有提交权限才能提交
  222. if ([RASingleton sharedInstance].currentOrderIsMerged && [RASingleton sharedInstance].permissions_submit_order) {
  223. [items addObject:self.btnSubmitOrder];
  224. }
  225. } else {
  226. [items addObject:self.btnSubmitOrder];
  227. }
  228. } else {
  229. // 恢复
  230. if (self.userType == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  231. // customer的订单必须是Sales Order并且有提交权限才能提交
  232. if (canSubmit) {
  233. [items addObject:self.btnSubmitOrder];
  234. }
  235. } else {
  236. [items addObject:self.btnSubmitOrder];
  237. }
  238. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_resume"];
  239. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_userType"];
  240. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_submitOrder"];
  241. }
  242. // [items addObject:item2];
  243. self.navigationItem.rightBarButtonItems=items;
  244. if(appDelegate.can_submit_order)
  245. {
  246. [self.btnSubmitOrder setImage:submit_img];
  247. self.btnSubmitOrder.enabled = true;
  248. }
  249. else
  250. {
  251. [self.btnSubmitOrder setImage:nil];
  252. self.btnSubmitOrder.enabled = false;
  253. }
  254. self.navigationController.navigationBarHidden=false;
  255. [self.navigationController.navigationBar layoutIfNeeded];
  256. }
  257. -(void) download_success
  258. {
  259. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  260. NSString *title = [self.content_data_download objectForKey:@"title"];
  261. self.title = title;
  262. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  263. NSString* order_customerid=[self getValue:@"customer_cid"];
  264. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  265. appDelegate.order_customer_id = order_customerid;
  266. }
  267. - (void)viewDidLoad {
  268. [super viewDidLoad];
  269. self.editable = YES;
  270. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  271. style:UIBarButtonItemStylePlain
  272. target:self
  273. action:@selector(onCloseClick:)];
  274. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  275. // closeButton.title = @"Close";
  276. self.navigationItem.leftBarButtonItem = closeButton;
  277. // self.navigationItem.backBarButtonItem = backButton;
  278. // Do any additional setup after loading the view.
  279. }
  280. - (void)onCommitOrderClick:(id)sender {
  281. // get customer info
  282. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  283. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  284. //
  285. // // 检查价格类型
  286. // // 提货价才能提交订单
  287. // /** 价格类型
  288. // * 0 提货价
  289. // * 1 统一价
  290. // * 2 计算价
  291. // */
  292. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  293. // if (priceType != 0) {
  294. //
  295. // NSString* pricename = nil;
  296. // switch (priceType) {
  297. // case 1:
  298. // pricename=flat_price;
  299. // break;
  300. // case 2:
  301. // pricename=given_price;
  302. // break;
  303. // default:
  304. // break;
  305. // }
  306. //
  307. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current price is %@, please change to %@ and try again.",pricename,[Singleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  308. //
  309. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  310. //
  311. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  312. //
  313. // }];
  314. //
  315. //
  316. // [alertVC addAction:cancelAction];
  317. //
  318. // [self presentViewController:alertVC animated:YES completion:nil];
  319. //
  320. // return;
  321. // }
  322. // }
  323. NSString* msg;
  324. #ifdef OFFLINE_MODE
  325. if(appDelegate.offline_mode)
  326. {
  327. msg=@"Are you sure to mark offline order as ready for submit?";
  328. }
  329. else
  330. #endif
  331. {
  332. msg=@"Submit order now?";
  333. }
  334. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Order Submission" message:msg preferredStyle:UIAlertControllerStyleAlert];
  335. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  336. // add params check here.
  337. [self.lastedit endEditing:true];
  338. [self.lasttextview endEditing:true];
  339. NSMutableDictionary* upparams = [self check_cancommit:true];
  340. if(self.cancommit==false)
  341. return;
  342. // ------
  343. [self.params enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  344. [upparams setObject:obj forKey:key];
  345. }];
  346. // 2018-1-2 Modify
  347. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  348. {
  349. [self customer_commit_order:upparams];
  350. }
  351. else // USER_ROLE_EMPLOYEE
  352. {
  353. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  354. {
  355. upparams[@"shipping"] = nil;
  356. }
  357. if(upparams[@"shipping"]==nil || [upparams[@"shipping"] doubleValue]!=0)
  358. [self empolyee_commit_order:upparams];
  359. else
  360. {
  361. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  362. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  363. {
  364. //yes
  365. [self empolyee_commit_order:upparams];
  366. }];
  367. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  368. //DebugLog(@"Cancel");
  369. }];
  370. [alertControl addAction:actionOne];
  371. [alertControl addAction:alertthree];
  372. [self presentViewController:alertControl animated:YES completion:nil];
  373. }
  374. }
  375. }];
  376. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  377. }];
  378. [alertVC addAction:yesAction];
  379. [alertVC addAction:cancelAction];
  380. [self presentViewController:alertVC animated:yesAction completion:nil];
  381. }
  382. - (UIView *)createDemoView:(NSString*) msg
  383. {
  384. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  385. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  386. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  387. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  388. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  389. titleLabel.text=@"Order Submission";
  390. titleLabel.numberOfLines = 0;
  391. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  392. // titleLabel.textAlignment = NSTextAlignmentRight;
  393. titleLabel.textAlignment = NSTextAlignmentCenter;
  394. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  395. // CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  396. CGSize sizetitle = [RAUtils sizeWithFont:titleLabel.text=@"Order Submission" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  397. //[titleLabel sizeToFit];
  398. // titleLabel.center.x = demoView.center.x;
  399. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  400. [demoView addSubview:titleLabel];
  401. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  402. lineLabel.font = [UIFont systemFontOfSize:17];
  403. lineLabel.text=msg;
  404. lineLabel.numberOfLines = 0;
  405. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  406. // CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  407. CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  408. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  409. //[lineLabel sizeToFit];
  410. [demoView addSubview:lineLabel];
  411. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  412. return demoView;
  413. }
  414. - (void)onCloseClick:(UIButton *)sender {
  415. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  416. if (self.resumeOrder) {
  417. [self.navigationController popToRootViewControllerAnimated:true];
  418. return;
  419. }
  420. NSString* a3title = nil;
  421. if(appDelegate.order_status==0)
  422. a3title= @"Close and cancel order";
  423. else
  424. a3title=@"Close and release order";
  425. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Choose your action" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  426. UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Continue edit order" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  427. // back edit order
  428. [self.navigationController popViewControllerAnimated:YES];
  429. }];
  430. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  431. // back to cart
  432. [self.navigationController popToRootViewControllerAnimated:true];
  433. }];
  434. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  435. [self.navigationController popToRootViewControllerAnimated:false];
  436. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  437. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  438. }];
  439. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:a3title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  440. // close order;
  441. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  442. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
  443. PopWaitAlert * pop = [RAUtils waiting_pop:@"Release Order" completion:nil];
  444. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
  445. NSDictionary* order_json = result;
  446. // [waitalert dismissViewControllerAnimated:YES completion:^{
  447. [pop hide];
  448. if([[order_json valueForKey:@"result"] intValue]==2)
  449. {
  450. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  451. // appDelegate.order_code = nil;
  452. [appDelegate closeOrder];
  453. #ifdef RA_NOTIFICATION
  454. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  455. #else
  456. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  457. #endif
  458. [((MainViewController*)appDelegate.main_vc) switchToHome];
  459. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  460. {
  461. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  462. }
  463. [self prepareReturn:nil];
  464. [self.navigationController popToRootViewControllerAnimated:true];
  465. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  466. // ;
  467. // }];
  468. }
  469. else
  470. {
  471. [RAUtils message_box:@"Open Order" message:[order_json valueForKey:@"err_msg"] completion:nil];
  472. }
  473. // }];
  474. }];
  475. // }];
  476. }];
  477. UIAlertAction *action_4 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  478. }];
  479. [alertController addAction:action_0];
  480. [alertController addAction:action_1];
  481. [alertController addAction:action_2];
  482. [alertController addAction:action_3];
  483. [alertController addAction:action_4];
  484. [self presentViewController:alertController animated:YES completion:nil];
  485. //
  486. //
  487. // UIAlertView * alert = nil;
  488. // if(appDelegate.order_status==0)
  489. // {
  490. // alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:@"Continue edit order",NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil];
  491. // }
  492. // else
  493. // {
  494. // alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:@"Continue edit order",NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil];
  495. //
  496. // }
  497. //
  498. //
  499. //
  500. // alert.tag = CLOSE_ACTION;
  501. // // alert.
  502. // [alert show];
  503. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  504. // appDelegate.order_code = nil;
  505. //
  506. // }
  507. }
  508. - (void)didReceiveMemoryWarning {
  509. [super didReceiveMemoryWarning];
  510. // Dispose of any resources that can be recreated.
  511. }
  512. - (IBAction)onSaveClick:(id)sender {
  513. // id foo = nil;
  514. // [[NSMutableArray array] addObject:foo];
  515. // add params check here.
  516. [self.lastedit endEditing:true];
  517. [self.lasttextview endEditing:true];
  518. NSMutableDictionary* upparams = [self check_cancommit:false];
  519. // if(self.cancommit==false)
  520. // return;
  521. [self.params enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  522. [upparams setObject:obj forKey:key];
  523. }];
  524. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  525. upparams[@"shipping"] = nil;
  526. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order" completion:^{
  527. PopWaitAlert * pop = [RAUtils waiting_pop:@"Saving Order" completion:nil];
  528. [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
  529. NSDictionary* editor_json =result;
  530. // [waitalert dismissViewControllerAnimated:YES completion:^{
  531. [pop hide];
  532. if([[editor_json valueForKey:@"result"] intValue]==2)
  533. {
  534. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  535. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  536. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  537. {
  538. appDelegate.customerInfo = customerInfo;
  539. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  540. }
  541. NSString *msg = nil;
  542. if ([editor_json objectForKey:@"so#"]) {
  543. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  544. }
  545. [RAUtils message_box:@"Order Saved" message:msg completion:nil];
  546. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  547. {
  548. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  549. [self prepareReturn:nil];
  550. [self.navigationController popToRootViewControllerAnimated:true];
  551. }
  552. else{
  553. #ifdef RA_NOTIFICATION
  554. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  555. #else
  556. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  557. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  558. #endif
  559. }
  560. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  561. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  562. [self releaseOrderAfterSave];
  563. }
  564. }
  565. }
  566. else
  567. {
  568. [RAUtils message_box:@"Save Order" message:[editor_json valueForKey:@"err_msg"] completion:nil];
  569. }
  570. // }];
  571. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  572. }];
  573. }
  574. - (void)textFieldDidEndEditing:(UITextField *)textField
  575. {
  576. [super textFieldDidEndEditing:textField];
  577. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  578. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  579. NSMutableDictionary* section_json=nil;
  580. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  581. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  582. NSString* name = [item_json valueForKey:@"name"];
  583. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  584. {
  585. float shipping = [self getprice:@"shipping" section:indexPath.section];
  586. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  587. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  588. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  589. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  590. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  591. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  592. int count=0;
  593. count=[[section_json valueForKey:@"count"] intValue];
  594. int total_row_idx=-1;
  595. for(int i=0;i<count;i++)
  596. {
  597. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  598. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  599. {
  600. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  601. [olditem setValue:@"true" forKey:@"dirty"];
  602. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  603. total_row_idx=i;
  604. }
  605. }
  606. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  607. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  608. if(total_row_idx>=0)
  609. {
  610. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  611. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  612. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  613. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  614. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  615. // CGSize tablecontent =self.editorTable.contentSize;
  616. // tablecontent.height=tablecontent.height+self.keyboard_h;
  617. // self.editorTable.contentSize=tablecontent;
  618. //
  619. //
  620. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  621. }
  622. // self.content_data = [editor_json mutableCopy];
  623. // self.content_data = [self translate_json:editor_json];
  624. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  625. // [self.editorTable reloadData];
  626. }
  627. //
  628. // [item_json setValue:@"true" forKey:@"dirty"];
  629. // [item_json setValue:textField.text forKey:@"value"];
  630. }
  631. -(float) getprice:(NSString*) name section :(long) index
  632. {
  633. NSMutableDictionary* section_json=nil;
  634. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  635. int count=0;
  636. count=[[section_json valueForKey:@"count"] intValue];
  637. for(int i=0;i<count;i++)
  638. {
  639. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  640. if([[olditem valueForKey:@"name"] isEqualToString:name])
  641. {
  642. return [[olditem valueForKey:@"value"] floatValue];
  643. }
  644. }
  645. return 0;
  646. }
  647. /*
  648. #pragma mark - Navigation
  649. // In a storyboard-based application, you will often want to do a little preparation before navigation
  650. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  651. // Get the new view controller using [segue destinationViewController].
  652. // Pass the selected object to the new view controller.
  653. }
  654. */
  655. - (void)releaseOrderAfterSave {
  656. dispatch_async(dispatch_get_main_queue(), ^{
  657. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  658. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:nil];
  659. [appDelegate closeOrder];
  660. [appDelegate SetSo:nil];
  661. appDelegate.cart_count=0;
  662. [appDelegate update_count_mark];
  663. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  664. [self prepareReturn:nil];
  665. [self.navigationController popToRootViewControllerAnimated:false];
  666. });
  667. // [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  668. // [appDelegate closeOrder];
  669. // [appDelegate SetSo:nil];
  670. // appDelegate.cart_count=0;
  671. // [appDelegate update_count_mark];
  672. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  673. //
  674. // [self prepareReturn:nil];
  675. // [self.navigationController popToRootViewControllerAnimated:false];
  676. }
  677. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  678. {
  679. NSString* ret=nil;
  680. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  681. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  682. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  683. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  684. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  685. if(customer_address1.length>0)
  686. [arraddr addObject:customer_address1];
  687. if(customer_address2.length>0)
  688. [arraddr addObject:customer_address2];
  689. if(customer_address3.length>0)
  690. [arraddr addObject:customer_address3];
  691. if(customer_address4.length>0)
  692. [arraddr addObject:customer_address4];
  693. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  694. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  695. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  696. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  697. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  698. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  699. if(customer_city.length>0)
  700. [arrcty addObject:customer_city];
  701. if(customer_state.length>0)
  702. [arrcty addObject:customer_state];
  703. if(customer_zipcode.length>0)
  704. [arrcty addObject:customer_zipcode];
  705. if(customer_country.length>0)
  706. [arrcty addObject:customer_country];
  707. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  708. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  709. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  710. //
  711. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  712. // if(customer_phone.length>0)
  713. // {
  714. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  715. // [arrpho addObject:customer_phone];
  716. // }
  717. // if(customer_fax.length>0)
  718. // {
  719. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  720. // [arrpho addObject:customer_fax];
  721. // }
  722. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  723. //
  724. //
  725. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  726. // if(customer_contact.length>0)
  727. // {
  728. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  729. //
  730. // }
  731. // NSString *contact_string = customer_contact;
  732. //
  733. //
  734. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  735. // if(customer_email.length>0)
  736. // {
  737. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  738. //
  739. // }
  740. // NSString *email_string = customer_email;
  741. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  742. if(addr_string.length>0)
  743. [arrext addObject:addr_string];
  744. if(cty_string.length>0)
  745. [arrext addObject:cty_string];
  746. // if(phone_string.length>0)
  747. // [arrext addObject:phone_string];
  748. // if(contact_string.length>0)
  749. // [arrext addObject:contact_string];
  750. // if(email_string.length>0)
  751. // [arrext addObject:email_string];
  752. ret = [arrext componentsJoinedByString:@"\r\n"];
  753. // NSString *string = [array componentsJoinedByString:@" "];
  754. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  755. return ret;
  756. }
  757. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  758. {
  759. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  760. NSArray *keys= [key_map allKeys];
  761. //遍历keys
  762. for(int i=0;i<[keys count];i++)
  763. {
  764. //得到当前key
  765. NSString *key=[keys objectAtIndex:i];
  766. //如果key不是pic,说明value是字符类型,比如name:Boris
  767. NSString* valuefrom = [key_map valueForKey:key];
  768. if(valuefrom.length==0)
  769. continue;
  770. NSString* value=[self getValue:valuefrom];
  771. [ret setValue:value forKey:valuefrom];
  772. }
  773. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  774. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  775. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  776. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  777. return ret;
  778. }
  779. -(NSMutableDictionary*)create_cusromer_info_from_table
  780. {
  781. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  782. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  783. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  784. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  785. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  786. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  787. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  788. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  789. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  790. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  791. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  792. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  793. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  794. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  795. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  796. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  797. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  798. NSString * firstname =nil;
  799. NSString* lastname = nil;
  800. NSString* contact_name = [self getValue:@"customer_contact"];
  801. if(contact_name!=nil)
  802. {
  803. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  804. if(_arr.count>=1)
  805. {
  806. firstname =_arr[0];
  807. if(_arr.count>1)
  808. {
  809. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  810. }
  811. }
  812. }
  813. [ret setValue:firstname forKey:@"customer_first_name"];
  814. [ret setValue:lastname forKey:@"customer_last_name"];
  815. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  816. return ret;
  817. }
  818. #pragma mark - multi_action sub action clicked
  819. - (void)MActionClicked:(UIButton *)sender {
  820. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  821. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  822. int refresh =0;
  823. NSMutableDictionary* section_json=nil;
  824. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  825. NSString* subid=[item_json valueForKey:@"subid"];
  826. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  827. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  828. NSString* type = [sub_action valueForKey:@"type"];
  829. bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
  830. if([type isEqualToString:@"pull"])
  831. {
  832. [self.lastedit endEditing:true];
  833. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  834. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  835. NSMutableDictionary* value=[self create_value_map:keymap];
  836. if(subid==nil)
  837. {
  838. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  839. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  840. int icount=[[section_json valueForKey:@"count"] intValue];
  841. for (int ic=0;ic<icount;ic++)
  842. {
  843. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  844. NSString* mapto = [modify_item valueForKey:@"name"];
  845. if(mapto.length==0)
  846. continue;
  847. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  848. if(valuefrom==nil)
  849. continue;
  850. NSString* valuestr=[value valueForKey:valuefrom];
  851. // valuestr = [self getValue:valuefrom];
  852. if(true)
  853. {
  854. if(valuestr.length>0)
  855. [modify_item setValue:valuestr forKey:@"value"];
  856. else
  857. [modify_item setValue:@"" forKey:@"value"];
  858. [modify_item setValue:@"true" forKey:@"dirty"];
  859. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  860. }
  861. }
  862. }
  863. else
  864. {
  865. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  866. int section = [(NSString*)idarr[0] intValue];
  867. int item=[(NSString*)idarr[1] intValue];
  868. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  869. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  870. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  871. NSString* control_type = [olditem valueForKey:@"control"];
  872. if([control_type isEqualToString:@"switch"])
  873. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  874. else if([control_type isEqualToString:@"enum"])
  875. {
  876. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  877. }
  878. else
  879. {
  880. [RAUtils message_box:@"Sorry" message:@"not impl." completion:nil];
  881. // [RAUtils alert_view:@"" title:@"not impl"];
  882. }
  883. [olditem setValue:@"true" forKey:@"dirty"];
  884. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  885. }
  886. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  887. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  888. if(refresh==1)
  889. {
  890. [self refresh:refresh_trigger discardDirty:discardDirty] ;
  891. return ;
  892. }
  893. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  894. [self.editorTable reloadData ];
  895. }
  896. else
  897. {
  898. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  899. NSDictionary * item_json = sub_action;
  900. NSString* value = [item_json valueForKey:@"value"];
  901. if([value isEqualToString:@"new_addr"])
  902. {
  903. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  904. addressVC.url_type = URL_REMOTE;
  905. addressVC.request_url=URL_ADDRESS_EDOTOR;
  906. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  907. // NSString * string = [checked componentsJoinedByString:@","];
  908. // [params setValue:string forKey:@"cart2Checkbox"];
  909. params[@"is_subaction"]=@"true";
  910. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  911. addressVC.params = params;
  912. addressVC.delegate = self;
  913. addressVC.from = indexPath;
  914. // orderinfoVC.params = params;
  915. [self.navigationController pushViewController:addressVC animated:true];
  916. }else if([value isEqualToString:@"credit_card"])
  917. {
  918. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  919. NSDictionary *data = [item_json objectForKey:@"data"];
  920. if(data!=nil)
  921. {
  922. cardVC.content_data_download = [data mutableCopy];
  923. cardVC.url_type = URL_NONE;
  924. cardVC.request_url=nil;
  925. }
  926. else
  927. {
  928. cardVC.url_type = URL_REMOTE;
  929. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  930. }
  931. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  932. params[@"orderCode"]=appDelegate.order_code;
  933. params[@"is_subaction"]=@"true";
  934. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  935. cardVC.params = params;
  936. cardVC.delegate = self;
  937. cardVC.from = indexPath;
  938. // orderinfoVC.params = params;
  939. [self.navigationController pushViewController:cardVC animated:true];
  940. }
  941. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  942. {
  943. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  944. cvc.showNavibar = true;
  945. cvc.contact_type = value;
  946. cvc.is_subaction = @"true";
  947. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  948. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  949. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  950. //
  951. // if(self.returnValue)
  952. // self.returnValue(value);
  953. };
  954. [self.navigationController pushViewController:cvc animated:true];
  955. }
  956. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  957. {
  958. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  959. cvc.showNavibar = true;
  960. cvc.contact_type = value;
  961. cvc.is_subaction = @"true";
  962. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  963. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  964. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  965. //
  966. // if(self.returnValue)
  967. // self.returnValue(value);
  968. };
  969. [self.navigationController pushViewController:cvc animated:true];
  970. }
  971. else if([value isEqualToString:@"Sales_Order_Customer"])
  972. {
  973. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  974. cvc.is_subaction = @"true";
  975. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  976. cvc.showNavibar = true;
  977. cvc.contact_type = value;
  978. __weak typeof(self) weakself = self;
  979. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  980. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  981. //
  982. // if(self.returnValue)
  983. // self.returnValue(value);
  984. };
  985. [self.navigationController pushViewController:cvc animated:true];
  986. }
  987. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  988. {
  989. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  990. cvc.showNavibar = true;
  991. cvc.contact_type = value;
  992. cvc.is_subaction = @"true";
  993. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  994. __weak typeof(self) weakself = self;
  995. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  996. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  997. //
  998. // if(self.returnValue)
  999. // self.returnValue(value);
  1000. };
  1001. [self.navigationController pushViewController:cvc animated:true];
  1002. }
  1003. else if([value isEqualToString:@"Contact_Return_To"])
  1004. {
  1005. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1006. cvc.is_subaction = @"true";
  1007. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1008. cvc.showNavibar = true;
  1009. cvc.contact_type = value;
  1010. __weak typeof(self) weakself = self;
  1011. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1012. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1013. //
  1014. // if(self.returnValue)
  1015. // self.returnValue(value);
  1016. };
  1017. [self.navigationController pushViewController:cvc animated:true];
  1018. }
  1019. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  1020. {
  1021. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1022. cvc.is_subaction = @"true";
  1023. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1024. cvc.showNavibar = true;
  1025. cvc.contact_type = value;
  1026. __weak typeof(self) weakself = self;
  1027. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1028. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1029. //
  1030. // if(self.returnValue)
  1031. // self.returnValue(value);
  1032. };
  1033. [self.navigationController pushViewController:cvc animated:true];
  1034. }
  1035. }
  1036. }
  1037. #pragma mark - Urgency
  1038. -(void) viewWillDisappear:(BOOL)animated
  1039. {
  1040. [super viewWillDisappear:animated];
  1041. [self cancel_urgency_timer];
  1042. }
  1043. - (void)start_urgency_timer {
  1044. if (!self.editable) {
  1045. return;
  1046. }
  1047. __weak typeof(self) weakSelf = self;
  1048. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1049. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  1050. #ifdef OFFLINE_MODE
  1051. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  1052. #endif
  1053. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  1054. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  1055. // DebugLog(@"timer start....");
  1056. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  1057. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  1058. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  1059. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  1060. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  1061. NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  1062. [urgencyDic setValue:so forKey:@"order_so"];
  1063. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  1064. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  1065. }
  1066. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  1067. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  1068. }];
  1069. }
  1070. - (void)cancel_urgency_timer {
  1071. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  1072. }
  1073. #pragma mark - Override
  1074. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  1075. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  1076. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  1077. NSString* control = [item_json valueForKey:@"control"];
  1078. if([control isEqualToString:@"model"]) {
  1079. ((CommonEditorCellModel *)cell).avalibilityLabel.hidden = YES;
  1080. }
  1081. return cell;
  1082. }
  1083. #pragma mark - Submit Order
  1084. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  1085. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1086. upparams[@"shipping"] = nil;
  1087. [upparams setValue:@"true" forKey:@"isHold"];
  1088. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  1089. PopWaitAlert * pop = [RAUtils waiting_pop:@"Order Submission" completion:nil];
  1090. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  1091. NSDictionary* editor_json =result;
  1092. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1093. [pop hide];
  1094. if([[editor_json valueForKey:@"result"] intValue]==2)
  1095. {
  1096. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1097. // appDelegate.customerInfo = customerInfo;
  1098. [appDelegate closeOrder];
  1099. #ifdef RA_NOTIFICATION
  1100. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1101. #else
  1102. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1103. #endif
  1104. NSString* title=nil;
  1105. NSString* msg=nil;
  1106. #ifdef OFFLINE_MODE
  1107. if(appDelegate.offline_mode)
  1108. {
  1109. title=TITLE_OFFLINE_SUBMIT;
  1110. msg=MSG_OFFLINE_SUBMIT;
  1111. }
  1112. else
  1113. #endif
  1114. {
  1115. title=@"Order submitted sucessfully";
  1116. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1117. }
  1118. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1119. //
  1120. // [alert show];
  1121. [self back_order_submit_alert:editor_json];
  1122. [self prepareReturn:nil];
  1123. [self.navigationController popToRootViewControllerAnimated:true];
  1124. }
  1125. else
  1126. {
  1127. [RAUtils message_box:@"Order Submission" message:[editor_json valueForKey:@"err_msg"] completion:nil];
  1128. }
  1129. // }];
  1130. }];
  1131. // }];
  1132. }
  1133. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  1134. [upparams setValue:@"false" forKey:@"isHold"];
  1135. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  1136. PopWaitAlert * pop = [RAUtils waiting_pop:@"Order Submission" completion:nil];
  1137. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  1138. NSDictionary* editor_json = result;
  1139. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1140. [pop hide];
  1141. if([[editor_json valueForKey:@"result"] intValue]==2)
  1142. {
  1143. // debug aaa
  1144. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1145. NSString* company= appDelegate.customerInfo[@"customer_name"];
  1146. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1147. [appDelegate closeOrder];
  1148. #ifdef RA_NOTIFICATION
  1149. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1150. #else
  1151. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1152. #endif
  1153. NSString* title=nil;
  1154. NSString* msg=nil;
  1155. #ifdef OFFLINE_MODE
  1156. if(appDelegate.offline_mode)
  1157. {
  1158. title=TITLE_OFFLINE_SUBMIT;
  1159. msg=MSG_OFFLINE_SUBMIT;
  1160. }
  1161. else
  1162. #endif
  1163. {
  1164. title=@"Order submitted sucessfully";
  1165. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1166. }
  1167. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1168. //
  1169. // [alert show];
  1170. UIViewController *alert = [self back_order_submit_alert:editor_json];
  1171. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1172. NSString* email_content =[editor_json valueForKey:@"email_content"];
  1173. // NSString* soid=[editor_json valueForKey:@"so#"];
  1174. {
  1175. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  1176. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1177. {
  1178. //bbb
  1179. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1180. value[@"commitorder_logout"]=@"true";
  1181. }
  1182. [self prepareReturn:value];
  1183. [self.navigationController popToRootViewControllerAnimated:true];
  1184. if(pdf_url.length>0)
  1185. {
  1186. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1187. [alert dismissViewControllerAnimated:YES completion:^{
  1188. NSString *pdf_title = [editor_json objectForKey:@"title"];
  1189. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:pdf_title content:email_content];
  1190. }];
  1191. }
  1192. }
  1193. }
  1194. else
  1195. {
  1196. [RAUtils message_box:@"Order Submission" message:[editor_json valueForKey:@"err_msg"] completion:nil];
  1197. }
  1198. // }];
  1199. }];
  1200. // }];
  1201. }
  1202. - (UIViewController *)back_order_submit_alert:(NSDictionary *)result_json {
  1203. NSString *title = @"Thank you for your order.";
  1204. NSString *html_msg = [result_json objectForKey:@"so#"];
  1205. RABackOrderSubmitAlertController *alert = [[RABackOrderSubmitAlertController alloc] initWithTitle:title Message:html_msg];
  1206. [self presentViewController:alert animated:YES completion:nil];
  1207. return alert;
  1208. }
  1209. @end