CreateOrderViewController.m 126 KB

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