OrderDetailViewController.m 152 KB

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