| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535 |
- //
- // PortfolioViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 12/7/15.
- // Copyright © 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "PortfolioViewController.h"
- #import "iSalesNetwork.h"
- #import "ModelItemCell.h"
- #import "DetailViewController.h"
- #import "LoginViewController.h"
- #import "MainViewController.h"
- #import "TearSheetParamViewController.h"
- #import "EditModelPriceViewController.h"
- #import "ContactListViewController.h"
- #import "PortfolioEditQTYViewController.h"
- #import "PDFViewController.h"
- #import "DefaultTableHeaderView.h"
- #import "DefaultAppearance.h"
- #define ALERT_DEL 1025
- @interface PortfolioViewController ()
- @end
- @implementation PortfolioViewController
- -(void) logout
- {
- self.content_data = nil;
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- -(void) reload_container_getdata:(bool) update_data
- {
- [super reload_container_getdata:update_data];
- if(update_data)
- [self reload_data];
- else
- [self.itemListTable reloadData];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.can_create_portfolio)
- {
-
-
- [self.btnCreatePort setTitle:@"Create Portfolio"];
- self.btnCreatePort.enabled = true;
- }
- else
- {
- [self.btnCreatePort setTitle:@""];
- self.btnCreatePort.enabled = false;
- }
- }
- -(void) showHidePrice
- {
- [self reload_container_getdata:false];
- // [self refresh_total];
-
- }
- - (IBAction)onAddtoCart:(id)sender {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(appDelegate.bLogin==false)
- {
-
- LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
- loginvc.returnValue = ^(bool blogin){
-
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
-
- if(blogin)
- {
- if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- {
-
- [main_vc checklogin:false];
-
- if(appDelegate.can_create_order)
- {
- NSString* msg =@"";
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
-
-
-
- // alert.
- [alert show];
- }
- else
- {
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil), nil];
-
- // alert.
- [alert show];
- }
- }
- else
- {
- [main_vc checklogin:true];
- }
- }
-
- // self.offset = 0;
- // [self.content_data removeAllObjects];
- // [self loadpage];
- //
- // [[self navigationController] setNavigationBarHidden:YES animated:NO];
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- NSLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
- if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
- {
- [main_vc checklogin:false];
- if(appDelegate.can_create_order)
- {
- NSString* msg =@"";
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
-
- // alert.
- [alert show];
- }
- else
- {
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil), nil];
-
- // alert.
- [alert show];
- }
- }
- else
- {
-
- if(appDelegate.order_code==nil)
- [ self neworder];
- else
- [self addtocart];
-
-
-
- }
- }
-
- }
- -(void) addtocart
- {
-
-
- NSMutableArray* checked = [[NSMutableArray alloc] init];
-
- NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
-
- int count = [[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- bool check = [[item_json valueForKey:@"check"] boolValue];
- if(check)
- {
- [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
- [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
- }
- }
-
- if(checked.count==0)
- {
- [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to cart." controller:self] ;
- return;
- }
-
- NSString * ids = [checked componentsJoinedByString:@","];
- self.btnCreatePort.enabled = false;
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [iSalesNetwork add_toCart:ids count:-1];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- self.btnCreatePort.enabled = true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- // int result=[[return_json valueForKey:@"result"] intValue];
- // if(result==2)
- // {
- // //successed.
-
- // NSString* order_code = [return_json valueForKey:@"order_code"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = order_code;
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = order_code;
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false ];
-
-
- NSString * msg = nil;
- if(checked.count==1)
- {
- msg=@"1 item added to Cart";
- }
- else
- {
- msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
- }
-
- [RAUtils message_alert:nil title:msg controller:self] ;
-
- // [self end_select];
-
-
-
- // }
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- }
-
-
-
-
- });
- });
- }
- -(void) neworder
- {
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [iSalesNetwork new_Order];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- int result=[[return_json valueForKey:@"result"] intValue];
- if(result==2)
- {
- //successed.
-
- NSString* order_code = [return_json valueForKey:@"orderCode"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.order_code = order_code;
-
-
- [self addtocart];
-
-
- // [self ReloadData];
-
-
- // if(self.shopCartBlock!=nil)
- // {
- // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
- //
- //
- // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- // iv.image = img;
- // // [self.contentView addSubview:iv];
- // self.shopCartBlock(iv);
- //
- // }
-
- }
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- }
-
-
-
-
- });
- });
- }
- - (IBAction)onCreateTearSheet:(id)sender {
-
-
- self.pdf_url= nil;
- NSMutableArray* checked = [[NSMutableArray alloc] init];
-
- NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
-
- int count = [[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- bool check = [[item_json valueForKey:@"check"] boolValue];
- if(check)
- {
- [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
- [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
- }
- }
- // disable for debug
- if(checked.count==0)
- {
- [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Create Portfolio." controller:self] ;
- return;
- }
-
-
-
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
- NSString * string = [checked componentsJoinedByString:@","];
-
- NSString * string_iid = [checked_iid componentsJoinedByString:@","];
- [params setValue:string forKey:@"product_ids"];
- [params setValue:string_iid forKey:@"item_ids"];
- TearSheetParamViewController * VC =[ self.storyboard instantiateViewControllerWithIdentifier:@"TearSheetParamViewController"];
-
-
- VC.url_type = URL_REMOTE;
- VC.request_url=URL_DM_PARAMS;
-
- VC.params = params;
-
- // VC.delegate=self;
-
- VC.return_url=^(NSString* url,NSString* path, bool remove_item)
- {
- self.pdf_url = url;
- self.path = path;
- self.remove_item = remove_item;
- };
- VC.onSaved=^(NSString* url,NSString* name)
- {
- // NSString* name=[self.content_data[indexPath.row] valueForKey:@"tear_name"];
- // NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
-
- PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
- ViewController.url = url;
- ViewController.canSave = false;
- NSString* subject;
- // if (company.length==0) {
-
- NSString* cur_time =[RAUtils current_date];
- subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
-
-
- 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;
-
- // }
- // else
- // {
- // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
- // }
- ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
- ViewController.mail_subject = subject;
-
- ViewController.hidenavi = false;
- [self.navigationController pushViewController:ViewController animated:YES];
- };
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- VC.onDismiss=^(NSString* catelog_name)
- {
-
- };
-
- //
- // if(checked.count==count)
- // {
- // orderinfoVC.have_tail = true
- // }
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:VC] ;
-
-
-
-
-
- navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- NSLog(@"TearSheetParamViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- [self.btnselect setTitle:@"Select all"];
-
-
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- // UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.000001)];
- // [line setBackgroundColor:[UIColor clearColor]];
- // self.itemListTable.tableHeaderView = line;
- //
- 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.itemListTable addSubview:ref];
-
- // [[UIToolbar appearance] setBackgroundColor: [UIColor whiteColor]];
-
- 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];
-
-
- }
- -(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!!!!!!!!");
-
- }
- - (IBAction)onSelectClick:(id)sender {
- // self.total=0;
-
-
- if([self.btnselect.title isEqualToString:@"Select all"])
- {
- int count =[[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- [item_json setValue:@"1" forKey:@"check"];
-
- ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
- cell.img_checkmark.hidden=false;
- // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
-
- [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
-
-
- }
-
- [self.btnselect setTitle:@"Deselect all"];
-
-
- }
- else
- {
- int count =[[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)i]] mutableCopy];
- [item_json setValue:@"0" forKey:@"check"];
-
- ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
- cell.img_checkmark.hidden=true;
- [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
-
- }
-
- [self.btnselect setTitle:@"Select all"];
- // self.btnselect.titleLabel.text=@"Select all";
- }
-
- }
- - (IBAction)onEditClick:(id)sender {
- NSMutableArray* checked = [[NSMutableArray alloc] init];
- NSMutableArray* fashion_ids = [[NSMutableArray alloc] init];
-
-
- int count = [[self.content_data valueForKey:@"count"] intValue];
- int single_idx=0;
- for(int i=0;i<count;i++)
- {
-
-
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- int check = [[item_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- single_idx = i;
- [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
- [fashion_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"fashion_id"] intValue]]];
- }
- }
- // disable for debug
- if(checked.count==0)
- return;
- if(checked.count==1)
- {
- //只选中一个和右滑一样处理。
- {
-
- NSLog(@"edit click");
-
-
-
- UIViewController* parentvc=self;
-
-
-
-
- PortfolioEditQTYViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
-
-
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",single_idx]] mutableCopy];
-
- vc.arr_fashion_ids = fashion_ids;
-
- // vc.fashionid = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]];
- if([[item_json allKeys] containsObject:@"available_qty"])
- vc.qty = [[item_json valueForKey:@"available_qty"] intValue];
- else
- vc.qty=-1;
- if([[item_json allKeys] containsObject:@"available_percent"])
- vc.qty_p = [[item_json valueForKey:@"available_percent"] intValue];
- else
- vc.qty_p=-1;
- vc.linenotes=[item_json valueForKey:@"linenotes"] ;
- vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
- vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
- vc.title=@"Edit Portfolio";
-
- // vc.delegate = parentvc.self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- vc.onSetValue = ^(int qty,double qty_p, double price, double discount , NSString* notes){
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Updating Quantity"];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = nil;
-
- cart_json= [iSalesNetwork portfolio_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty qty_p:qty_p notes:notes];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- if(qty>=0)
- item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
- else
- [item_json removeObjectForKey:@"available_qty"];
- if(qty_p>=0)
- item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
- else
- [item_json removeObjectForKey:@"available_percent"];
- item_json[@"linenotes"]=notes;
- item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
- item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
- self.content_data[[NSString stringWithFormat:@"item_%d",single_idx]]=item_json;
- // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
- [self.itemListTable reloadData];
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
- }
-
-
-
-
- });
- });
- //
- //
- //
- // [self reload_data];//[main_vc checklogin:true];
- };
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [parentvc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- NSLog(@"EditModelPriceViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- // [//tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
-
-
-
-
- }
- return;
- }
- // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
- NSString * ids = [checked componentsJoinedByString:@","];
-
- {
-
- NSLog(@"edit click");
-
-
-
- UIViewController* parentvc=self;
-
-
-
-
- PortfolioEditQTYViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
-
-
- // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
-
- vc.arr_fashion_ids = nil;
- vc.ids_count=checked.count;
-
- // vc.fashionid = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]];
- // vc.qty = [[item_json valueForKey:@"available_qty"] intValue];
- //
- // vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
- // vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
-
-
- // vc.delegate = parentvc.self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- vc.onSetValue = ^(int qty,double qty_p,double price, double discount , NSString* notes){
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Updating Quantity"];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = nil;
-
- cart_json= [iSalesNetwork portfolio_setPrice:ids price:-1 discount:discount QTY:qty qty_p:qty_p notes:notes];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- [RAUtils message_alert:[NSString stringWithFormat:@"%d items saved.",checked.count] title:@"Edit Portfolio" controller:self] ;
- [self reload_data];
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
- }
-
-
-
-
- });
- });
- //
- //
- //
- // [self reload_data];//[main_vc checklogin:true];
- };
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [parentvc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- NSLog(@"EditModelPriceViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
-
-
-
-
- }
- }
- - (IBAction)onDeleteClick:(id)sender {
- NSMutableArray* checked = [[NSMutableArray alloc] init];
-
-
-
- int count = [[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- int check = [[item_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
-
- }
- }
- // disable for debug
- if(checked.count==0)
- return;
-
- // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
- NSString * string = [checked componentsJoinedByString:@","];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = [iSalesNetwork portfolio_remove:string];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- [self reload_data];
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Portfolio" controller:self] ;
- }
-
- });
- });
-
-
- }
- -(void) viewWillAppear:(BOOL)animated
- {
-
- [super viewWillAppear:animated];
-
- [[self navigationController] setNavigationBarHidden:YES animated:NO];
- }
- -(void) reload_data
- {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- if(self.isrefreshing)
- return;
- self.isrefreshing=true;
- self.label_net_err.hidden=true;
- self.itemListTable.hidden=true;
- [self.content_data removeAllObjects];
- [self.itemListTable reloadData];
- self.mum.center = self.view.center;
-
- self.mum.hidden = false;
- [self.mum startAnimating];
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = [iSalesNetwork request_Portfolio];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.mum stopAnimating];
-
- int result=[[cart_json valueForKey:@"result"] intValue];
-
- if(result==2||result==1||result==0)
- {
- self.itemListTable.hidden=false;
- self.content_data = [cart_json mutableCopy];
- [self.itemListTable reloadData];
-
- [self.btnselect setTitle: @"Deselect all"];
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- appDelegate.port_count =[[self.content_data valueForKey:@"count"] intValue];
- }
- else
- if(result==RESULT_NET_ERROR)
- {
- self.label_net_err.hidden=false;
- self.itemListTable.hidden=true;
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Portfolio" controller:self] ;
- }
-
- self.isrefreshing=false;
-
- });
- });
- });
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- //{
- //
- // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
- //
- //
- //
- // [self.itemListTable reloadData];
- //
- //
- //
- //}
- #pragma mark - Table view data source
- //- (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;
- //}
- //
- //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- // if(section==0)
- // return nil;
- // else
- // return @"detail section";
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
-
- return 33;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
-
-
-
- NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
-
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
-
- NSString *sectionTitle = @"Portfolio";
-
- DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 33)];
-
-
- UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5.5, tableView.bounds.size.width, 22)];
- titlelabel.textColor=UIColorFromRGB(color);
- titlelabel.textAlignment=NSTextAlignmentCenter;
- titlelabel.autoresizingMask=UIViewAutoresizingFlexibleWidth;
-
- titlelabel.text=sectionTitle;
- titlelabel.center = myView.center;
-
- myView.autoresizesSubviews=true;
-
- [myView addSubview:titlelabel];
-
-
- return myView;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
- int count =[[self.content_data valueForKey:@"count"] intValue];
- return count;
-
- }
- - (IBAction)imgbtnClicked:(UIButton *)sender {
- UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
-
- NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
- // 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];
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(tableView==self.itemListTable)
- // {
- NSString *CellIdentifier = @"WatchListItemCell";
- ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
-
- NSString* img_url = [item_json valueForKey:@"img"];
- 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];
- float discount = [[item_json valueForKey:@"tear_sheet_discount"] floatValue];
- float price =[[item_json valueForKey:@"tear_sheet_price"] floatValue];
- // cell.labelAttribute.text = attribute;
- // cell.labelCurrency.text = currency;
- cell.labelDescription.text = description;
- // cell.labelIdentifier.text = identifier;
-
-
- int qty;
- if([[item_json allKeys] containsObject:@"available_qty"])
- qty= [[item_json valueForKey:@"available_qty"] intValue];
- else
- qty=-1;
- float qty_p;
-
- if([[item_json allKeys] containsObject:@"available_percent"])
- qty_p= [[item_json valueForKey:@"available_percent"] floatValue];
- else
- qty_p=-1;
-
-
- // if(![[item_json allKeys] containsObject:@"available_qty"])
- // {
- // cell.available_qty_label.hidden=true;
- // cell.available_qty_value_label.hidden=true;
- // }
- // else
- // {
- // cell.available_qty_label.hidden=false;
- // cell.available_qty_value_label.hidden=false;
- // cell.available_qty_value_label.text = [NSString stringWithFormat:@"%d",qty];
- //
- // }
-
-
- if(qty>=0)
- {
- cell.available_qty_label.hidden=false;
- cell.available_qty_value_label.hidden=false;
- cell.available_qty_value_label.text = [NSString stringWithFormat:@"%d",qty];
- }
- else if(qty_p>=0)
- {
- cell.available_qty_label.hidden=false;
- cell.available_qty_value_label.hidden=false;
- cell.available_qty_value_label.text = [NSString stringWithFormat:@"%.2f %%",qty_p];
- }
- else
- {
- cell.available_qty_label.hidden=true;
- cell.available_qty_value_label.hidden=true;
- }
- NSString* str_price =[NSString stringWithFormat:@"%.2f",price * (1.0-discount/100)];
- bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
- if(noprice)
- str_price=@"No Price";
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- str_price=nil;
- }
- cell.labelPrice.text = str_price;
- // cell.labelPrice.text = price;
- // cell.editCount.text =[NSString stringWithFormat:@"%d",count];
-
- // NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[item_json valueForKey:@"check"] intValue];
- if(check==1)
- cell.img_checkmark.hidden=false;
- else
- cell.img_checkmark.hidden=true;
-
- // UIImageView* iv =cell.btnImage.imageView;
- [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
- // cell.btnImage.imageView.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 filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
- }
- else
- [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
-
-
- });
- });
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];// [UIColor whiteColor];;
- return cell;
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
-
- cell.selected = false;
- // self.dirty = true;
-
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
- int check = [[item_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- [item_json setValue:@"0" forKey:@"check"];
- cell.img_checkmark.hidden=true;
- [self.btnselect setTitle: @"Select all"];
- }
- else
- {
- [item_json setValue:@"1" forKey:@"check"];
- cell.img_checkmark.hidden=false;
- }
- [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
-
-
-
- }
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- return UITableViewCellEditingStyleDelete;
- }
- //#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
- //{
- //
- //
- //
- //}
- - (BOOL)isPureFloat:(NSString*)string{
- NSScanner* scan = [NSScanner scannerWithString:string];
- float val;
- return[scan scanFloat:&val] && [scan isAtEnd];
- }
- #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
- - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- // 添加一个删除按钮
-
- self.indexPath=indexPath;
-
- UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
-
- NSLog(@"delete click");
-
-
-
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure remove model from portfolio?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
- alert.tag = ALERT_DEL;
- // alert.
- [alert show];
-
-
-
-
-
-
- }];
- deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
-
-
- // edit qty
-
- UITableViewRowAction *EditQTYAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" Edit " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
-
- NSLog(@"edit click");
-
-
-
- UIViewController* parentvc=self;
-
-
-
-
- PortfolioEditQTYViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
-
-
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
-
- vc.arr_fashion_ids = [[NSArray arrayWithObject:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]]] mutableCopy];
- // vc.fashionid = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]];
- if([[item_json allKeys] containsObject:@"available_qty"])
- vc.qty = [[item_json valueForKey:@"available_qty"] intValue];
- else
- vc.qty=-1;
- if([[item_json allKeys] containsObject:@"available_percent"])
- vc.qty_p = [[item_json valueForKey:@"available_percent"] intValue];
- else
- vc.qty_p=-1;
- vc.linenotes=[item_json valueForKey:@"linenotes"] ;
- vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
- vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
- vc.title=@"Edit Portfolio";
-
- // vc.delegate = parentvc.self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- vc.onSetValue = ^(int qty,double qty_p, double price, double discount , NSString* notes){
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Updating Quantity"];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = nil;
-
- cart_json= [iSalesNetwork portfolio_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty qty_p:qty_p notes:notes];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- if(qty>=0)
- item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
- else
- [item_json removeObjectForKey:@"available_qty"];
- if(qty_p>=0)
- item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
- else
- [item_json removeObjectForKey:@"available_percent"];
- item_json[@"linenotes"]=notes;
- item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
- item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
- self.content_data[[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]=item_json;
- // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
- [self.itemListTable reloadData];
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Portfolio" controller:self] ;
- }
-
-
-
-
- });
- });
- //
- //
- //
- // [self reload_data];//[main_vc checklogin:true];
- };
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [parentvc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- NSLog(@"EditModelPriceViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
-
-
-
-
- }];
- EditQTYAction.backgroundColor = UIColorFromRGB(0xff9933);
-
-
-
-
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- {
- NSMutableArray* arr=[@[] mutableCopy];
-
- [arr addObject:deleteRowAction];
- if(appDelegate.can_set_tearsheet_price)
- {
- //[arr addObject:editRowAction];
- [arr addObject:EditQTYAction];
- }
-
- return arr;
- // return @[deleteRowAction, editRowAction];
- }
- else
- return @[deleteRowAction];
-
-
- }
- - (void)tableView:(UITableView *)tableView
- commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
-
- }
- #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
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // if(alertView.tag==1234)
- // {
- //
- // // availability warring;
- //
- //
- // if(buttonIndex!=alertView.cancelButtonIndex)
- // {
- // if(appDelegate.order_code==nil)
- // {
- // [self neworder];
- // }
- // else
- // {
- // [self addtocart];
- // }
- // }
- // return;
- // }
- // int count=[self.quantity_text.text intValue];
-
-
-
- if(alertView.tag==ALERT_DEL)
- {
- if(buttonIndex!=alertView.cancelButtonIndex)
- {
- [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
-
- NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = [iSalesNetwork portfolio_remove:ids];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- [self reload_data];
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
- }
-
- });
- });
-
- }
- return;
- }
-
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(buttonIndex==alertView.cancelButtonIndex)
- {
-
-
-
- }
- else if(buttonIndex==1)
- {
- //open exist
-
- OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
- ovc.showNavibar = true;
- ovc.selectOrder = ^(NSMutableDictionary* order_detail){
- if(appDelegate.order_code==nil)
- {
- [self neworder];
- }
- else
- {
- [self addtocart];
- [main_vc checklogin:true];
-
- }
-
- };
- ovc.init_style = OL_OPEN;
- ovc.onCancel = ^(){
-
- [main_vc checklogin:true];
-
- };
-
- [self.navigationController pushViewController:ovc animated:true];
- }
- else
- {
- //create new;
-
- if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- {
- ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = @"Sales_Order_Customer";
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- appDelegate.contact_id=[value valueForKey:@"customer_cid"];
- appDelegate.customerInfo = value;
-
-
- if(appDelegate.order_code==nil)
- [self neworder];
-
- // [main_vc checklogin:true];
- // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
- cvc.onCancel = ^(){
-
- [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
-
-
-
- };
- cvc.onReset = ^(){
- [main_vc checklogin:true];
- };
-
- [self.navigationController pushViewController:cvc animated:true];
- }
- else
- {
- [self neworder];
- }
-
- }
- }
- /*
- #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.
- }
- */
- @end
|