OrderDetailViewController.m 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. //
  2. // OrderDetailViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/28/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OrderDetailViewController.h"
  9. #import "OrderDetailInfoCell.h"
  10. #import "OrderDetailHtmlCell.h"
  11. #import "OrderDetailModelCell.h"
  12. #import "OrderDetailPriceCell.h"
  13. #import "iSalesNetwork.h"
  14. #import "RTLabel.h"
  15. #import "DetailViewController.h"
  16. #import "PDFViewController.h"
  17. #import "MainViewController.h"
  18. #define DEF_CELL_HEIGHT 44
  19. #define DEF_TABLE_HEIGHT 44
  20. #define LINE_WIDTH 0
  21. #define CELL_MARGIN 0
  22. #define LABEL_MARGIN 15
  23. @interface OrderDetailViewController ()
  24. @end
  25. @implementation OrderDetailViewController
  26. - (void)onBackClick:(UIButton *)sender {
  27. [self.navigationController popViewControllerAnimated:FALSE];
  28. }
  29. -(void)manually_refresh
  30. {
  31. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  32. if(self.isrefreshing)
  33. {
  34. [reF endRefreshing];
  35. return;
  36. }
  37. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  38. if ([self respondsToSelector:@selector(reload_data)])
  39. [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
  40. // DebugLog(@"refresh!!!!!!!!");
  41. }
  42. -(void) reload_data
  43. {
  44. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  45. [reF endRefreshing];
  46. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  47. [self loaddata];
  48. }
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  52. self.label_net_err.layer.borderWidth = 2.0;
  53. self.label_net_err.layer.cornerRadius=15;
  54. self.label_net_err.layer.masksToBounds=true;
  55. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  56. // tap.minimumPressDuration = 0.8; //定义按的时间
  57. [self.label_net_err addGestureRecognizer:tap];
  58. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  59. ref.tag = 200 ;
  60. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  61. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  62. // ref.hidden = true;
  63. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  64. [self.detailTable addSubview:ref];
  65. NSMutableArray * items = [[NSMutableArray alloc]init];
  66. self.navigationItem.title=@"View Order Detail";
  67. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  68. style:UIBarButtonItemStylePlain
  69. target:self
  70. action:@selector( onBackClick:)];
  71. closeButton.tintColor = UIColorFromRGB(0x996633);
  72. self.navigationItem.leftBarButtonItem = closeButton;
  73. self.btnOpen = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  74. style:UIBarButtonItemStylePlain
  75. target:self
  76. action:@selector(onOpenOrderClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onOpenOrderClick:)];
  77. self.btnOpen.tintColor = UIColorFromRGB(0x996633);
  78. self.btnCommit =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  79. style:UIBarButtonItemStylePlain
  80. target:self
  81. action:@selector(onCommitOrderClick:)];// [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Commit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCommitOrderClick:)];
  82. self.btnCommit.tintColor = UIColorFromRGB(0x996633);
  83. // self.btnSend = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Email", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSendMailClick:)];
  84. self.btnRelease = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"unlock"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  85. style:UIBarButtonItemStylePlain
  86. target:self
  87. action:@selector(onReleaseOrderClick:)];
  88. self.btnRelease.tintColor = UIColorFromRGB(0x996633);
  89. self.btnPDF = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"sales_order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  90. style:UIBarButtonItemStylePlain
  91. target:self
  92. action:@selector(onDownloadOrderClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  93. self.btnPDF.tintColor = UIColorFromRGB(0x996633);
  94. // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
  95. // item1.title = @"item1";
  96. //// item1.image = [UIImage imageNamed:@"rect_setting"];
  97. // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
  98. //// item2.image = [UIImage imageNamed:@"rect_about"];
  99. // item2.title = @"item2";
  100. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  101. fixedItem.width = 0.0f;
  102. [items addObject:self.btnOpen];
  103. [items addObject:fixedItem];
  104. // [items addObject:self.btnCommit];
  105. // [items addObject:fixedItem];
  106. [items addObject:self.btnRelease];
  107. [items addObject:fixedItem];
  108. [items addObject:self.btnPDF];
  109. // [items addObject:item2];
  110. self.navigationItem.rightBarButtonItems=items;
  111. self.btnOpen.enabled =false;
  112. self.btnCommit.enabled =false;
  113. self.btnPDF.enabled =false;
  114. self.btnRelease.enabled =false;
  115. // if(self.isTempOrder)
  116. // {
  117. //
  118. //
  119. // self.btnOpen.enabled =true;
  120. //
  121. //
  122. // self.btnCommit.enabled =true;
  123. // }
  124. // else
  125. // {
  126. //
  127. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  128. //
  129. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  130. // self.btnOpen.enabled =false;
  131. // self.btnCommit.enabled =false;
  132. // }
  133. // Do any additional setup after loading the view.
  134. }
  135. - (IBAction)onReleaseOrderClick:(id)sender {
  136. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  137. //block代码块取代了delegate
  138. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  139. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  140. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  141. NSDictionary* order_json = [iSalesNetwork release_Order:self.order_code];
  142. dispatch_async(dispatch_get_main_queue(), ^{
  143. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  144. if([[order_json valueForKey:@"result"] intValue]==2)
  145. {
  146. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  147. // appDelegate.order_code = nil;
  148. [appDelegate closeOrder];
  149. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  150. //
  151. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  152. // if(self.selectOrder)
  153. // self.selectOrder();
  154. [self.navigationController popToRootViewControllerAnimated:false];
  155. }
  156. else
  157. {
  158. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  159. }
  160. });
  161. });
  162. }];
  163. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  164. NSLog(@"Cancel");
  165. }];
  166. [alertControl addAction:actionOne];
  167. [alertControl addAction:alertthree];
  168. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  169. [self presentViewController:alertControl animated:YES completion:nil];
  170. // get customer info
  171. }
  172. - (void)onDownloadOrderClick:(id)sender {
  173. // get customer info
  174. NSString* url=[self.content_data valueForKey:@"pdfUrl"];
  175. NSLog(@"pdf url:%@",url);
  176. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  177. ViewController.url = url;
  178. ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
  179. NSString* so = [self.content_data valueForKey:@"so#"];
  180. if(so==nil)
  181. so =@"";
  182. NSString* company = [self.content_data[@"customerInfo"] valueForKey:@"customer_name"];
  183. if(company==nil)
  184. company =@"";
  185. ViewController.save_name =so;
  186. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  187. // NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  188. // NSString* cid= [appDelegate.customerInfo valueForKey:@"customer_cid"];
  189. // if(cid==nil)
  190. // cid=@"";
  191. if(company==nil)
  192. company=@"";
  193. NSString* customer_email= [self.content_data[@"customerInfo"] valueForKey:@"customer_email"];
  194. NSMutableArray* arr_subject = [[NSMutableArray alloc]init];
  195. if(company.length>0)
  196. [arr_subject addObject:company];
  197. if(so.length>0)
  198. [arr_subject addObject:so];
  199. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  200. if(customer_email.length>0)
  201. {
  202. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  203. // customer_email compo
  204. // [send_to addObject:customer_email];
  205. }
  206. ViewController.mail_to = send_to;
  207. NSString* subject=[arr_subject componentsJoinedByString:@" : "];
  208. // NSString* str_sendto=[send_to componentsJoinedByString:@";"];
  209. // if (company.length==0) {
  210. // subject = @"Tear sheet";
  211. //
  212. // }
  213. // else
  214. // {
  215. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  216. // }
  217. ViewController.mail_subject = subject;
  218. // ViewController.onSavePDF=^(NSString* name,NSString* file)
  219. // {
  220. //
  221. // NSString *path = NSTemporaryDirectory();
  222. // NSString *temp_path = [path stringByAppendingPathComponent:file];
  223. //
  224. // [iSalesDB save_pdf:temp_path filename:file];
  225. //
  226. // NSString *sql = [NSString stringWithFormat:
  227. // @"INSERT INTO pdf_cache (name,file_name,c_id,c_name,o_id,pdf_type,send_to) VALUES ('%@', '%@', '%@', '%@', '%@', '%@', '%@')",
  228. // name, file,cid, company, so, @"Sales Order",str_sendto];
  229. //
  230. // [iSalesDB execSql:sql];
  231. //
  232. // };
  233. // ViewController. = self.function_name;
  234. // ViewController.behavior =BEHAVIOR_SEARCH;
  235. [self.navigationController pushViewController:ViewController animated:YES];
  236. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Commit confirm", nil) message:NSLocalizedString(@"Are you sure to commit order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  237. // [alert show];
  238. }
  239. - (void)onCommitOrderClick:(id)sender {
  240. // get customer info
  241. int model_count = [[self.content_data valueForKey:@"model_count"] intValue];
  242. if(model_count==0)
  243. {
  244. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error." message:@"Can not submit an order without models." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  245. //
  246. // [alert show];
  247. [RAUtils alert_view:@"Cannot submit an order without models" title:@""];
  248. }
  249. else
  250. {
  251. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit confirm", nil) message:NSLocalizedString(@"Are you sure to submit order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  252. [alert show];
  253. }
  254. }
  255. - (IBAction)onOpenOrderClick:(id)sender {
  256. // get customer info
  257. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to open order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  258. //block代码块取代了delegate
  259. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  260. // int count =[[self.content_data valueForKey:@"model_count"] intValue];
  261. // if(count>0)
  262. // {
  263. // /*
  264. //
  265. // //检查赠品符合条件
  266. // NSDictionary * freejson = [self.content_data objectForKey:@"freeGiveaway"];
  267. //
  268. // int free_count = [[freejson valueForKey:@"count"]intValue];
  269. // for(int ic=free_count-1;ic>=0;ic--)
  270. // {
  271. // float compare_price = [[freejson valueForKey:[NSString stringWithFormat:@"item_%d",ic]] floatValue];
  272. // if(self.total>=compare_price && !have_free)
  273. // {
  274. //
  275. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away available.", nil) message:[NSString stringWithFormat:@"Order total price more than %.2f, do you want to add free give away item before place order?", compare_price] delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  276. // alert.tag = ALERT_FREE;
  277. // [alert show];
  278. // return;
  279. //
  280. // }
  281. // }
  282. //
  283. //
  284. // */
  285. //
  286. //
  287. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  288. // // NSString * string = [checked componentsJoinedByString:@","];
  289. // // [params setValue:string forKey:@"cart2Checkbox"];
  290. //
  291. //
  292. //
  293. // CreateOrderViewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreateOrderViewController"];
  294. //
  295. //
  296. // orderinfoVC.url_type = URL_REMOTE;
  297. // orderinfoVC.request_url=URL_CARTDELIVERY;
  298. //
  299. // orderinfoVC.params = params;
  300. //
  301. // orderinfoVC.delegate=self;
  302. // //
  303. // // if(checked.count==count)
  304. // // {
  305. // // orderinfoVC.have_tail = true
  306. // // }
  307. //
  308. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:orderinfoVC] ;
  309. //
  310. //
  311. //
  312. //
  313. //
  314. // navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  315. // [self presentViewController:navi animated:YES completion:^{
  316. //
  317. // NSLog(@"CreateOrderViewController present.........");
  318. //
  319. // // self.btop = false;
  320. // // <#code#>
  321. // }];
  322. //
  323. // }
  324. //
  325. // else
  326. {
  327. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Open Order"];
  328. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  329. NSDictionary* order_json = [iSalesNetwork open_Order:self.order_code];
  330. dispatch_async(dispatch_get_main_queue(), ^{
  331. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  332. if([[order_json valueForKey:@"result"] intValue]==2)
  333. {
  334. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  335. appDelegate.order_code = self.order_code;
  336. [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  337. appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  338. appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  339. [self.navigationController popViewControllerAnimated:false];
  340. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  341. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  342. if(self.selectOrder)
  343. self.selectOrder(self.content_data);
  344. }
  345. else
  346. {
  347. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  348. }
  349. });
  350. });
  351. }
  352. }];
  353. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  354. NSLog(@"Cancel");
  355. }];
  356. [alertControl addAction:actionOne];
  357. [alertControl addAction:alertthree];
  358. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  359. [self presentViewController:alertControl animated:YES completion:nil];
  360. }
  361. - (void)didReceiveMemoryWarning {
  362. [super didReceiveMemoryWarning];
  363. // Dispose of any resources that can be recreated.
  364. }
  365. -(void) loaddata
  366. {
  367. dispatch_async(dispatch_get_main_queue(), ^{
  368. if(self.isrefreshing)
  369. return;
  370. self.detailTable.hidden = true;
  371. self.label_net_err.hidden=true;
  372. self.isrefreshing=true;
  373. self.mum.center = self.view.center;
  374. self.mum.hidden = false;
  375. [self.mum startAnimating];
  376. NSLog(@"reloading...");
  377. self.web_info_height=0;
  378. self.web_moreinfo_height=0;
  379. self.content_data = nil;
  380. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  381. NSDictionary* order_json = [iSalesNetwork request_OrderDetail:self.orderid];
  382. dispatch_async(dispatch_get_main_queue(), ^{
  383. [self.mum stopAnimating];
  384. if([[order_json valueForKey:@"result"] intValue]==2)
  385. {
  386. self.detailTable.hidden = false;
  387. self.content_data = [order_json mutableCopy];
  388. }
  389. else
  390. if([[order_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  391. {
  392. self.label_net_err.hidden=false;
  393. self.detailTable.hidden=true;
  394. }
  395. else
  396. {
  397. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Loading Order Detail" controller:self] ;
  398. }
  399. int model_count =[[self.content_data valueForKey:@"model_count"] intValue];
  400. if(model_count>0)
  401. self.btnPDF.enabled =true;
  402. // [self.btnPDF setImage:[[UIImage imageNamed:@"download"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  403. NSString* status = [self.content_data valueForKey:@"order_status"];
  404. NSString* lock_user = [self.content_data valueForKey:@"opened_customer"];
  405. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  406. if([status isEqualToString:@"SO Saved"])
  407. {
  408. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  409. //
  410. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  411. self.btnOpen.enabled =true;
  412. if([lock_user isEqualToString:appDelegate.user])
  413. {
  414. self.btnCommit.enabled =true;
  415. }
  416. else
  417. self.btnCommit.enabled =false;
  418. }
  419. else
  420. if([status isEqualToString:@"Quote Saved"])
  421. {
  422. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  423. //
  424. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  425. self.btnOpen.enabled =true;
  426. self.btnCommit.enabled =false;
  427. }
  428. if([lock_user isEqualToString:appDelegate.user])
  429. {
  430. // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  431. self.btnRelease.enabled =true;
  432. }
  433. else
  434. {
  435. // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  436. self.btnRelease.enabled =false;
  437. }
  438. [self.detailTable reloadData];
  439. self.isrefreshing=false;
  440. });
  441. });
  442. });
  443. }
  444. - (void)viewWillAppear:(BOOL)animated
  445. {
  446. [self loaddata];
  447. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  448. if(appDelegate.can_submit_order)
  449. {
  450. [self.btnCommit setImage:[UIImage imageNamed:@"commit"]];
  451. self.btnCommit.enabled = true;
  452. }
  453. else
  454. {
  455. [self.btnCommit setImage:nil];
  456. self.btnCommit.enabled = false;
  457. }
  458. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  459. }
  460. - (IBAction)imgbtnClicked:(UIButton*)sender {
  461. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  462. NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  463. if(indexPath.section!=1)
  464. return ;
  465. // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  466. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  467. NSString* product_id = [item_json valueForKey:@"product_id"];
  468. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  469. // dvc
  470. dvc.product_id=product_id;
  471. dvc.category_id=nil;
  472. dvc.ispush=true;
  473. [dvc reload];
  474. [self.navigationController pushViewController:dvc animated:true];
  475. }
  476. /*
  477. #pragma mark - Navigation
  478. // In a storyboard-based application, you will often want to do a little preparation before navigation
  479. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  480. // Get the new view controller using [segue destinationViewController].
  481. // Pass the selected object to the new view controller.
  482. }
  483. */
  484. #pragma mark - Table view data source
  485. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  486. {
  487. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  488. // if([item_json objectForKey:@"combine"] == nil)
  489. // {
  490. // return 120;
  491. // }
  492. // else
  493. // return 150;
  494. switch (indexPath.section) {
  495. case 0:
  496. {
  497. float height= self.web_info_height;
  498. if(height==0)
  499. height=DEF_TABLE_HEIGHT;
  500. // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
  501. //wait(1000);
  502. return height;
  503. // float width = tableView.frame.size.width;
  504. // width-=CELL_MARGIN*2;
  505. // CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  506. //// CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  507. //
  508. //
  509. //
  510. // // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  511. // NSString* key =[self.content_data valueForKey:@"order_info"];
  512. //
  513. // // [cell.keyLabel sizeToFit];
  514. //// NSString* val=[item_json valueForKey:@"val"] ;
  515. //
  516. //// if([val isEqual:[NSNull null]])
  517. //// val=@"";
  518. //// if(val==nil)
  519. //// val=@"";
  520. //// if([val isEqualToString:@"null"])
  521. //// val=@"";
  522. //
  523. //
  524. //
  525. // CGRect frame;
  526. // frame.size = constraintkey;
  527. // frame.origin.x=0;
  528. // frame.origin.y=0;
  529. //
  530. // RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  531. //// [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  532. // // rtlabel.lineSpacing = 20.0;
  533. // [rtlabel setText: key];
  534. // CGSize optimumSize = [rtlabel optimumSize];
  535. //// NSLog(@"%@",key);
  536. //
  537. //// [rtlabel sizeThatFits:constraintkey];
  538. //
  539. //// rtlabel frameHeight:<#(CTFrameRef)#>
  540. //// rtlabel
  541. //// [rtlabel sizeToFit];
  542. ////CGSize newsize= rtlabel.frame.size;
  543. //// CGSize sizeval=rtlabel.optimumSize;
  544. //
  545. //
  546. //// CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  547. // // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  548. // float height = optimumSize.height;
  549. // height = MAX(height+LINE_WIDTH+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  550. //
  551. //
  552. // return height;
  553. }
  554. break;
  555. case 1:
  556. {
  557. float height= self.web_moreinfo_height;
  558. if(height==0)
  559. height=DEF_TABLE_HEIGHT;
  560. // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
  561. //wait(1000);
  562. return height;
  563. }
  564. break;
  565. case 2:
  566. return 162;
  567. case 3:
  568. return 44;
  569. default:
  570. break;
  571. }
  572. return 44;
  573. }
  574. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  575. //{
  576. // return 0;
  577. //}
  578. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  579. //{
  580. // return 0;
  581. //}
  582. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  583. //{
  584. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  585. // return myView;
  586. //
  587. //}
  588. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  589. //{
  590. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  591. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  592. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  593. //// titleLabel.textColor=[UIColor whiteColor];
  594. //// titleLabel.backgroundColor = [UIColor clearColor];
  595. //// if(section==0)
  596. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  597. //// else
  598. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  599. //// [titleLabel sizeToFit];
  600. //// [myView addSubview:titleLabel];
  601. ////
  602. // return myView;
  603. //}
  604. //
  605. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  606. {
  607. UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  608. myView.backgroundColor = UIColorFromRGB(0x996633);;
  609. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  610. // myView.layer.masksToBounds = false;
  611. //添加四个边阴影
  612. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  613. myView.layer.shadowOffset = CGSizeMake(0, 0);
  614. myView.layer.shadowOpacity = 0.5;
  615. myView.layer.shadowRadius = 2.0;
  616. NSString*labeltitle = nil;
  617. switch (section) {
  618. case 0:
  619. labeltitle= @"Order Info";
  620. break;
  621. case 1:
  622. {
  623. labeltitle= @"More Info";
  624. NSString* btntitle=nil ;
  625. if(self.showMore)
  626. {
  627. btntitle=@"Hide";
  628. // [section setValue:@"false" forKey:@"hide"];
  629. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  630. }
  631. else{
  632. btntitle=@"Show";
  633. }
  634. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  635. btn.tag=section;
  636. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  637. [btn setTitle:btntitle forState:UIControlStateNormal];
  638. [myView addSubview:btn];
  639. }
  640. break;
  641. case 2:
  642. labeltitle= @"Models";
  643. break;
  644. case 3:
  645. labeltitle= @"Price Info";
  646. default:
  647. break;
  648. }
  649. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
  650. titlelabel.textColor=[UIColor whiteColor];
  651. titlelabel.backgroundColor = [UIColor clearColor];
  652. titlelabel.text=NSLocalizedString(labeltitle, nil);
  653. [titlelabel sizeToFit];
  654. [myView addSubview:titlelabel];
  655. //
  656. return myView;
  657. }
  658. #pragma mark - hide section button clicked
  659. - (void)HideSction:(UIButton *)sender {
  660. /*
  661. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",sender.tag]] mutableCopy];
  662. bool hide = [[section valueForKey:@"hide"]boolValue];
  663. if(hide)
  664. {
  665. [section setValue:@"false" forKey:@"hide"];
  666. [sender setTitle:@"Show" forState:UIControlStateNormal];
  667. }
  668. else{
  669. [section setValue:@"true" forKey:@"hide"];
  670. [sender setTitle:@"Hide" forState:UIControlStateNormal];
  671. }
  672. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",sender.tag]];
  673. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  674. */
  675. self.showMore=!self.showMore;
  676. NSRange range = NSMakeRange(1, 1);
  677. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  678. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  679. }
  680. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  681. switch (section) {
  682. case 0:
  683. return @"Order Info";
  684. break;
  685. case 1:
  686. return @"More Info";
  687. break;
  688. case 2:
  689. return @"Models";
  690. case 3:
  691. return @"Price Info";
  692. default:
  693. break;
  694. }
  695. return nil;
  696. }
  697. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  698. {
  699. if(self.content_data==nil)
  700. return 0;
  701. return 4;
  702. }
  703. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  704. {
  705. return 33;
  706. }
  707. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  708. {
  709. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  710. if(section==0)
  711. return 1;
  712. if(section==1)
  713. {
  714. if(self.showMore)
  715. return 1;
  716. else
  717. return 0;
  718. }
  719. if(section==2)
  720. {
  721. int count =[[self.content_data valueForKey:@"model_count"] intValue];
  722. return count;
  723. }
  724. if(section==3)
  725. return 5;
  726. return 0;
  727. }
  728. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  729. {
  730. UIApplication * app = [UIApplication sharedApplication];
  731. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  732. switch(indexPath.section)
  733. {
  734. case 0:
  735. {
  736. // NSString *CellIdentifier = @"OrderDetailInfoCell";
  737. // OrderDetailInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  738. //
  739. //
  740. //
  741. // NSString* emailcontent=[self.content_data valueForKey:@"email_content"];
  742. // emailcontent=[emailcontent stringByReplacingOccurrencesOfString:@"\t" withString:@""];
  743. // cell.infoLabel.text =emailcontent;//[self.content_data valueForKey:@"order_info"];
  744. //
  745. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  746. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  747. // NSString* emailcontent=[self.content_data valueForKey:@"email_content"];
  748. // emailcontent=[emailcontent stringByReplacingOccurrencesOfString:@"\t" withString:@""];
  749. // cell.infoLabel.text =emailcontent;//[self.content_data valueForKey:@"order_info"];
  750. //
  751. // NSString* tablecontent = [item valueForKey:@"content"];
  752. cell.webview.tag = indexPath.section;
  753. // cell.webview.scrollView.contentInset = UIEdgeInsetsZero;
  754. // self.automaticallyAdjustsScrollViewInsets=no;
  755. cell.webview.delegate = self;
  756. // cell.webView.scrollView.contentSize.height = 0;
  757. cell.webview.scrollView.bounces=NO;
  758. cell.webview.scrollView.directionalLockEnabled = true;
  759. CGSize size= cell.webview.scrollView.contentSize;
  760. size.height=10;
  761. cell.webview.scrollView.contentSize=size;
  762. // nsstring* c = [NSString stringwith]
  763. // NSString *filePath = [[NSBundle mainBundle]pathForResource:@"about" ofType:@"htm"];
  764. // NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
  765. // NSString* aaa= @"<html><body bgcolor='#cccccc'></body></html>";
  766. [cell.webview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
  767. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  768. return cell;
  769. }
  770. break;
  771. case 1:
  772. {
  773. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  774. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  775. cell.webview.tag = indexPath.section;
  776. cell.webview.delegate = self;
  777. // cell.webView.scrollView.contentSize.height = 0;
  778. cell.webview.scrollView.bounces=NO;
  779. cell.webview.scrollView.directionalLockEnabled = true;
  780. CGSize size= cell.webview.scrollView.contentSize;
  781. size.height=10;
  782. cell.webview.scrollView.contentSize=size;
  783. [cell.webview loadHTMLString:[self.content_data valueForKey:@"more_order_info"] baseURL:nil];
  784. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  785. return cell;
  786. // NSString *CellIdentifier = @"OrderDetailInfoCell";
  787. // OrderDetailInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  788. //
  789. // cell.infoLabel.text =[self.content_data valueForKey:@"more_order_info"];
  790. //
  791. //
  792. //
  793. //// float width = tableView.frame.size.width;
  794. //// width-=CELL_MARGIN*2;
  795. //// CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  796. ////
  797. //// NSString* key =[self.content_data valueForKey:@"order_info"];
  798. ////
  799. ////
  800. ////
  801. //// CGRect frame;
  802. //// frame.size = constraintkey;
  803. //// frame.origin.x=0;
  804. //// frame.origin.y=0;
  805. ////
  806. //// RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  807. ////
  808. //// [rtlabel setText: key];
  809. //// CGSize optimumSize = [rtlabel optimumSize];
  810. ////
  811. //// float height = optimumSize.height;
  812. //// height = MAX(height+LINE_WIDTH+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  813. ////
  814. ////
  815. //// frame.origin.x=LABEL_MARGIN;
  816. //// frame.size=CGSizeMake(width, height);
  817. ////
  818. //// cell.infoLabel.frame = frame;
  819. //
  820. //
  821. //
  822. //
  823. // cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  824. // return cell;
  825. }
  826. break;
  827. case 2:
  828. {
  829. NSString *CellIdentifier = @"OrderDetailModelCell";
  830. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  831. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  832. int count = [[item_json valueForKey:@"count"] intValue];
  833. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  834. cell.bundle_item=combine_json;
  835. double dprice=0.0;
  836. if(cell.bundle_item!=nil)
  837. {
  838. int citem=0;
  839. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  840. for(int bc=0;bc<bcount;bc++)
  841. {
  842. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  843. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  844. citem+= modulus;
  845. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  846. dprice+= uprice*modulus*count;
  847. }
  848. if(citem==1)
  849. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  850. else
  851. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  852. cell.buttonBundle.hidden = NO;
  853. }
  854. else
  855. {
  856. cell.buttonBundle.hidden = YES;
  857. }
  858. NSString* img_url = [item_json valueForKey:@"img"];
  859. NSString* description = [item_json valueForKey:@"Item Number"];
  860. // NSString* description = [item_json valueForKey:@"Item Number"];
  861. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  862. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  863. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  864. NSString* qty = [item_json valueForKey:@"QTY"];
  865. NSString* status = [item_json valueForKey:@"order_item_status"];
  866. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  867. {
  868. }
  869. else
  870. {
  871. unitprice=nil;
  872. origin_price=nil;
  873. subtotal=nil;
  874. }
  875. cell.descriptionLabel.text=description;
  876. cell.unitpriceLabel.text = unitprice;
  877. cell.subtotalLabel.text = subtotal;
  878. cell.qtyLabel.text = qty;
  879. cell.statusLabel.text = status;
  880. cell.labelOldPrice.text = origin_price;
  881. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  882. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  883. cell.labelDiscount.text = discountstr;
  884. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  885. if(isfree)
  886. {
  887. cell.labelOldPrice.hidden = false;
  888. cell.labelOldPrice.textColor = [UIColor redColor];
  889. cell.labelOldPrice.text=@"Free";
  890. cell.labelOldPrice.hideline = true;
  891. cell.labelDiscount.hidden = true;
  892. }
  893. else
  894. {
  895. cell.labelOldPrice.textColor = [UIColor blackColor];
  896. cell.labelOldPrice.hideline = false;
  897. if(discount==0)
  898. {
  899. cell.labelOldPrice.hidden = true;
  900. cell.labelDiscount.hidden = true;
  901. }
  902. else
  903. {
  904. cell.labelOldPrice.hidden = false;
  905. cell.labelDiscount.hidden = false;
  906. }
  907. }
  908. [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  909. NSString* file_name=[img_url lastPathComponent];
  910. NSData* img_data=[iSalesDB load_cached_img:file_name];
  911. if(img_data!=nil)
  912. {
  913. UIImage * img =[UIImage imageWithData:img_data];
  914. [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  915. }
  916. else
  917. {
  918. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  919. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  920. dispatch_async(dispatch_get_main_queue(), ^{
  921. if(downloadimg_data!=nil)
  922. {
  923. [iSalesDB cache_img:downloadimg_data :file_name ];
  924. UIImage * img =[UIImage imageWithData:downloadimg_data];
  925. [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  926. }
  927. else
  928. [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  929. });
  930. });
  931. }
  932. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  933. return cell;
  934. }
  935. break;
  936. case 3:
  937. {
  938. NSString *CellIdentifier = @"OrderDetailPriceCell";
  939. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  940. switch (indexPath.row) {
  941. case 0:
  942. {
  943. cell.chargeLabel.text =@"Payments/Credits:";
  944. NSString* price=[self.content_data valueForKey:@"Payments/Credits"];
  945. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  946. {
  947. }
  948. else
  949. {
  950. price=nil;
  951. }
  952. cell.priceLabel.text =price;
  953. break;
  954. }
  955. case 1:
  956. cell.chargeLabel.text = @"Shipping:";
  957. cell.priceLabel.text =[self.content_data valueForKey:@"Shipping"];
  958. break;
  959. case 2:
  960. cell.chargeLabel.text = @"Lift Gate Fee:";
  961. cell.priceLabel.text =[self.content_data valueForKey:@"Lift Gate Fee"];
  962. break;
  963. case 3:
  964. cell.chargeLabel.text = @"Handling Fee:";
  965. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  966. break;
  967. case 4:
  968. {
  969. NSString* price=[self.content_data valueForKey:@"Total"];
  970. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  971. {
  972. }
  973. else
  974. {
  975. price=nil;
  976. }
  977. cell.chargeLabel.text = @"Total:";
  978. cell.priceLabel.text =price;
  979. break;
  980. }
  981. default:
  982. break;
  983. }
  984. cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
  985. return cell;
  986. }
  987. }
  988. return nil;
  989. // if(tableView==self.itemListTable)
  990. // {
  991. // NSString *CellIdentifier = @"CartItemCell";
  992. // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  993. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  994. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  995. //
  996. // cell.bundle_item=combine_json;
  997. // NSString* img_url = [item_json valueForKey:@"img_url"];
  998. // NSString* description = [item_json valueForKey:@"description"];
  999. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  1000. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  1001. // NSString* currency = [item_json valueForKey:@"currency"];
  1002. // int count =[[item_json valueForKey:@"count"] intValue];
  1003. //
  1004. // int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  1005. //
  1006. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  1007. //
  1008. // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  1009. // cell.unit_price = unitprice;
  1010. // // cell.labelAttribute.text = attribute;
  1011. // // cell.labelCurrency.text = currency;
  1012. // cell.labelDescription.text = description;
  1013. // // cell.labelIdentifier.text = identifier;
  1014. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
  1015. //
  1016. // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
  1017. //
  1018. //
  1019. //
  1020. // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  1021. // cell.cart_id = cart_item_id;
  1022. // [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  1023. //
  1024. //
  1025. //
  1026. // [cell set_Count:count];
  1027. //
  1028. // NSString* file_name=[img_url lastPathComponent];
  1029. // NSData* img_data=[iSalesDB load_cached_img:file_name];
  1030. // if(img_data!=nil)
  1031. // {
  1032. //
  1033. // UIImage * img =[UIImage imageWithData:img_data];
  1034. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  1035. // }
  1036. // else
  1037. // {
  1038. //
  1039. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1040. //
  1041. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1042. //
  1043. // dispatch_async(dispatch_get_main_queue(), ^{
  1044. //
  1045. //
  1046. //
  1047. // if(downloadimg_data!=nil)
  1048. // {
  1049. // [iSalesDB cache_img:downloadimg_data :file_name ];
  1050. //
  1051. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  1052. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  1053. // }
  1054. //
  1055. // });
  1056. // });
  1057. //
  1058. //
  1059. // }
  1060. // return cell;
  1061. // }
  1062. // else
  1063. // {
  1064. // NSString *CellIdentifier = @"OrderInfoListItem";
  1065. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1066. // return cell;
  1067. // }
  1068. }
  1069. #pragma mark - UIAlertViewDelegate
  1070. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1071. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1072. {
  1073. if(buttonIndex!=alertView.cancelButtonIndex)
  1074. {
  1075. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  1076. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1077. NSDictionary* order_json = [iSalesNetwork commit_Order:self.order_code];
  1078. dispatch_async(dispatch_get_main_queue(), ^{
  1079. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1080. if([[order_json valueForKey:@"result"] intValue]==2)
  1081. {
  1082. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1083. if([appDelegate.order_code isEqualToString: self.order_code])
  1084. {
  1085. [appDelegate closeOrder];
  1086. // appDelegate.order_code= nil;
  1087. [appDelegate SetSo:nil];
  1088. }
  1089. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[order_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1090. [alert show];
  1091. [self.navigationController popViewControllerAnimated:false];
  1092. }
  1093. else
  1094. {
  1095. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  1096. }
  1097. });
  1098. });
  1099. }
  1100. }
  1101. #pragma mark - web view delegate
  1102. //- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  1103. //{
  1104. // if(navigationType != UIWebViewNavigationTypeLinkClicked)
  1105. // return true;
  1106. // // NSString *currentURL =[webView.request.URL lastPathComponent];// [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
  1107. //
  1108. // NSString* str = request.URL.absoluteString;
  1109. // if([str isEqualToString:@"about:blank"])
  1110. // return true;
  1111. // WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  1112. // ViewController.url = str;
  1113. // // ViewController. = self.function_name;
  1114. // // ViewController.behavior =BEHAVIOR_SEARCH;
  1115. //
  1116. // [self.navigationController pushViewController:ViewController animated:YES];
  1117. // DebugLog(@"shouldStartLoadWithRequest");
  1118. // return false;
  1119. //}
  1120. - (void)webViewDidFinishLoad:(UIWebView *)webView
  1121. {
  1122. DebugLog(@"webViewDidFinishLoad @@@@@@@@@@@@@@@@@ entry");
  1123. UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
  1124. NSIndexPath *indexPath = [self.detailTable indexPathForCell:cell];
  1125. if(indexPath==nil)
  1126. {//for ios7
  1127. cell = (UITableViewCell *) webView.superview.superview.superview;
  1128. indexPath = [self.detailTable indexPathForCell:cell];
  1129. }
  1130. float height= 0;
  1131. if(indexPath.section==0)
  1132. height=self.web_info_height;
  1133. else
  1134. height = self.web_moreinfo_height;
  1135. if(height>0)
  1136. return;
  1137. // UIScrollView *scrollerView = [webView.subviews objectAtIndex:0];
  1138. // CGSize size= webView.scrollView.contentSize;
  1139. // CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
  1140. CGRect frame = webView.frame;
  1141. NSString *fitHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
  1142. frame.size.height = [fitHeight floatValue];
  1143. //webView.frame = frame;
  1144. // DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^Saveheight height=%f section=%ld",webView.scrollView.contentSize.height,indexPath.section);
  1145. if(indexPath.section==0)
  1146. self.web_info_height=frame.size.height;
  1147. else
  1148. self.web_moreinfo_height = frame.size.height;
  1149. // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
  1150. DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^reloadRowsAtIndexPaths");
  1151. // [self.table beginUpdates];
  1152. [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  1153. // [self.table endUpdates];
  1154. // [self.webviewoprationQueue addOperationWithBlock:^{
  1155. // }];
  1156. // [self.table endUpdates];
  1157. // }
  1158. }
  1159. @end