OrderDetailViewController.m 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232
  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. #import "OrderDetailPickInfoCell.h"
  25. #define DEF_CELL_HEIGHT 44
  26. #define DEF_TABLE_HEIGHT 44
  27. #define LINE_WIDTH 0
  28. #define CELL_MARGIN 0
  29. #define LABEL_MARGIN 15
  30. @interface OrderDetailViewController ()
  31. @property (nonatomic,assign) BOOL showModels;
  32. @end
  33. @implementation OrderDetailViewController
  34. - (void)saleOrderWithPath:(NSString *)path {
  35. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  36. ViewController.url = path;
  37. ViewController.canSave = false;
  38. ViewController.isLocalfile=YES;
  39. NSString* subject;
  40. subject =[NSString stringWithFormat:@"Sales Order %@",self.order_code];
  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.filename = [NSString stringWithFormat:@"%@.pdf",self.order_code];
  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 withScreen:ScreenCodeOrderInfo];
  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. #ifdef BUILD_NPD
  262. NSString* subject=[NSString stringWithFormat:@"%@ -- SO# %@ from NEW PACIFIC DIRECT,INC.",company,so];
  263. if (appDelegate.user_type == USER_ROLE_CUSTOMER&&self.is_shoporder) {
  264. NSString *companyName = [appDelegate.customerInfo objectForKey:@"customer_name"];
  265. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,companyName];
  266. }
  267. #endif
  268. #ifdef BUILD_HOMER
  269. NSString* subject=[NSString stringWithFormat:@"%@ -- SO# %@ from HOMELEGANCE LA, INC.",company,so];
  270. if (appDelegate.user_type == USER_ROLE_CUSTOMER&&self.is_shoporder) {
  271. NSString *companyName = [appDelegate.customerInfo objectForKey:@"customer_name"];
  272. subject=[NSString stringWithFormat:@"%@ -- SO# %@ from %@",company,so,companyName];
  273. }
  274. #endif
  275. #ifdef BUILD_HMLG
  276. NSString* subject=[NSString stringWithFormat:@"%@ -- SO# %@ from Homelegance.",company,so];
  277. #endif
  278. ViewController.mail_subject = subject;
  279. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  280. NSString *alertTitle = @"View Sales Order:";
  281. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30)) {
  282. alertTitle = @"View Store Order";
  283. }
  284. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:alertTitle message:nil preferredStyle:UIAlertControllerStyleAlert];
  285. //block代码块取代了delegate
  286. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Thumbnails" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  287. if(appDelegate.offline_mode)
  288. {
  289. NSMutableDictionary* params = [@{
  290. @"thumb" : @"1",
  291. @"order_code" : self.order_code,
  292. } mutableCopy];
  293. NSData *dicData = [OLDataProvider offline_request_salesorder:params];
  294. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:dicData options:NSJSONReadingMutableContainers error:nil];
  295. if ([dic[@"result"] integerValue] == RESULT_TRUE) {
  296. NSString *path = dic[@"pdf_path"];
  297. [weakself saleOrderWithPath:path];
  298. // ViewController.url = path;
  299. // ViewController.isLocalfile = YES;
  300. //
  301. // [self.navigationController pushViewController:ViewController animated:YES];
  302. } else {
  303. [RAUtils message_alert:@"Sales Order Open Failed" title:@"Message" controller:weakself];
  304. }
  305. }
  306. else
  307. {
  308. NSString* url=[self.content_data valueForKey:@"pdfUrl"];
  309. url= [url stringByAppendingString:@"&has_item_pic=true"];
  310. DebugLog(@"pdf url:%@",url);
  311. ViewController.url = url;
  312. [self.navigationController pushViewController:ViewController animated:YES];
  313. }
  314. }];
  315. NSString* alertthreetitle=@"Without Thumbnails";
  316. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30))
  317. {
  318. alertthreetitle=@"Print Quotation";
  319. }
  320. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:alertthreetitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  321. if(appDelegate.offline_mode)
  322. {
  323. NSMutableDictionary* params = [@{
  324. @"thumb" : @"0",
  325. @"order_code" : self.order_code,
  326. } mutableCopy];
  327. NSData *dicData = [OLDataProvider offline_request_salesorder:params];
  328. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:dicData options:NSJSONReadingMutableContainers error:nil];
  329. if ([dic[@"result"] integerValue] == RESULT_TRUE) {
  330. NSString *path = dic[@"pdf_path"];
  331. [weakself saleOrderWithPath:path];
  332. // ViewController.url = path;
  333. // ViewController.isLocalfile = YES;
  334. //
  335. // [self.navigationController pushViewController:ViewController animated:YES];
  336. } else {
  337. [RAUtils message_alert:@"Sales Order Open Failed" title:@"Message" controller:weakself];
  338. }
  339. }
  340. else
  341. {
  342. NSString* url=[self.content_data valueForKey:@"pdfUrl"];
  343. DebugLog(@"pdf url:%@",url);
  344. ViewController.url = url;
  345. [self.navigationController pushViewController:ViewController animated:YES];
  346. }
  347. }];
  348. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {}];
  349. if(appDelegate.user_type==USER_ROLE_CUSTOMER&&self.is_shoporder&& (status_code==1 /*||status_code==0*/||status_code==30))//[status isEqualToString:@"Saved Order"])
  350. {
  351. [alertControl addAction:alertthree];
  352. [alertControl addAction:alertCancel];
  353. }
  354. else
  355. {
  356. [alertControl addAction:actionOne];
  357. [alertControl addAction:alertthree];
  358. [alertControl addAction:alertCancel];
  359. }
  360. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  361. [self presentViewController:alertControl animated:YES completion:nil];
  362. // get customer info
  363. //
  364. }
  365. - (void)onCopyOrderClick:(id)sender {
  366. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  367. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.order_code) {
  368. __weak typeof(self) weakself = self;
  369. 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];
  370. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  371. }];
  372. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  373. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  374. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  375. NSDictionary* order_json = [iSalesNetwork release_Order:appDelegate.order_code withScreen:ScreenCodeOrderInfo];
  376. dispatch_async(dispatch_get_main_queue(), ^{
  377. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  378. if([[order_json valueForKey:@"result"] intValue]==2)
  379. {
  380. [appDelegate closeOrder];
  381. [weakself copyOrder];
  382. } else {
  383. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:weakself] ;
  384. }
  385. });
  386. });
  387. }];
  388. [alertVC addAction:cancelAction];
  389. [alertVC addAction:yesAction];
  390. [self presentViewController:alertVC animated:YES completion:nil];
  391. } else {
  392. 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];
  393. [alert show];
  394. }
  395. }
  396. //- (void)onCommitOrderClick:(id)sender {
  397. // // get customer info
  398. //
  399. // int model_count = [[self.content_data valueForKey:@"model_count"] intValue];
  400. // if(model_count==0)
  401. // {
  402. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error." message:@"Can not submit an order without models." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  403. ////
  404. //// [alert show];
  405. //
  406. //
  407. // [RAUtils alert_view:@"Cannot submit an order without models" title:@""];
  408. // }
  409. //
  410. // else
  411. // {
  412. //
  413. // 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];
  414. // [alert show];
  415. //
  416. // }
  417. //
  418. //
  419. //}
  420. -(void) upload_img :(UIImage*) img
  421. {
  422. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  423. if(appDelegate.offline_mode)
  424. {
  425. NSData *data = [OLDataProvider offline_saveBusinesscard:UIImagePNGRepresentation(img)];;
  426. // 再将NSData转为字符串
  427. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  428. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  429. DebugLog(@"data string: %@",jsonStr);
  430. NSError *error=nil;
  431. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
  432. if([[json valueForKey:@"result"] intValue]==2)
  433. {
  434. NSString* img_url_down = json[@"img_url_aname"];
  435. NSString* img_url_up = json[@"img_url"];
  436. {
  437. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Signature"];
  438. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  439. NSDictionary* order_json = [iSalesNetwork sign_Order:self.order_code path:img_url_up];
  440. dispatch_async(dispatch_get_main_queue(), ^{
  441. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  442. if([[order_json valueForKey:@"result"] intValue]==2)
  443. {
  444. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  445. // appDelegate.order_code = self.order_code;
  446. // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  447. //
  448. //
  449. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  450. //
  451. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  452. // [self.navigationController popViewControllerAnimated:false];
  453. //
  454. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  455. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  456. // if(self.selectOrder)
  457. // self.selectOrder(self.content_data);
  458. #ifdef BUILD_NPD
  459. int count = [[self.content_data objectForKey:@"count"] intValue];
  460. for (int i = 0; i < count; i++) {
  461. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  462. NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  463. NSString *type = [section objectForKey:@"type"];
  464. if ([type isEqualToString:@"sign_url"]) {
  465. [section setObject:img_url_down forKey:@"data"];
  466. [self.content_data setObject:section forKey:key];
  467. break;
  468. }
  469. }
  470. #endif
  471. #ifdef BUILD_HOMER
  472. int count = [[self.content_data objectForKey:@"count"] intValue];
  473. for (int i = 0; i < count; i++) {
  474. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  475. NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  476. NSString *type = [section objectForKey:@"type"];
  477. if ([type isEqualToString:@"sign_url"]) {
  478. [section setObject:img_url_down forKey:@"data"];
  479. [self.content_data setObject:section forKey:key];
  480. break;
  481. }
  482. }
  483. #endif
  484. #ifdef BUILD_HMLG
  485. [self.content_data setValue:img_url_down forKey:@"sign_url"];
  486. #endif
  487. //self.btnSign.enabled = false;
  488. [self.detailTable reloadData];
  489. [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
  490. }
  491. else
  492. {
  493. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
  494. }
  495. });
  496. });
  497. }
  498. }
  499. else
  500. {
  501. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
  502. }
  503. }
  504. else
  505. {
  506. // UIAlertView * waitalert = [[UIAlertView alloc] initWithTitle:@"wait" message:@"uploading" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
  507. // [waitalert show];
  508. NSData *imageData = UIImagePNGRepresentation(img);
  509. AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
  510. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  511. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  512. if(appDelegate.user!=nil)
  513. [params setValue:appDelegate.user forKey:@"user"];
  514. // if(appDelegate.contact_id!=nil)
  515. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  516. if(appDelegate.password!=nil)
  517. [params setValue:appDelegate.password forKey:@"password"];
  518. DebugLog(URL_UPLOAD_IMG);
  519. NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  520. [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
  521. } error:nil];
  522. // NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  523. // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"];
  524. // } error:nil];
  525. //
  526. AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  527. //manager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
  528. //
  529. NSProgress *progress = nil;
  530. NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
  531. // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
  532. if (error) {
  533. NSString* err_msg = [error localizedDescription];
  534. DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
  535. NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  536. DebugLog(@"data string: %@",str);
  537. [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
  538. } else {
  539. DebugLog(@"response ");
  540. NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
  541. // 再将NSData转为字符串
  542. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  543. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  544. DebugLog(@"data string: %@",jsonStr);
  545. NSDictionary* json = responseObject;
  546. if([[json valueForKey:@"result"] intValue]==2)
  547. {
  548. NSString* img_url_down = json[@"img_url_aname"];
  549. NSString* img_url_up = json[@"img_url"];
  550. {
  551. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Signature"];
  552. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  553. NSDictionary* order_json = [iSalesNetwork sign_Order:self.order_code path:img_url_up];
  554. dispatch_async(dispatch_get_main_queue(), ^{
  555. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  556. if([[order_json valueForKey:@"result"] intValue]==2)
  557. {
  558. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  559. // appDelegate.order_code = self.order_code;
  560. // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  561. //
  562. //
  563. // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  564. //
  565. // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  566. // [self.navigationController popViewControllerAnimated:false];
  567. //
  568. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  569. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  570. // if(self.selectOrder)
  571. // self.selectOrder(self.content_data);
  572. #ifdef BUILD_NPD
  573. int count = [[self.content_data objectForKey:@"count"] intValue];
  574. for (int i = 0; i < count; i++) {
  575. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  576. NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  577. NSString *type = [section objectForKey:@"type"];
  578. if ([type isEqualToString:@"sign_url"]) {
  579. [section setObject:img_url_down forKey:@"data"];
  580. [self.content_data setObject:section forKey:key];
  581. break;
  582. }
  583. }
  584. #endif
  585. #ifdef BUILD_HOMER
  586. int count = [[self.content_data objectForKey:@"count"] intValue];
  587. for (int i = 0; i < count; i++) {
  588. NSString *key = [NSString stringWithFormat:@"section_%d",i];
  589. NSMutableDictionary *section = [[self.content_data objectForKey:key] mutableCopy];
  590. NSString *type = [section objectForKey:@"type"];
  591. if ([type isEqualToString:@"sign_url"]) {
  592. [section setObject:img_url_down forKey:@"data"];
  593. [self.content_data setObject:section forKey:key];
  594. break;
  595. }
  596. }
  597. #endif
  598. #ifdef BUILD_HMLG
  599. [self.content_data setValue:img_url_down forKey:@"sign_url"];
  600. #endif
  601. //self.btnSign.enabled = false;
  602. [self.detailTable reloadData];
  603. [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
  604. }
  605. else
  606. {
  607. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
  608. }
  609. });
  610. });
  611. }
  612. }
  613. else
  614. {
  615. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
  616. }
  617. }
  618. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  619. }];
  620. [uploadTask resume];
  621. }
  622. }
  623. - (IBAction)onSignOrderClick:(id)sender {
  624. // SignatureViewController * vc;
  625. __block UIImage* signimg=nil;
  626. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  627. vc.onReturnImg = ^(UIImage* img)
  628. {
  629. signimg = img;
  630. if(signimg!=nil)
  631. [self upload_img:signimg];
  632. };
  633. // orderinfoVC.url_type = URL_REMOTE;
  634. // orderinfoVC.request_url=URL_CARTDELIVERY;
  635. //
  636. // orderinfoVC.params = params;
  637. //
  638. // orderinfoVC.delegate=self;
  639. //
  640. // if(checked.count==count)
  641. // {
  642. // orderinfoVC.have_tail = true
  643. // }
  644. [self.navigationController pushViewController:vc animated:true];
  645. }
  646. - (IBAction)onOpenOrderClick:(id)sender {
  647. // get customer info
  648. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to open order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  649. //block代码块取代了delegate
  650. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  651. {
  652. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Open Order"];
  653. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  654. NSDictionary* order_json = [iSalesNetwork open_Order:self.order_code];
  655. dispatch_async(dispatch_get_main_queue(), ^{
  656. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  657. if([[order_json valueForKey:@"result"] intValue]==2)
  658. {
  659. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  660. appDelegate.order_code = self.order_code;
  661. appDelegate.order_status = self.order_status;
  662. [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
  663. appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
  664. appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
  665. [self.navigationController popViewControllerAnimated:false];
  666. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  667. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  668. [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  669. if(self.selectOrder)
  670. self.selectOrder(self.content_data);
  671. }
  672. else
  673. {
  674. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
  675. }
  676. });
  677. });
  678. }
  679. }];
  680. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  681. DebugLog(@"Cancel");
  682. }];
  683. [alertControl addAction:actionOne];
  684. [alertControl addAction:alertthree];
  685. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  686. [self presentViewController:alertControl animated:YES completion:nil];
  687. }
  688. - (void)didReceiveMemoryWarning {
  689. [super didReceiveMemoryWarning];
  690. // Dispose of any resources that can be recreated.
  691. }
  692. -(void) loaddata
  693. {
  694. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Loading"];
  695. dispatch_async(dispatch_get_main_queue(), ^{
  696. if(self.isrefreshing)
  697. return;
  698. self.detailTable.hidden = true;
  699. self.label_net_err.hidden=true;
  700. self.isrefreshing=true;
  701. self.mum.center = self.view.center;
  702. self.mum.hidden = false;
  703. [self.mum startAnimating];
  704. DebugLog(@"reloading...");
  705. self.web_info_height=0;
  706. self.web_moreinfo_height=0;
  707. // self.content_data = nil;
  708. self.btnOpen.enabled =false;
  709. self.btnSign.enabled = false;
  710. self.btnCopy.enabled =false;
  711. self.btnPDF.enabled =false;
  712. self.btnRelease.enabled =false;
  713. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  714. NSDictionary* order_json = [iSalesNetwork request_OrderDetail:self.orderid];
  715. dispatch_async(dispatch_get_main_queue(), ^{
  716. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  717. [self.mum stopAnimating];
  718. if([[order_json valueForKey:@"result"] intValue]==2)
  719. {
  720. self.detailTable.hidden = false;
  721. self.content_data = [order_json mutableCopy];
  722. }
  723. else {
  724. self.content_data = nil;
  725. if([[order_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  726. {
  727. self.label_net_err.hidden=false;
  728. self.detailTable.hidden=true;
  729. }
  730. else
  731. {
  732. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Loading Order Detail" controller:self] ;
  733. }
  734. }
  735. bool web_order =[[self.content_data valueForKey:@"from_online"] boolValue];
  736. if(web_order)
  737. self.btnCopy.enabled = false;
  738. else
  739. self.btnCopy.enabled = true;
  740. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  741. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  742. int model_count =[[self.content_data valueForKey:@"model_count"] intValue];
  743. if(model_count>0)/*&& ! appDelegate.offline_mode*/
  744. {
  745. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  746. self.btnPDF.enabled =true;
  747. else
  748. {
  749. // || appDelegate.user_type==USER_ROLE_CUSTOMER
  750. if(self.is_shoporder)
  751. {
  752. if(status_code==1||status_code==30)
  753. self.btnPDF.enabled =true;
  754. }
  755. else
  756. {
  757. if(status_code==2)
  758. self.btnPDF.enabled =true;
  759. }
  760. }
  761. }
  762. // [self.btnPDF setImage:[[UIImage imageNamed:@"download"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  763. // NSString* status = [self.content_data valueForKey:@"order_status"];
  764. NSString* lock_user = [self.content_data valueForKey:@"opened_customer"];
  765. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  766. if(status_code==1)//[status isEqualToString:@"Saved Order"])
  767. {
  768. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  769. //
  770. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  771. if(appDelegate.offline_mode==false||offline_edit)
  772. {
  773. self.btnOpen.enabled =true;
  774. self.btnSign.enabled = true;
  775. }
  776. // if([lock_user isEqualToString:appDelegate.user])
  777. // {
  778. // self.btnCommit.enabled =true;
  779. // }
  780. // else
  781. // self.btnCommit.enabled =false;
  782. }
  783. else
  784. if(status_code==0)//[status isEqualToString:@"Quote Saved"])
  785. {
  786. // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  787. //
  788. // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  789. if(appDelegate.offline_mode==false||offline_edit)
  790. {
  791. self.btnOpen.enabled =true;
  792. self.btnSign.enabled = true;
  793. }
  794. // self.btnCommit.enabled =false;
  795. }
  796. 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))
  797. {
  798. // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  799. self.btnRelease.enabled =true;
  800. }
  801. else
  802. {
  803. // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
  804. self.btnRelease.enabled =false;
  805. }
  806. [self.detailTable reloadData];
  807. self.isrefreshing=false;
  808. });
  809. });
  810. });
  811. }
  812. - (void)viewWillAppear:(BOOL)animated
  813. {
  814. [super viewWillAppear:animated];
  815. // if(appDelegate.can_submit_order)
  816. // {
  817. //
  818. //
  819. // [self.btnCommit setImage:[UIImage imageNamed:@"commit"]];
  820. // self.btnCommit.enabled = true;
  821. // }
  822. // else
  823. // {
  824. // [self.btnCommit setImage:nil];
  825. // self.btnCommit.enabled = false;
  826. // }
  827. //
  828. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  829. }
  830. - (IBAction)imgbtnClicked:(UIButton*)sender {
  831. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  832. NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
  833. if(indexPath.section!=1)
  834. return ;
  835. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  836. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  837. NSString* product_id = [item_json valueForKey:@"product_id"];
  838. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  839. // dvc
  840. dvc.product_id=product_id;
  841. dvc.category_id=nil;
  842. dvc.ispush=true;
  843. [dvc reload];
  844. [self.navigationController pushViewController:dvc animated:true];
  845. }
  846. /*
  847. #pragma mark - Navigation
  848. // In a storyboard-based application, you will often want to do a little preparation before navigation
  849. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  850. // Get the new view controller using [segue destinationViewController].
  851. // Pass the selected object to the new view controller.
  852. }
  853. */
  854. #pragma mark - Table view data source
  855. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  856. {
  857. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  858. // if([item_json objectForKey:@"combine"] == nil)
  859. // {
  860. // return 120;
  861. // }
  862. // else
  863. // return 150;
  864. #ifdef BUILD_NPD
  865. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  866. NSDictionary *data = [section_item objectForKey:@"data"];
  867. NSString *type = [section_item objectForKey:@"type"];
  868. if ([type isEqualToString:@"order_info"]) {
  869. float height= self.web_info_height;
  870. if(height==0)
  871. height=DEF_TABLE_HEIGHT;
  872. return height;
  873. } else if ([type isEqualToString:@"sign_url"]) {
  874. return 148;
  875. } else if ([type isEqualToString:@"more_order_info"]) {
  876. float height= self.web_moreinfo_height;
  877. if(height==0)
  878. height=DEF_TABLE_HEIGHT;
  879. return height;
  880. } else if ([type isEqualToString:@"sub_order"]) {
  881. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  882. NSString *item_type = [item objectForKey:@"type"];
  883. if ([item_type isEqualToString:@"pick_info"]) {
  884. return 218;
  885. } else {
  886. NSString* notes =[item valueForKey:@"note"];
  887. if(notes.length>0)
  888. {
  889. return 190;
  890. }
  891. else
  892. return 162;
  893. }
  894. } else if ([type isEqualToString:@"price_info"]) {
  895. return 44;
  896. }
  897. #endif
  898. #ifdef BUILD_HOMER
  899. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  900. NSDictionary *data = [section_item objectForKey:@"data"];
  901. NSString *type = [section_item objectForKey:@"type"];
  902. if ([type isEqualToString:@"order_info"]) {
  903. float height= self.web_info_height;
  904. if(height==0)
  905. height=DEF_TABLE_HEIGHT;
  906. return height;
  907. } else if ([type isEqualToString:@"sign_url"]) {
  908. return 148;
  909. } else if ([type isEqualToString:@"more_order_info"]) {
  910. float height= self.web_moreinfo_height;
  911. if(height==0)
  912. height=DEF_TABLE_HEIGHT;
  913. return height;
  914. } else if ([type isEqualToString:@"sub_order"]) {
  915. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  916. NSString *item_type = [item objectForKey:@"type"];
  917. if ([item_type isEqualToString:@"pick_info"]) {
  918. return 218;
  919. } else {
  920. NSString* notes =[item valueForKey:@"note"];
  921. if(notes.length>0)
  922. {
  923. return 190;
  924. }
  925. else
  926. return 162;
  927. }
  928. } else if ([type isEqualToString:@"price_info"]) {
  929. return 44;
  930. }
  931. #endif
  932. #ifdef BUILD_HMLG
  933. switch (indexPath.section) {
  934. case 0:
  935. {
  936. if(indexPath.row==0)
  937. {
  938. float height= self.web_info_height;
  939. if(height==0)
  940. height=DEF_TABLE_HEIGHT;
  941. return height;
  942. }
  943. else
  944. return 148;
  945. }
  946. break;
  947. case 1:
  948. {
  949. float height= self.web_moreinfo_height;
  950. if(height==0)
  951. height=DEF_TABLE_HEIGHT;
  952. // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
  953. //wait(1000);
  954. return height;
  955. }
  956. break;
  957. case 2:
  958. {
  959. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  960. NSString* notes =[item_json valueForKey:@"note"];
  961. if(notes.length>0)
  962. {
  963. return 190;
  964. }
  965. else
  966. return 162;
  967. }
  968. case 3:
  969. return 44;
  970. default:
  971. break;
  972. }
  973. #endif
  974. return 44;
  975. }
  976. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  977. //{
  978. // return 0;
  979. //}
  980. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  981. //{
  982. // return 0;
  983. //}
  984. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  985. //{
  986. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  987. // return myView;
  988. //
  989. //}
  990. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  991. //{
  992. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  993. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  994. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  995. //// titleLabel.textColor=[UIColor whiteColor];
  996. //// titleLabel.backgroundColor = [UIColor clearColor];
  997. //// if(section==0)
  998. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  999. //// else
  1000. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  1001. //// [titleLabel sizeToFit];
  1002. //// [myView addSubview:titleLabel];
  1003. ////
  1004. // return myView;
  1005. //}
  1006. //
  1007. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1008. {
  1009. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  1010. if(value==nil)
  1011. value=@"";
  1012. unsigned long color = strtoul([value UTF8String],0,16);
  1013. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1014. // myView.backgroundColor = UIColorFromRGB(0x996633);;
  1015. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  1016. // myView.layer.masksToBounds = false;
  1017. //添加四个边阴影
  1018. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  1019. myView.layer.shadowOffset = CGSizeMake(0, 0);
  1020. myView.layer.shadowOpacity = 0.5;
  1021. myView.layer.shadowRadius = 2.0;
  1022. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1023. NSString*labeltitle = nil;
  1024. #ifdef BUILD_NPD
  1025. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1026. NSString *title = [section_item objectForKey:@"title"];
  1027. labeltitle = title;
  1028. if ([title isEqualToString:@"More Info"]) {
  1029. NSString* btntitle=nil ;
  1030. if(self.showMore)
  1031. {
  1032. btntitle=@"Hide";
  1033. }
  1034. else{
  1035. btntitle=@"Show";
  1036. }
  1037. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1038. btn.tag=section;
  1039. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1040. [btn setTitle:btntitle forState:UIControlStateNormal];
  1041. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1042. [myView addSubview:btn];
  1043. } else if ([title containsString:@"Models"]) {
  1044. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1045. NSString *normalTitle = @"Show";
  1046. NSString *selectedTitle = @"Hide";
  1047. if (item_switch == YES) {
  1048. normalTitle = @"Hide";
  1049. selectedTitle = @"Show";
  1050. }
  1051. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1052. btn.tag=section;
  1053. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1054. [btn setTitle:normalTitle forState:UIControlStateNormal];
  1055. [btn setTitle:selectedTitle forState:UIControlStateSelected];
  1056. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1057. [myView addSubview:btn];
  1058. }
  1059. #endif
  1060. #ifdef BUILD_HOMER
  1061. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1062. NSString *title = [section_item objectForKey:@"title"];
  1063. labeltitle = title;
  1064. if ([title isEqualToString:@"More Info"]) {
  1065. NSString* btntitle=nil ;
  1066. if(self.showMore)
  1067. {
  1068. btntitle=@"Hide";
  1069. }
  1070. else{
  1071. btntitle=@"Show";
  1072. }
  1073. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1074. btn.tag=section;
  1075. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1076. [btn setTitle:btntitle forState:UIControlStateNormal];
  1077. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1078. [myView addSubview:btn];
  1079. } else if ([title containsString:@"Models"]) {
  1080. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1081. NSString *normalTitle = @"Show";
  1082. NSString *selectedTitle = @"Hide";
  1083. if (item_switch == YES) {
  1084. normalTitle = @"Hide";
  1085. selectedTitle = @"Show";
  1086. }
  1087. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1088. btn.tag=section;
  1089. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1090. [btn setTitle:normalTitle forState:UIControlStateNormal];
  1091. [btn setTitle:selectedTitle forState:UIControlStateSelected];
  1092. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1093. [myView addSubview:btn];
  1094. }
  1095. #endif
  1096. #ifdef BUILD_HMLG
  1097. switch (section) {
  1098. case 0:
  1099. labeltitle= @"Order Info";
  1100. break;
  1101. case 1:
  1102. {
  1103. labeltitle= @"More Info";
  1104. NSString* btntitle=nil ;
  1105. if(self.showMore)
  1106. {
  1107. btntitle=@"Hide";
  1108. // [section setValue:@"false" forKey:@"hide"];
  1109. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  1110. }
  1111. else{
  1112. btntitle=@"Show";
  1113. }
  1114. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1115. btn.tag=section;
  1116. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1117. [btn setTitle:btntitle forState:UIControlStateNormal];
  1118. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1119. [myView addSubview:btn];
  1120. }
  1121. break;
  1122. case 2:{
  1123. labeltitle= @"Models";
  1124. NSString* btntitle=nil ;
  1125. if(self.showModels)
  1126. {
  1127. btntitle=@"Hide";
  1128. }
  1129. else{
  1130. btntitle=@"Show";
  1131. }
  1132. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
  1133. btn.tag=section;
  1134. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  1135. [btn setTitle:btntitle forState:UIControlStateNormal];
  1136. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1137. [myView addSubview:btn];
  1138. }
  1139. break;
  1140. case 3:
  1141. labeltitle= @"Price Info";
  1142. default:
  1143. break;
  1144. }
  1145. #endif
  1146. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
  1147. titlelabel.textColor=UIColorFromRGB(color);;
  1148. titlelabel.backgroundColor = [UIColor clearColor];
  1149. titlelabel.text=NSLocalizedString(labeltitle, nil);
  1150. [titlelabel sizeToFit];
  1151. titlelabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  1152. [myView addSubview:titlelabel];
  1153. //
  1154. return myView;
  1155. }
  1156. #pragma mark - hide section button clicked
  1157. - (void)HideSction:(UIButton *)sender {
  1158. /*
  1159. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",sender.tag]] mutableCopy];
  1160. bool hide = [[section valueForKey:@"hide"]boolValue];
  1161. if(hide)
  1162. {
  1163. [section setValue:@"false" forKey:@"hide"];
  1164. [sender setTitle:@"Show" forState:UIControlStateNormal];
  1165. }
  1166. else{
  1167. [section setValue:@"true" forKey:@"hide"];
  1168. [sender setTitle:@"Hide" forState:UIControlStateNormal];
  1169. }
  1170. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",sender.tag]];
  1171. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1172. */
  1173. #ifdef BUILD_NPD
  1174. NSUInteger section = sender.tag;
  1175. NSMutableDictionary *section_item = [[self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]] mutableCopy];
  1176. NSString *title = [section_item objectForKey:@"title"];
  1177. if ([title isEqualToString:@"More Info"]) {
  1178. self.showMore = !self.showMore;
  1179. NSRange range = NSMakeRange(section, 1);
  1180. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1181. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1182. } else if ([title containsString:@"Models"]) {
  1183. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1184. if (item_switch == YES) {
  1185. [section_item setObject:@(NO) forKey:@"switch"];
  1186. } else {
  1187. [section_item setObject:@(YES) forKey:@"switch"];
  1188. }
  1189. [self.content_data setObject:section_item forKey:[NSString stringWithFormat:@"section_%ld",section]];
  1190. sender.selected = !sender.selected;
  1191. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:section];
  1192. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1193. }
  1194. #endif
  1195. #ifdef BUILD_HOMER
  1196. NSUInteger section = sender.tag;
  1197. NSMutableDictionary *section_item = [[self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]] mutableCopy];
  1198. NSString *title = [section_item objectForKey:@"title"];
  1199. if ([title isEqualToString:@"More Info"]) {
  1200. self.showMore = !self.showMore;
  1201. NSRange range = NSMakeRange(section, 1);
  1202. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1203. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1204. } else if ([title containsString:@"Models"]) {
  1205. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1206. if (item_switch == YES) {
  1207. [section_item setObject:@(NO) forKey:@"switch"];
  1208. } else {
  1209. [section_item setObject:@(YES) forKey:@"switch"];
  1210. }
  1211. [self.content_data setObject:section_item forKey:[NSString stringWithFormat:@"section_%ld",section]];
  1212. sender.selected = !sender.selected;
  1213. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:section];
  1214. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1215. }
  1216. #endif
  1217. #ifdef BUILD_HMLG
  1218. switch (sender.tag) {
  1219. case 0:{
  1220. }
  1221. break;
  1222. case 1:{
  1223. self.showMore=!self.showMore;
  1224. NSRange range = NSMakeRange(1, 1);
  1225. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1226. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1227. }
  1228. break;
  1229. case 2:{
  1230. self.showModels = !self.showModels;
  1231. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndex:2];
  1232. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1233. }
  1234. break;
  1235. default:
  1236. break;
  1237. }
  1238. #endif
  1239. }
  1240. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1241. switch (section) {
  1242. case 0:
  1243. return @"Order Info";
  1244. break;
  1245. case 1:
  1246. return @"More Info";
  1247. break;
  1248. case 2:
  1249. return @"Models";
  1250. case 3:
  1251. return @"Price Info";
  1252. default:
  1253. break;
  1254. }
  1255. return nil;
  1256. }
  1257. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1258. {
  1259. if(self.content_data==nil)
  1260. return 0;
  1261. #ifdef BUILD_NPD
  1262. return [[self.content_data objectForKey:@"count"] integerValue];
  1263. #endif
  1264. #ifdef BUILD_HOMER
  1265. return [[self.content_data objectForKey:@"count"] integerValue];
  1266. #endif
  1267. #ifdef BUILD_HMLG
  1268. return 4;
  1269. #endif
  1270. }
  1271. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1272. {
  1273. return 33;
  1274. }
  1275. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1276. {
  1277. #ifdef BUILD_NPD
  1278. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1279. NSDictionary *data = [section_item objectForKey:@"data"];
  1280. NSString *section_type = [section_item objectForKey:@"type"];
  1281. if ([section_type isEqualToString:@"sub_order"]) {
  1282. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1283. if (item_switch == YES) {
  1284. return [[data objectForKey:@"count"] integerValue];
  1285. } else {
  1286. return 0;
  1287. }
  1288. } else if ([section_type isEqualToString:@"order_info"]){
  1289. if (self.showModels) {
  1290. return 1;
  1291. } else {
  1292. return 0;
  1293. }
  1294. } else if ([section_type isEqualToString:@"sign_url"]){
  1295. return 1;
  1296. } else if ([section_type isEqualToString:@"more_order_info"]){
  1297. if(self.showMore)
  1298. return 1;
  1299. else
  1300. return 0;
  1301. }else if ([section_type isEqualToString:@"price_info"]){
  1302. return [[data objectForKey:@"count"] integerValue];
  1303. }
  1304. return 0;
  1305. #endif
  1306. #ifdef BUILD_HOMER
  1307. NSDictionary *section_item = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  1308. NSDictionary *data = [section_item objectForKey:@"data"];
  1309. NSString *section_type = [section_item objectForKey:@"type"];
  1310. if ([section_type isEqualToString:@"sub_order"]) {
  1311. BOOL item_switch = [[section_item objectForKey:@"switch"] boolValue];
  1312. if (item_switch == YES) {
  1313. return [[data objectForKey:@"count"] integerValue];
  1314. } else {
  1315. return 0;
  1316. }
  1317. } else if ([section_type isEqualToString:@"order_info"]){
  1318. if (self.showModels) {
  1319. return 1;
  1320. } else {
  1321. return 0;
  1322. }
  1323. } else if ([section_type isEqualToString:@"sign_url"]){
  1324. return 1;
  1325. } else if ([section_type isEqualToString:@"more_order_info"]){
  1326. if(self.showMore)
  1327. return 1;
  1328. else
  1329. return 0;
  1330. }else if ([section_type isEqualToString:@"price_info"]){
  1331. return [[data objectForKey:@"count"] integerValue];
  1332. }
  1333. return 0;
  1334. #endif
  1335. #ifdef BUILD_HMLG
  1336. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  1337. if(section==0)
  1338. return 2;
  1339. if(section==1)
  1340. {
  1341. if(self.showMore)
  1342. return 1;
  1343. else
  1344. return 0;
  1345. }
  1346. if(section==2)
  1347. {
  1348. if (self.showModels) {
  1349. int count =[[self.content_data valueForKey:@"model_count"] intValue];
  1350. return count;
  1351. } else {
  1352. return 0;
  1353. }
  1354. }
  1355. if(section==3) {
  1356. #ifdef BUILD_NPD
  1357. return 6;
  1358. #endif
  1359. #ifdef BUILD_HOMER
  1360. return 6;
  1361. #endif
  1362. #ifdef BUILD_HMLG
  1363. return 4;
  1364. #endif
  1365. }
  1366. #endif
  1367. return 0;
  1368. }
  1369. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1370. {
  1371. UIApplication * app = [UIApplication sharedApplication];
  1372. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1373. #ifdef BUILD_NPD
  1374. /**
  1375. * ver1.90
  1376. */
  1377. NSDictionary *section = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1378. NSString *type = [section objectForKey:@"type"];
  1379. if ([type isEqualToString:@"order_info"]) {/** Order Info */
  1380. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1381. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1382. cell.webview.tag = indexPath.section;
  1383. cell.webview.delegate = self;
  1384. // cell.webView.scrollView.contentSize.height = 0;
  1385. cell.webview.scrollView.bounces=NO;
  1386. cell.webview.scrollView.directionalLockEnabled = true;
  1387. CGSize size= cell.webview.scrollView.contentSize;
  1388. size.height=10;
  1389. cell.webview.scrollView.contentSize=size;
  1390. [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  1391. cell.backgroundColor = [UIColor whiteColor];
  1392. return cell;
  1393. } else if ([type isEqualToString:@"sign_url"]) { /** Sign */
  1394. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  1395. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1396. NSString* img_url = [section valueForKey:@"data"];
  1397. cell.sign_img.userInteractionEnabled = NO;
  1398. __block BOOL hasTapGesture = NO;
  1399. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1400. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  1401. hasTapGesture = YES;
  1402. *stop = YES;
  1403. }
  1404. }];
  1405. if (!hasTapGesture) {
  1406. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  1407. [cell.sign_img addGestureRecognizer:signatureTap];
  1408. }
  1409. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1410. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1411. if(status_code==1) {
  1412. if(appDelegate.offline_mode==false||offline_edit) {
  1413. cell.sign_img.userInteractionEnabled = YES;
  1414. }
  1415. }
  1416. else if(status_code==0) {
  1417. if(appDelegate.offline_mode==false||offline_edit) {
  1418. cell.sign_img.userInteractionEnabled = YES;
  1419. }
  1420. }
  1421. NSString* file_name=[img_url lastPathComponent];
  1422. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1423. if(img_data!=nil)
  1424. {
  1425. UIImage * img =[UIImage imageWithData:img_data];
  1426. cell.sign_img.image=img ;
  1427. }
  1428. else
  1429. {
  1430. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1431. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1432. dispatch_async(dispatch_get_main_queue(), ^{
  1433. if(downloadimg_data!=nil)
  1434. {
  1435. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1436. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1437. cell.sign_img.image=img ;
  1438. }
  1439. else {
  1440. if (cell.sign_img.userInteractionEnabled) {
  1441. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  1442. } else {
  1443. cell.sign_img.image = nil;
  1444. }
  1445. }
  1446. });
  1447. });
  1448. }
  1449. cell.backgroundColor = [UIColor whiteColor];
  1450. return cell;
  1451. } else if ([type isEqualToString:@"more_order_info"]) { /** More Info */
  1452. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1453. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1454. cell.webview.tag = indexPath.section;
  1455. cell.webview.delegate = self;
  1456. // cell.webView.scrollView.contentSize.height = 0;
  1457. cell.webview.scrollView.bounces=NO;
  1458. cell.webview.scrollView.directionalLockEnabled = true;
  1459. CGSize size= cell.webview.scrollView.contentSize;
  1460. size.height=10;
  1461. cell.webview.scrollView.contentSize=size;
  1462. [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  1463. cell.backgroundColor = [UIColor whiteColor];
  1464. return cell;
  1465. } else if ([type isEqualToString:@"sub_order"]) { /** Sub Order */
  1466. NSDictionary *data = [section objectForKey:@"data"];
  1467. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1468. NSString *item_type = [item objectForKey:@"type"];
  1469. if ([item_type isEqualToString:@"pick_info"]) { /** Pick Info */
  1470. NSString *CellIdentifier = @"OrderDetailPickInfoCell";
  1471. OrderDetailPickInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1472. NSString *carrier = [item objectForKey:@"delivery_carrier"];
  1473. NSString *web_url = [item objectForKey:@"delivery_web_url"];
  1474. NSString *track_number = [item objectForKey:@"tracking_number"];
  1475. NSString *status = [item objectForKey:@"status"];
  1476. cell.track_number_lb.text = track_number;
  1477. cell.status_lb.text = status;
  1478. cell.carrier_lb.text = carrier;
  1479. cell.url_lb.text = web_url;
  1480. return cell;
  1481. } else if ([item_type isEqualToString:@"order_item"]) { /** Item Info */
  1482. NSString *CellIdentifier = @"OrderDetailModelCell";
  1483. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1484. NSDictionary * item_json = item;
  1485. // int count = [[item_json valueForKey:@"count"] intValue];
  1486. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  1487. cell.bundle_item=combine_json;
  1488. double dprice=0.0;
  1489. if(cell.bundle_item!=nil)
  1490. {
  1491. int citem=0;
  1492. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  1493. for(int bc=0;bc<bcount;bc++)
  1494. {
  1495. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  1496. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  1497. citem+= modulus;
  1498. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  1499. dprice+= uprice*modulus;
  1500. }
  1501. if(citem==1)
  1502. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  1503. else
  1504. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  1505. cell.buttonBundle.hidden = NO;
  1506. }
  1507. else
  1508. {
  1509. cell.buttonBundle.hidden = YES;
  1510. }
  1511. NSString* img_url = [item_json valueForKey:@"img"];
  1512. NSString* description = [item_json valueForKey:@"Item Number"];
  1513. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  1514. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  1515. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  1516. NSString* qty = [item_json valueForKey:@"QTY"];
  1517. NSString* status = [item_json valueForKey:@"order_item_status"];
  1518. NSString* notes = [item_json valueForKey:@"note"];
  1519. if(notes.length>0)
  1520. {
  1521. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  1522. }
  1523. else
  1524. cell.noteLabel.text = nil;
  1525. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1526. {
  1527. }
  1528. else
  1529. {
  1530. unitprice=nil;
  1531. origin_price=nil;
  1532. subtotal=nil;
  1533. }
  1534. float duprice = [unitprice floatValue];
  1535. float dsubtotal = (duprice+dprice)*[qty intValue];
  1536. cell.descriptionLabel.text=description;
  1537. if(dprice>0)
  1538. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  1539. else
  1540. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  1541. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  1542. cell.qtyLabel.text = qty;
  1543. cell.statusLabel.text = status;
  1544. cell.labelOldPrice.text = origin_price;
  1545. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  1546. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  1547. cell.labelDiscount.text = discountstr;
  1548. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  1549. if(isfree)
  1550. {
  1551. cell.labelOldPrice.hidden = false;
  1552. cell.labelOldPrice.textColor = [UIColor redColor];
  1553. cell.labelOldPrice.text=@"Free";
  1554. cell.labelOldPrice.hideline = true;
  1555. cell.labelDiscount.hidden = true;
  1556. }
  1557. else
  1558. {
  1559. cell.labelOldPrice.textColor = [UIColor blackColor];
  1560. cell.labelOldPrice.hideline = false;
  1561. if(discount==0)
  1562. {
  1563. cell.labelOldPrice.hidden = true;
  1564. cell.labelDiscount.hidden = true;
  1565. }
  1566. else
  1567. {
  1568. cell.labelOldPrice.hidden = false;
  1569. cell.labelDiscount.hidden = false;
  1570. }
  1571. }
  1572. if (![cell.imageName isEqualToString:img_url]) {
  1573. cell.imageName = img_url;
  1574. [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  1575. NSString* file_name=[img_url lastPathComponent];
  1576. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1577. if(img_data!=nil)
  1578. {
  1579. UIImage * img =[UIImage imageWithData:img_data];
  1580. [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  1581. }
  1582. else
  1583. {
  1584. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1585. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1586. dispatch_async(dispatch_get_main_queue(), ^{
  1587. if(downloadimg_data!=nil)
  1588. {
  1589. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1590. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1591. [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  1592. }
  1593. else
  1594. [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  1595. });
  1596. });
  1597. }
  1598. }
  1599. cell.backgroundColor = [UIColor whiteColor];
  1600. return cell;
  1601. }
  1602. } else if ([type isEqualToString:@"price_info"]) { /** Price */
  1603. NSString *CellIdentifier = @"OrderDetailPriceCell";
  1604. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1605. NSDictionary *data = [section objectForKey:@"data"];
  1606. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1607. NSString *title = [item objectForKey:@"title"];
  1608. NSString *value = [item objectForKey:@"value"];
  1609. if ([title isEqualToString:@"Sub-Total"] || [title isEqualToString:@"Total"]) {
  1610. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1611. {
  1612. }
  1613. else
  1614. {
  1615. value=nil;
  1616. }
  1617. }
  1618. cell.chargeLabel.text = [title stringByAppendingString:@":"];
  1619. cell.priceLabel.text = value;
  1620. cell.backgroundColor = [UIColor whiteColor];
  1621. return cell;
  1622. }
  1623. #endif
  1624. #ifdef BUILD_HOMER
  1625. /**
  1626. * ver1.90
  1627. */
  1628. NSDictionary *section = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",indexPath.section]];
  1629. NSString *type = [section objectForKey:@"type"];
  1630. if ([type isEqualToString:@"order_info"]) {/** Order Info */
  1631. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1632. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1633. cell.webview.tag = indexPath.section;
  1634. cell.webview.delegate = self;
  1635. // cell.webView.scrollView.contentSize.height = 0;
  1636. cell.webview.scrollView.bounces=NO;
  1637. cell.webview.scrollView.directionalLockEnabled = true;
  1638. CGSize size= cell.webview.scrollView.contentSize;
  1639. size.height=10;
  1640. cell.webview.scrollView.contentSize=size;
  1641. [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  1642. cell.backgroundColor = [UIColor whiteColor];
  1643. return cell;
  1644. } else if ([type isEqualToString:@"sign_url"]) { /** Sign */
  1645. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  1646. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1647. NSString* img_url = [section valueForKey:@"data"];
  1648. cell.sign_img.userInteractionEnabled = NO;
  1649. __block BOOL hasTapGesture = NO;
  1650. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1651. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  1652. hasTapGesture = YES;
  1653. *stop = YES;
  1654. }
  1655. }];
  1656. if (!hasTapGesture) {
  1657. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  1658. [cell.sign_img addGestureRecognizer:signatureTap];
  1659. }
  1660. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1661. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1662. if(status_code==1) {
  1663. if(appDelegate.offline_mode==false||offline_edit) {
  1664. cell.sign_img.userInteractionEnabled = YES;
  1665. }
  1666. }
  1667. else if(status_code==0) {
  1668. if(appDelegate.offline_mode==false||offline_edit) {
  1669. cell.sign_img.userInteractionEnabled = YES;
  1670. }
  1671. }
  1672. NSString* file_name=[img_url lastPathComponent];
  1673. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1674. if(img_data!=nil)
  1675. {
  1676. UIImage * img =[UIImage imageWithData:img_data];
  1677. cell.sign_img.image=img ;
  1678. }
  1679. else
  1680. {
  1681. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1682. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1683. dispatch_async(dispatch_get_main_queue(), ^{
  1684. if(downloadimg_data!=nil)
  1685. {
  1686. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1687. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1688. cell.sign_img.image=img ;
  1689. }
  1690. else {
  1691. if (cell.sign_img.userInteractionEnabled) {
  1692. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  1693. } else {
  1694. cell.sign_img.image = nil;
  1695. }
  1696. }
  1697. });
  1698. });
  1699. }
  1700. cell.backgroundColor = [UIColor whiteColor];
  1701. return cell;
  1702. } else if ([type isEqualToString:@"more_order_info"]) { /** More Info */
  1703. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1704. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1705. cell.webview.tag = indexPath.section;
  1706. cell.webview.delegate = self;
  1707. // cell.webView.scrollView.contentSize.height = 0;
  1708. cell.webview.scrollView.bounces=NO;
  1709. cell.webview.scrollView.directionalLockEnabled = true;
  1710. CGSize size= cell.webview.scrollView.contentSize;
  1711. size.height=10;
  1712. cell.webview.scrollView.contentSize=size;
  1713. [cell.webview loadHTMLString:[section valueForKey:@"data"] baseURL:nil];
  1714. cell.backgroundColor = [UIColor whiteColor];
  1715. return cell;
  1716. } else if ([type isEqualToString:@"sub_order"]) { /** Sub Order */
  1717. NSDictionary *data = [section objectForKey:@"data"];
  1718. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1719. NSString *item_type = [item objectForKey:@"type"];
  1720. if ([item_type isEqualToString:@"pick_info"]) { /** Pick Info */
  1721. NSString *CellIdentifier = @"OrderDetailPickInfoCell";
  1722. OrderDetailPickInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1723. NSString *carrier = [item objectForKey:@"delivery_carrier"];
  1724. NSString *web_url = [item objectForKey:@"delivery_web_url"];
  1725. NSString *track_number = [item objectForKey:@"tracking_number"];
  1726. NSString *status = [item objectForKey:@"status"];
  1727. cell.track_number_lb.text = track_number;
  1728. cell.status_lb.text = status;
  1729. cell.carrier_lb.text = carrier;
  1730. cell.url_lb.text = web_url;
  1731. return cell;
  1732. } else if ([item_type isEqualToString:@"order_item"]) { /** Item Info */
  1733. NSString *CellIdentifier = @"OrderDetailModelCell";
  1734. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1735. NSDictionary * item_json = item;
  1736. // int count = [[item_json valueForKey:@"count"] intValue];
  1737. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  1738. cell.bundle_item=combine_json;
  1739. double dprice=0.0;
  1740. if(cell.bundle_item!=nil)
  1741. {
  1742. int citem=0;
  1743. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  1744. for(int bc=0;bc<bcount;bc++)
  1745. {
  1746. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  1747. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  1748. citem+= modulus;
  1749. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  1750. dprice+= uprice*modulus;
  1751. }
  1752. if(citem==1)
  1753. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  1754. else
  1755. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  1756. cell.buttonBundle.hidden = NO;
  1757. }
  1758. else
  1759. {
  1760. cell.buttonBundle.hidden = YES;
  1761. }
  1762. NSString* img_url = [item_json valueForKey:@"img"];
  1763. NSString* description = [item_json valueForKey:@"Item Number"];
  1764. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  1765. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  1766. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  1767. NSString* qty = [item_json valueForKey:@"QTY"];
  1768. NSString* status = [item_json valueForKey:@"order_item_status"];
  1769. NSString* notes = [item_json valueForKey:@"note"];
  1770. if(notes.length>0)
  1771. {
  1772. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  1773. }
  1774. else
  1775. cell.noteLabel.text = nil;
  1776. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1777. {
  1778. }
  1779. else
  1780. {
  1781. unitprice=nil;
  1782. origin_price=nil;
  1783. subtotal=nil;
  1784. }
  1785. float duprice = [unitprice floatValue];
  1786. float dsubtotal = (duprice+dprice)*[qty intValue];
  1787. cell.descriptionLabel.text=description;
  1788. if(dprice>0)
  1789. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  1790. else
  1791. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  1792. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  1793. cell.qtyLabel.text = qty;
  1794. cell.statusLabel.text = status;
  1795. cell.labelOldPrice.text = origin_price;
  1796. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  1797. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  1798. cell.labelDiscount.text = discountstr;
  1799. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  1800. if(isfree)
  1801. {
  1802. cell.labelOldPrice.hidden = false;
  1803. cell.labelOldPrice.textColor = [UIColor redColor];
  1804. cell.labelOldPrice.text=@"Free";
  1805. cell.labelOldPrice.hideline = true;
  1806. cell.labelDiscount.hidden = true;
  1807. }
  1808. else
  1809. {
  1810. cell.labelOldPrice.textColor = [UIColor blackColor];
  1811. cell.labelOldPrice.hideline = false;
  1812. if(discount==0)
  1813. {
  1814. cell.labelOldPrice.hidden = true;
  1815. cell.labelDiscount.hidden = true;
  1816. }
  1817. else
  1818. {
  1819. cell.labelOldPrice.hidden = false;
  1820. cell.labelDiscount.hidden = false;
  1821. }
  1822. }
  1823. if (![cell.imageName isEqualToString:img_url]) {
  1824. cell.imageName = img_url;
  1825. [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  1826. NSString* file_name=[img_url lastPathComponent];
  1827. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1828. if(img_data!=nil)
  1829. {
  1830. UIImage * img =[UIImage imageWithData:img_data];
  1831. [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  1832. }
  1833. else
  1834. {
  1835. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1836. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1837. dispatch_async(dispatch_get_main_queue(), ^{
  1838. if(downloadimg_data!=nil)
  1839. {
  1840. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1841. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1842. [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  1843. }
  1844. else
  1845. [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  1846. });
  1847. });
  1848. }
  1849. }
  1850. cell.backgroundColor = [UIColor whiteColor];
  1851. return cell;
  1852. }
  1853. } else if ([type isEqualToString:@"price_info"]) { /** Price */
  1854. NSString *CellIdentifier = @"OrderDetailPriceCell";
  1855. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1856. NSDictionary *data = [section objectForKey:@"data"];
  1857. NSDictionary *item = [data objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  1858. NSString *title = [item objectForKey:@"title"];
  1859. NSString *value = [item objectForKey:@"value"];
  1860. if ([title isEqualToString:@"Sub-Total"] || [title isEqualToString:@"Total"]) {
  1861. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1862. {
  1863. }
  1864. else
  1865. {
  1866. value=nil;
  1867. }
  1868. }
  1869. cell.chargeLabel.text = [title stringByAppendingString:@":"];
  1870. cell.priceLabel.text = value;
  1871. cell.backgroundColor = [UIColor whiteColor];
  1872. return cell;
  1873. }
  1874. #endif
  1875. #ifdef BUILD_HMLG
  1876. switch(indexPath.section)
  1877. {
  1878. case 0:
  1879. {
  1880. if(indexPath.row==0)
  1881. {
  1882. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1883. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1884. cell.webview.tag = indexPath.section;
  1885. cell.webview.delegate = self;
  1886. // cell.webView.scrollView.contentSize.height = 0;
  1887. cell.webview.scrollView.bounces=NO;
  1888. cell.webview.scrollView.directionalLockEnabled = true;
  1889. CGSize size= cell.webview.scrollView.contentSize;
  1890. size.height=10;
  1891. cell.webview.scrollView.contentSize=size;
  1892. [cell.webview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
  1893. cell.backgroundColor = [UIColor whiteColor];
  1894. return cell;
  1895. }
  1896. else
  1897. {
  1898. NSString *CellIdentifier = @"OrderDetailSignatureCell";
  1899. OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1900. NSString* img_url = [self.content_data valueForKey:@"sign_url"];
  1901. cell.sign_img.userInteractionEnabled = NO;
  1902. __block BOOL hasTapGesture = NO;
  1903. [cell.sign_img.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1904. if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
  1905. hasTapGesture = YES;
  1906. *stop = YES;
  1907. }
  1908. }];
  1909. if (!hasTapGesture) {
  1910. UITapGestureRecognizer *signatureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSignOrderClick:)];
  1911. [cell.sign_img addGestureRecognizer:signatureTap];
  1912. }
  1913. int status_code = [[self.content_data valueForKey:@"orderStatus"] intValue];
  1914. bool offline_edit =[[self.content_data valueForKey:@"offline_edit"] boolValue];
  1915. if(status_code==1) {
  1916. if(appDelegate.offline_mode==false||offline_edit) {
  1917. cell.sign_img.userInteractionEnabled = YES;
  1918. }
  1919. }
  1920. else if(status_code==0) {
  1921. if(appDelegate.offline_mode==false||offline_edit) {
  1922. cell.sign_img.userInteractionEnabled = YES;
  1923. }
  1924. }
  1925. NSString* file_name=[img_url lastPathComponent];
  1926. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1927. if(img_data!=nil)
  1928. {
  1929. UIImage * img =[UIImage imageWithData:img_data];
  1930. cell.sign_img.image=img ;
  1931. }
  1932. else
  1933. {
  1934. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1935. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1936. dispatch_async(dispatch_get_main_queue(), ^{
  1937. if(downloadimg_data!=nil)
  1938. {
  1939. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1940. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1941. cell.sign_img.image=img ;
  1942. }
  1943. else {
  1944. if (cell.sign_img.userInteractionEnabled) {
  1945. cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
  1946. } else {
  1947. cell.sign_img.image = nil;
  1948. }
  1949. }
  1950. });
  1951. });
  1952. }
  1953. cell.backgroundColor = [UIColor whiteColor];
  1954. return cell;
  1955. }
  1956. }
  1957. break;
  1958. case 1:
  1959. {
  1960. NSString *CellIdentifier = @"OrderDetailHtmlCell";
  1961. OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1962. cell.webview.tag = indexPath.section;
  1963. cell.webview.delegate = self;
  1964. // cell.webView.scrollView.contentSize.height = 0;
  1965. cell.webview.scrollView.bounces=NO;
  1966. cell.webview.scrollView.directionalLockEnabled = true;
  1967. CGSize size= cell.webview.scrollView.contentSize;
  1968. size.height=10;
  1969. cell.webview.scrollView.contentSize=size;
  1970. [cell.webview loadHTMLString:[self.content_data valueForKey:@"more_order_info"] baseURL:nil];
  1971. cell.backgroundColor = [UIColor whiteColor];
  1972. return cell;
  1973. // NSString *CellIdentifier = @"OrderDetailInfoCell";
  1974. // OrderDetailInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1975. //
  1976. // cell.infoLabel.text =[self.content_data valueForKey:@"more_order_info"];
  1977. //
  1978. //
  1979. //
  1980. //// float width = tableView.frame.size.width;
  1981. //// width-=CELL_MARGIN*2;
  1982. //// CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  1983. ////
  1984. //// NSString* key =[self.content_data valueForKey:@"order_info"];
  1985. ////
  1986. ////
  1987. ////
  1988. //// CGRect frame;
  1989. //// frame.size = constraintkey;
  1990. //// frame.origin.x=0;
  1991. //// frame.origin.y=0;
  1992. ////
  1993. //// RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  1994. ////
  1995. //// [rtlabel setText: key];
  1996. //// CGSize optimumSize = [rtlabel optimumSize];
  1997. ////
  1998. //// float height = optimumSize.height;
  1999. //// height = MAX(height+LINE_WIDTH+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  2000. ////
  2001. ////
  2002. //// frame.origin.x=LABEL_MARGIN;
  2003. //// frame.size=CGSizeMake(width, height);
  2004. ////
  2005. //// cell.infoLabel.frame = frame;
  2006. //
  2007. //
  2008. //
  2009. //
  2010. // cell.backgroundColor = [UIColor whiteColor];
  2011. // return cell;
  2012. }
  2013. break;
  2014. case 2:
  2015. {
  2016. NSString *CellIdentifier = @"OrderDetailModelCell";
  2017. OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2018. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2019. int count = [[item_json valueForKey:@"count"] intValue];
  2020. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2021. cell.bundle_item=combine_json;
  2022. double dprice=0.0;
  2023. if(cell.bundle_item!=nil)
  2024. {
  2025. int citem=0;
  2026. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  2027. for(int bc=0;bc<bcount;bc++)
  2028. {
  2029. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2030. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2031. citem+= modulus;
  2032. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2033. dprice+= uprice*modulus;
  2034. }
  2035. if(citem==1)
  2036. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2037. else
  2038. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  2039. cell.buttonBundle.hidden = NO;
  2040. }
  2041. else
  2042. {
  2043. cell.buttonBundle.hidden = YES;
  2044. }
  2045. NSString* img_url = [item_json valueForKey:@"img"];
  2046. NSString* description = [item_json valueForKey:@"Item Number"];
  2047. // NSString* description = [item_json valueForKey:@"Item Number"];
  2048. NSString* unitprice = [item_json valueForKey:@"The unit price"];
  2049. NSString* origin_price = [item_json valueForKey:@"origin_price"];
  2050. NSString* subtotal = [item_json valueForKey:@"Subtotal"];
  2051. NSString* qty = [item_json valueForKey:@"QTY"];
  2052. NSString* status = [item_json valueForKey:@"order_item_status"];
  2053. NSString* notes = [item_json valueForKey:@"note"];
  2054. if(notes.length>0)
  2055. {
  2056. cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  2057. }
  2058. else
  2059. cell.noteLabel.text = nil;
  2060. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2061. {
  2062. }
  2063. else
  2064. {
  2065. unitprice=nil;
  2066. origin_price=nil;
  2067. subtotal=nil;
  2068. }
  2069. float duprice = [unitprice floatValue];
  2070. float dsubtotal = (duprice+dprice)*[qty intValue];
  2071. cell.descriptionLabel.text=description;
  2072. if(dprice>0)
  2073. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f+%.2f",duprice,dprice];//unitprice;
  2074. else
  2075. cell.unitpriceLabel.text = [NSString stringWithFormat:@"%.2f",duprice];//unitprice;
  2076. cell.subtotalLabel.text = [NSString stringWithFormat:@"%.2f",dsubtotal];//subtotal;
  2077. cell.qtyLabel.text = qty;
  2078. cell.statusLabel.text = status;
  2079. cell.labelOldPrice.text = origin_price;
  2080. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  2081. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  2082. cell.labelDiscount.text = discountstr;
  2083. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  2084. if(isfree)
  2085. {
  2086. cell.labelOldPrice.hidden = false;
  2087. cell.labelOldPrice.textColor = [UIColor redColor];
  2088. cell.labelOldPrice.text=@"Free";
  2089. cell.labelOldPrice.hideline = true;
  2090. cell.labelDiscount.hidden = true;
  2091. }
  2092. else
  2093. {
  2094. cell.labelOldPrice.textColor = [UIColor blackColor];
  2095. cell.labelOldPrice.hideline = false;
  2096. if(discount==0)
  2097. {
  2098. cell.labelOldPrice.hidden = true;
  2099. cell.labelDiscount.hidden = true;
  2100. }
  2101. else
  2102. {
  2103. cell.labelOldPrice.hidden = false;
  2104. cell.labelDiscount.hidden = false;
  2105. }
  2106. }
  2107. if (![cell.imageName isEqualToString:img_url]) {
  2108. cell.imageName = img_url;
  2109. [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  2110. NSString* file_name=[img_url lastPathComponent];
  2111. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2112. if(img_data!=nil)
  2113. {
  2114. UIImage * img =[UIImage imageWithData:img_data];
  2115. [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2116. }
  2117. else
  2118. {
  2119. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2120. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2121. dispatch_async(dispatch_get_main_queue(), ^{
  2122. if(downloadimg_data!=nil)
  2123. {
  2124. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  2125. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2126. [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
  2127. }
  2128. else
  2129. [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  2130. });
  2131. });
  2132. }
  2133. }
  2134. cell.backgroundColor = [UIColor whiteColor];
  2135. return cell;
  2136. }
  2137. break;
  2138. case 3:
  2139. {
  2140. NSString *CellIdentifier = @"OrderDetailPriceCell";
  2141. OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2142. switch (indexPath.row) {
  2143. case 0:
  2144. {
  2145. cell.chargeLabel.text =@"Sub-Total:";
  2146. NSString* price=[self.content_data valueForKey:@"Sub-Total"];
  2147. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2148. {
  2149. }
  2150. else
  2151. {
  2152. price=nil;
  2153. }
  2154. cell.priceLabel.text =price;
  2155. break;
  2156. }
  2157. case 1:
  2158. cell.chargeLabel.text = @"Shipping:";
  2159. cell.priceLabel.text =[self.content_data valueForKey:@"Shipping"];
  2160. break;
  2161. case 2: {
  2162. #ifdef BUILD_NPD
  2163. cell.chargeLabel.text = @"Liftgate Fee(No loading dock):";
  2164. cell.priceLabel.text =[self.content_data valueForKey:@"Liftgate Fee(No loading dock)"];
  2165. #endif
  2166. #ifdef BUILD_HOMER
  2167. cell.chargeLabel.text = @"Liftgate Fee(No loading dock):";
  2168. cell.priceLabel.text =[self.content_data valueForKey:@"Liftgate Fee(No loading dock)"];
  2169. #endif
  2170. #ifdef BUILD_HMLG
  2171. cell.chargeLabel.text = @"Tax:";
  2172. NSString *tax = [self.content_data valueForKey:@"Tax"] ? [self.content_data valueForKey:@"Tax"] : @"$0.00";
  2173. cell.priceLabel.text = tax;
  2174. #endif
  2175. }
  2176. break;
  2177. case 3: {
  2178. #ifdef BUILD_NPD
  2179. cell.chargeLabel.text = @"Handling Fee:";
  2180. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  2181. #endif
  2182. #ifdef BUILD_HOMER
  2183. cell.chargeLabel.text = @"Handling Fee:";
  2184. cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
  2185. #endif
  2186. #ifdef BUILD_HMLG
  2187. NSString* price=[self.content_data valueForKey:@"Total"];
  2188. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2189. {
  2190. }
  2191. else
  2192. {
  2193. price=nil;
  2194. }
  2195. cell.chargeLabel.text = @"Total:";
  2196. cell.priceLabel.text =price;
  2197. #endif
  2198. }
  2199. break;
  2200. case 4: {
  2201. cell.chargeLabel.text = @"Tax:";
  2202. NSString *tax = [self.content_data valueForKey:@"Tax"] ? [self.content_data valueForKey:@"Tax"] : @"$0.00";
  2203. cell.priceLabel.text = tax;
  2204. }
  2205. break;
  2206. case 5:
  2207. {
  2208. NSString* price=[self.content_data valueForKey:@"Total"];
  2209. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2210. {
  2211. }
  2212. else
  2213. {
  2214. price=nil;
  2215. }
  2216. cell.chargeLabel.text = @"Total:";
  2217. cell.priceLabel.text =price;
  2218. break;
  2219. }
  2220. default:
  2221. break;
  2222. }
  2223. cell.backgroundColor = [UIColor whiteColor];
  2224. return cell;
  2225. }
  2226. }
  2227. #endif
  2228. return nil;
  2229. // if(tableView==self.itemListTable)
  2230. // {
  2231. // NSString *CellIdentifier = @"CartItemCell";
  2232. // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2233. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2234. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  2235. //
  2236. // cell.bundle_item=combine_json;
  2237. // NSString* img_url = [item_json valueForKey:@"img_url"];
  2238. // NSString* description = [item_json valueForKey:@"description"];
  2239. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  2240. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  2241. // NSString* currency = [item_json valueForKey:@"currency"];
  2242. // int count =[[item_json valueForKey:@"count"] intValue];
  2243. //
  2244. // int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2245. //
  2246. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2247. //
  2248. // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2249. // cell.unit_price = unitprice;
  2250. // // cell.labelAttribute.text = attribute;
  2251. // // cell.labelCurrency.text = currency;
  2252. // cell.labelDescription.text = description;
  2253. // // cell.labelIdentifier.text = identifier;
  2254. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
  2255. //
  2256. // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
  2257. //
  2258. //
  2259. //
  2260. // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2261. // cell.cart_id = cart_item_id;
  2262. // [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2263. //
  2264. //
  2265. //
  2266. // [cell set_Count:count];
  2267. //
  2268. // NSString* file_name=[img_url lastPathComponent];
  2269. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  2270. // if(img_data!=nil)
  2271. // {
  2272. //
  2273. // UIImage * img =[UIImage imageWithData:img_data];
  2274. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2275. // }
  2276. // else
  2277. // {
  2278. //
  2279. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2280. //
  2281. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  2282. //
  2283. // dispatch_async(dispatch_get_main_queue(), ^{
  2284. //
  2285. //
  2286. //
  2287. // if(downloadimg_data!=nil)
  2288. // {
  2289. // [iSalesDB cache_img:downloadimg_data :file_name ];
  2290. //
  2291. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  2292. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  2293. // }
  2294. //
  2295. // });
  2296. // });
  2297. //
  2298. //
  2299. // }
  2300. // return cell;
  2301. // }
  2302. // else
  2303. // {
  2304. // NSString *CellIdentifier = @"OrderInfoListItem";
  2305. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2306. // return cell;
  2307. // }
  2308. }
  2309. #pragma mark - UIAlertViewDelegate
  2310. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  2311. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  2312. {
  2313. if(buttonIndex!=alertView.cancelButtonIndex)
  2314. {
  2315. [self copyOrder];
  2316. }
  2317. }
  2318. - (void)copyOrder {
  2319. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Copy Order"];
  2320. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2321. NSDictionary* order_json = [iSalesNetwork copy_Order:self.order_code];
  2322. dispatch_async(dispatch_get_main_queue(), ^{
  2323. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  2324. if([[order_json valueForKey:@"result"] intValue]==2)
  2325. {
  2326. // NSString* orderCode = [order_json valueForKey:@"orderCode"];
  2327. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2328. // if([appDelegate.order_code isEqualToString: self.order_code])
  2329. // {
  2330. // [appDelegate closeOrder];
  2331. //// appDelegate.order_code= nil;
  2332. // [appDelegate SetSo:nil];
  2333. //
  2334. //
  2335. // }
  2336. 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];
  2337. [alert show];
  2338. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2339. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2340. [self.navigationController popViewControllerAnimated:false];
  2341. }
  2342. else
  2343. {
  2344. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
  2345. }
  2346. });
  2347. });
  2348. }
  2349. #pragma mark - web view delegate
  2350. //- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  2351. //{
  2352. // if(navigationType != UIWebViewNavigationTypeLinkClicked)
  2353. // return true;
  2354. // // NSString *currentURL =[webView.request.URL lastPathComponent];// [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
  2355. //
  2356. // NSString* str = request.URL.absoluteString;
  2357. // if([str isEqualToString:@"about:blank"])
  2358. // return true;
  2359. // WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
  2360. // ViewController.url = str;
  2361. // // ViewController. = self.function_name;
  2362. // // ViewController.behavior =BEHAVIOR_SEARCH;
  2363. //
  2364. // [self.navigationController pushViewController:ViewController animated:YES];
  2365. // DebugLog(@"shouldStartLoadWithRequest");
  2366. // return false;
  2367. //}
  2368. - (void)webViewDidFinishLoad:(UIWebView *)webView
  2369. {
  2370. DebugLog(@"webViewDidFinishLoad @@@@@@@@@@@@@@@@@ entry");
  2371. UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
  2372. NSIndexPath *indexPath = [self.detailTable indexPathForCell:cell];
  2373. if(indexPath==nil)
  2374. {//for ios7
  2375. cell = (UITableViewCell *) webView.superview.superview.superview;
  2376. indexPath = [self.detailTable indexPathForCell:cell];
  2377. }
  2378. float height= 0;
  2379. if(indexPath.section==0)
  2380. height=self.web_info_height;
  2381. else
  2382. height = self.web_moreinfo_height;
  2383. if(height>0)
  2384. return;
  2385. // UIScrollView *scrollerView = [webView.subviews objectAtIndex:0];
  2386. // CGSize size= webView.scrollView.contentSize;
  2387. // CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
  2388. CGRect frame = webView.frame;
  2389. NSString *fitHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
  2390. frame.size.height = [fitHeight floatValue];
  2391. //webView.frame = frame;
  2392. // DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^Saveheight height=%f section=%ld",webView.scrollView.contentSize.height,indexPath.section);
  2393. if(indexPath.section==0)
  2394. self.web_info_height=frame.size.height;
  2395. else
  2396. self.web_moreinfo_height = frame.size.height;
  2397. // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
  2398. DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^reloadRowsAtIndexPaths");
  2399. // [self.table beginUpdates];
  2400. [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  2401. // [self.table endUpdates];
  2402. // [self.webviewoprationQueue addOperationWithBlock:^{
  2403. // }];
  2404. // [self.table endUpdates];
  2405. // }
  2406. }
  2407. @end