OrderDetailViewController.m 63 KB

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