OrderDetailViewController.m 63 KB

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