OrderDetailViewController.m 62 KB

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