CreateOrderViewController.m 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300
  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. #define SUBMIT_CONFIRM 123
  15. #define KEEP_TAIL 456
  16. #define CLOSE_ACTION 567
  17. @interface CreateOrderViewController ()
  18. // static const char associatedkey;
  19. @end
  20. @implementation CreateOrderViewController
  21. -(void) viewWillAppear:(BOOL)animated
  22. {
  23. [super viewWillAppear:animated];
  24. // 检查权限
  25. NSMutableArray * items = [[NSMutableArray alloc]init];
  26. UIBarButtonItem *savebtn = nil;
  27. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  28. style:UIBarButtonItemStylePlain
  29. target:self
  30. action:@selector(onSaveClick:)];
  31. self.btnSubmitOrder = nil;
  32. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  33. style:UIBarButtonItemStylePlain
  34. target:self
  35. action:@selector(onCommitOrderClick:)];
  36. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  37. fixedItem.width = 20.0f;
  38. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  39. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  40. {
  41. [items addObject:savebtn];
  42. [items addObject:fixedItem];
  43. }
  44. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  45. // customer的订单必须是Sales Order才能提交
  46. if ([Singleton sharedInstance].customer_order_type == 1 && [Singleton sharedInstance].permissions_submit_order) {
  47. [items addObject:self.btnSubmitOrder];
  48. }
  49. } else {
  50. [items addObject:self.btnSubmitOrder];
  51. }
  52. // [items addObject:item2];
  53. self.navigationItem.rightBarButtonItems=items;
  54. if(appDelegate.can_submit_order)
  55. {
  56. [self.btnSubmitOrder setImage:[UIImage imageNamed:@"commit"]];
  57. self.btnSubmitOrder.enabled = true;
  58. }
  59. else
  60. {
  61. [self.btnSubmitOrder setImage:nil];
  62. self.btnSubmitOrder.enabled = false;
  63. }
  64. self.navigationController.navigationBarHidden=false;
  65. }
  66. -(void) download_success
  67. {
  68. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  69. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  70. NSString* order_customerid=[self getValue:@"customer_cid"];
  71. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  72. appDelegate.order_customer_id = order_customerid;
  73. }
  74. - (void)viewDidLoad {
  75. [super viewDidLoad];
  76. self.editable = YES;
  77. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  78. style:UIBarButtonItemStylePlain
  79. target:self
  80. action:@selector(onCloseClick:)];
  81. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  82. // closeButton.title = @"Close";
  83. self.navigationItem.leftBarButtonItem = closeButton;
  84. // self.navigationItem.backBarButtonItem = backButton;
  85. // Do any additional setup after loading the view.
  86. }
  87. - (void)onCommitOrderClick:(id)sender {
  88. // get customer info
  89. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  90. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  91. //
  92. // // 检查价格类型
  93. // // 提货价才能提交订单
  94. // /** 价格类型
  95. // * 0 提货价
  96. // * 1 统一价
  97. // * 2 计算价
  98. // */
  99. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  100. // if (priceType != 0) {
  101. //
  102. // NSString* pricename = nil;
  103. // switch (priceType) {
  104. // case 1:
  105. // pricename=flat_price;
  106. // break;
  107. // case 2:
  108. // pricename=given_price;
  109. // break;
  110. // default:
  111. // break;
  112. // }
  113. //
  114. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current price is %@, please change to %@ and try again.",pricename,[Singleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  115. //
  116. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  117. //
  118. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  119. //
  120. // }];
  121. //
  122. //
  123. // [alertVC addAction:cancelAction];
  124. //
  125. // [self presentViewController:alertVC animated:YES completion:nil];
  126. //
  127. // return;
  128. // }
  129. // }
  130. NSString* msg;
  131. if(appDelegate.offline_mode)
  132. {
  133. msg=@"Are you sure to mark offline order as ready for submit?";
  134. }
  135. else
  136. {
  137. msg=@"Are you sure to submit order?";
  138. if(appDelegate.user_type == USER_ROLE_CUSTOMER) {
  139. NSString *specialInstuction = [Singleton sharedInstance].specialInstruction;
  140. msg = [NSString stringWithFormat:@"Are you sure to submit order?\n\n1. Current Price Type is %@",[self currentPriceTypeName]];
  141. if (specialInstuction.length) {
  142. msg = [msg stringByAppendingFormat:@"\n2. Special Instruction: %@.",specialInstuction];
  143. }
  144. }
  145. }
  146. CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
  147. // Add some custom content to the alert view
  148. [alertView setContainerView:[self createDemoView:msg]];
  149. // Modify the parameters
  150. [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"NO",@"YES", nil]];
  151. //[alertView setDelegate:self];
  152. // You may use a Block, rather than a delegate.
  153. [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
  154. // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
  155. if(buttonIndex==0)
  156. [alertView close];
  157. else
  158. {
  159. // add params check here.
  160. [self.lastedit endEditing:true];
  161. [self.lasttextview endEditing:true];
  162. // self.cancommit=true;
  163. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  164. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  165. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  166. // for(int i=0;i<section_count;i++)
  167. // {
  168. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  169. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  170. // for(int j=0;j<item_count;j++)
  171. // {
  172. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  173. // NSString* key = [itemjson valueForKey:@"name"];
  174. // if(key==nil || key.length==0)
  175. // continue;
  176. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  177. // {
  178. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  179. // if([single_select isEqualToString:@"true"])
  180. // {
  181. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  182. // int count = [[cadejson valueForKey:@"count"] intValue];
  183. // bool setvalue = false;
  184. // for(int cc=0;cc<count;cc++)
  185. // {
  186. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  187. // if([[valjson valueForKey:@"check"]intValue]==1)
  188. // {
  189. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  190. // setvalue=true;
  191. // break;
  192. // }
  193. // }
  194. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  195. // {
  196. // self.cancommit = false;
  197. // }
  198. // }
  199. // else
  200. // {
  201. // //not support multi select for now;
  202. // }
  203. // /*
  204. // upparams setValue:itemjson forKey:<#(NSString *)#>
  205. //
  206. // */
  207. // }else
  208. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  209. // {
  210. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  211. // self.cancommit = false;
  212. // }
  213. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  214. // {
  215. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  216. // self.cancommit = false;
  217. //
  218. // NSString* valuestr = [itemjson valueForKey:@"value"];
  219. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  220. // }
  221. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  222. // {
  223. // NSString* valuestr = [itemjson valueForKey:@"value"];
  224. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  225. //
  226. // NSString* value = [itemjson valueForKey:@"value"];
  227. // NSMutableDictionary* boolitem=nil;
  228. // NSMutableDictionary* subjson=nil;
  229. // if([value isEqualToString:@"true"])
  230. // {
  231. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  232. //
  233. // }
  234. // else
  235. // {
  236. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  237. //
  238. // }
  239. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  240. // if( subjson!=nil /*&& !active*/)
  241. // {
  242. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  243. // for(int l=0;l<sub_count;l++)
  244. // {
  245. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  246. //
  247. //
  248. //
  249. //
  250. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  251. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  252. // else
  253. // {
  254. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  255. // self.cancommit = false;
  256. // }
  257. // }
  258. //
  259. //
  260. //
  261. // }
  262. // }
  263. // else
  264. // {
  265. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  266. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  267. // else
  268. // {
  269. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  270. // self.cancommit = false;
  271. // }
  272. // }
  273. // upparams= [self subitem_param:itemjson addto:upparams ];
  274. // }
  275. // }
  276. // if(self.cancommit==false)
  277. // {
  278. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  279. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  280. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  281. // //[self.editorTable reloadData ];
  282. // [self.editorTable reloadData];
  283. // // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  284. // return;
  285. // }
  286. NSMutableDictionary* upparams = [self check_cancommit:true];
  287. if(self.cancommit==false)
  288. return;
  289. if(upparams[@"shipping"]==nil)
  290. goto commit_order;
  291. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"])
  292. {
  293. upparams[@"shipping"] = nil;
  294. goto commit_order;
  295. }
  296. else if([upparams[@"shipping"] doubleValue]==0)
  297. {
  298. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  299. //block代码块取代了delegate
  300. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  301. {
  302. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  303. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  304. {
  305. if(/*!self.have_tail*/ true)
  306. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  307. [upparams setValue:@"false" forKey:@"isHold"];
  308. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  309. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  310. dispatch_async(dispatch_get_main_queue(), ^{
  311. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  312. if([[editor_json valueForKey:@"result"] intValue]==2)
  313. {
  314. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  315. // debug aaa
  316. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  317. NSString* company= appDelegate.customerInfo[@"customer_name"];
  318. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  319. // appDelegate.customerInfo = customerInfo;
  320. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  321. // appDelegate.order_code = nil;
  322. [appDelegate closeOrder];
  323. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  324. NSString* title=nil;
  325. NSString* msg=nil;
  326. if(appDelegate.offline_mode)
  327. {
  328. title=TITLE_OFFLINE_SUBMIT;
  329. msg=MSG_OFFLINE_SUBMIT;
  330. }
  331. else
  332. {
  333. title=@"Submit successful.";
  334. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  335. }
  336. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  337. [alert show];
  338. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  339. NSString* email_content =[editor_json valueForKey:@"email_content"];
  340. NSString* soid=[editor_json valueForKey:@"so#"];
  341. // if(pdf_url.length>0)
  342. // {
  343. //
  344. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  345. // //[self downloadpdf:pdf_url];
  346. //
  347. //
  348. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  349. // {
  350. // //bbb
  351. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  352. // }
  353. //
  354. // [self prepareReturn:nil];
  355. //
  356. // [self.navigationController popViewControllerAnimated:true];
  357. //
  358. // [appDelegate printPdf:pdf_url];
  359. //// if(self.printPdfCallback)
  360. //// self.printPdfCallback(pdf_url);
  361. // }
  362. // else
  363. {
  364. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  365. {
  366. //bbb
  367. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  368. }
  369. [self prepareReturn:nil];
  370. [self.navigationController popViewControllerAnimated:true];
  371. if(pdf_url.length>0)
  372. {
  373. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  374. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  375. // [appDelegate printPdf:pdf_url];
  376. }
  377. }
  378. }
  379. else
  380. {
  381. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  382. }
  383. });
  384. });
  385. }
  386. else
  387. {
  388. 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];
  389. alert.tag = KEEP_TAIL;
  390. self.upparams = upparams;
  391. [alert show];
  392. }
  393. }
  394. else
  395. { //USER_ROLE_CUSTOMER
  396. // if(self.have_tail)
  397. // [upparams setValue:@"true" forKey:@"isHold"];
  398. // else
  399. // [upparams setValue:@"false" forKey:@"isHold"];
  400. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  401. [upparams setValue:@"true" forKey:@"isHold"];
  402. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  403. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  404. dispatch_async(dispatch_get_main_queue(), ^{
  405. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  406. if([[editor_json valueForKey:@"result"] intValue]==2)
  407. {
  408. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  409. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  410. // appDelegate.customerInfo = customerInfo;
  411. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  412. // appDelegate.order_code = orderCode;
  413. // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  414. [appDelegate closeOrder];
  415. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  416. NSString* title=nil;
  417. NSString* msg=nil;
  418. if(appDelegate.offline_mode)
  419. {
  420. title=TITLE_OFFLINE_SUBMIT;
  421. msg=MSG_OFFLINE_SUBMIT;
  422. }
  423. else
  424. {
  425. title=@"Submit successful.";
  426. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  427. }
  428. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  429. [alert show];
  430. // // self.labelContact.text=appDelegate.contact_name;
  431. //
  432. // NSDictionary * customerinfo = appDelegate.customerInfo;
  433. [self prepareReturn:nil];
  434. [self.navigationController popViewControllerAnimated:true];
  435. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  436. //
  437. //
  438. // ;
  439. // }];
  440. }
  441. else
  442. {
  443. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  444. }
  445. });
  446. });
  447. }
  448. }];
  449. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  450. //DebugLog(@"Cancel");
  451. }];
  452. [alertControl addAction:actionOne];
  453. [alertControl addAction:alertthree];
  454. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  455. [self presentViewController:alertControl animated:YES completion:nil];
  456. }
  457. else
  458. {
  459. commit_order:
  460. {
  461. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  462. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  463. {
  464. if(/*!self.have_tail*/ true)
  465. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  466. [upparams setValue:@"false" forKey:@"isHold"];
  467. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  468. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  469. dispatch_async(dispatch_get_main_queue(), ^{
  470. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  471. if([[editor_json valueForKey:@"result"] intValue]==2)
  472. {
  473. //debug bbb
  474. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  475. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  476. NSString* company= appDelegate.customerInfo[@"customer_name"];
  477. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  478. // appDelegate.customerInfo = customerInfo;
  479. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  480. // appDelegate.order_code = nil;
  481. [appDelegate closeOrder];
  482. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  483. NSString* title=nil;
  484. NSString* msg=nil;
  485. if(appDelegate.offline_mode)
  486. {
  487. title=TITLE_OFFLINE_SUBMIT;
  488. msg=MSG_OFFLINE_SUBMIT;
  489. }
  490. else
  491. {
  492. title=@"Submit successful.";
  493. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  494. }
  495. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  496. [alert show];
  497. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  498. NSString* email_content =[editor_json valueForKey:@"email_content"];
  499. NSString* soid=[editor_json valueForKey:@"so#"];
  500. // if(pdf_url.length>0)
  501. // {
  502. //
  503. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  504. //// [self downloadpdf:pdf_url];
  505. //
  506. //
  507. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  508. // {
  509. // //bbb
  510. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  511. // }
  512. //
  513. // [self prepareReturn:nil];
  514. //
  515. // [self.navigationController popViewControllerAnimated:true];
  516. //
  517. // [appDelegate printPdf:pdf_url];
  518. //
  519. //// if(self.printPdfCallback)
  520. //// self.printPdfCallback(pdf_url);
  521. // }
  522. // else
  523. {
  524. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  525. {
  526. //bbb
  527. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  528. }
  529. [self prepareReturn:nil];
  530. [self.navigationController popViewControllerAnimated:true];
  531. if(pdf_url.length>0)
  532. {
  533. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  534. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  535. }
  536. }
  537. // // self.labelContact.text=appDelegate.contact_name;
  538. //
  539. // NSDictionary * customerinfo = appDelegate.customerInfo;
  540. }
  541. else
  542. {
  543. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  544. }
  545. });
  546. });
  547. }
  548. else
  549. {
  550. 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];
  551. alert.tag = KEEP_TAIL;
  552. self.upparams = upparams;
  553. [alert show];
  554. }
  555. }
  556. else
  557. { //USER_ROLE_CUSTOMER
  558. // if(self.have_tail)
  559. // [upparams setValue:@"true" forKey:@"isHold"];
  560. // else
  561. // [upparams setValue:@"false" forKey:@"isHold"];
  562. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  563. [upparams setValue:@"true" forKey:@"isHold"];
  564. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  565. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  566. dispatch_async(dispatch_get_main_queue(), ^{
  567. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  568. if([[editor_json valueForKey:@"result"] intValue]==2)
  569. {
  570. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  571. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  572. // appDelegate.customerInfo = customerInfo;
  573. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  574. // appDelegate.order_code = orderCode;
  575. // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  576. [appDelegate closeOrder];
  577. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  578. NSString* title=nil;
  579. NSString* msg=nil;
  580. if(appDelegate.offline_mode)
  581. {
  582. title=TITLE_OFFLINE_SUBMIT;
  583. msg=MSG_OFFLINE_SUBMIT;
  584. }
  585. else
  586. {
  587. title=@"Submit successful.";
  588. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  589. }
  590. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  591. [alert show];
  592. // // self.labelContact.text=appDelegate.contact_name;
  593. //
  594. // NSDictionary * customerinfo = appDelegate.customerInfo;
  595. [self prepareReturn:nil];
  596. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  597. //
  598. //
  599. // ;
  600. // }];
  601. [self.navigationController popViewControllerAnimated:true];
  602. }
  603. else
  604. {
  605. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  606. }
  607. });
  608. });
  609. }
  610. }
  611. }
  612. }
  613. }];
  614. // [alertView setUseMotionEffects:true];
  615. // And launch the dialog
  616. [alertView sizeToFit];
  617. [alertView show];
  618. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit Confirm.", nil) message:NSLocalizedString(msg, nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  619. //
  620. // alert.tag = SUBMIT_CONFIRM;
  621. // [alert show];
  622. //
  623. }
  624. - (UIView *)createDemoView:(NSString*) msg
  625. {
  626. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  627. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  628. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  629. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  630. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  631. titleLabel.text=@"Submit Confirm.";
  632. titleLabel.numberOfLines = 0;
  633. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  634. // titleLabel.textAlignment = NSTextAlignmentRight;
  635. titleLabel.textAlignment = NSTextAlignmentCenter;
  636. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  637. CGSize sizetitle = [titleLabel.text=@"Submit Confirm." sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  638. //[titleLabel sizeToFit];
  639. // titleLabel.center.x = demoView.center.x;
  640. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  641. [demoView addSubview:titleLabel];
  642. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  643. lineLabel.font = [UIFont systemFontOfSize:17];
  644. lineLabel.text=msg;
  645. lineLabel.numberOfLines = 0;
  646. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  647. CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  648. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  649. //[lineLabel sizeToFit];
  650. [demoView addSubview:lineLabel];
  651. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  652. return demoView;
  653. }
  654. - (void)onCloseClick:(UIButton *)sender {
  655. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  656. if (self.resumeOrder) {
  657. [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
  658. return;
  659. }
  660. //
  661. // NSRange range = [tempStr rangeOfString:@")\">"];//判断字符串是否包含
  662. //
  663. // //if (range.location ==NSNotFound)//不包含
  664. // if (range.length >0)//包含
  665. // {
  666. //
  667. //
  668. //
  669. // }
  670. // else//不包含
  671. // {
  672. //
  673. // }
  674. UIAlertView * alert = nil;
  675. if(appDelegate.order_status==0)
  676. {
  677. 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];
  678. }
  679. else
  680. {
  681. 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];
  682. }
  683. alert.tag = CLOSE_ACTION;
  684. // alert.
  685. [alert show];
  686. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  687. // appDelegate.order_code = nil;
  688. //
  689. // }
  690. }
  691. - (void)didReceiveMemoryWarning {
  692. [super didReceiveMemoryWarning];
  693. // Dispose of any resources that can be recreated.
  694. }
  695. - (IBAction)onSaveClick:(id)sender {
  696. // id foo = nil;
  697. // [[NSMutableArray array] addObject:foo];
  698. // add params check here.
  699. [self.lastedit endEditing:true];
  700. [self.lasttextview endEditing:true];
  701. // self.cancommit=true;
  702. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  703. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  704. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  705. // for(int i=0;i<section_count;i++)
  706. // {
  707. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  708. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  709. // for(int j=0;j<item_count;j++)
  710. // {
  711. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  712. // NSString* key = [itemjson valueForKey:@"name"];
  713. // if(key==nil || key.length==0)
  714. // continue;
  715. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  716. // {
  717. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  718. // if([single_select isEqualToString:@"true"])
  719. // {
  720. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  721. // int count = [[cadejson valueForKey:@"count"] intValue];
  722. // bool setvalue = false;
  723. // for(int cc=0;cc<count;cc++)
  724. // {
  725. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  726. // if([[valjson valueForKey:@"check"]intValue]==1)
  727. // {
  728. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  729. // setvalue=true;
  730. // break;
  731. // }
  732. // }
  733. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  734. // {
  735. // self.cancommit = false;
  736. // }
  737. // }
  738. // else
  739. // {
  740. // //not support multi select for now;
  741. // }
  742. // /*
  743. // upparams setValue:itemjson forKey:<#(NSString *)#>
  744. //
  745. // */
  746. // }else
  747. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  748. // {
  749. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  750. // self.cancommit = false;
  751. // }
  752. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  753. // {
  754. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"]==nil)
  755. // self.cancommit = false;
  756. //
  757. // NSString* valuestr = [itemjson valueForKey:@"value"];
  758. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  759. // }
  760. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  761. // {
  762. // NSString* valuestr = [itemjson valueForKey:@"value"];
  763. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  764. //
  765. // NSString* value = [itemjson valueForKey:@"value"];
  766. // NSMutableDictionary* boolitem=nil;
  767. // NSMutableDictionary* subjson=nil;
  768. // if([value isEqualToString:@"true"])
  769. // {
  770. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  771. //
  772. // }
  773. // else
  774. // {
  775. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  776. //
  777. // }
  778. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  779. // if( subjson!=nil /*&& !active*/)
  780. // {
  781. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  782. // for(int l=0;l<sub_count;l++)
  783. // {
  784. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  785. //
  786. //
  787. //
  788. //
  789. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  790. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  791. // else
  792. // {
  793. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  794. // self.cancommit = false;
  795. // }
  796. // }
  797. //
  798. //
  799. //
  800. // }
  801. // }
  802. // else
  803. // {
  804. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  805. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  806. // else
  807. // {
  808. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  809. // self.cancommit = false;
  810. // }
  811. // }
  812. // upparams= [self subitem_param:itemjson addto:upparams ];
  813. // }
  814. // }
  815. // // save order 不检查必填项;
  816. // self.cancommit=true;
  817. // if(self.cancommit==false)
  818. // {
  819. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  820. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  821. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  822. // //[self.editorTable reloadData ];
  823. // [self.editorTable reloadData];
  824. // return;
  825. // }
  826. NSMutableDictionary* upparams = [self check_cancommit:false];
  827. // if(self.cancommit==false)
  828. // return;
  829. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"])
  830. upparams[@"shipping"] = nil;
  831. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving Order"];
  832. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  833. NSDictionary* editor_json = [iSalesNetwork save_Order:upparams];
  834. dispatch_async(dispatch_get_main_queue(), ^{
  835. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  836. if([[editor_json valueForKey:@"result"] intValue]==2)
  837. {
  838. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  839. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  840. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  841. {
  842. appDelegate.customerInfo = customerInfo;
  843. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  844. }
  845. [RAUtils message_alert:nil title:@"Order Saved" controller:self] ;
  846. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  847. {
  848. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  849. [self prepareReturn:nil];
  850. [self.navigationController popViewControllerAnimated:true];
  851. }
  852. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  853. // appDelegate.order_code = nil;
  854. //
  855. // }
  856. // // self.labelContact.text=appDelegate.contact_name;
  857. //
  858. // NSDictionary * customerinfo = appDelegate.customerInfo;
  859. // [self prepareReturn:nil];
  860. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  861. //
  862. //
  863. // ;
  864. // }];
  865. }
  866. else
  867. {
  868. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  869. }
  870. });
  871. });
  872. }
  873. - (void)textFieldDidEndEditing:(UITextField *)textField
  874. {
  875. [super textFieldDidEndEditing:textField];
  876. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  877. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  878. NSMutableDictionary* section_json=nil;
  879. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  880. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  881. NSString* name = [item_json valueForKey:@"name"];
  882. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"])
  883. {
  884. float shipping = [self getprice:@"shipping" section:indexPath.section];
  885. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  886. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  887. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  888. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate;
  889. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  890. int count=0;
  891. count=[[section_json valueForKey:@"count"] intValue];
  892. int total_row_idx=-1;
  893. for(int i=0;i<count;i++)
  894. {
  895. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  896. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  897. {
  898. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  899. [olditem setValue:@"true" forKey:@"dirty"];
  900. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  901. total_row_idx=i;
  902. }
  903. }
  904. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  905. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  906. if(total_row_idx>=0)
  907. {
  908. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  909. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  910. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  911. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  912. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  913. // CGSize tablecontent =self.editorTable.contentSize;
  914. // tablecontent.height=tablecontent.height+self.keyboard_h;
  915. // self.editorTable.contentSize=tablecontent;
  916. //
  917. //
  918. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  919. }
  920. // self.content_data = [editor_json mutableCopy];
  921. // self.content_data = [self translate_json:editor_json];
  922. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  923. // [self.editorTable reloadData];
  924. }
  925. //
  926. // [item_json setValue:@"true" forKey:@"dirty"];
  927. // [item_json setValue:textField.text forKey:@"value"];
  928. }
  929. -(float) getprice:(NSString*) name section :(long) index
  930. {
  931. NSMutableDictionary* section_json=nil;
  932. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  933. int count=0;
  934. count=[[section_json valueForKey:@"count"] intValue];
  935. for(int i=0;i<count;i++)
  936. {
  937. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  938. if([[olditem valueForKey:@"name"] isEqualToString:name])
  939. {
  940. return [[olditem valueForKey:@"value"] floatValue];
  941. }
  942. }
  943. return 0;
  944. }
  945. /*
  946. #pragma mark - Navigation
  947. // In a storyboard-based application, you will often want to do a little preparation before navigation
  948. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  949. // Get the new view controller using [segue destinationViewController].
  950. // Pass the selected object to the new view controller.
  951. }
  952. */
  953. #pragma mark - UIAlertViewDelegate
  954. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  955. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  956. {
  957. if(buttonIndex!=alertView.cancelButtonIndex && alertView.tag == SUBMIT_CONFIRM)
  958. {
  959. // add params check here.
  960. [self.lastedit endEditing:true];
  961. [self.lasttextview endEditing:true];
  962. // self.cancommit=true;
  963. // NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  964. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  965. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  966. // for(int i=0;i<section_count;i++)
  967. // {
  968. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  969. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  970. // for(int j=0;j<item_count;j++)
  971. // {
  972. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  973. // NSString* key = [itemjson valueForKey:@"name"];
  974. // if(key==nil || key.length==0)
  975. // continue;
  976. // if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  977. // {
  978. // NSString* single_select = [itemjson valueForKey:@"single_select"];
  979. // if([single_select isEqualToString:@"true"])
  980. // {
  981. // NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  982. // int count = [[cadejson valueForKey:@"count"] intValue];
  983. // bool setvalue = false;
  984. // for(int cc=0;cc<count;cc++)
  985. // {
  986. // NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  987. // if([[valjson valueForKey:@"check"]intValue]==1)
  988. // {
  989. // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  990. // setvalue=true;
  991. // break;
  992. // }
  993. // }
  994. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  995. // {
  996. // self.cancommit = false;
  997. // }
  998. // }
  999. // else
  1000. // {
  1001. // //not support multi select for now;
  1002. // }
  1003. // /*
  1004. // upparams setValue:itemjson forKey:<#(NSString *)#>
  1005. //
  1006. // */
  1007. // }else
  1008. // if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  1009. // {
  1010. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  1011. // self.cancommit = false;
  1012. // }
  1013. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  1014. // {
  1015. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  1016. // self.cancommit = false;
  1017. //
  1018. // NSString* valuestr = [itemjson valueForKey:@"value"];
  1019. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1020. // }
  1021. // else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  1022. // {
  1023. // NSString* valuestr = [itemjson valueForKey:@"value"];
  1024. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1025. //
  1026. // NSString* value = [itemjson valueForKey:@"value"];
  1027. // NSMutableDictionary* boolitem=nil;
  1028. // NSMutableDictionary* subjson=nil;
  1029. // if([value isEqualToString:@"true"])
  1030. // {
  1031. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  1032. //
  1033. // }
  1034. // else
  1035. // {
  1036. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  1037. //
  1038. // }
  1039. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  1040. // if( subjson!=nil /*&& !active*/)
  1041. // {
  1042. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  1043. // for(int l=0;l<sub_count;l++)
  1044. // {
  1045. // NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1046. //
  1047. //
  1048. //
  1049. //
  1050. // if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  1051. // [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  1052. // else
  1053. // {
  1054. // if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  1055. // self.cancommit = false;
  1056. // }
  1057. // }
  1058. //
  1059. //
  1060. //
  1061. // }
  1062. // }
  1063. // else
  1064. // {
  1065. // if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  1066. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  1067. // else
  1068. // {
  1069. // if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  1070. // self.cancommit = false;
  1071. // }
  1072. // }
  1073. // upparams= [self subitem_param:itemjson addto:upparams ];
  1074. // }
  1075. // }
  1076. // if(self.cancommit==false)
  1077. // {
  1078. // [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  1079. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1080. // //DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1081. // //[self.editorTable reloadData ];
  1082. // [self.editorTable reloadData];
  1083. // // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1084. // return;
  1085. // }
  1086. NSMutableDictionary* upparams = [self check_cancommit:true];
  1087. if(self.cancommit==false)
  1088. return;
  1089. if(upparams[@"shipping"]==nil)
  1090. goto commit_order;
  1091. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"])
  1092. {
  1093. upparams[@"shipping"] = nil;
  1094. goto commit_order;
  1095. }
  1096. else if([upparams[@"shipping"] doubleValue]==0)
  1097. {
  1098. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1099. //block代码块取代了delegate
  1100. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  1101. {
  1102. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1103. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1104. {
  1105. if(/*!self.have_tail*/ true)
  1106. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1107. [upparams setValue:@"false" forKey:@"isHold"];
  1108. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1109. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  1110. dispatch_async(dispatch_get_main_queue(), ^{
  1111. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1112. if([[editor_json valueForKey:@"result"] intValue]==2)
  1113. {
  1114. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1115. // debug aaa
  1116. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1117. NSString* company= appDelegate.customerInfo[@"customer_name"];
  1118. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1119. // appDelegate.customerInfo = customerInfo;
  1120. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1121. // appDelegate.order_code = nil;
  1122. [appDelegate closeOrder];
  1123. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1124. NSString* title=nil;
  1125. NSString* msg=nil;
  1126. if(appDelegate.offline_mode)
  1127. {
  1128. title=TITLE_OFFLINE_SUBMIT;
  1129. msg=MSG_OFFLINE_SUBMIT;
  1130. }
  1131. else
  1132. {
  1133. title=@"Submit successful.";
  1134. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  1135. }
  1136. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1137. [alert show];
  1138. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1139. NSString* email_content =[editor_json valueForKey:@"email_content"];
  1140. NSString* soid=[editor_json valueForKey:@"so#"];
  1141. // if(pdf_url.length>0)
  1142. // {
  1143. //
  1144. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1145. // //[self downloadpdf:pdf_url];
  1146. //
  1147. //
  1148. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1149. // {
  1150. // //bbb
  1151. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1152. // }
  1153. //
  1154. // [self prepareReturn:nil];
  1155. //
  1156. // [self.navigationController popViewControllerAnimated:true];
  1157. //
  1158. // [appDelegate printPdf:pdf_url];
  1159. //// if(self.printPdfCallback)
  1160. //// self.printPdfCallback(pdf_url);
  1161. // }
  1162. // else
  1163. {
  1164. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1165. {
  1166. //bbb
  1167. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1168. }
  1169. [self prepareReturn:nil];
  1170. [self.navigationController popViewControllerAnimated:true];
  1171. if(pdf_url.length>0)
  1172. {
  1173. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1174. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1175. // [appDelegate printPdf:pdf_url];
  1176. }
  1177. }
  1178. }
  1179. else
  1180. {
  1181. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1182. }
  1183. });
  1184. });
  1185. }
  1186. else
  1187. {
  1188. 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];
  1189. alert.tag = KEEP_TAIL;
  1190. self.upparams = upparams;
  1191. [alert show];
  1192. }
  1193. }
  1194. else
  1195. { //USER_ROLE_CUSTOMER
  1196. // if(self.have_tail)
  1197. // [upparams setValue:@"true" forKey:@"isHold"];
  1198. // else
  1199. // [upparams setValue:@"false" forKey:@"isHold"];
  1200. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1201. [upparams setValue:@"true" forKey:@"isHold"];
  1202. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1203. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  1204. dispatch_async(dispatch_get_main_queue(), ^{
  1205. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1206. if([[editor_json valueForKey:@"result"] intValue]==2)
  1207. {
  1208. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1209. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1210. // appDelegate.customerInfo = customerInfo;
  1211. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1212. // appDelegate.order_code = orderCode;
  1213. // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1214. [appDelegate closeOrder];
  1215. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1216. NSString* title=nil;
  1217. NSString* msg=nil;
  1218. if(appDelegate.offline_mode)
  1219. {
  1220. title=TITLE_OFFLINE_SUBMIT;
  1221. msg=MSG_OFFLINE_SUBMIT;
  1222. }
  1223. else
  1224. {
  1225. title=@"Submit successful.";
  1226. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  1227. }
  1228. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1229. [alert show];
  1230. // // self.labelContact.text=appDelegate.contact_name;
  1231. //
  1232. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1233. [self prepareReturn:nil];
  1234. [self.navigationController popViewControllerAnimated:true];
  1235. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1236. //
  1237. //
  1238. // ;
  1239. // }];
  1240. }
  1241. else
  1242. {
  1243. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1244. }
  1245. });
  1246. });
  1247. }
  1248. }];
  1249. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1250. //DebugLog(@"Cancel");
  1251. }];
  1252. [alertControl addAction:actionOne];
  1253. [alertControl addAction:alertthree];
  1254. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1255. [self presentViewController:alertControl animated:YES completion:nil];
  1256. }
  1257. else
  1258. {
  1259. commit_order:
  1260. {
  1261. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1262. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  1263. {
  1264. if(/*!self.have_tail*/ true)
  1265. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1266. [upparams setValue:@"false" forKey:@"isHold"];
  1267. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1268. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  1269. dispatch_async(dispatch_get_main_queue(), ^{
  1270. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1271. if([[editor_json valueForKey:@"result"] intValue]==2)
  1272. {
  1273. //debug bbb
  1274. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1275. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1276. NSString* company= appDelegate.customerInfo[@"customer_name"];
  1277. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  1278. // appDelegate.customerInfo = customerInfo;
  1279. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1280. // appDelegate.order_code = nil;
  1281. [appDelegate closeOrder];
  1282. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1283. NSString* title=nil;
  1284. NSString* msg=nil;
  1285. if(appDelegate.offline_mode)
  1286. {
  1287. title=TITLE_OFFLINE_SUBMIT;
  1288. msg=MSG_OFFLINE_SUBMIT;
  1289. }
  1290. else
  1291. {
  1292. title=@"Submit successful.";
  1293. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  1294. }
  1295. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1296. [alert show];
  1297. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  1298. NSString* email_content =[editor_json valueForKey:@"email_content"];
  1299. NSString* soid=[editor_json valueForKey:@"so#"];
  1300. // if(pdf_url.length>0)
  1301. // {
  1302. //
  1303. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1304. //// [self downloadpdf:pdf_url];
  1305. //
  1306. //
  1307. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1308. // {
  1309. // //bbb
  1310. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1311. // }
  1312. //
  1313. // [self prepareReturn:nil];
  1314. //
  1315. // [self.navigationController popViewControllerAnimated:true];
  1316. //
  1317. // [appDelegate printPdf:pdf_url];
  1318. //
  1319. //// if(self.printPdfCallback)
  1320. //// self.printPdfCallback(pdf_url);
  1321. // }
  1322. // else
  1323. {
  1324. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1325. {
  1326. //bbb
  1327. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1328. }
  1329. [self prepareReturn:nil];
  1330. [self.navigationController popViewControllerAnimated:true];
  1331. if(pdf_url.length>0)
  1332. {
  1333. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  1334. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  1335. }
  1336. }
  1337. // // self.labelContact.text=appDelegate.contact_name;
  1338. //
  1339. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1340. }
  1341. else
  1342. {
  1343. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1344. }
  1345. });
  1346. });
  1347. }
  1348. else
  1349. {
  1350. 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];
  1351. alert.tag = KEEP_TAIL;
  1352. self.upparams = upparams;
  1353. [alert show];
  1354. }
  1355. }
  1356. else
  1357. { //USER_ROLE_CUSTOMER
  1358. // if(self.have_tail)
  1359. // [upparams setValue:@"true" forKey:@"isHold"];
  1360. // else
  1361. // [upparams setValue:@"false" forKey:@"isHold"];
  1362. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1363. [upparams setValue:@"true" forKey:@"isHold"];
  1364. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1365. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  1366. dispatch_async(dispatch_get_main_queue(), ^{
  1367. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1368. if([[editor_json valueForKey:@"result"] intValue]==2)
  1369. {
  1370. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1371. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1372. // appDelegate.customerInfo = customerInfo;
  1373. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1374. // appDelegate.order_code = orderCode;
  1375. // appDelegate.order_status = [[editor_json valueForKey:@"orderStatus"] intValue];
  1376. [appDelegate closeOrder];
  1377. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1378. NSString* title=nil;
  1379. NSString* msg=nil;
  1380. if(appDelegate.offline_mode)
  1381. {
  1382. title=TITLE_OFFLINE_SUBMIT;
  1383. msg=MSG_OFFLINE_SUBMIT;
  1384. }
  1385. else
  1386. {
  1387. title=@"Submit successful.";
  1388. msg=[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]];
  1389. }
  1390. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1391. [alert show];
  1392. // // self.labelContact.text=appDelegate.contact_name;
  1393. //
  1394. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1395. [self prepareReturn:nil];
  1396. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1397. //
  1398. //
  1399. // ;
  1400. // }];
  1401. [self.navigationController popViewControllerAnimated:true];
  1402. }
  1403. else
  1404. {
  1405. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1406. }
  1407. });
  1408. });
  1409. }
  1410. }
  1411. }
  1412. }
  1413. // else if( alertView.tag == KEEP_TAIL)
  1414. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1415. // if(buttonIndex!=alertView.cancelButtonIndex)
  1416. // {//keep tail;
  1417. //
  1418. // [self.upparams setValue:@"true" forKey:@"isHold"];
  1419. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1420. //
  1421. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  1422. //
  1423. // dispatch_async(dispatch_get_main_queue(), ^{
  1424. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1425. //
  1426. //
  1427. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1428. // {
  1429. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1430. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1431. //
  1432. // [alert show];
  1433. //
  1434. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1435. // appDelegate.customerInfo = customerInfo;
  1436. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1437. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  1438. // appDelegate.order_code = orderCode;
  1439. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1440. // // // self.labelContact.text=appDelegate.contact_name;
  1441. // //
  1442. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1443. // [self prepareReturn:nil];
  1444. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  1445. ////
  1446. ////
  1447. //// ;
  1448. //// }];
  1449. // [self.navigationController popViewControllerAnimated:true];
  1450. //
  1451. // }
  1452. // else
  1453. // {
  1454. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1455. // }
  1456. //
  1457. //
  1458. //
  1459. //
  1460. // });
  1461. // });
  1462. // }
  1463. // else
  1464. // {// not keep tail;
  1465. // [self.upparams setValue:@"false" forKey:@"isHold"];
  1466. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1467. //
  1468. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  1469. //
  1470. // dispatch_async(dispatch_get_main_queue(), ^{
  1471. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1472. //
  1473. //
  1474. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1475. // {
  1476. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1477. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1478. //
  1479. // [alert show];
  1480. //
  1481. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1482. // // appDelegate.customerInfo = customerInfo;
  1483. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1484. // // appDelegate.order_code = nil;
  1485. // [appDelegate closeOrder];
  1486. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1487. // // // self.labelContact.text=appDelegate.contact_name;
  1488. // //
  1489. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1490. // [self prepareReturn:nil];
  1491. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  1492. ////
  1493. ////
  1494. //// ;
  1495. //// }];
  1496. // [self.navigationController popViewControllerAnimated:true];
  1497. //
  1498. // }
  1499. // else
  1500. // {
  1501. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1502. // }
  1503. //
  1504. //
  1505. //
  1506. //
  1507. // });
  1508. // });
  1509. // }
  1510. // }
  1511. else if(alertView.tag == CLOSE_ACTION)
  1512. {
  1513. if(buttonIndex==1)
  1514. {
  1515. [self.navigationController popViewControllerAnimated:true];
  1516. // back to cart;
  1517. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1518. // ;
  1519. // }];
  1520. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1521. // appDelegate.order_code = nil;
  1522. //
  1523. // }
  1524. }
  1525. if(buttonIndex==2)
  1526. {
  1527. [self.navigationController popViewControllerAnimated:true];
  1528. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1529. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1530. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1531. // back to cart;
  1532. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1533. // ;
  1534. // }];
  1535. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1536. // appDelegate.order_code = nil;
  1537. //
  1538. // }
  1539. }
  1540. else if(buttonIndex==3)
  1541. {
  1542. // close order;
  1543. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1544. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  1545. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1546. NSDictionary* order_json = [iSalesNetwork release_Order:appDelegate.order_code];
  1547. dispatch_async(dispatch_get_main_queue(), ^{
  1548. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1549. if([[order_json valueForKey:@"result"] intValue]==2)
  1550. {
  1551. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1552. // appDelegate.order_code = nil;
  1553. [appDelegate closeOrder];
  1554. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1555. [((MainViewController*)appDelegate.main_vc) switchToHome];
  1556. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1557. {
  1558. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1559. }
  1560. [self prepareReturn:nil];
  1561. [self.navigationController popViewControllerAnimated:true];
  1562. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1563. // ;
  1564. // }];
  1565. }
  1566. else
  1567. {
  1568. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  1569. }
  1570. });
  1571. });
  1572. //
  1573. // }
  1574. }
  1575. }
  1576. }
  1577. //
  1578. //
  1579. //-(void) downloadpdf:(NSString* )url
  1580. //{
  1581. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Printing..."];
  1582. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1583. //
  1584. //
  1585. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  1586. //
  1587. // //设置请求方式为get
  1588. //
  1589. // [request setHTTPMethod:@"GET"];
  1590. //
  1591. // //添加用户会话id
  1592. //
  1593. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  1594. //
  1595. // //连接发送请求
  1596. //
  1597. //
  1598. // NSHTTPURLResponse* urlResponse = nil;
  1599. //
  1600. // NSError *error = [[NSError alloc] init];
  1601. //
  1602. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  1603. //
  1604. // // self.filename = [urlResponse suggestedFilename];
  1605. //
  1606. //
  1607. // dispatch_async(dispatch_get_main_queue(), ^{
  1608. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1609. // // self.navigationItem.title = self.save_name;
  1610. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  1611. // // self.content=nil;
  1612. // if(content!=nil&&content.length>0)
  1613. // {
  1614. //
  1615. //
  1616. // [self startAirPrintWithData:content];
  1617. //
  1618. //
  1619. // }
  1620. // else
  1621. // {
  1622. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  1623. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  1624. // }
  1625. //
  1626. // ;
  1627. // // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  1628. // //
  1629. //
  1630. //
  1631. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  1632. //
  1633. //
  1634. //
  1635. //
  1636. // });
  1637. // });
  1638. //}
  1639. //
  1640. //- (void)startAirPrintWithData:(id )data
  1641. //{
  1642. //
  1643. //
  1644. //
  1645. //
  1646. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  1647. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  1648. // printInfo.outputType = UIPrintInfoOutputGeneral;
  1649. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  1650. // printInfo.jobName = @"CoolVisitAirPrint";
  1651. // airPrinterController.printInfo = printInfo;
  1652. // airPrinterController.printingItem = data;
  1653. // airPrinterController.delegate = self;
  1654. //
  1655. //
  1656. // airPrinterController.showsNumberOfCopies=true;
  1657. // airPrinterController.showsPageRange = true;
  1658. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  1659. //
  1660. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  1661. // if(completed && error)
  1662. // 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);
  1663. // };
  1664. //
  1665. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1666. //
  1667. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  1668. //
  1669. //
  1670. //
  1671. //
  1672. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  1673. // {
  1674. // if (available&& appDelegate.printerURL.length>0)
  1675. // {
  1676. //
  1677. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  1678. // DebugLog(@"AIRPRINTER AVAILABLE");
  1679. // }
  1680. // else
  1681. // {
  1682. //
  1683. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1684. // //
  1685. // //
  1686. // //
  1687. // // // [printPicker presentAnimated:YES completionHandler:
  1688. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  1689. // // {
  1690. // // if (userDidSelect)
  1691. // // {
  1692. // // NSString* sid= printerController.printInfo.printerID;
  1693. // // UIPrintPaper*paper= printerController.printPaper;
  1694. // //
  1695. // // }
  1696. // // }];
  1697. //
  1698. //
  1699. // DebugLog(@"AIRPRINTER NOT AVAILABLE");
  1700. //
  1701. //
  1702. //
  1703. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  1704. // {
  1705. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  1706. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  1707. //
  1708. //
  1709. //
  1710. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  1711. //
  1712. //
  1713. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1714. //
  1715. //
  1716. //
  1717. // // [printPicker presentAnimated:YES completionHandler:
  1718. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  1719. // {
  1720. // if (userDidSelect)
  1721. // {
  1722. // //User selected the item in the UIPrinterPickerController and got the printer details.
  1723. //
  1724. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  1725. //
  1726. // //Here you will get the printer and printer details.ie,
  1727. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  1728. //
  1729. //
  1730. //
  1731. //
  1732. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  1733. //
  1734. // [self startAirPrintWithData:data];
  1735. //
  1736. // }
  1737. // else
  1738. // {
  1739. //
  1740. //
  1741. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1742. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1743. // {
  1744. //
  1745. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1746. // }
  1747. // [self prepareReturn:nil];
  1748. //
  1749. // [self.navigationController popViewControllerAnimated:true];
  1750. // }
  1751. // }];
  1752. // }
  1753. // }
  1754. // }];
  1755. //
  1756. //
  1757. //
  1758. //}
  1759. //
  1760. //#pragma mark - UIPrintInteractionControllerDelegate
  1761. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  1762. //{
  1763. //
  1764. // ;
  1765. //
  1766. // // (int) width = 29700
  1767. // // Printing description of (*( (int *)0x7caa3a40)):
  1768. // // (int) height = 42000
  1769. // //设置纸张大小
  1770. //
  1771. //
  1772. // for(UIPrintPaper* paper in paperList)
  1773. // {
  1774. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  1775. // return paper;
  1776. //
  1777. // }
  1778. // CGSize paperSize = CGSizeMake(612, 792);
  1779. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  1780. // return p;
  1781. //}
  1782. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1783. //{
  1784. //
  1785. //}
  1786. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1787. //{
  1788. //
  1789. //}
  1790. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1791. //{
  1792. //
  1793. //}
  1794. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1795. //{
  1796. //
  1797. //}
  1798. //
  1799. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  1800. //{
  1801. //
  1802. //}
  1803. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  1804. //{
  1805. //
  1806. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1807. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1808. // {
  1809. //
  1810. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1811. // }
  1812. //
  1813. // [self prepareReturn:nil];
  1814. //
  1815. // [self.navigationController popViewControllerAnimated:true];
  1816. //}
  1817. - (NSString *)currentPriceTypeName {
  1818. NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  1819. NSString* pricename = nil;
  1820. switch (priceType) {
  1821. case 0:
  1822. pricename=[Singleton sharedInstance].deliveryString;
  1823. break;
  1824. case 1:
  1825. pricename=flat_price;
  1826. break;
  1827. case 2:
  1828. pricename=given_price;
  1829. break;
  1830. default:
  1831. break;
  1832. }
  1833. return pricename;
  1834. }
  1835. @end