OrderDetailViewController.m 154 KB

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