OrderDetailViewController.m 74 KB

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