OrderDetailViewController.m 76 KB

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