CreateOrderViewController.m 179 KB

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