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