CreateOrderViewController.m 189 KB

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