OrderDetailViewController.m 80 KB

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