OrderDetailViewController.m 135 KB

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