OrderDetailViewController.m 79 KB

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