RAOrderPreviewController.m 185 KB

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