| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666 |
- //
- // OrderDetailViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 8/28/15.
- // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "OrderDetailViewController.h"
- #import "OrderDetailInfoCell.h"
- #import "OrderDetailHtmlCell.h"
- #import "OrderDetailModelCell.h"
- #import "OrderDetailPriceCell.h"
- #import "OrderDetailSignatureCell.h"
- #import "iSalesNetwork.h"
- #import "RTLabel.h"
- #import "DetailViewController.h"
- #import "PDFViewController.h"
- #import "SignatureViewController.h"
- #import "MainViewController.h"
- #import "AFHTTPSessionManager.h"
- #define DEF_CELL_HEIGHT 44
- #define DEF_TABLE_HEIGHT 44
- #define LINE_WIDTH 0
- #define CELL_MARGIN 0
- #define LABEL_MARGIN 15
- @interface OrderDetailViewController ()
- @end
- @implementation OrderDetailViewController
- -(void) reload_container_getdata:(bool) update_data
- {
-
- [super reload_container_getdata:update_data];
- if(update_data)
- [self reload_data];
- else
- {
- [self.detailTable reloadData];
-
- }
- }
- - (void)onBackClick:(UIButton *)sender {
-
-
- [self.navigationController popViewControllerAnimated:FALSE];
- }
- -(void)manually_refresh
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- if(self.isrefreshing)
- {
- [reF endRefreshing];
- return;
- }
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
-
-
- if ([self respondsToSelector:@selector(reload_data)])
- [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
-
- }
- -(void) reload_data
- {
-
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
-
- [self loaddata];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
-
-
- self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
- self.label_net_err.layer.borderWidth = 2.0;
- self.label_net_err.layer.cornerRadius=15;
- self.label_net_err.layer.masksToBounds=true;
-
-
-
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
- // tap.minimumPressDuration = 0.8; //定义按的时间
- [self.label_net_err addGestureRecognizer:tap];
-
-
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 200 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
- [self.detailTable addSubview:ref];
-
-
- NSMutableArray * items = [[NSMutableArray alloc]init];
-
-
- self.navigationItem.title=@"View Order Detail";
-
-
-
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onBackClick:)];
-
- closeButton.tintColor = UIColorFromRGB(0x996633);
-
-
-
- self.navigationItem.leftBarButtonItem = closeButton;
-
-
-
- self.btnOpen = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onOpenOrderClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onOpenOrderClick:)];
-
- self.btnOpen.tintColor = UIColorFromRGB(0x996633);
-
-
-
- self.btnSign = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"signature"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onSignOrderClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onOpenOrderClick:)];
-
- self.btnSign.tintColor = UIColorFromRGB(0x996633);
-
-
- self.btnCopy =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"copy"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onCopyOrderClick:)];// [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Commit", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCommitOrderClick:)];
-
- self.btnCopy.tintColor = UIColorFromRGB(0x996633);
-
- // self.btnSend = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Email", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSendMailClick:)];
-
-
-
- self.btnRelease = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"unlock"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onReleaseOrderClick:)];
- self.btnRelease.tintColor = UIColorFromRGB(0x996633);
-
- self.btnPDF = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"sales_order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onDownloadOrderClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
-
-
- self.btnPDF.tintColor = UIColorFromRGB(0x996633);
-
- // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
- // item1.title = @"item1";
- //// item1.image = [UIImage imageNamed:@"rect_setting"];
- // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
- //// item2.image = [UIImage imageNamed:@"rect_about"];
- // item2.title = @"item2";
-
- // UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- // fixedItem.width = 0.0f;
-
- [items addObject:self.btnOpen];
- // [items addObject:fixedItem];
- // [items addObject:self.btnCommit];
- // [items addObject:fixedItem];
- [items addObject:self.btnRelease];
- // [items addObject:fixedItem];
- [items addObject:self.btnPDF];
- // [items addObject:fixedItem];
- [items addObject:self.btnSign];
- // [items addObject:fixedItem];
- [items addObject:self.btnCopy];
-
- // [items addObject:item2];
- self.navigationItem.rightBarButtonItems=items;
-
- self.btnOpen.enabled =false;
- self.btnSign.enabled = false;
-
- self.btnCopy.enabled =false;
- self.btnPDF.enabled =false;
- self.btnRelease.enabled =false;
- // if(self.isTempOrder)
- // {
- //
- //
- // self.btnOpen.enabled =true;
- //
- //
- // self.btnCommit.enabled =true;
- // }
- // else
- // {
- //
- // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
- //
- // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
- // self.btnOpen.enabled =false;
- // self.btnCommit.enabled =false;
- // }
- // Do any additional setup after loading the view.
-
-
- [self loaddata];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- }
- - (IBAction)onReleaseOrderClick:(id)sender {
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* order_json = [iSalesNetwork release_Order:self.order_code];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = nil;
- [appDelegate closeOrder];
-
- // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
- //
- // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
- // if(self.selectOrder)
- // self.selectOrder();
- [self.navigationController popToRootViewControllerAnimated:false];
-
- }
- else
- {
- [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
- }
-
-
-
- });
- });
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"Cancel");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
- // get customer info
-
-
-
-
- }
- - (void)onDownloadOrderClick:(id)sender {
-
-
-
- PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
-
- ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
-
- NSString* so = [self.content_data valueForKey:@"so#"];
- if(so==nil)
- so =@"";
-
- NSString* company = [self.content_data[@"customerInfo"] valueForKey:@"customer_name"];
- if(company==nil)
- company =@"";
-
-
- ViewController.save_name =so;
- ViewController.hidenavi = false;
- if(company==nil)
- company=@"";
- NSString* customer_email= [self.content_data[@"customerInfo"] valueForKey:@"customer_email"];
- NSMutableArray* arr_subject = [[NSMutableArray alloc]init];
-
- if(company.length>0)
- [arr_subject addObject:company];
- if(so.length>0)
- [arr_subject addObject:so];
-
-
-
- NSMutableArray* send_to = [[NSMutableArray alloc]init];
- if(customer_email.length>0)
- {
- send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
- // customer_email compo
- // [send_to addObject:customer_email];
- }
- ViewController.mail_to = send_to;
-
- NSString* subject=[arr_subject componentsJoinedByString:@" : "];
-
- ViewController.mail_subject = subject;
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"View Sales Order:" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Thumbnails" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- NSString* url=[self.content_data valueForKey:@"pdfUrl"];
-
-
- url= [url stringByAppendingString:@"&has_item_pic=true"];
- NSLog(@"pdf url:%@",url);
-
- ViewController.url = url;
-
-
- [self.navigationController pushViewController:ViewController animated:YES];
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Without Thumbnails" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSString* url=[self.content_data valueForKey:@"pdfUrl"];
- NSLog(@"pdf url:%@",url);
- ViewController.url = url;
- [self.navigationController pushViewController:ViewController animated:YES];
-
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
- // get customer info
-
- //
-
-
-
-
-
-
- }
- - (void)onCopyOrderClick:(id)sender {
-
- 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];
- [alert show];
-
- }
- //- (void)onCommitOrderClick:(id)sender {
- // // get customer info
- //
- // int model_count = [[self.content_data valueForKey:@"model_count"] intValue];
- // if(model_count==0)
- // {
- //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error." message:@"Can not submit an order without models." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- ////
- //// [alert show];
- //
- //
- // [RAUtils alert_view:@"Cannot submit an order without models" title:@""];
- // }
- //
- // else
- // {
- //
- // 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];
- // [alert show];
- //
- // }
- //
- //
- //}
- -(void) upload_img :(UIImage*) img
- {
-
-
-
-
-
-
-
-
- // UIAlertView * waitalert = [[UIAlertView alloc] initWithTitle:@"wait" message:@"uploading" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
- // [waitalert show];
-
- NSData *imageData = UIImagePNGRepresentation(img);
-
- AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
-
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.user!=nil)
- [params setValue:appDelegate.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(appDelegate.password!=nil)
- [params setValue:appDelegate.password forKey:@"password"];
-
-
- NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
- [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
- } error:nil];
-
-
- // NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
- // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"];
- // } error:nil];
- //
- AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
-
-
-
- //manager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
-
-
-
- //
- NSProgress *progress = nil;
-
- NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
-
- // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
-
-
-
-
- if (error) {
-
- NSString* err_msg = [error localizedDescription];
- NSLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
-
-
- NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- NSLog(@"data string: %@",str);
-
- [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
-
- } else {
- NSLog(@"response ");
-
-
-
- NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
-
- // 再将NSData转为字符串
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- NSLog(@"data string: %@",jsonStr);
-
- NSDictionary* json = responseObject;
-
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSString* img_url_down = json[@"img_url_aname"];
- NSString* img_url_up = json[@"img_url"];
-
- {
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Signature"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* order_json = [iSalesNetwork sign_Order:self.order_code path:img_url_up];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = self.order_code;
- // [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
- //
- //
- // appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
- //
- // appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
- // [self.navigationController popViewControllerAnimated:false];
- //
- // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- // if(self.selectOrder)
- // self.selectOrder(self.content_data);
-
- [self.content_data setValue:img_url_down forKey:@"sign_url"];
- //self.btnSign.enabled = false;
- [self.detailTable reloadData];
-
- [RAUtils message_alert:@"Successful." title:@"Signature" controller:self];
-
-
- }
- else
- {
- [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Signature" controller:self] ;
- }
-
-
-
- });
- });
- }
-
-
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
- }
-
-
-
-
-
-
- }
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- }];
-
- [uploadTask resume];
-
-
- }
- - (IBAction)onSignOrderClick:(id)sender {
-
- // SignatureViewController * vc;
-
- __block UIImage* signimg=nil;
- SignatureViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"SignatureViewController"];
-
- vc.onReturnImg = ^(UIImage* img)
- {
- signimg = img;
-
- if(signimg!=nil)
- [self upload_img:signimg];
-
-
- };
- // orderinfoVC.url_type = URL_REMOTE;
- // orderinfoVC.request_url=URL_CARTDELIVERY;
- //
- // orderinfoVC.params = params;
- //
- // orderinfoVC.delegate=self;
- //
- // if(checked.count==count)
- // {
- // orderinfoVC.have_tail = true
- // }
-
- [self.navigationController pushViewController:vc animated:true];
- }
- - (IBAction)onOpenOrderClick:(id)sender {
- // get customer info
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to open order?" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- {
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Open Order"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* order_json = [iSalesNetwork open_Order:self.order_code];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.order_code = self.order_code;
- [appDelegate SetSo:[self.content_data valueForKey:@"so#"]];
-
-
- appDelegate.customerInfo=[[self.content_data objectForKey:@"customerInfo"] mutableCopy];
-
- appDelegate.contact_id=[appDelegate.customerInfo valueForKey:@"customer_cid"];
- [self.navigationController popViewControllerAnimated:false];
-
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- if(self.selectOrder)
- self.selectOrder(self.content_data);
-
-
- }
- else
- {
- [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:self] ;
- }
-
-
-
- });
- });
- }
-
-
-
-
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"Cancel");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void) loaddata
- {
-
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if(self.isrefreshing)
- return;
-
- self.detailTable.hidden = true;
- self.label_net_err.hidden=true;
- self.isrefreshing=true;
-
- self.mum.center = self.view.center;
- self.mum.hidden = false;
- [self.mum startAnimating];
-
- NSLog(@"reloading...");
-
- self.web_info_height=0;
- self.web_moreinfo_height=0;
- self.content_data = nil;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* order_json = [iSalesNetwork request_OrderDetail:self.orderid];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
- [self.mum stopAnimating];
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- self.detailTable.hidden = false;
- self.content_data = [order_json mutableCopy];
-
-
- }
- else
- if([[order_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
- {
- self.label_net_err.hidden=false;
- self.detailTable.hidden=true;
- }
- else
- {
- [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Loading Order Detail" controller:self] ;
- }
-
- bool web_order =[[self.content_data valueForKey:@"from_online"] boolValue];
- if(web_order)
- self.btnCopy.enabled = false;
- else
- self.btnCopy.enabled = true;
- int model_count =[[self.content_data valueForKey:@"model_count"] intValue];
- if(model_count>0)
- self.btnPDF.enabled =true;
- // [self.btnPDF setImage:[[UIImage imageNamed:@"download"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
-
- NSString* status = [self.content_data valueForKey:@"order_status"];
- NSString* lock_user = [self.content_data valueForKey:@"opened_customer"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if([status isEqualToString:@"SO Saved"])
- {
- // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
- //
- // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
- self.btnOpen.enabled =true;
-
- self.btnSign.enabled = true;
- // if([lock_user isEqualToString:appDelegate.user])
- // {
- // self.btnCommit.enabled =true;
- // }
- // else
- // self.btnCommit.enabled =false;
- }
- else
- if([status isEqualToString:@"Quote Saved"])
- {
- // [self.btnOpen setImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
- //
- // [self.btnCommit setImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
- self.btnOpen.enabled =true;
-
- self.btnSign.enabled = true;
- // self.btnCommit.enabled =false;
- }
-
- if([lock_user isEqualToString:appDelegate.user])
- {
- // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
-
-
- self.btnRelease.enabled =true;
- }
- else
- {
-
-
- // [self.btnRelease setImage:[[UIImage imageNamed:@"order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
- self.btnRelease.enabled =false;
- }
-
- [self.detailTable reloadData];
- self.isrefreshing=false;
-
- });
-
- });
- });
- }
- - (void)viewWillAppear:(BOOL)animated
- {
-
-
- // if(appDelegate.can_submit_order)
- // {
- //
- //
- // [self.btnCommit setImage:[UIImage imageNamed:@"commit"]];
- // self.btnCommit.enabled = true;
- // }
- // else
- // {
- // [self.btnCommit setImage:nil];
- // self.btnCommit.enabled = false;
- // }
- //
- [[self navigationController] setNavigationBarHidden:NO animated:NO];
- }
- - (IBAction)imgbtnClicked:(UIButton*)sender {
- UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
-
- NSIndexPath * indexPath = [self.detailTable indexPathForCell:cell];
-
- if(indexPath.section!=1)
- return ;
- // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
- NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
-
- NSString* product_id = [item_json valueForKey:@"product_id"];
-
- DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
- // dvc
-
- dvc.product_id=product_id;
- dvc.category_id=nil;
- dvc.ispush=true;
- [dvc reload];
- [self.navigationController pushViewController:dvc animated:true];
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark - Table view data source
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- // if([item_json objectForKey:@"combine"] == nil)
- // {
- // return 120;
- // }
- // else
- // return 150;
-
- switch (indexPath.section) {
- case 0:
- {
- if(indexPath.row==0)
- {
- float height= self.web_info_height;
- if(height==0)
- height=DEF_TABLE_HEIGHT;
-
-
- return height;
- }
- else
- return 148;
-
- }
- break;
-
- case 1:
- {
- float height= self.web_moreinfo_height;
- if(height==0)
- height=DEF_TABLE_HEIGHT;
-
-
- // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
- //wait(1000);
- return height;
- }
- break;
- case 2:
-
- {
- NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
-
- NSString* notes =[item_json valueForKey:@"note"];
- if(notes.length>0)
- {
- return 190;
- }
- else
- return 162;
- }
- case 3:
- return 44;
- default:
- break;
- }
- return 44;
-
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // return myView;
- //
- //}
- //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
- //// titleLabel.textColor=[UIColor whiteColor];
- //// titleLabel.backgroundColor = [UIColor clearColor];
- //// if(section==0)
- //// titleLabel.text=NSLocalizedString(@"display_items", nil);
- //// else
- //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
- //// [titleLabel sizeToFit];
- //// [myView addSubview:titleLabel];
- ////
- // return myView;
- //}
- //
- - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
-
- UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- myView.backgroundColor = UIColorFromRGB(0x996633);;
-
-
- myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
- // myView.layer.masksToBounds = false;
- //添加四个边阴影
-
- myView.layer.shadowColor = [UIColor blackColor].CGColor;
- myView.layer.shadowOffset = CGSizeMake(0, 0);
- myView.layer.shadowOpacity = 0.5;
- myView.layer.shadowRadius = 2.0;
-
-
- NSString*labeltitle = nil;
- switch (section) {
- case 0:
- labeltitle= @"Order Info";
- break;
- case 1:
- {
- labeltitle= @"More Info";
-
- NSString* btntitle=nil ;
- if(self.showMore)
- {
- btntitle=@"Hide";
- // [section setValue:@"false" forKey:@"hide"];
- // [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- btntitle=@"Show";
- }
-
-
- UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
- btn.tag=section;
- [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitle:btntitle forState:UIControlStateNormal];
- [myView addSubview:btn];
-
- }
- break;
- case 2:
- labeltitle= @"Models";
- break;
- case 3:
- labeltitle= @"Price Info";
- default:
- break;
- }
-
-
-
- UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
- titlelabel.textColor=[UIColor whiteColor];
- titlelabel.backgroundColor = [UIColor clearColor];
- titlelabel.text=NSLocalizedString(labeltitle, nil);
- [titlelabel sizeToFit];
- [myView addSubview:titlelabel];
-
- //
- return myView;
- }
- #pragma mark - hide section button clicked
- - (void)HideSction:(UIButton *)sender {
- /*
- NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",sender.tag]] mutableCopy];
- bool hide = [[section valueForKey:@"hide"]boolValue];
- if(hide)
- {
- [section setValue:@"false" forKey:@"hide"];
- [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- [section setValue:@"true" forKey:@"hide"];
- [sender setTitle:@"Hide" forState:UIControlStateNormal];
- }
-
- [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",sender.tag]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- */
-
- self.showMore=!self.showMore;
- NSRange range = NSMakeRange(1, 1);
- NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
-
- }
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- switch (section) {
- case 0:
- return @"Order Info";
- break;
- case 1:
- return @"More Info";
- break;
- case 2:
- return @"Models";
- case 3:
- return @"Price Info";
- default:
- break;
- }
- return nil;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- if(self.content_data==nil)
- return 0;
- return 4;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 33;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
- if(section==0)
- return 2;
- if(section==1)
- {
- if(self.showMore)
- return 1;
- else
- return 0;
- }
-
- if(section==2)
- {
- int count =[[self.content_data valueForKey:@"model_count"] intValue];
- return count;
- }
- if(section==3)
- return 5;
- return 0;
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- switch(indexPath.section)
- {
- case 0:
- {
-
- if(indexPath.row==0)
- {
- NSString *CellIdentifier = @"OrderDetailHtmlCell";
- OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
-
-
-
-
- cell.webview.tag = indexPath.section;
-
- cell.webview.delegate = self;
- // cell.webView.scrollView.contentSize.height = 0;
- cell.webview.scrollView.bounces=NO;
- cell.webview.scrollView.directionalLockEnabled = true;
- CGSize size= cell.webview.scrollView.contentSize;
- size.height=10;
- cell.webview.scrollView.contentSize=size;
-
- [cell.webview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- {
-
- NSString *CellIdentifier = @"OrderDetailSignatureCell";
- OrderDetailSignatureCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* img_url = [self.content_data valueForKey:@"sign_url"];
-
-
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.sign_img.image=img ;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
- [iSalesDB cache_img:downloadimg_data :file_name ];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.sign_img.image=img ;
- }
- else
- cell.sign_img.image=[UIImage imageNamed:@"taptosign_s"];
-
-
- });
- });
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
-
- }
- }
- break;
- case 1:
- {
- NSString *CellIdentifier = @"OrderDetailHtmlCell";
- OrderDetailHtmlCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
-
-
-
- cell.webview.tag = indexPath.section;
- cell.webview.delegate = self;
- // cell.webView.scrollView.contentSize.height = 0;
- cell.webview.scrollView.bounces=NO;
- cell.webview.scrollView.directionalLockEnabled = true;
- CGSize size= cell.webview.scrollView.contentSize;
- size.height=10;
- cell.webview.scrollView.contentSize=size;
-
-
-
- [cell.webview loadHTMLString:[self.content_data valueForKey:@"more_order_info"] baseURL:nil];
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
-
- // NSString *CellIdentifier = @"OrderDetailInfoCell";
- // OrderDetailInfoCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- //
- // cell.infoLabel.text =[self.content_data valueForKey:@"more_order_info"];
- //
- //
- //
- //// float width = tableView.frame.size.width;
- //// width-=CELL_MARGIN*2;
- //// CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
- ////
- //// NSString* key =[self.content_data valueForKey:@"order_info"];
- ////
- ////
- ////
- //// CGRect frame;
- //// frame.size = constraintkey;
- //// frame.origin.x=0;
- //// frame.origin.y=0;
- ////
- //// RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
- ////
- //// [rtlabel setText: key];
- //// CGSize optimumSize = [rtlabel optimumSize];
- ////
- //// float height = optimumSize.height;
- //// height = MAX(height+LINE_WIDTH+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
- ////
- ////
- //// frame.origin.x=LABEL_MARGIN;
- //// frame.size=CGSizeMake(width, height);
- ////
- //// cell.infoLabel.frame = frame;
- //
- //
- //
- //
- // cell.backgroundColor = [UIColor whiteColor];
- // return cell;
- }
- break;
- case 2:
- {
- NSString *CellIdentifier = @"OrderDetailModelCell";
- OrderDetailModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
-
- int count = [[item_json valueForKey:@"count"] intValue];
- NSDictionary * combine_json =[item_json objectForKey:@"combine"];
- cell.bundle_item=combine_json;
-
- double dprice=0.0;
-
- if(cell.bundle_item!=nil)
- {
- int citem=0;
-
- int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
- for(int bc=0;bc<bcount;bc++)
- {
- NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
- int modulus= [[bitem valueForKey:@"modulus"] intValue];
- citem+= modulus;
- double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
- dprice+= uprice*modulus*count;
-
- }
- if(citem==1)
- [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
- else
- [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
-
- cell.buttonBundle.hidden = NO;
- }
- else
- {
- cell.buttonBundle.hidden = YES;
-
- }
-
-
-
- NSString* img_url = [item_json valueForKey:@"img"];
- NSString* description = [item_json valueForKey:@"Item Number"];
- // NSString* description = [item_json valueForKey:@"Item Number"];
- NSString* unitprice = [item_json valueForKey:@"The unit price"];
- NSString* origin_price = [item_json valueForKey:@"origin_price"];
- NSString* subtotal = [item_json valueForKey:@"Subtotal"];
- NSString* qty = [item_json valueForKey:@"QTY"];
- NSString* status = [item_json valueForKey:@"order_item_status"];
- NSString* notes = [item_json valueForKey:@"note"];
-
- if(notes.length>0)
- {
- cell.noteLabel.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
- }
- else
- cell.noteLabel.text = nil;
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- unitprice=nil;
- origin_price=nil;
- subtotal=nil;
- }
-
- cell.descriptionLabel.text=description;
- cell.unitpriceLabel.text = unitprice;
- cell.subtotalLabel.text = subtotal;
- cell.qtyLabel.text = qty;
- cell.statusLabel.text = status;
-
-
- cell.labelOldPrice.text = origin_price;
-
- double discount =[[item_json valueForKey:@"discount"] doubleValue];
- NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
- cell.labelDiscount.text = discountstr;
- bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
- if(isfree)
- {
- cell.labelOldPrice.hidden = false;
- cell.labelOldPrice.textColor = [UIColor redColor];
- cell.labelOldPrice.text=@"Free";
- cell.labelOldPrice.hideline = true;
-
- cell.labelDiscount.hidden = true;
- }
- else
- {
- cell.labelOldPrice.textColor = [UIColor blackColor];
- cell.labelOldPrice.hideline = false;
- if(discount==0)
- {
- cell.labelOldPrice.hidden = true;
- cell.labelDiscount.hidden = true;
-
- }
- else
- {
- cell.labelOldPrice.hidden = false;
- cell.labelDiscount.hidden = false;
- }
- }
-
- [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
- [iSalesDB cache_img:downloadimg_data :file_name ];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- [cell.imgbtn setBackgroundImage:img forState:UIControlStateNormal];
- }
- else
- [cell.imgbtn setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
-
-
- });
- });
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }
- break;
-
- case 3:
- {
- NSString *CellIdentifier = @"OrderDetailPriceCell";
- OrderDetailPriceCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- switch (indexPath.row) {
- case 0:
- {
- cell.chargeLabel.text =@"Payments/Credits:";
- NSString* price=[self.content_data valueForKey:@"Payments/Credits"];
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- price=nil;
- }
- cell.priceLabel.text =price;
- break;
- }
- case 1:
- cell.chargeLabel.text = @"Shipping:";
- cell.priceLabel.text =[self.content_data valueForKey:@"Shipping"];
- break;
- case 2:
- cell.chargeLabel.text = @"Lift Gate Fee:";
- cell.priceLabel.text =[self.content_data valueForKey:@"Lift Gate Fee"];
- break;
- case 3:
- cell.chargeLabel.text = @"Handling Fee:";
- cell.priceLabel.text =[self.content_data valueForKey:@"Handling Fee"];
- break;
- case 4:
- {
- NSString* price=[self.content_data valueForKey:@"Total"];
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- price=nil;
- }
- cell.chargeLabel.text = @"Total:";
- cell.priceLabel.text =price;
- break;
- }
- default:
- break;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- }
- return nil;
- // if(tableView==self.itemListTable)
- // {
- // NSString *CellIdentifier = @"CartItemCell";
- // ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
- //
- // cell.bundle_item=combine_json;
- // NSString* img_url = [item_json valueForKey:@"img_url"];
- // NSString* description = [item_json valueForKey:@"description"];
- // // NSString* identifier = [item_json valueForKey:@"identifier"];
- // // NSString* attribute = [item_json valueForKey:@"attribute"];
- // NSString* currency = [item_json valueForKey:@"currency"];
- // int count =[[item_json valueForKey:@"count"] intValue];
- //
- // int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
- //
- // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
- //
- // double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
- // cell.unit_price = unitprice;
- // // cell.labelAttribute.text = attribute;
- // // cell.labelCurrency.text = currency;
- // cell.labelDescription.text = description;
- // // cell.labelIdentifier.text = identifier;
- // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
- //
- // cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
- //
- //
- //
- // NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
- // cell.cart_id = cart_item_id;
- // [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
- //
- //
- //
- // [cell set_Count:count];
- //
- // NSString* file_name=[img_url lastPathComponent];
- // NSData* img_data=[iSalesDB load_cached_img:file_name];
- // if(img_data!=nil)
- // {
- //
- // UIImage * img =[UIImage imageWithData:img_data];
- // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
- // }
- // else
- // {
- //
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //
- //
- // if(downloadimg_data!=nil)
- // {
- // [iSalesDB cache_img:downloadimg_data :file_name ];
- //
- // UIImage * img =[UIImage imageWithData:downloadimg_data];
- // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
- // }
- //
- // });
- // });
- //
- //
- // }
- // return cell;
- // }
- // else
- // {
- // NSString *CellIdentifier = @"OrderInfoListItem";
- // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- // return cell;
- // }
- }
- #pragma mark - UIAlertViewDelegate
- // Called when a button is clicked. The view will be automatically dismissed after this call returns
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
-
- if(buttonIndex!=alertView.cancelButtonIndex)
- {
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Copy Order"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* order_json = [iSalesNetwork copy_Order:self.order_code];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- // NSString* orderCode = [order_json valueForKey:@"orderCode"];
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if([appDelegate.order_code isEqualToString: self.order_code])
- // {
- // [appDelegate closeOrder];
- //// appDelegate.order_code= nil;
- // [appDelegate SetSo:nil];
- //
- //
- // }
- 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];
-
- [alert show];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [self.navigationController popViewControllerAnimated:false];
-
- }
- else
- {
- [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Cpoy Order" controller:self] ;
- }
-
-
-
- });
- });
-
-
-
-
-
-
-
- }
- }
- #pragma mark - web view delegate
- //- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
- //{
- // if(navigationType != UIWebViewNavigationTypeLinkClicked)
- // return true;
- // // NSString *currentURL =[webView.request.URL lastPathComponent];// [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
- //
- // NSString* str = request.URL.absoluteString;
- // if([str isEqualToString:@"about:blank"])
- // return true;
- // WebViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
- // ViewController.url = str;
- // // ViewController. = self.function_name;
- // // ViewController.behavior =BEHAVIOR_SEARCH;
- //
- // [self.navigationController pushViewController:ViewController animated:YES];
- // DebugLog(@"shouldStartLoadWithRequest");
- // return false;
- //}
- - (void)webViewDidFinishLoad:(UIWebView *)webView
- {
-
-
- DebugLog(@"webViewDidFinishLoad @@@@@@@@@@@@@@@@@ entry");
-
-
-
- UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
-
-
- NSIndexPath *indexPath = [self.detailTable indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (UITableViewCell *) webView.superview.superview.superview;
- indexPath = [self.detailTable indexPathForCell:cell];
- }
- float height= 0;
- if(indexPath.section==0)
- height=self.web_info_height;
- else
- height = self.web_moreinfo_height;
-
- if(height>0)
- return;
-
-
- // UIScrollView *scrollerView = [webView.subviews objectAtIndex:0];
- // CGSize size= webView.scrollView.contentSize;
- // CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
-
- CGRect frame = webView.frame;
- NSString *fitHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
- frame.size.height = [fitHeight floatValue];
- //webView.frame = frame;
-
-
- // DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^Saveheight height=%f section=%ld",webView.scrollView.contentSize.height,indexPath.section);
-
- if(indexPath.section==0)
- self.web_info_height=frame.size.height;
- else
- self.web_moreinfo_height = frame.size.height;
- // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
-
- DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^reloadRowsAtIndexPaths");
-
-
-
- // [self.table beginUpdates];
- [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
- // [self.table endUpdates];
-
- // [self.webviewoprationQueue addOperationWithBlock:^{
- // }];
-
-
- // [self.table endUpdates];
- // }
-
-
- }
- @end
|