RAOrderPreviewController.m 179 KB

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