RAOrderPreviewController.m 186 KB

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