OrderDetailViewController.m 148 KB

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