RAOrderPreviewController.m 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840
  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 = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  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 = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  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 = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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 = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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 = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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 = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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 = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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 = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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. NSMutableDictionary* upparams = [self check_cancommit:false];
  1560. // if(self.cancommit==false)
  1561. // return;
  1562. [self.params enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  1563. [upparams setObject:obj forKey:key];
  1564. }];
  1565. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1566. upparams[@"shipping"] = nil;
  1567. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving Order"];
  1568. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1569. NSDictionary* editor_json = [RANetwork save_Order:upparams];
  1570. dispatch_async(dispatch_get_main_queue(), ^{
  1571. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1572. if([[editor_json valueForKey:@"result"] intValue]==2)
  1573. {
  1574. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1575. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1576. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1577. {
  1578. appDelegate.customerInfo = customerInfo;
  1579. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1580. }
  1581. NSString *msg = nil;
  1582. if ([editor_json objectForKey:@"so#"]) {
  1583. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1584. }
  1585. [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1586. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1587. {
  1588. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1589. [self prepareReturn:nil];
  1590. [self.navigationController popToRootViewControllerAnimated:true];
  1591. }
  1592. else{
  1593. #ifdef RA_NOTIFICATION
  1594. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1595. #else
  1596. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1597. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1598. #endif
  1599. }
  1600. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1601. if (![Singleton sharedInstance].currentOrderIsMerged) {
  1602. [self releaseOrderAfterSave];
  1603. }
  1604. }
  1605. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1606. // appDelegate.order_code = nil;
  1607. //
  1608. // }
  1609. // // self.labelContact.text=appDelegate.contact_name;
  1610. //
  1611. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1612. // [self prepareReturn:nil];
  1613. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1614. //
  1615. //
  1616. // ;
  1617. // }];
  1618. }
  1619. else
  1620. {
  1621. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1622. }
  1623. });
  1624. });
  1625. }
  1626. - (void)textFieldDidEndEditing:(UITextField *)textField
  1627. {
  1628. [super textFieldDidEndEditing:textField];
  1629. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  1630. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1631. NSMutableDictionary* section_json=nil;
  1632. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  1633. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1634. NSString* name = [item_json valueForKey:@"name"];
  1635. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  1636. {
  1637. float shipping = [self getprice:@"shipping" section:indexPath.section];
  1638. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  1639. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  1640. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  1641. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  1642. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  1643. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1644. int count=0;
  1645. count=[[section_json valueForKey:@"count"] intValue];
  1646. int total_row_idx=-1;
  1647. for(int i=0;i<count;i++)
  1648. {
  1649. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1650. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  1651. {
  1652. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  1653. [olditem setValue:@"true" forKey:@"dirty"];
  1654. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1655. total_row_idx=i;
  1656. }
  1657. }
  1658. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1659. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  1660. if(total_row_idx>=0)
  1661. {
  1662. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  1663. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  1664. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1665. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1666. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1667. // CGSize tablecontent =self.editorTable.contentSize;
  1668. // tablecontent.height=tablecontent.height+self.keyboard_h;
  1669. // self.editorTable.contentSize=tablecontent;
  1670. //
  1671. //
  1672. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  1673. }
  1674. // self.content_data = [editor_json mutableCopy];
  1675. // self.content_data = [self translate_json:editor_json];
  1676. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  1677. // [self.editorTable reloadData];
  1678. }
  1679. //
  1680. // [item_json setValue:@"true" forKey:@"dirty"];
  1681. // [item_json setValue:textField.text forKey:@"value"];
  1682. }
  1683. -(float) getprice:(NSString*) name section :(long) index
  1684. {
  1685. NSMutableDictionary* section_json=nil;
  1686. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  1687. int count=0;
  1688. count=[[section_json valueForKey:@"count"] intValue];
  1689. for(int i=0;i<count;i++)
  1690. {
  1691. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1692. if([[olditem valueForKey:@"name"] isEqualToString:name])
  1693. {
  1694. return [[olditem valueForKey:@"value"] floatValue];
  1695. }
  1696. }
  1697. return 0;
  1698. }
  1699. /*
  1700. #pragma mark - Navigation
  1701. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1702. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1703. // Get the new view controller using [segue destinationViewController].
  1704. // Pass the selected object to the new view controller.
  1705. }
  1706. */
  1707. #pragma mark - UIAlertViewDelegate
  1708. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1709. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1710. {
  1711. if(alertView.tag == CLOSE_ACTION)
  1712. {
  1713. if (buttonIndex == 1) {
  1714. // back edit order
  1715. [self.navigationController popViewControllerAnimated:YES];
  1716. }
  1717. else if(buttonIndex==2)
  1718. {
  1719. // back to cart
  1720. [self.navigationController popToRootViewControllerAnimated:true];
  1721. }
  1722. else if(buttonIndex==3)
  1723. {
  1724. [self.navigationController popToRootViewControllerAnimated:false];
  1725. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1726. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1727. }
  1728. else if(buttonIndex==4)
  1729. {
  1730. // close order;
  1731. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1732. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  1733. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1734. NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1735. dispatch_async(dispatch_get_main_queue(), ^{
  1736. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1737. if([[order_json valueForKey:@"result"] intValue]==2)
  1738. {
  1739. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1740. // appDelegate.order_code = nil;
  1741. [appDelegate closeOrder];
  1742. #ifdef RA_NOTIFICATION
  1743. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1744. #else
  1745. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1746. #endif
  1747. [((MainViewController*)appDelegate.main_vc) switchToHome];
  1748. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1749. {
  1750. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1751. }
  1752. [self prepareReturn:nil];
  1753. [self.navigationController popToRootViewControllerAnimated:true];
  1754. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1755. // ;
  1756. // }];
  1757. }
  1758. else
  1759. {
  1760. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  1761. }
  1762. });
  1763. });
  1764. }
  1765. }
  1766. }
  1767. - (void)releaseOrderAfterSave {
  1768. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1769. [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1770. [appDelegate closeOrder];
  1771. [appDelegate SetSo:nil];
  1772. appDelegate.cart_count=0;
  1773. [appDelegate update_count_mark];
  1774. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1775. [self prepareReturn:nil];
  1776. [self.navigationController popToRootViewControllerAnimated:false];
  1777. }
  1778. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  1779. {
  1780. NSString* ret=nil;
  1781. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  1782. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  1783. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  1784. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  1785. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  1786. if(customer_address1.length>0)
  1787. [arraddr addObject:customer_address1];
  1788. if(customer_address2.length>0)
  1789. [arraddr addObject:customer_address2];
  1790. if(customer_address3.length>0)
  1791. [arraddr addObject:customer_address3];
  1792. if(customer_address4.length>0)
  1793. [arraddr addObject:customer_address4];
  1794. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  1795. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  1796. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  1797. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  1798. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  1799. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  1800. if(customer_city.length>0)
  1801. [arrcty addObject:customer_city];
  1802. if(customer_state.length>0)
  1803. [arrcty addObject:customer_state];
  1804. if(customer_zipcode.length>0)
  1805. [arrcty addObject:customer_zipcode];
  1806. if(customer_country.length>0)
  1807. [arrcty addObject:customer_country];
  1808. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  1809. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  1810. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  1811. //
  1812. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  1813. // if(customer_phone.length>0)
  1814. // {
  1815. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  1816. // [arrpho addObject:customer_phone];
  1817. // }
  1818. // if(customer_fax.length>0)
  1819. // {
  1820. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  1821. // [arrpho addObject:customer_fax];
  1822. // }
  1823. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  1824. //
  1825. //
  1826. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  1827. // if(customer_contact.length>0)
  1828. // {
  1829. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  1830. //
  1831. // }
  1832. // NSString *contact_string = customer_contact;
  1833. //
  1834. //
  1835. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  1836. // if(customer_email.length>0)
  1837. // {
  1838. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  1839. //
  1840. // }
  1841. // NSString *email_string = customer_email;
  1842. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  1843. if(addr_string.length>0)
  1844. [arrext addObject:addr_string];
  1845. if(cty_string.length>0)
  1846. [arrext addObject:cty_string];
  1847. // if(phone_string.length>0)
  1848. // [arrext addObject:phone_string];
  1849. // if(contact_string.length>0)
  1850. // [arrext addObject:contact_string];
  1851. // if(email_string.length>0)
  1852. // [arrext addObject:email_string];
  1853. ret = [arrext componentsJoinedByString:@"\r\n"];
  1854. // NSString *string = [array componentsJoinedByString:@" "];
  1855. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  1856. return ret;
  1857. }
  1858. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  1859. {
  1860. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  1861. NSArray *keys= [key_map allKeys];
  1862. //遍历keys
  1863. for(int i=0;i<[keys count];i++)
  1864. {
  1865. //得到当前key
  1866. NSString *key=[keys objectAtIndex:i];
  1867. //如果key不是pic,说明value是字符类型,比如name:Boris
  1868. NSString* valuefrom = [key_map valueForKey:key];
  1869. if(valuefrom.length==0)
  1870. continue;
  1871. NSString* value=[self getValue:valuefrom];
  1872. [ret setValue:value forKey:valuefrom];
  1873. }
  1874. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  1875. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  1876. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  1877. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  1878. return ret;
  1879. }
  1880. -(NSMutableDictionary*)create_cusromer_info_from_table
  1881. {
  1882. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1883. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  1884. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  1885. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  1886. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  1887. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  1888. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  1889. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  1890. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  1891. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  1892. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  1893. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  1894. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1895. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  1896. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1897. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  1898. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  1899. NSString * firstname =nil;
  1900. NSString* lastname = nil;
  1901. NSString* contact_name = [self getValue:@"customer_contact"];
  1902. if(contact_name!=nil)
  1903. {
  1904. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  1905. if(_arr.count>=1)
  1906. {
  1907. firstname =_arr[0];
  1908. if(_arr.count>1)
  1909. {
  1910. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  1911. }
  1912. }
  1913. }
  1914. [ret setValue:firstname forKey:@"customer_first_name"];
  1915. [ret setValue:lastname forKey:@"customer_last_name"];
  1916. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  1917. return ret;
  1918. }
  1919. #pragma mark - multi_action sub action clicked
  1920. - (void)MActionClicked:(UIButton *)sender {
  1921. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  1922. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1923. int refresh =0;
  1924. NSMutableDictionary* section_json=nil;
  1925. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1926. NSString* subid=[item_json valueForKey:@"subid"];
  1927. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1928. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  1929. NSString* type = [sub_action valueForKey:@"type"];
  1930. if([type isEqualToString:@"pull"])
  1931. {
  1932. [self.lastedit endEditing:true];
  1933. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  1934. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  1935. NSMutableDictionary* value=[self create_value_map:keymap];
  1936. if(subid==nil)
  1937. {
  1938. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1939. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1940. int icount=[[section_json valueForKey:@"count"] intValue];
  1941. for (int ic=0;ic<icount;ic++)
  1942. {
  1943. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1944. NSString* mapto = [modify_item valueForKey:@"name"];
  1945. if(mapto.length==0)
  1946. continue;
  1947. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1948. if(valuefrom==nil)
  1949. continue;
  1950. NSString* valuestr=[value valueForKey:valuefrom];
  1951. // valuestr = [self getValue:valuefrom];
  1952. if(true)
  1953. {
  1954. if(valuestr.length>0)
  1955. [modify_item setValue:valuestr forKey:@"value"];
  1956. else
  1957. [modify_item setValue:@"" forKey:@"value"];
  1958. [modify_item setValue:@"true" forKey:@"dirty"];
  1959. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1960. }
  1961. }
  1962. }
  1963. else
  1964. {
  1965. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1966. int section = [(NSString*)idarr[0] intValue];
  1967. int item=[(NSString*)idarr[1] intValue];
  1968. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1969. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1970. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1971. NSString* control_type = [olditem valueForKey:@"control"];
  1972. if([control_type isEqualToString:@"switch"])
  1973. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1974. else if([control_type isEqualToString:@"enum"])
  1975. {
  1976. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1977. }
  1978. else
  1979. {
  1980. [RAUtils alert_view:@"" title:@"not impl"];
  1981. }
  1982. [olditem setValue:@"true" forKey:@"dirty"];
  1983. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1984. }
  1985. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1986. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1987. if(refresh==1)
  1988. {
  1989. // if(restore_json!=nil)
  1990. // {
  1991. // int rc=[[restore_json valueForKey:@"count"] intValue];
  1992. // for(int ir=0;ir<rc;ir++)
  1993. // {
  1994. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1995. //
  1996. //
  1997. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1998. // for(int i=0;i<section_count;i++)
  1999. // {
  2000. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2001. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2002. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2003. // for(int j=0;j<item_count;j++)
  2004. // {
  2005. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2006. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2007. //
  2008. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2009. // {
  2010. // [itemjson removeObjectForKey:@"dirty"];
  2011. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2012. // }
  2013. //
  2014. // }
  2015. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2016. // }
  2017. //
  2018. //
  2019. // }
  2020. //
  2021. // }
  2022. [self refresh:refresh_trigger] ;
  2023. return ;
  2024. }
  2025. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  2026. [self.editorTable reloadData ];
  2027. }
  2028. else
  2029. {
  2030. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2031. NSDictionary * item_json = sub_action;
  2032. NSString* value = [item_json valueForKey:@"value"];
  2033. if([value isEqualToString:@"new_addr"])
  2034. {
  2035. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2036. addressVC.url_type = URL_REMOTE;
  2037. addressVC.request_url=URL_ADDRESS_EDOTOR;
  2038. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2039. // NSString * string = [checked componentsJoinedByString:@","];
  2040. // [params setValue:string forKey:@"cart2Checkbox"];
  2041. params[@"is_subaction"]=@"true";
  2042. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2043. addressVC.params = params;
  2044. addressVC.delegate = self;
  2045. addressVC.from = indexPath;
  2046. // orderinfoVC.params = params;
  2047. [self.navigationController pushViewController:addressVC animated:true];
  2048. }else if([value isEqualToString:@"credit_card"])
  2049. {
  2050. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2051. NSDictionary *data = [item_json objectForKey:@"data"];
  2052. if(data!=nil)
  2053. {
  2054. cardVC.content_data_download = [data mutableCopy];
  2055. cardVC.url_type = URL_NONE;
  2056. cardVC.request_url=nil;
  2057. }
  2058. else
  2059. {
  2060. cardVC.url_type = URL_REMOTE;
  2061. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  2062. }
  2063. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2064. params[@"orderCode"]=appDelegate.order_code;
  2065. params[@"is_subaction"]=@"true";
  2066. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2067. cardVC.params = params;
  2068. cardVC.delegate = self;
  2069. cardVC.from = indexPath;
  2070. // orderinfoVC.params = params;
  2071. [self.navigationController pushViewController:cardVC animated:true];
  2072. }
  2073. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  2074. {
  2075. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2076. cvc.showNavibar = true;
  2077. cvc.contact_type = value;
  2078. cvc.is_subaction = @"true";
  2079. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2080. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2081. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2082. //
  2083. // if(self.returnValue)
  2084. // self.returnValue(value);
  2085. };
  2086. [self.navigationController pushViewController:cvc animated:true];
  2087. }
  2088. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  2089. {
  2090. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2091. cvc.showNavibar = true;
  2092. cvc.contact_type = value;
  2093. cvc.is_subaction = @"true";
  2094. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2095. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2096. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2097. //
  2098. // if(self.returnValue)
  2099. // self.returnValue(value);
  2100. };
  2101. [self.navigationController pushViewController:cvc animated:true];
  2102. }
  2103. else if([value isEqualToString:@"Sales_Order_Customer"])
  2104. {
  2105. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2106. cvc.is_subaction = @"true";
  2107. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2108. cvc.showNavibar = true;
  2109. cvc.contact_type = value;
  2110. __weak typeof(self) weakself = self;
  2111. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2112. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2113. //
  2114. // if(self.returnValue)
  2115. // self.returnValue(value);
  2116. };
  2117. [self.navigationController pushViewController:cvc animated:true];
  2118. }
  2119. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  2120. {
  2121. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2122. cvc.showNavibar = true;
  2123. cvc.contact_type = value;
  2124. cvc.is_subaction = @"true";
  2125. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2126. __weak typeof(self) weakself = self;
  2127. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2128. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2129. //
  2130. // if(self.returnValue)
  2131. // self.returnValue(value);
  2132. };
  2133. [self.navigationController pushViewController:cvc animated:true];
  2134. }
  2135. else if([value isEqualToString:@"Contact_Return_To"])
  2136. {
  2137. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2138. cvc.is_subaction = @"true";
  2139. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2140. cvc.showNavibar = true;
  2141. cvc.contact_type = value;
  2142. __weak typeof(self) weakself = self;
  2143. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2144. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2145. //
  2146. // if(self.returnValue)
  2147. // self.returnValue(value);
  2148. };
  2149. [self.navigationController pushViewController:cvc animated:true];
  2150. }
  2151. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  2152. {
  2153. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2154. cvc.is_subaction = @"true";
  2155. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2156. cvc.showNavibar = true;
  2157. cvc.contact_type = value;
  2158. __weak typeof(self) weakself = self;
  2159. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2160. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2161. //
  2162. // if(self.returnValue)
  2163. // self.returnValue(value);
  2164. };
  2165. [self.navigationController pushViewController:cvc animated:true];
  2166. }
  2167. }
  2168. }
  2169. #pragma mark - Urgency
  2170. -(void) viewWillDisappear:(BOOL)animated
  2171. {
  2172. [super viewWillDisappear:animated];
  2173. [self cancel_urgency_timer];
  2174. }
  2175. - (void)start_urgency_timer {
  2176. if (!self.editable) {
  2177. return;
  2178. }
  2179. __weak typeof(self) weakSelf = self;
  2180. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  2181. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  2182. #ifdef OFFLINE_MODE
  2183. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  2184. #endif
  2185. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  2186. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  2187. // DebugLog(@"timer start....");
  2188. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  2189. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  2190. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  2191. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  2192. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  2193. NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  2194. [urgencyDic setValue:so forKey:@"order_so"];
  2195. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  2196. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  2197. }
  2198. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  2199. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  2200. }];
  2201. }
  2202. - (void)cancel_urgency_timer {
  2203. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  2204. }
  2205. #pragma mark - Override
  2206. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2207. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  2208. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  2209. NSString* control = [item_json valueForKey:@"control"];
  2210. if([control isEqualToString:@"model"]) {
  2211. ((CommonEditorCellModel *)cell).avalibilityLabel.hidden = YES;
  2212. }
  2213. return cell;
  2214. }
  2215. #pragma mark - Submit Order
  2216. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  2217. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  2218. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  2219. upparams[@"shipping"] = nil;
  2220. [upparams setValue:@"true" forKey:@"isHold"];
  2221. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2222. NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2223. dispatch_async(dispatch_get_main_queue(), ^{
  2224. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2225. if([[editor_json valueForKey:@"result"] intValue]==2)
  2226. {
  2227. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2228. // appDelegate.customerInfo = customerInfo;
  2229. [appDelegate closeOrder];
  2230. #ifdef RA_NOTIFICATION
  2231. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2232. #else
  2233. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2234. #endif
  2235. NSString* title=nil;
  2236. NSString* msg=nil;
  2237. #ifdef OFFLINE_MODE
  2238. if(appDelegate.offline_mode)
  2239. {
  2240. title=TITLE_OFFLINE_SUBMIT;
  2241. msg=MSG_OFFLINE_SUBMIT;
  2242. }
  2243. else
  2244. #endif
  2245. {
  2246. title=@"Order submitted sucessfully";
  2247. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2248. }
  2249. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2250. //
  2251. // [alert show];
  2252. [self back_order_submit_alert:editor_json];
  2253. [self prepareReturn:nil];
  2254. [self.navigationController popToRootViewControllerAnimated:true];
  2255. }
  2256. else
  2257. {
  2258. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2259. }
  2260. });
  2261. });
  2262. }
  2263. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  2264. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Order Submission"];
  2265. [upparams setValue:@"false" forKey:@"isHold"];
  2266. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2267. NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2268. dispatch_async(dispatch_get_main_queue(), ^{
  2269. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2270. if([[editor_json valueForKey:@"result"] intValue]==2)
  2271. {
  2272. // debug aaa
  2273. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2274. NSString* company= appDelegate.customerInfo[@"customer_name"];
  2275. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  2276. [appDelegate closeOrder];
  2277. #ifdef RA_NOTIFICATION
  2278. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2279. #else
  2280. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2281. #endif
  2282. NSString* title=nil;
  2283. NSString* msg=nil;
  2284. #ifdef OFFLINE_MODE
  2285. if(appDelegate.offline_mode)
  2286. {
  2287. title=TITLE_OFFLINE_SUBMIT;
  2288. msg=MSG_OFFLINE_SUBMIT;
  2289. }
  2290. else
  2291. #endif
  2292. {
  2293. title=@"Order submitted sucessfully";
  2294. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2295. }
  2296. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2297. //
  2298. // [alert show];
  2299. UIViewController *alert = [self back_order_submit_alert:editor_json];
  2300. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2301. NSString* email_content =[editor_json valueForKey:@"email_content"];
  2302. // NSString* soid=[editor_json valueForKey:@"so#"];
  2303. {
  2304. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  2305. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2306. {
  2307. //bbb
  2308. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2309. value[@"commitorder_logout"]=@"true";
  2310. }
  2311. [self prepareReturn:value];
  2312. [self.navigationController popToRootViewControllerAnimated:true];
  2313. if(pdf_url.length>0)
  2314. {
  2315. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2316. [alert dismissViewControllerAnimated:YES completion:nil];
  2317. NSString *pdf_title = [editor_json objectForKey:@"title"];
  2318. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:pdf_title content:email_content];
  2319. }
  2320. }
  2321. }
  2322. else
  2323. {
  2324. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2325. }
  2326. });
  2327. });
  2328. }
  2329. - (UIViewController *)back_order_submit_alert:(NSDictionary *)result_json {
  2330. NSString *title = @"Thank you for your order.";
  2331. NSString *html_msg = [result_json objectForKey:@"so#"];
  2332. RABackOrderSubmitAlertController *alert = [[RABackOrderSubmitAlertController alloc] initWithTitle:title Message:html_msg];
  2333. [self presentViewController:alert animated:YES completion:nil];
  2334. return alert;
  2335. }
  2336. @end