OrderDetailViewController.m 64 KB

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