OrderDetailViewController.m 63 KB

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