OrderDetailViewController.m 135 KB

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