RAOrderPreviewController.m 187 KB

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