RAOrderPreviewController.m 145 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842
  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 "Singleton.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_alert:msg title:nil controller:self] ;
  41. }
  42. } else {
  43. [RAUtils message_alert:msg title:nil controller:self] ;
  44. }
  45. }
  46. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  47. {
  48. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  49. if([value isEqualToString:@"new_addr"])
  50. {
  51. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  52. addressVC.url_type = URL_REMOTE;
  53. addressVC.request_url=URL_ADDRESS_EDOTOR;
  54. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  55. // NSString * string = [checked componentsJoinedByString:@","];
  56. // [params setValue:string forKey:@"cart2Checkbox"];
  57. addressVC.params = params;
  58. addressVC.delegate = self;
  59. addressVC.from = indexPath;
  60. // orderinfoVC.params = params;
  61. [self.navigationController pushViewController:addressVC animated:true];
  62. }else if([value isEqualToString:@"credit_card"])
  63. {
  64. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  65. NSDictionary *data = [item_json objectForKey:@"data"];
  66. if(data!=nil)
  67. {
  68. cardVC.content_data_download = [data mutableCopy];
  69. cardVC.url_type = URL_NONE;
  70. cardVC.request_url=nil;
  71. }
  72. else
  73. {
  74. cardVC.url_type = URL_REMOTE;
  75. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  76. }
  77. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  78. params[@"orderCode"]=appDelegate.order_code;
  79. cardVC.params = params;
  80. cardVC.delegate = self;
  81. cardVC.from = indexPath;
  82. // orderinfoVC.params = params;
  83. [self.navigationController pushViewController:cardVC animated:true];
  84. }
  85. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  86. {
  87. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  88. cvc.showNavibar = true;
  89. cvc.contact_type = value;
  90. __weak typeof(self) weakself = self;
  91. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  92. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  93. //
  94. // if(self.returnValue)
  95. // self.returnValue(value);
  96. };
  97. [self.navigationController pushViewController:cvc animated:true];
  98. }
  99. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  100. {
  101. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  102. cvc.showNavibar = true;
  103. cvc.contact_type = value;
  104. __weak typeof(self) weakself = self;
  105. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  106. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  107. //
  108. // if(self.returnValue)
  109. // self.returnValue(value);
  110. };
  111. [self.navigationController pushViewController:cvc animated:true];
  112. }
  113. else if([value isEqualToString:@"Sales_Order_Customer"])
  114. {
  115. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  116. cvc.contact_type = value;
  117. cvc.showNavibar = true;
  118. __weak typeof(self) weakself = self;
  119. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  120. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  121. //
  122. // if(self.returnValue)
  123. // self.returnValue(value);
  124. };
  125. [self.navigationController pushViewController:cvc animated:true];
  126. }
  127. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  128. {
  129. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  130. cvc.showNavibar = true;
  131. cvc.contact_type = value;
  132. __weak typeof(self) weakself = self;
  133. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  134. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  135. //
  136. // if(self.returnValue)
  137. // self.returnValue(value);
  138. };
  139. [self.navigationController pushViewController:cvc animated:true];
  140. }
  141. else if([value isEqualToString:@"Contact_Return_To"])
  142. {
  143. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  144. cvc.showNavibar = true;
  145. cvc.contact_type = value;
  146. __weak typeof(self) weakself = self;
  147. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  148. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  149. //
  150. // if(self.returnValue)
  151. // self.returnValue(value);
  152. };
  153. [self.navigationController pushViewController:cvc animated:true];
  154. }
  155. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  156. {
  157. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  158. cvc.showNavibar = true;
  159. cvc.contact_type = value;
  160. __weak typeof(self) weakself = self;
  161. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  162. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  163. //
  164. // if(self.returnValue)
  165. // self.returnValue(value);
  166. };
  167. [self.navigationController pushViewController:cvc animated:true];
  168. }
  169. }
  170. - (void)dealloc {
  171. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  172. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  173. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  174. if (self.isResume && self.userType == USER_ROLE_CUSTOMER) {
  175. [self releaseOrderAfterSave];
  176. }
  177. }
  178. -(void) viewWillAppear:(BOOL)animated
  179. {
  180. [super viewWillAppear:animated];
  181. // [self start_urgency_timer];
  182. self.isResume = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_resume"] boolValue];
  183. self.userType = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_userType"] integerValue];
  184. BOOL canSubmit = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_submitOrder"] boolValue];
  185. // 检查权限
  186. NSMutableArray * items = [[NSMutableArray alloc]init];
  187. UIBarButtonItem *savebtn = nil;
  188. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  189. style:UIBarButtonItemStylePlain
  190. target:self
  191. action:@selector(onSaveClick:)];
  192. #ifdef BUILD_NPD
  193. UIImage *submit_img = [[UIImage imageNamed:@"submit_red"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  194. self.btnSubmitOrder = nil;
  195. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:submit_img
  196. style:UIBarButtonItemStylePlain
  197. target:self
  198. action:@selector(onCommitOrderClick:)];
  199. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  200. fixedItem.width = 20.0f;
  201. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  202. {
  203. [items addObject:savebtn];
  204. [items addObject:fixedItem];
  205. }
  206. #else
  207. UIImage *submit_img = [UIImage imageNamed:@"submit_red"];
  208. self.btnSubmitOrder = nil;
  209. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:submit_img
  210. style:UIBarButtonItemStylePlain
  211. target:self
  212. action:@selector(onCommitOrderClick:)];
  213. [items addObject:savebtn];
  214. #endif
  215. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  216. if (!self.isResume) {
  217. // 正常情况
  218. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  219. // customer的订单必须是Sales Order并且有提交权限才能提交
  220. if ([Singleton sharedInstance].currentOrderIsMerged && [Singleton sharedInstance].permissions_submit_order) {
  221. [items addObject:self.btnSubmitOrder];
  222. }
  223. } else {
  224. [items addObject:self.btnSubmitOrder];
  225. }
  226. } else {
  227. // 恢复
  228. if (self.userType == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  229. // customer的订单必须是Sales Order并且有提交权限才能提交
  230. if (canSubmit) {
  231. [items addObject:self.btnSubmitOrder];
  232. }
  233. } else {
  234. [items addObject:self.btnSubmitOrder];
  235. }
  236. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_resume"];
  237. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_userType"];
  238. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_submitOrder"];
  239. }
  240. // [items addObject:item2];
  241. self.navigationItem.rightBarButtonItems=items;
  242. if(appDelegate.can_submit_order)
  243. {
  244. [self.btnSubmitOrder setImage:submit_img];
  245. self.btnSubmitOrder.enabled = true;
  246. }
  247. else
  248. {
  249. [self.btnSubmitOrder setImage:nil];
  250. self.btnSubmitOrder.enabled = false;
  251. }
  252. self.navigationController.navigationBarHidden=false;
  253. [self.navigationController.navigationBar layoutIfNeeded];
  254. }
  255. -(void) download_success
  256. {
  257. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  258. NSString *title = [self.content_data_download objectForKey:@"title"];
  259. self.title = title;
  260. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  261. NSString* order_customerid=[self getValue:@"customer_cid"];
  262. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  263. appDelegate.order_customer_id = order_customerid;
  264. }
  265. - (void)viewDidLoad {
  266. [super viewDidLoad];
  267. self.editable = YES;
  268. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  269. style:UIBarButtonItemStylePlain
  270. target:self
  271. action:@selector(onCloseClick:)];
  272. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  273. // closeButton.title = @"Close";
  274. self.navigationItem.leftBarButtonItem = closeButton;
  275. // self.navigationItem.backBarButtonItem = backButton;
  276. // Do any additional setup after loading the view.
  277. }
  278. - (void)onCommitOrderClick:(id)sender {
  279. // get customer info
  280. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  281. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  282. //
  283. // // 检查价格类型
  284. // // 提货价才能提交订单
  285. // /** 价格类型
  286. // * 0 提货价
  287. // * 1 统一价
  288. // * 2 计算价
  289. // */
  290. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  291. // if (priceType != 0) {
  292. //
  293. // NSString* pricename = nil;
  294. // switch (priceType) {
  295. // case 1:
  296. // pricename=flat_price;
  297. // break;
  298. // case 2:
  299. // pricename=given_price;
  300. // break;
  301. // default:
  302. // break;
  303. // }
  304. //
  305. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current price is %@, please change to %@ and try again.",pricename,[Singleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  306. //
  307. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  308. //
  309. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  310. //
  311. // }];
  312. //
  313. //
  314. // [alertVC addAction:cancelAction];
  315. //
  316. // [self presentViewController:alertVC animated:YES completion:nil];
  317. //
  318. // return;
  319. // }
  320. // }
  321. NSString* msg;
  322. #ifdef OFFLINE_MODE
  323. if(appDelegate.offline_mode)
  324. {
  325. msg=@"Are you sure to mark offline order as ready for submit?";
  326. }
  327. else
  328. #endif
  329. {
  330. msg=@"Submit order now?";
  331. // if(appDelegate.user_type == USER_ROLE_CUSTOMER) {
  332. //
  333. // NSString *specialInstuction = [Singleton sharedInstance].specialInstruction;
  334. // NSString * deliverprice=[Singleton sharedInstance].deliveryString;
  335. // msg = [NSString stringWithFormat:@"Are you sure to submit order?\n\n1. Your price type is %@, Order will sent to NPD with this price.",deliverprice];
  336. // if (specialInstuction.length) {
  337. // msg = [msg stringByAppendingFormat:@"\n2. Special Instruction: %@.",specialInstuction];
  338. // }
  339. //
  340. // }
  341. }
  342. // 2017-03-20 修改
  343. //
  344. // CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
  345. //
  346. //
  347. //
  348. //
  349. // // Add some custom content to the alert view
  350. // [alertView setContainerView:[self createDemoView:msg]];
  351. //
  352. // // Modify the parameters
  353. //
  354. //
  355. // NSArray *titleArr = [NSMutableArray arrayWithObjects:@"NO",@"YES", nil];
  356. // [alertView setButtonTitles:titleArr];
  357. // //[alertView setDelegate:self];
  358. //
  359. // // You may use a Block, rather than a delegate.
  360. // [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
  361. // // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
  362. // if(buttonIndex==0)
  363. // [alertView close];
  364. // else
  365. // {
  366. // // add params check here.
  367. // [self.lastedit endEditing:true];
  368. // [self.lasttextview endEditing:true];
  369. //
  370. //
  371. //
  372. // // self.cancommit=true;
  373. // // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  374. // // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  375. // // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  376. // // for(int i=0;i<section_count;i++)
  377. // // {
  378. // // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  379. // // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  380. // // for(int j=0;j<item_count;j++)
  381. // // {
  382. // // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  383. // // NSString* key = [itemjson valueForKey:@"name"];
  384. // // if(key==nil || key.length==0)
  385. // // continue;
  386. // // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  387. // // {
  388. // // NSString* single_select = [itemjson valueForKey:@"single_select"];
  389. // // if([single_select isEqualToString:@"true"])
  390. // // {
  391. // // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  392. // // int count = [[cadejson valueForKey:@"count"] intValue];
  393. // // bool setvalue = false;
  394. // // for(int cc=0;cc<count;cc++)
  395. // // {
  396. // // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  397. // // if([[valjson valueForKey:@"check"]intValue]==1)
  398. // // {
  399. // // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  400. // // setvalue=true;
  401. // // break;
  402. // // }
  403. // // }
  404. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  405. // // {
  406. // // self.cancommit = false;
  407. // // }
  408. // // }
  409. // // else
  410. // // {
  411. // // //not support multi select for now;
  412. // // }
  413. // // /*
  414. // // upparams setValue:itemjson forKey:<#(NSString *)#>
  415. // //
  416. // // */
  417. // // }else
  418. // // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  419. // // {
  420. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  421. // // self.cancommit = false;
  422. // // }
  423. // // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  424. // // {
  425. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  426. // // self.cancommit = false;
  427. // //
  428. // // NSString* valuestr = [itemjson valueForKey:@"value"];
  429. // // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  430. // // }
  431. // // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  432. // // {
  433. // // NSString* valuestr = [itemjson valueForKey:@"value"];
  434. // // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  435. // //
  436. // // NSString* value = [itemjson valueForKey:@"value"];
  437. // // NSMutableDictionary* boolitem=nil;
  438. // // NSMutableDictionary* subjson=nil;
  439. // // if([value isEqualToString:@"true"])
  440. // // {
  441. // // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  442. // //
  443. // // }
  444. // // else
  445. // // {
  446. // // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  447. // //
  448. // // }
  449. // // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  450. // // if( subjson!=nil /*&& !active*/)
  451. // // {
  452. // // int sub_count = [[subjson valueForKey:@"count"] intValue];
  453. // // for(int l=0;l<sub_count;l++)
  454. // // {
  455. // // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  456. // //
  457. // //
  458. // //
  459. // //
  460. // // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  461. // // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  462. // // else
  463. // // {
  464. // // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  465. // // self.cancommit = false;
  466. // // }
  467. // // }
  468. // //
  469. // //
  470. // //
  471. // // }
  472. // // }
  473. // // else
  474. // // {
  475. // // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  476. // // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  477. // // else
  478. // // {
  479. // // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  480. // // self.cancommit = false;
  481. // // }
  482. // // }
  483. // // upparams= [self subitem_param:itemjson addto:upparams ];
  484. // // }
  485. // // }
  486. // // if(self.cancommit==false)
  487. // // {
  488. // // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  489. // // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  490. // // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  491. // // //[self.editorTable reloadData ];
  492. // // [self.editorTable reloadData];
  493. // // // [waitalert dismissViewControllerAnimated:YES completion:nil];
  494. // // return;
  495. // // }
  496. //
  497. // NSMutableDictionary* upparams = [self check_cancommit:true];
  498. // if(self.cancommit==false)
  499. // return;
  500. //
  501. // if(upparams[@"shipping"]==nil)
  502. // goto commit_order;
  503. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  504. // {
  505. // upparams[@"shipping"] = nil;
  506. // goto commit_order;
  507. // }
  508. // else if([upparams[@"shipping"] doubleValue]==0)
  509. // {
  510. //
  511. //
  512. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  513. // //block代码块取代了delegate
  514. //
  515. //
  516. //
  517. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  518. // {
  519. //
  520. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  521. //
  522. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  523. // {
  524. //
  525. // if(/*!self.have_tail*/ true)
  526. // {UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  527. // [upparams setValue:@"false" forKey:@"isHold"];
  528. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  529. //
  530. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  531. //
  532. // dispatch_async(dispatch_get_main_queue(), ^{
  533. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  534. //
  535. //
  536. // if([[editor_json valueForKey:@"result"] intValue]==2)
  537. // {
  538. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  539. //
  540. // // debug aaa
  541. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  542. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  543. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  544. //
  545. // // appDelegate.customerInfo = customerInfo;
  546. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  547. // // appDelegate.order_code = nil;
  548. // [appDelegate closeOrder];
  549. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  550. //
  551. // NSString* title=nil;
  552. // NSString* msg=nil;
  553. // if(appDelegate.offline_mode)
  554. // {
  555. // title=TITLE_OFFLINE_SUBMIT;
  556. // msg=MSG_OFFLINE_SUBMIT;
  557. // }
  558. // else
  559. // {
  560. // title=@"Submit successful.";
  561. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  562. // }
  563. //
  564. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  565. //
  566. // [alert show];
  567. //
  568. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  569. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  570. // NSString* soid=[editor_json valueForKey:@"so#"];
  571. // // if(pdf_url.length>0)
  572. // // {
  573. // //
  574. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  575. // // //[self downloadpdf:pdf_url];
  576. // //
  577. // //
  578. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  579. // // {
  580. // // //bbb
  581. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  582. // // }
  583. // //
  584. // // [self prepareReturn:nil];
  585. // //
  586. // // [self.navigationController popViewControllerAnimated:true];
  587. // //
  588. // // [appDelegate printPdf:pdf_url];
  589. // //// if(self.printPdfCallback)
  590. // //// self.printPdfCallback(pdf_url);
  591. // // }
  592. // // else
  593. // {
  594. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  595. // {
  596. // //bbb
  597. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  598. // }
  599. // [self prepareReturn:nil];
  600. //
  601. // [self.navigationController popViewControllerAnimated:true];
  602. //
  603. // if(pdf_url.length>0)
  604. // {
  605. //
  606. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  607. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  608. // // [appDelegate printPdf:pdf_url];
  609. //
  610. // }
  611. // }
  612. //
  613. // }
  614. // else
  615. // {
  616. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  617. // }
  618. //
  619. //
  620. //
  621. //
  622. // });
  623. // });
  624. // }
  625. // else
  626. // {
  627. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  628. //
  629. //
  630. // alert.tag = KEEP_TAIL;
  631. //
  632. //
  633. // self.upparams = upparams;
  634. //
  635. // [alert show];
  636. // }
  637. //
  638. // }
  639. // else
  640. // { //USER_ROLE_CUSTOMER
  641. //
  642. // // if(self.have_tail)
  643. // // [upparams setValue:@"true" forKey:@"isHold"];
  644. // // else
  645. // // [upparams setValue:@"false" forKey:@"isHold"];
  646. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  647. //
  648. // [upparams setValue:@"true" forKey:@"isHold"];
  649. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  650. //
  651. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  652. //
  653. // dispatch_async(dispatch_get_main_queue(), ^{
  654. //
  655. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  656. //
  657. // if([[editor_json valueForKey:@"result"] intValue]==2)
  658. // {
  659. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  660. //
  661. //
  662. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  663. // // appDelegate.customerInfo = customerInfo;
  664. //
  665. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  666. // // appDelegate.order_code = orderCode;
  667. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  668. // [appDelegate closeOrder];
  669. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  670. //
  671. // NSString* title=nil;
  672. // NSString* msg=nil;
  673. // if(appDelegate.offline_mode)
  674. // {
  675. // title=TITLE_OFFLINE_SUBMIT;
  676. // msg=MSG_OFFLINE_SUBMIT;
  677. // }
  678. // else
  679. // {
  680. // title=@"Submit successful.";
  681. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  682. // }
  683. //
  684. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  685. //
  686. // [alert show];
  687. // // // self.labelContact.text=appDelegate.contact_name;
  688. // //
  689. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  690. // [self prepareReturn:nil];
  691. // [self.navigationController popViewControllerAnimated:true];
  692. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  693. // //
  694. // //
  695. // // ;
  696. // // }];
  697. //
  698. // }
  699. // else
  700. // {
  701. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  702. // }
  703. //
  704. //
  705. //
  706. //
  707. // });
  708. // });
  709. //
  710. // }
  711. //
  712. //
  713. //
  714. // }];
  715. //
  716. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  717. // //DebugLog(@"Cancel");
  718. //
  719. //
  720. // }];
  721. // [alertControl addAction:actionOne];
  722. //
  723. // [alertControl addAction:alertthree];
  724. //
  725. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  726. //
  727. //
  728. //
  729. //
  730. // [self presentViewController:alertControl animated:YES completion:nil];
  731. //
  732. //
  733. //
  734. // }
  735. // else
  736. // {
  737. // commit_order:
  738. //
  739. // {
  740. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  741. //
  742. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  743. // {
  744. //
  745. // if(/*!self.have_tail*/ true)
  746. // {UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  747. // [upparams setValue:@"false" forKey:@"isHold"];
  748. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  749. //
  750. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  751. //
  752. // dispatch_async(dispatch_get_main_queue(), ^{
  753. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  754. //
  755. //
  756. // if([[editor_json valueForKey:@"result"] intValue]==2)
  757. // {
  758. //
  759. // //debug bbb
  760. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  761. //
  762. //
  763. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  764. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  765. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  766. // // appDelegate.customerInfo = customerInfo;
  767. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  768. // // appDelegate.order_code = nil;
  769. // [appDelegate closeOrder];
  770. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  771. //
  772. // NSString* title=nil;
  773. // NSString* msg=nil;
  774. // if(appDelegate.offline_mode)
  775. // {
  776. // title=TITLE_OFFLINE_SUBMIT;
  777. // msg=MSG_OFFLINE_SUBMIT;
  778. // }
  779. // else
  780. // {
  781. // title=@"Submit successful.";
  782. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  783. // }
  784. //
  785. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  786. //
  787. // [alert show];
  788. //
  789. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  790. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  791. // NSString* soid=[editor_json valueForKey:@"so#"];
  792. // // if(pdf_url.length>0)
  793. // // {
  794. // //
  795. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  796. // //// [self downloadpdf:pdf_url];
  797. // //
  798. // //
  799. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  800. // // {
  801. // // //bbb
  802. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  803. // // }
  804. // //
  805. // // [self prepareReturn:nil];
  806. // //
  807. // // [self.navigationController popViewControllerAnimated:true];
  808. // //
  809. // // [appDelegate printPdf:pdf_url];
  810. // //
  811. // //// if(self.printPdfCallback)
  812. // //// self.printPdfCallback(pdf_url);
  813. // // }
  814. // // else
  815. // {
  816. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  817. // {
  818. // //bbb
  819. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  820. // }
  821. // [self prepareReturn:nil];
  822. //
  823. // [self.navigationController popViewControllerAnimated:true];
  824. //
  825. //
  826. // if(pdf_url.length>0)
  827. // {
  828. //
  829. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  830. //
  831. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  832. //
  833. //
  834. // }
  835. //
  836. //
  837. // }
  838. // // // self.labelContact.text=appDelegate.contact_name;
  839. // //
  840. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  841. //
  842. //
  843. //
  844. //
  845. //
  846. //
  847. // }
  848. // else
  849. // {
  850. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  851. // }
  852. //
  853. //
  854. //
  855. //
  856. // });
  857. // });
  858. // }
  859. // else
  860. // {
  861. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  862. //
  863. //
  864. // alert.tag = KEEP_TAIL;
  865. //
  866. //
  867. // self.upparams = upparams;
  868. //
  869. // [alert show];
  870. // }
  871. //
  872. // }
  873. // else
  874. // { //USER_ROLE_CUSTOMER
  875. //
  876. // // if(self.have_tail)
  877. // // [upparams setValue:@"true" forKey:@"isHold"];
  878. // // else
  879. // // [upparams setValue:@"false" forKey:@"isHold"];
  880. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  881. //
  882. // [upparams setValue:@"true" forKey:@"isHold"];
  883. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  884. //
  885. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  886. //
  887. // dispatch_async(dispatch_get_main_queue(), ^{
  888. //
  889. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  890. //
  891. // if([[editor_json valueForKey:@"result"] intValue]==2)
  892. // {
  893. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  894. //
  895. //
  896. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  897. // // appDelegate.customerInfo = customerInfo;
  898. //
  899. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  900. // // appDelegate.order_code = orderCode;
  901. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  902. // [appDelegate closeOrder];
  903. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  904. //
  905. // NSString* title=nil;
  906. // NSString* msg=nil;
  907. // if(appDelegate.offline_mode)
  908. // {
  909. // title=TITLE_OFFLINE_SUBMIT;
  910. // msg=MSG_OFFLINE_SUBMIT;
  911. // }
  912. // else
  913. // {
  914. // title=@"Submit successful.";
  915. // msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  916. // }
  917. //
  918. //
  919. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  920. //
  921. // [alert show];
  922. // // // self.labelContact.text=appDelegate.contact_name;
  923. // //
  924. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  925. // [self prepareReturn:nil];
  926. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  927. // //
  928. // //
  929. // // ;
  930. // // }];
  931. // [self.navigationController popViewControllerAnimated:true];
  932. //
  933. // }
  934. // else
  935. // {
  936. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  937. // }
  938. //
  939. //
  940. //
  941. //
  942. // });
  943. // });
  944. //
  945. // }
  946. // }
  947. //
  948. //
  949. //
  950. //
  951. // }
  952. //
  953. //
  954. //
  955. //
  956. //
  957. //
  958. //
  959. //
  960. //
  961. //
  962. //
  963. // }
  964. // }];
  965. //
  966. // // [alertView setUseMotionEffects:true];
  967. //
  968. //
  969. // // And launch the dialog
  970. //
  971. // [alertView sizeToFit];
  972. // [alertView show];
  973. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit Confirm.", nil) message:NSLocalizedString(msg, nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  974. //
  975. // alert.tag = SUBMIT_CONFIRM;
  976. // [alert show];
  977. //
  978. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Order Submission" message:msg preferredStyle:UIAlertControllerStyleAlert];
  979. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  980. // add params check here.
  981. [self.lastedit endEditing:true];
  982. [self.lasttextview endEditing:true];
  983. NSMutableDictionary* upparams = [self check_cancommit:true];
  984. if(self.cancommit==false)
  985. return;
  986. // ------
  987. [self.params enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  988. [upparams setObject:obj forKey:key];
  989. }];
  990. // 2018-1-2 Modify
  991. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  992. {
  993. [self customer_commit_order:upparams];
  994. }
  995. else // USER_ROLE_EMPLOYEE
  996. {
  997. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  998. {
  999. upparams[@"shipping"] = nil;
  1000. }
  1001. if(upparams[@"shipping"]==nil || [upparams[@"shipping"] doubleValue]!=0)
  1002. [self empolyee_commit_order:upparams];
  1003. else
  1004. {
  1005. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1006. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  1007. {
  1008. //yes
  1009. [self empolyee_commit_order:upparams];
  1010. }];
  1011. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1012. //DebugLog(@"Cancel");
  1013. }];
  1014. [alertControl addAction:actionOne];
  1015. [alertControl addAction:alertthree];
  1016. [self presentViewController:alertControl animated:YES completion:nil];
  1017. }
  1018. }
  1019. // if(upparams[@"shipping"]==nil)
  1020. // goto commit_order;
  1021. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1022. // {
  1023. // upparams[@"shipping"] = nil;
  1024. // goto commit_order;
  1025. // }
  1026. // else if([upparams[@"shipping"] doubleValue]==0)
  1027. // {
  1028. //
  1029. //
  1030. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1031. // //block代码块取代了delegate
  1032. //
  1033. //
  1034. //
  1035. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  1036. // {
  1037. //
  1038. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1039. //
  1040. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1041. // {
  1042. //
  1043. // if(/*!self.have_tail*/ true)
  1044. // {UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  1045. // [upparams setValue:@"false" forKey:@"isHold"];
  1046. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1047. //
  1048. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1049. //
  1050. // dispatch_async(dispatch_get_main_queue(), ^{
  1051. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1052. //
  1053. //
  1054. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1055. // {
  1056. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1057. //
  1058. // // debug aaa
  1059. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1060. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  1061. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1062. //
  1063. // // appDelegate.customerInfo = customerInfo;
  1064. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1065. // // appDelegate.order_code = nil;
  1066. // [appDelegate closeOrder];
  1067. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1068. //
  1069. // NSString* title=nil;
  1070. // NSString* msg=nil;
  1071. //#ifdef OFFLINE_MODE
  1072. // if(appDelegate.offline_mode)
  1073. // {
  1074. // title=TITLE_OFFLINE_SUBMIT;
  1075. // msg=MSG_OFFLINE_SUBMIT;
  1076. // }
  1077. // else
  1078. //#endif
  1079. // {
  1080. // title=@"Order submitted sucessfully";
  1081. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1082. // }
  1083. //
  1084. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1085. //
  1086. // [alert show];
  1087. //
  1088. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1089. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  1090. // NSString* soid=[editor_json valueForKey:@"so#"];
  1091. // // if(pdf_url.length>0)
  1092. // // {
  1093. // //
  1094. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1095. // // //[self downloadpdf:pdf_url];
  1096. // //
  1097. // //
  1098. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1099. // // {
  1100. // // //bbb
  1101. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1102. // // }
  1103. // //
  1104. // // [self prepareReturn:nil];
  1105. // //
  1106. // // [self.navigationController popViewControllerAnimated:true];
  1107. // //
  1108. // // [appDelegate printPdf:pdf_url];
  1109. // //// if(self.printPdfCallback)
  1110. // //// self.printPdfCallback(pdf_url);
  1111. // // }
  1112. // // else
  1113. // {
  1114. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1115. // {
  1116. // //bbb
  1117. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1118. // }
  1119. // [self prepareReturn:nil];
  1120. //
  1121. // [self.navigationController popToRootViewControllerAnimated:true];
  1122. //
  1123. // if(pdf_url.length>0)
  1124. // {
  1125. //
  1126. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1127. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1128. // // [appDelegate printPdf:pdf_url];
  1129. //
  1130. // }
  1131. // }
  1132. //
  1133. // }
  1134. // else
  1135. // {
  1136. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1137. // }
  1138. //
  1139. //
  1140. //
  1141. //
  1142. // });
  1143. // });
  1144. // }
  1145. // else
  1146. // {
  1147. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1148. //
  1149. //
  1150. // alert.tag = KEEP_TAIL;
  1151. //
  1152. //
  1153. // self.upparams = upparams;
  1154. //
  1155. // [alert show];
  1156. // }
  1157. //
  1158. // }
  1159. // else
  1160. // { //USER_ROLE_CUSTOMER
  1161. //
  1162. // // if(self.have_tail)
  1163. // // [upparams setValue:@"true" forKey:@"isHold"];
  1164. // // else
  1165. // // [upparams setValue:@"false" forKey:@"isHold"];
  1166. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  1167. //
  1168. // [upparams setValue:@"true" forKey:@"isHold"];
  1169. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1170. //
  1171. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1172. //
  1173. // dispatch_async(dispatch_get_main_queue(), ^{
  1174. //
  1175. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1176. //
  1177. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1178. // {
  1179. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1180. //
  1181. //
  1182. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1183. // // appDelegate.customerInfo = customerInfo;
  1184. //
  1185. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1186. // // appDelegate.order_code = orderCode;
  1187. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1188. // [appDelegate closeOrder];
  1189. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1190. //
  1191. // NSString* title=nil;
  1192. // NSString* msg=nil;
  1193. //#ifdef OFFLINE_MODE
  1194. // if(appDelegate.offline_mode)
  1195. // {
  1196. // title=TITLE_OFFLINE_SUBMIT;
  1197. // msg=MSG_OFFLINE_SUBMIT;
  1198. // }
  1199. // else
  1200. //#endif
  1201. // {
  1202. // title=@"Order submitted sucessfully";
  1203. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1204. // }
  1205. //
  1206. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1207. //
  1208. // [alert show];
  1209. // // // self.labelContact.text=appDelegate.contact_name;
  1210. // //
  1211. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1212. // [self prepareReturn:nil];
  1213. // [self.navigationController popToRootViewControllerAnimated:true];
  1214. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1215. // //
  1216. // //
  1217. // // ;
  1218. // // }];
  1219. //
  1220. // }
  1221. // else
  1222. // {
  1223. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1224. // }
  1225. //
  1226. //
  1227. //
  1228. //
  1229. // });
  1230. // });
  1231. //
  1232. // }
  1233. //
  1234. //
  1235. //
  1236. // }];
  1237. //
  1238. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1239. // //DebugLog(@"Cancel");
  1240. //
  1241. //
  1242. // }];
  1243. // [alertControl addAction:actionOne];
  1244. //
  1245. // [alertControl addAction:alertthree];
  1246. //
  1247. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1248. //
  1249. //
  1250. //
  1251. //
  1252. // [self presentViewController:alertControl animated:YES completion:nil];
  1253. //
  1254. //
  1255. //
  1256. // }
  1257. // else
  1258. // {
  1259. // commit_order:
  1260. //
  1261. // {
  1262. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1263. //
  1264. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1265. // {
  1266. //
  1267. // if(/*!self.have_tail*/ true)
  1268. // {UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  1269. // [upparams setValue:@"false" forKey:@"isHold"];
  1270. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1271. //
  1272. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1273. //
  1274. // dispatch_async(dispatch_get_main_queue(), ^{
  1275. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1276. //
  1277. //
  1278. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1279. // {
  1280. //
  1281. // //debug bbb
  1282. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1283. //
  1284. //
  1285. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1286. // NSString* company= appDelegate.customerInfo[@"customer_name"];
  1287. // NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1288. // // appDelegate.customerInfo = customerInfo;
  1289. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1290. // // appDelegate.order_code = nil;
  1291. // [appDelegate closeOrder];
  1292. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1293. //
  1294. // NSString* title=nil;
  1295. // NSString* msg=nil;
  1296. //#ifdef OFFLINE_MODE
  1297. // if(appDelegate.offline_mode)
  1298. // {
  1299. // title=TITLE_OFFLINE_SUBMIT;
  1300. // msg=MSG_OFFLINE_SUBMIT;
  1301. // }
  1302. // else
  1303. //#endif
  1304. // {
  1305. // title=@"Order submitted sucessfully";
  1306. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1307. // }
  1308. //
  1309. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1310. //
  1311. // [alert show];
  1312. //
  1313. // NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1314. // NSString* email_content =[editor_json valueForKey:@"email_content"];
  1315. // NSString* soid=[editor_json valueForKey:@"so#"];
  1316. // // if(pdf_url.length>0)
  1317. // // {
  1318. // //
  1319. // // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1320. // //// [self downloadpdf:pdf_url];
  1321. // //
  1322. // //
  1323. // // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1324. // // {
  1325. // // //bbb
  1326. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1327. // // }
  1328. // //
  1329. // // [self prepareReturn:nil];
  1330. // //
  1331. // // [self.navigationController popViewControllerAnimated:true];
  1332. // //
  1333. // // [appDelegate printPdf:pdf_url];
  1334. // //
  1335. // //// if(self.printPdfCallback)
  1336. // //// self.printPdfCallback(pdf_url);
  1337. // // }
  1338. // // else
  1339. // {
  1340. // NSMutableDictionary* value=[[NSMutableDictionary alloc]init];
  1341. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1342. // {
  1343. // //bbb
  1344. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1345. // value[@"commitorder_logout"]=@"true";
  1346. // }
  1347. //
  1348. //
  1349. // value[@"is_subaction"] = self.params[@"is_subaction"];
  1350. // value[@"subaction_tag"] = self.params[@"subaction_tag"];
  1351. //
  1352. // [self prepareReturn:value];
  1353. //
  1354. // [self.navigationController popToRootViewControllerAnimated:true];
  1355. //
  1356. //
  1357. // if(pdf_url.length>0)
  1358. // {
  1359. //
  1360. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1361. //
  1362. // [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1363. //
  1364. //
  1365. // }
  1366. //
  1367. //
  1368. // }
  1369. // // // self.labelContact.text=appDelegate.contact_name;
  1370. // //
  1371. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1372. //
  1373. //
  1374. //
  1375. //
  1376. //
  1377. //
  1378. // }
  1379. // else
  1380. // {
  1381. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1382. // }
  1383. //
  1384. //
  1385. //
  1386. //
  1387. // });
  1388. // });
  1389. // }
  1390. // else
  1391. // {
  1392. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1393. //
  1394. //
  1395. // alert.tag = KEEP_TAIL;
  1396. //
  1397. //
  1398. // self.upparams = upparams;
  1399. //
  1400. // [alert show];
  1401. // }
  1402. //
  1403. // }
  1404. // else
  1405. // { //USER_ROLE_CUSTOMER
  1406. //
  1407. // // if(self.have_tail)
  1408. // // [upparams setValue:@"true" forKey:@"isHold"];
  1409. // // else
  1410. // // [upparams setValue:@"false" forKey:@"isHold"];
  1411. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  1412. //
  1413. // [upparams setValue:@"true" forKey:@"isHold"];
  1414. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1415. //
  1416. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  1417. //
  1418. // dispatch_async(dispatch_get_main_queue(), ^{
  1419. //
  1420. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1421. //
  1422. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1423. // {
  1424. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1425. //
  1426. //
  1427. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1428. // // appDelegate.customerInfo = customerInfo;
  1429. //
  1430. // // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1431. // // appDelegate.order_code = orderCode;
  1432. // // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1433. // [appDelegate closeOrder];
  1434. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1435. //
  1436. // NSString* title=nil;
  1437. // NSString* msg=nil;
  1438. //#ifdef OFFLINE_MODE
  1439. // if(appDelegate.offline_mode)
  1440. // {
  1441. // title=TITLE_OFFLINE_SUBMIT;
  1442. // msg=MSG_OFFLINE_SUBMIT;
  1443. // }
  1444. // else
  1445. //#endif
  1446. // {
  1447. // title=@"Order submitted sucessfully";
  1448. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1449. // }
  1450. //
  1451. //
  1452. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1453. //
  1454. // [alert show];
  1455. // // // self.labelContact.text=appDelegate.contact_name;
  1456. // //
  1457. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1458. // [self prepareReturn:nil];
  1459. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1460. // //
  1461. // //
  1462. // // ;
  1463. // // }];
  1464. // [self.navigationController popToRootViewControllerAnimated:true];
  1465. //
  1466. // }
  1467. // else
  1468. // {
  1469. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  1470. // }
  1471. //
  1472. //
  1473. //
  1474. //
  1475. // });
  1476. // });
  1477. //
  1478. // }
  1479. // }
  1480. //
  1481. //
  1482. //
  1483. //
  1484. // }
  1485. //
  1486. //
  1487. // }
  1488. //
  1489. }];
  1490. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1491. }];
  1492. [alertVC addAction:yesAction];
  1493. [alertVC addAction:cancelAction];
  1494. [self presentViewController:alertVC animated:yesAction completion:nil];
  1495. }
  1496. - (UIView *)createDemoView:(NSString*) msg
  1497. {
  1498. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  1499. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  1500. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  1501. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  1502. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  1503. titleLabel.text=@"Order Submission";
  1504. titleLabel.numberOfLines = 0;
  1505. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1506. // titleLabel.textAlignment = NSTextAlignmentRight;
  1507. titleLabel.textAlignment = NSTextAlignmentCenter;
  1508. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  1509. CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1510. //[titleLabel sizeToFit];
  1511. // titleLabel.center.x = demoView.center.x;
  1512. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  1513. [demoView addSubview:titleLabel];
  1514. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  1515. lineLabel.font = [UIFont systemFontOfSize:17];
  1516. lineLabel.text=msg;
  1517. lineLabel.numberOfLines = 0;
  1518. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  1519. CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1520. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  1521. //[lineLabel sizeToFit];
  1522. [demoView addSubview:lineLabel];
  1523. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  1524. return demoView;
  1525. }
  1526. - (void)onCloseClick:(UIButton *)sender {
  1527. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1528. if (self.resumeOrder) {
  1529. [self.navigationController popToRootViewControllerAnimated:true];
  1530. return;
  1531. }
  1532. UIAlertView * alert = nil;
  1533. if(appDelegate.order_status==0)
  1534. {
  1535. 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];
  1536. }
  1537. else
  1538. {
  1539. 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];
  1540. }
  1541. alert.tag = CLOSE_ACTION;
  1542. // alert.
  1543. [alert show];
  1544. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1545. // appDelegate.order_code = nil;
  1546. //
  1547. // }
  1548. }
  1549. - (void)didReceiveMemoryWarning {
  1550. [super didReceiveMemoryWarning];
  1551. // Dispose of any resources that can be recreated.
  1552. }
  1553. - (IBAction)onSaveClick:(id)sender {
  1554. // id foo = nil;
  1555. // [[NSMutableArray array] addObject:foo];
  1556. // add params check here.
  1557. [self.lastedit endEditing:true];
  1558. [self.lasttextview endEditing:true];
  1559. NSMutableDictionary* upparams = [self check_cancommit:false];
  1560. // if(self.cancommit==false)
  1561. // return;
  1562. [self.params enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  1563. [upparams setObject:obj forKey:key];
  1564. }];
  1565. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1566. upparams[@"shipping"] = nil;
  1567. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order"];
  1568. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1569. NSDictionary* editor_json = [RANetwork save_Order:upparams];
  1570. dispatch_async(dispatch_get_main_queue(), ^{
  1571. [waitalert dismissViewControllerAnimated:YES completion:nil];
  1572. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1573. if([[editor_json valueForKey:@"result"] intValue]==2)
  1574. {
  1575. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1576. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1577. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1578. {
  1579. appDelegate.customerInfo = customerInfo;
  1580. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1581. }
  1582. NSString *msg = nil;
  1583. if ([editor_json objectForKey:@"so#"]) {
  1584. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1585. }
  1586. [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1587. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1588. {
  1589. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1590. [self prepareReturn:nil];
  1591. [self.navigationController popToRootViewControllerAnimated:true];
  1592. }
  1593. else{
  1594. #ifdef RA_NOTIFICATION
  1595. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1596. #else
  1597. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1598. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1599. #endif
  1600. }
  1601. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1602. if (![Singleton sharedInstance].currentOrderIsMerged) {
  1603. [self releaseOrderAfterSave];
  1604. }
  1605. }
  1606. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1607. // appDelegate.order_code = nil;
  1608. //
  1609. // }
  1610. // // self.labelContact.text=appDelegate.contact_name;
  1611. //
  1612. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1613. // [self prepareReturn:nil];
  1614. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1615. //
  1616. //
  1617. // ;
  1618. // }];
  1619. }
  1620. else
  1621. {
  1622. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1623. }
  1624. });
  1625. });
  1626. }
  1627. - (void)textFieldDidEndEditing:(UITextField *)textField
  1628. {
  1629. [super textFieldDidEndEditing:textField];
  1630. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  1631. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1632. NSMutableDictionary* section_json=nil;
  1633. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  1634. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1635. NSString* name = [item_json valueForKey:@"name"];
  1636. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  1637. {
  1638. float shipping = [self getprice:@"shipping" section:indexPath.section];
  1639. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  1640. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  1641. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  1642. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  1643. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  1644. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1645. int count=0;
  1646. count=[[section_json valueForKey:@"count"] intValue];
  1647. int total_row_idx=-1;
  1648. for(int i=0;i<count;i++)
  1649. {
  1650. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1651. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  1652. {
  1653. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  1654. [olditem setValue:@"true" forKey:@"dirty"];
  1655. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1656. total_row_idx=i;
  1657. }
  1658. }
  1659. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1660. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  1661. if(total_row_idx>=0)
  1662. {
  1663. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  1664. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  1665. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1666. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1667. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1668. // CGSize tablecontent =self.editorTable.contentSize;
  1669. // tablecontent.height=tablecontent.height+self.keyboard_h;
  1670. // self.editorTable.contentSize=tablecontent;
  1671. //
  1672. //
  1673. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  1674. }
  1675. // self.content_data = [editor_json mutableCopy];
  1676. // self.content_data = [self translate_json:editor_json];
  1677. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  1678. // [self.editorTable reloadData];
  1679. }
  1680. //
  1681. // [item_json setValue:@"true" forKey:@"dirty"];
  1682. // [item_json setValue:textField.text forKey:@"value"];
  1683. }
  1684. -(float) getprice:(NSString*) name section :(long) index
  1685. {
  1686. NSMutableDictionary* section_json=nil;
  1687. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  1688. int count=0;
  1689. count=[[section_json valueForKey:@"count"] intValue];
  1690. for(int i=0;i<count;i++)
  1691. {
  1692. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1693. if([[olditem valueForKey:@"name"] isEqualToString:name])
  1694. {
  1695. return [[olditem valueForKey:@"value"] floatValue];
  1696. }
  1697. }
  1698. return 0;
  1699. }
  1700. /*
  1701. #pragma mark - Navigation
  1702. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1703. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1704. // Get the new view controller using [segue destinationViewController].
  1705. // Pass the selected object to the new view controller.
  1706. }
  1707. */
  1708. #pragma mark - UIAlertViewDelegate
  1709. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1710. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1711. {
  1712. if(alertView.tag == CLOSE_ACTION)
  1713. {
  1714. if (buttonIndex == 1) {
  1715. // back edit order
  1716. [self.navigationController popViewControllerAnimated:YES];
  1717. }
  1718. else if(buttonIndex==2)
  1719. {
  1720. // back to cart
  1721. [self.navigationController popToRootViewControllerAnimated:true];
  1722. }
  1723. else if(buttonIndex==3)
  1724. {
  1725. [self.navigationController popToRootViewControllerAnimated:false];
  1726. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1727. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1728. }
  1729. else if(buttonIndex==4)
  1730. {
  1731. // close order;
  1732. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1733. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  1734. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1735. NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1736. dispatch_async(dispatch_get_main_queue(), ^{
  1737. [waitalert dismissViewControllerAnimated:YES completion:nil];
  1738. if([[order_json valueForKey:@"result"] intValue]==2)
  1739. {
  1740. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1741. // appDelegate.order_code = nil;
  1742. [appDelegate closeOrder];
  1743. #ifdef RA_NOTIFICATION
  1744. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1745. #else
  1746. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1747. #endif
  1748. [((MainViewController*)appDelegate.main_vc) switchToHome];
  1749. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1750. {
  1751. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1752. }
  1753. [self prepareReturn:nil];
  1754. [self.navigationController popToRootViewControllerAnimated:true];
  1755. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1756. // ;
  1757. // }];
  1758. }
  1759. else
  1760. {
  1761. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  1762. }
  1763. });
  1764. });
  1765. }
  1766. }
  1767. }
  1768. - (void)releaseOrderAfterSave {
  1769. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1770. [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1771. [appDelegate closeOrder];
  1772. [appDelegate SetSo:nil];
  1773. appDelegate.cart_count=0;
  1774. [appDelegate update_count_mark];
  1775. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1776. [self prepareReturn:nil];
  1777. [self.navigationController popToRootViewControllerAnimated:false];
  1778. }
  1779. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  1780. {
  1781. NSString* ret=nil;
  1782. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  1783. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  1784. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  1785. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  1786. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  1787. if(customer_address1.length>0)
  1788. [arraddr addObject:customer_address1];
  1789. if(customer_address2.length>0)
  1790. [arraddr addObject:customer_address2];
  1791. if(customer_address3.length>0)
  1792. [arraddr addObject:customer_address3];
  1793. if(customer_address4.length>0)
  1794. [arraddr addObject:customer_address4];
  1795. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  1796. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  1797. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  1798. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  1799. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  1800. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  1801. if(customer_city.length>0)
  1802. [arrcty addObject:customer_city];
  1803. if(customer_state.length>0)
  1804. [arrcty addObject:customer_state];
  1805. if(customer_zipcode.length>0)
  1806. [arrcty addObject:customer_zipcode];
  1807. if(customer_country.length>0)
  1808. [arrcty addObject:customer_country];
  1809. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  1810. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  1811. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  1812. //
  1813. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  1814. // if(customer_phone.length>0)
  1815. // {
  1816. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  1817. // [arrpho addObject:customer_phone];
  1818. // }
  1819. // if(customer_fax.length>0)
  1820. // {
  1821. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  1822. // [arrpho addObject:customer_fax];
  1823. // }
  1824. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  1825. //
  1826. //
  1827. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  1828. // if(customer_contact.length>0)
  1829. // {
  1830. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  1831. //
  1832. // }
  1833. // NSString *contact_string = customer_contact;
  1834. //
  1835. //
  1836. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  1837. // if(customer_email.length>0)
  1838. // {
  1839. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  1840. //
  1841. // }
  1842. // NSString *email_string = customer_email;
  1843. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  1844. if(addr_string.length>0)
  1845. [arrext addObject:addr_string];
  1846. if(cty_string.length>0)
  1847. [arrext addObject:cty_string];
  1848. // if(phone_string.length>0)
  1849. // [arrext addObject:phone_string];
  1850. // if(contact_string.length>0)
  1851. // [arrext addObject:contact_string];
  1852. // if(email_string.length>0)
  1853. // [arrext addObject:email_string];
  1854. ret = [arrext componentsJoinedByString:@"\r\n"];
  1855. // NSString *string = [array componentsJoinedByString:@" "];
  1856. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  1857. return ret;
  1858. }
  1859. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  1860. {
  1861. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  1862. NSArray *keys= [key_map allKeys];
  1863. //遍历keys
  1864. for(int i=0;i<[keys count];i++)
  1865. {
  1866. //得到当前key
  1867. NSString *key=[keys objectAtIndex:i];
  1868. //如果key不是pic,说明value是字符类型,比如name:Boris
  1869. NSString* valuefrom = [key_map valueForKey:key];
  1870. if(valuefrom.length==0)
  1871. continue;
  1872. NSString* value=[self getValue:valuefrom];
  1873. [ret setValue:value forKey:valuefrom];
  1874. }
  1875. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  1876. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  1877. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  1878. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  1879. return ret;
  1880. }
  1881. -(NSMutableDictionary*)create_cusromer_info_from_table
  1882. {
  1883. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1884. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  1885. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  1886. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  1887. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  1888. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  1889. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  1890. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  1891. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  1892. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  1893. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  1894. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  1895. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1896. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  1897. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1898. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  1899. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  1900. NSString * firstname =nil;
  1901. NSString* lastname = nil;
  1902. NSString* contact_name = [self getValue:@"customer_contact"];
  1903. if(contact_name!=nil)
  1904. {
  1905. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  1906. if(_arr.count>=1)
  1907. {
  1908. firstname =_arr[0];
  1909. if(_arr.count>1)
  1910. {
  1911. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  1912. }
  1913. }
  1914. }
  1915. [ret setValue:firstname forKey:@"customer_first_name"];
  1916. [ret setValue:lastname forKey:@"customer_last_name"];
  1917. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  1918. return ret;
  1919. }
  1920. #pragma mark - multi_action sub action clicked
  1921. - (void)MActionClicked:(UIButton *)sender {
  1922. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  1923. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1924. int refresh =0;
  1925. NSMutableDictionary* section_json=nil;
  1926. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1927. NSString* subid=[item_json valueForKey:@"subid"];
  1928. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1929. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  1930. NSString* type = [sub_action valueForKey:@"type"];
  1931. if([type isEqualToString:@"pull"])
  1932. {
  1933. [self.lastedit endEditing:true];
  1934. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  1935. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  1936. NSMutableDictionary* value=[self create_value_map:keymap];
  1937. if(subid==nil)
  1938. {
  1939. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1940. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1941. int icount=[[section_json valueForKey:@"count"] intValue];
  1942. for (int ic=0;ic<icount;ic++)
  1943. {
  1944. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1945. NSString* mapto = [modify_item valueForKey:@"name"];
  1946. if(mapto.length==0)
  1947. continue;
  1948. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1949. if(valuefrom==nil)
  1950. continue;
  1951. NSString* valuestr=[value valueForKey:valuefrom];
  1952. // valuestr = [self getValue:valuefrom];
  1953. if(true)
  1954. {
  1955. if(valuestr.length>0)
  1956. [modify_item setValue:valuestr forKey:@"value"];
  1957. else
  1958. [modify_item setValue:@"" forKey:@"value"];
  1959. [modify_item setValue:@"true" forKey:@"dirty"];
  1960. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1961. }
  1962. }
  1963. }
  1964. else
  1965. {
  1966. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1967. int section = [(NSString*)idarr[0] intValue];
  1968. int item=[(NSString*)idarr[1] intValue];
  1969. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1970. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1971. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1972. NSString* control_type = [olditem valueForKey:@"control"];
  1973. if([control_type isEqualToString:@"switch"])
  1974. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1975. else if([control_type isEqualToString:@"enum"])
  1976. {
  1977. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1978. }
  1979. else
  1980. {
  1981. [RAUtils message_alert:@"not impl." title:@"Sorry" controller:self];
  1982. // [RAUtils alert_view:@"" title:@"not impl"];
  1983. }
  1984. [olditem setValue:@"true" forKey:@"dirty"];
  1985. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1986. }
  1987. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1988. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1989. if(refresh==1)
  1990. {
  1991. // if(restore_json!=nil)
  1992. // {
  1993. // int rc=[[restore_json valueForKey:@"count"] intValue];
  1994. // for(int ir=0;ir<rc;ir++)
  1995. // {
  1996. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1997. //
  1998. //
  1999. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2000. // for(int i=0;i<section_count;i++)
  2001. // {
  2002. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2003. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2004. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2005. // for(int j=0;j<item_count;j++)
  2006. // {
  2007. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2008. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2009. //
  2010. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2011. // {
  2012. // [itemjson removeObjectForKey:@"dirty"];
  2013. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2014. // }
  2015. //
  2016. // }
  2017. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2018. // }
  2019. //
  2020. //
  2021. // }
  2022. //
  2023. // }
  2024. [self refresh:refresh_trigger] ;
  2025. return ;
  2026. }
  2027. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  2028. [self.editorTable reloadData ];
  2029. }
  2030. else
  2031. {
  2032. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2033. NSDictionary * item_json = sub_action;
  2034. NSString* value = [item_json valueForKey:@"value"];
  2035. if([value isEqualToString:@"new_addr"])
  2036. {
  2037. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2038. addressVC.url_type = URL_REMOTE;
  2039. addressVC.request_url=URL_ADDRESS_EDOTOR;
  2040. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2041. // NSString * string = [checked componentsJoinedByString:@","];
  2042. // [params setValue:string forKey:@"cart2Checkbox"];
  2043. params[@"is_subaction"]=@"true";
  2044. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2045. addressVC.params = params;
  2046. addressVC.delegate = self;
  2047. addressVC.from = indexPath;
  2048. // orderinfoVC.params = params;
  2049. [self.navigationController pushViewController:addressVC animated:true];
  2050. }else if([value isEqualToString:@"credit_card"])
  2051. {
  2052. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2053. NSDictionary *data = [item_json objectForKey:@"data"];
  2054. if(data!=nil)
  2055. {
  2056. cardVC.content_data_download = [data mutableCopy];
  2057. cardVC.url_type = URL_NONE;
  2058. cardVC.request_url=nil;
  2059. }
  2060. else
  2061. {
  2062. cardVC.url_type = URL_REMOTE;
  2063. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  2064. }
  2065. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2066. params[@"orderCode"]=appDelegate.order_code;
  2067. params[@"is_subaction"]=@"true";
  2068. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2069. cardVC.params = params;
  2070. cardVC.delegate = self;
  2071. cardVC.from = indexPath;
  2072. // orderinfoVC.params = params;
  2073. [self.navigationController pushViewController:cardVC animated:true];
  2074. }
  2075. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  2076. {
  2077. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2078. cvc.showNavibar = true;
  2079. cvc.contact_type = value;
  2080. cvc.is_subaction = @"true";
  2081. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2082. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2083. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2084. //
  2085. // if(self.returnValue)
  2086. // self.returnValue(value);
  2087. };
  2088. [self.navigationController pushViewController:cvc animated:true];
  2089. }
  2090. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  2091. {
  2092. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2093. cvc.showNavibar = true;
  2094. cvc.contact_type = value;
  2095. cvc.is_subaction = @"true";
  2096. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2097. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2098. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2099. //
  2100. // if(self.returnValue)
  2101. // self.returnValue(value);
  2102. };
  2103. [self.navigationController pushViewController:cvc animated:true];
  2104. }
  2105. else if([value isEqualToString:@"Sales_Order_Customer"])
  2106. {
  2107. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2108. cvc.is_subaction = @"true";
  2109. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2110. cvc.showNavibar = true;
  2111. cvc.contact_type = value;
  2112. __weak typeof(self) weakself = self;
  2113. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2114. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2115. //
  2116. // if(self.returnValue)
  2117. // self.returnValue(value);
  2118. };
  2119. [self.navigationController pushViewController:cvc animated:true];
  2120. }
  2121. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  2122. {
  2123. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2124. cvc.showNavibar = true;
  2125. cvc.contact_type = value;
  2126. cvc.is_subaction = @"true";
  2127. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2128. __weak typeof(self) weakself = self;
  2129. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2130. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2131. //
  2132. // if(self.returnValue)
  2133. // self.returnValue(value);
  2134. };
  2135. [self.navigationController pushViewController:cvc animated:true];
  2136. }
  2137. else if([value isEqualToString:@"Contact_Return_To"])
  2138. {
  2139. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2140. cvc.is_subaction = @"true";
  2141. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2142. cvc.showNavibar = true;
  2143. cvc.contact_type = value;
  2144. __weak typeof(self) weakself = self;
  2145. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2146. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2147. //
  2148. // if(self.returnValue)
  2149. // self.returnValue(value);
  2150. };
  2151. [self.navigationController pushViewController:cvc animated:true];
  2152. }
  2153. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  2154. {
  2155. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2156. cvc.is_subaction = @"true";
  2157. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2158. cvc.showNavibar = true;
  2159. cvc.contact_type = value;
  2160. __weak typeof(self) weakself = self;
  2161. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2162. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2163. //
  2164. // if(self.returnValue)
  2165. // self.returnValue(value);
  2166. };
  2167. [self.navigationController pushViewController:cvc animated:true];
  2168. }
  2169. }
  2170. }
  2171. #pragma mark - Urgency
  2172. -(void) viewWillDisappear:(BOOL)animated
  2173. {
  2174. [super viewWillDisappear:animated];
  2175. [self cancel_urgency_timer];
  2176. }
  2177. - (void)start_urgency_timer {
  2178. if (!self.editable) {
  2179. return;
  2180. }
  2181. __weak typeof(self) weakSelf = self;
  2182. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  2183. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  2184. #ifdef OFFLINE_MODE
  2185. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  2186. #endif
  2187. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  2188. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  2189. // DebugLog(@"timer start....");
  2190. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  2191. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  2192. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  2193. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  2194. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  2195. NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  2196. [urgencyDic setValue:so forKey:@"order_so"];
  2197. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  2198. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  2199. }
  2200. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  2201. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  2202. }];
  2203. }
  2204. - (void)cancel_urgency_timer {
  2205. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  2206. }
  2207. #pragma mark - Override
  2208. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2209. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  2210. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  2211. NSString* control = [item_json valueForKey:@"control"];
  2212. if([control isEqualToString:@"model"]) {
  2213. ((CommonEditorCellModel *)cell).avalibilityLabel.hidden = YES;
  2214. }
  2215. return cell;
  2216. }
  2217. #pragma mark - Submit Order
  2218. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  2219. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  2220. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  2221. upparams[@"shipping"] = nil;
  2222. [upparams setValue:@"true" forKey:@"isHold"];
  2223. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2224. NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2225. dispatch_async(dispatch_get_main_queue(), ^{
  2226. [waitalert dismissViewControllerAnimated:YES completion:nil];
  2227. if([[editor_json valueForKey:@"result"] intValue]==2)
  2228. {
  2229. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2230. // appDelegate.customerInfo = customerInfo;
  2231. [appDelegate closeOrder];
  2232. #ifdef RA_NOTIFICATION
  2233. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2234. #else
  2235. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2236. #endif
  2237. NSString* title=nil;
  2238. NSString* msg=nil;
  2239. #ifdef OFFLINE_MODE
  2240. if(appDelegate.offline_mode)
  2241. {
  2242. title=TITLE_OFFLINE_SUBMIT;
  2243. msg=MSG_OFFLINE_SUBMIT;
  2244. }
  2245. else
  2246. #endif
  2247. {
  2248. title=@"Order submitted sucessfully";
  2249. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2250. }
  2251. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2252. //
  2253. // [alert show];
  2254. [self back_order_submit_alert:editor_json];
  2255. [self prepareReturn:nil];
  2256. [self.navigationController popToRootViewControllerAnimated:true];
  2257. }
  2258. else
  2259. {
  2260. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2261. }
  2262. });
  2263. });
  2264. }
  2265. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  2266. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission"];
  2267. [upparams setValue:@"false" forKey:@"isHold"];
  2268. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2269. NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2270. dispatch_async(dispatch_get_main_queue(), ^{
  2271. [waitalert dismissViewControllerAnimated:YES completion:nil];
  2272. if([[editor_json valueForKey:@"result"] intValue]==2)
  2273. {
  2274. // debug aaa
  2275. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2276. NSString* company= appDelegate.customerInfo[@"customer_name"];
  2277. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  2278. [appDelegate closeOrder];
  2279. #ifdef RA_NOTIFICATION
  2280. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2281. #else
  2282. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2283. #endif
  2284. NSString* title=nil;
  2285. NSString* msg=nil;
  2286. #ifdef OFFLINE_MODE
  2287. if(appDelegate.offline_mode)
  2288. {
  2289. title=TITLE_OFFLINE_SUBMIT;
  2290. msg=MSG_OFFLINE_SUBMIT;
  2291. }
  2292. else
  2293. #endif
  2294. {
  2295. title=@"Order submitted sucessfully";
  2296. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2297. }
  2298. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2299. //
  2300. // [alert show];
  2301. UIViewController *alert = [self back_order_submit_alert:editor_json];
  2302. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2303. NSString* email_content =[editor_json valueForKey:@"email_content"];
  2304. // NSString* soid=[editor_json valueForKey:@"so#"];
  2305. {
  2306. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  2307. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2308. {
  2309. //bbb
  2310. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2311. value[@"commitorder_logout"]=@"true";
  2312. }
  2313. [self prepareReturn:value];
  2314. [self.navigationController popToRootViewControllerAnimated:true];
  2315. if(pdf_url.length>0)
  2316. {
  2317. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2318. [alert dismissViewControllerAnimated:YES completion:nil];
  2319. NSString *pdf_title = [editor_json objectForKey:@"title"];
  2320. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:pdf_title content:email_content];
  2321. }
  2322. }
  2323. }
  2324. else
  2325. {
  2326. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2327. }
  2328. });
  2329. });
  2330. }
  2331. - (UIViewController *)back_order_submit_alert:(NSDictionary *)result_json {
  2332. NSString *title = @"Thank you for your order.";
  2333. NSString *html_msg = [result_json objectForKey:@"so#"];
  2334. RABackOrderSubmitAlertController *alert = [[RABackOrderSubmitAlertController alloc] initWithTitle:title Message:html_msg];
  2335. [self presentViewController:alert animated:YES completion:nil];
  2336. return alert;
  2337. }
  2338. @end