OrderDetailViewController.m 74 KB

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