CreateOrderViewController.m 125 KB

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