| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990 |
- //
- // 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 "RANetwork.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 "RAPDFViewController.h"
- #import "DefaultTableHeaderView.h"
- #import "DefaultAppearance.h"
- #import "SortItemViewController.h"
- #import "SortButton.h"
- #import "TextUtils.h"
- #import "FileCache.h"
- #ifdef BUILD_UWAVER
- //#import "RAPortfolioInputDialog.h"
- #endif
- //#define ALERT_DEL 1025
- #define checked_Count @"checkedCount"
- @interface PortfolioViewController ()
- @property (nonatomic,strong) SortItemViewController *sortItemController;
- @property (nonatomic,assign) int sortIndex;
- @property (nonatomic,strong) SortButton *sortButton;
- @property (nonatomic,assign) NSInteger editedRow;
- @property (nonatomic,assign) NSInteger deletedRow;
- @property (strong, nonatomic) NSIndexPath *deleteIndexPath;// 点击delete action
- @end
- @implementation PortfolioViewController
- -(void) logout
- {
- self.content_data = nil;
- [self refresh_ui];
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- #ifndef RA_NOTIFICATION
- -(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)
- {
-
-
- //#ifdef BUILD_UWAVER
- // self.btnCreatePort.title = @"Create Hang Tag";
- //#else
- [self.btnCreatePort setTitle:@"Create Portfolio"];
- //#endif
- self.btnCreatePort.enabled = true;
- }
- else
- {
- [self.btnCreatePort setTitle:@""];
- self.btnCreatePort.enabled = false;
- }
- }
- #endif
- -(void) showHidePrice
- {
- #ifndef RA_NOTIFICATION
- [self reload_container_getdata:false];
- // [self refresh_total];
- #endif
- }
- //- (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 =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] 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 = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- // [self presentViewController:navi animated:YES completion:^{
- //
- // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
- //
- // DebugLog(@"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_box:@"Cannot Add to cart." message:@"You must select at least one model." completion:nil];
- return;
- }
-
- NSString * ids = [checked componentsJoinedByString:@","];
- self.btnCreatePort.enabled = false;
-
-
- [RANetwork request_addto_cart:ids count:-1 name:nil completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* return_json = result;
- self.btnCreatePort.enabled = true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false ];
- #endif
- 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_box:msg message:nil completion:nil];
-
- // [self end_select];
-
-
-
- // }
- }
- else
- {
- [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil];
- }
-
-
-
-
- }];
- }
- -(void) neworder
- {
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
- [RANetwork request_create_order:^(NSMutableDictionary *result) {
- NSMutableDictionary* return_json = result;
-
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
-
- [pop hide];
- 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];
-
-
-
- }
- }
- else
- {
-
- [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
-
-
-
- }];
- // }];
- }
- - (IBAction)onCreateTearSheet:(id)sender {
-
- //#ifdef BUILD_UWAVER
- //
- // [self createPreviewPortfolio];
- //
- //#else
-
- [self createTearSheet];
-
- //#endif
-
- }
- - (void)createTearSheet {
-
-
- 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)
- {
- NSString *title = @"Cannot Create Portfolio.";
- //#ifdef BUILD_UWAVER
- // title = @"Cannot Create Hang Tag.";
- //#else
- title=@"Cannot Create Portfolio.";
- //#endif
-
-
- [RAUtils message_box:title message:@"You must select at least one model." completion:nil];
- 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"];
- [params setObject:@(self.sortIndex) forKey:@"sort"];
-
- TearSheetParamViewController * VC=[[TearSheetParamViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
-
- VC.url_type = URL_REMOTE;
- VC.request_url=URL_DM_PARAMS;
-
- VC.params = params;
- VC.product_ids=string;
- VC.item_ids=string_iid;
-
- // 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,bool isLocalFile)
- {
- // NSString* name=[self.content_data[indexPath.row] valueForKey:@"tear_name"];
- // NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
-
- RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
- ViewController.url = url;
- ViewController.canSave = false;
- ViewController.isLocalfile=isLocalFile;
- 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.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:name]];
- 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:^{
-
- DebugLog(@"TearSheetParamViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- [self.btnselect setTitle:@"Select all"];
- }
- - (void)createPreviewPortfolio:(NSString *)catelog_name Note:(NSString *)internal_note ProductIds:(NSArray *)productIds ItemIds:(NSArray *)itemIds {
-
- if (catelog_name.length == 0) {
- NSString *msg = @"Portfolio name can not be empty";
- //#ifdef BUILD_UWAVER
- // msg = @"hang tag name can not be empty";
- //#else
- msg = @"Portfolio name can not be empty";
- //#endif
-
-
- [RAUtils message_box:@"Warning" message:msg completion:nil];
- return;
- }
-
- self.pdf_url= nil;
-
- NSString* pdf_url = [self.content_data valueForKey:@"pdf_url"];
- if (!pdf_url) {
- pdf_url = @"";
- }
-
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
- NSString * string = [productIds componentsJoinedByString:@","];
-
- NSString * string_iid = [itemIds componentsJoinedByString:@","];
- [params setValue:string forKey:@"product_ids"];
- [params setValue:string_iid forKey:@"item_ids"];
- [params setObject:@(self.sortIndex) forKey:@"sort"];
- [params setObject:pdf_url forKey:@"pdfUrl"];
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Processing" completion:nil];
- [RANetwork request_portfoliopreview:params completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* editor_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSString* url = [editor_json valueForKey:@"pdf_path"];
- NSString* path = [editor_json valueForKey:@"pdf_real_path"];
- bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
- RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
- ViewController.url = url;
- ViewController.canSave = true;
- ViewController.isLocalfile=isLocalFile;
-
- ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
- ViewController.save_name =catelog_name;
- ViewController.save_note =internal_note;
-
- NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
-
- if(company==nil)
- company=@"";
-
- 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];
- }
- ViewController.mail_to = send_to;
-
- NSString* subject;
-
- subject =catelog_name;
-
- ViewController.mail_subject = subject;
-
- ViewController.onSavePDF=^(NSString* name,NSString* file)
- {
-
-
- NSString* del_ids = nil;
- #ifdef OFFLINE_MODE
- if (appDelegate.offline_mode)
- {
- [params setValue:url forKey:@"pdfPath"];
- }
- else
- #endif
- {
- [params setValue:path forKey:@"pdfPath"];
- }
- [params setValue:name forKey:@"pdfName"];
- [params setValue:internal_note forKey:@"pdfNote"];
- [params setValue:del_ids forKey:@"itemIds"];
- [params setValue:pdf_url forKey:@"configureParams"];
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..." completion:^{
-
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Saving..." completion:nil];
- [RANetwork request_save_portfolio:params completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* json =result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- if([[json valueForKey:@"result"] intValue]==2)
- {
-
-
-
- [RAUtils message_box:@"Save Portfolio" message:@"Portfolio saved. You can find it from View Portfolios" completion:nil];
-
- // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
-
- [self.navigationController dismissViewControllerAnimated:true completion:^{
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
- [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- #endif
- }];
- }
- else
- {
-
-
- [RAUtils message_box:@"Save Portfolio" message:[json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
- }];
- // }];
-
-
-
-
-
-
- };
-
- ViewController.hidenavi = false;
- [self.navigationController pushViewController:ViewController animated:YES];
-
- }
- else
- {
-
- [RAUtils message_box:@"Create Portfolio" message:[editor_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
- }];
- // }];
-
- }
- - (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;
-
- self.sortIndex = 0;
- self.editedRow = -1;
- self.deletedRow = -1;
- self.indexPath = [NSIndexPath indexPathForRow:-1 inSection:0];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
- // tap.minimumPressDuration = 0.8; //定义按的时间
- [self.label_net_err addGestureRecognizer:tap];
-
- //#ifdef BUILD_UWAVER
- // self.btnCreatePort.title = @"Create Hang Tag";
- // self.btnEdit.title = nil;
- // self.btnEdit.enabled = NO;
- //#endif
-
- [self initCheckedCount];
- }
- -(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;
-
- int count =[[self.content_data valueForKey:@"count"] intValue];
-
- if (count) {
- if([self.btnselect.title isEqualToString:@"Select all"])
- {
-
- 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 initCheckedCount];
- [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 clearCheckedCount];
- [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)
- {
- //只选中一个和右滑一样处理。
- {
-
- DebugLog(@"edit click");
-
-
-
- UIViewController* parentvc=self;
-
-
-
-
- PortfolioEditQTYViewController * vc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] 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){
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Updating Quantity" completion:nil];
- [RANetwork request_update_portfolio_price:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* cart_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
-
-
-
- if (!(qty == -INT32_MAX && qty_p == -MAXFLOAT)) {
- // qty
- if (qty != -INT32_MAX)
- item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
- else
- [item_json removeObjectForKey:@"available_qty"];
-
- // qty_p
- if (qty_p != -MAXFLOAT)
- item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
- else
- [item_json removeObjectForKey:@"available_percent"];
- }
-
- if (notes) {
- item_json[@"linenotes"]=notes;
- }
-
- if (discount != -MAXFLOAT) {
- item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
- }
-
- if (price != -MAXFLOAT) {
- 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_box:@"Edit Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
-
-
-
- }];
- // }];
-
-
- };
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- [parentvc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"EditModelPriceViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- // [//tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
-
-
-
-
- }
- return;
- }
- // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
- NSString * ids = [checked componentsJoinedByString:@","];
-
- {
-
- DebugLog(@"edit click");
-
-
-
- UIViewController* parentvc=self;
-
-
-
-
- PortfolioEditQTYViewController * vc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] 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=(int)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){
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Updating Quantity" completion:nil];
- [RANetwork request_update_portfolio_price:ids price:price discount:discount QTY:qty qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* cart_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
-
- [RAUtils message_box:@"Edit Portfolio" message:[NSString stringWithFormat:@"%ld items saved.",checked.count] completion:nil];
- [self reload_data];
- }
- else
- {
-
-
- [RAUtils message_box:@"Edit Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
-
-
- }];
- // }];
-
- };
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- [parentvc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"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:@","];
- [RANetwork request_removeportfolio:string completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* cart_json =result;
-
-
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- [self reload_data];
- }
- else
- {
-
- [RAUtils message_box:@"Remove Model From Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
- }
-
- }];
-
-
- }
- -(void) viewWillAppear:(BOOL)animated
- {
-
- [super viewWillAppear:animated];
-
- [[self navigationController] setNavigationBarHidden:YES animated:NO];
- }
- - (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";
- //#ifdef BUILD_UWAVER
- // sectionTitle = @"Hang Tag";
- //#endif
-
- DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 33)];
-
- // UIButton *sortButton = [UIButton buttonWithType:UIButtonTypeCustom];
- // sortButton.frame = CGRectMake(20, 5.5, (33 - 5.5 * 2), (33 - 5.5 * 2));
- // [sortButton setImage:[UIImage imageNamed:@"check_1_24"] forState:UIControlStateNormal];
- // [sortButton addTarget:self action:@selector(portfolioSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- [myView addSubview:self.sortButton];
-
-
- 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];
- // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
- NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- NSString *name = [item_json objectForKey:@"description"];
- NSRange subRange = [name rangeOfString:@"\n"];
- name = [name substringToIndex:subRange.location];
-
- NSString* product_id = [item_json valueForKey:@"product_id"];
-
- DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
- // dvc
-
- dvc.product_id=product_id;
- dvc.category_id=nil;
- dvc.ispush=true;
- dvc.model_name = name;
- [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]];
-
- // Button 设置了大小约束,Size就不会随内容变化
- [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
- #if __IPHONE_OS_VERSION_MIN_REQUIRED <150000
- [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
- #endif
- [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
- [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
- cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
-
- 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];
- [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[FileCache 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 setImage: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)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
- [cell.btnImage setImage:img forState:UIControlStateNormal];
- }
- else
- // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
- [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
-
-
- });
- });
-
-
- }
-
- cell.backgroundColor = [UIColor whiteColor];// [UIColor whiteColor];;
- // if (indexPath.row == self.editedRow) {
- // cell.backgroundColor = UIColorFromRGB(0xEAEBED);
- // }
- // if (indexPath.row == self.deletedRow) {
- // cell.backgroundColor = UIColorFromRGB(0xEAEBED);
- // }
- if (indexPath.row == self.indexPath.row) {
- cell.backgroundColor = UIColorFromRGB(0xEAEBED);
- }
-
- 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"];
- [self checkedCountRise:NO];
- }
- else
- {
- [item_json setValue:@"1" forKey:@"check"];
- cell.img_checkmark.hidden=false;
- [self checkedCountRise:YES];
- if ([self allChecked]) {
- [self.btnselect setTitle: @"DeSelect all"];
- }
- }
- [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
- - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- // 添加一个删除按钮
-
- // self.indexPath=indexPath;
- // ModelItemCell * cell = [tableView cellForRowAtIndexPath:indexPath];
-
-
- // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
-
-
- UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
-
- DebugLog(@"delete click");
- self.deleteIndexPath = indexPath;
-
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Delete confirm" message:@"Are you sure remove model from portfolio?" preferredStyle:UIAlertControllerStyleAlert];
-
-
- UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
-
-
- self.indexPath = self.deleteIndexPath;
-
- int count =[[self.content_data valueForKey:@"count"] intValue];
- BOOL delete_last = self.indexPath.row == count - 1 ? YES : NO;
-
- [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]];
-
- [RANetwork request_removeportfolio:ids completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* cart_json =result;
-
-
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- self.deletedRow = delete_last ? -1 : self.indexPath.row;
- if (delete_last) {
- self.indexPath = [NSIndexPath indexPathForRow:count - 2 inSection:0];
- }
- [self reload_data];
- }
- else
- {
-
- [RAUtils message_box:@"Delete Model" message:[cart_json valueForKey:@"err_msg"] completion:nil];
- }
-
-
- }];
-
-
-
- self.deleteIndexPath = nil;
- return;
-
-
- }];
- UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- self.deleteIndexPath = nil;
- return;
-
- }];
-
- [alertController addAction:action_2];
- [alertController addAction:action_3];
-
-
- [self presentViewController:alertController animated:YES completion:nil];
-
-
-
-
- // 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) {
-
- UIContextualAction* EditQTYAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@" Edit " handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
-
- DebugLog(@"edit click");
-
-
-
- UIViewController* parentvc=self;
-
-
-
-
- PortfolioEditQTYViewController * vc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
-
-
- __block 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){
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Updating Quantity" completion:nil];
- [RANetwork request_update_portfolio_price:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
-
- NSDictionary* cart_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- self.editedRow = indexPath.row;
-
- if (!(qty == -INT32_MAX && qty_p == -MAXFLOAT)) {
- // qty
- if (qty != -INT32_MAX)
- item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
- else
- [item_json removeObjectForKey:@"available_qty"];
-
- // qty_p
- if (qty_p != -MAXFLOAT)
- item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
- else
- [item_json removeObjectForKey:@"available_percent"];
- }
-
- if (notes) {
- item_json[@"linenotes"]=notes;
- }
-
- if (discount != -MAXFLOAT) {
- item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
- }
-
- if (price != -MAXFLOAT) {
- 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.indexPath=indexPath;
- [self.itemListTable reloadData];
- }
- else
- {
-
- [RAUtils message_box:@"Edit Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
-
-
-
- }];
- };
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- [parentvc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"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 [UISwipeActionsConfiguration configurationWithActions:arr];
- // return @[deleteRowAction, editRowAction];
- }
- else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
- if (appDelegate.customer_type == CustomerTypeStore) {
- // return @[deleteRowAction];
- return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
- } else {
-
- if(appDelegate.can_set_tearsheet_price) {
- // return @[deleteRowAction,EditQTYAction];
- return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction,EditQTYAction]];
- } else {
- // return @[deleteRowAction];
- return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
- }
- }
- }
- else
- // return @[deleteRowAction];
- return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
-
- }
- - (void)tableView:(UITableView *)tableView
- commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
-
- }
- /*
- #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 - Jack
- - (BOOL)allChecked {
- int checkedCount = [[self.content_data objectForKey:checked_Count] intValue];
- int count = [[self.content_data objectForKey:@"count"] intValue];
-
- return checkedCount == count;
- }
- - (void)initCheckedCount {
- NSNumber *count = [self.content_data objectForKey:@"count"];
- if (!count) {
- count = [NSNumber numberWithInteger:0];
- }
- [self.content_data setObject:count forKey:checked_Count];
- }
- - (void)clearCheckedCount {
- [self.content_data setObject:[NSNumber numberWithInteger:0] forKey:checked_Count];
- }
- - (void)checkedCountRise:(BOOL)rise {
-
- int checkedCount = [[self.content_data objectForKey:checked_Count] intValue];
-
- if (rise) {
- checkedCount++;
- } else {
- checkedCount--;
- }
-
- [self.content_data setObject:[NSNumber numberWithInteger:checkedCount] forKey:checked_Count];
-
- }
- - (SortItemViewController *)sortItemController {
- if (!_sortItemController) {
- _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(40, 40)];
- _sortItemController.sortIndex = self.sortIndex;
- _sortItemController.sortData = @[
- @{@"title":@"Last",@"icon":@"TX_18"},
- @{@"title":@"First",@"icon":@"TS_18"},
- @{@"title":@"Item number a-z",@"icon":@"IX_18"},
- @{@"title":@"Item number z-a",@"icon":@"IS_18"},
- @{@"title":@"Description",@"icon":@"DX_18"},
- @{@"title":@"Category",@"icon":@"cs_18"}
- ];
- __weak typeof(self) weakSelf = self;
- _sortItemController.sortBlock = ^(int sort){
- weakSelf.sortIndex = sort;
- [weakSelf reload_data];
- };
-
- }
- // _sortItemController.sortIndex = self.sortIndex;
-
- return _sortItemController;
- }
- - (void)portfolioSortButtonClicked:(UIButton *)sender {
- [self.view addSubview:self.sortItemController.view];
- }
- - (SortButton *)sortButton {
- if (!_sortButton) {
- _sortButton = [SortButton sortButtonWithHeight:33];
-
- [_sortButton addTarget:self action:@selector(portfolioSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _sortButton;
- }
- - (void)setSortIndex:(int)sortIndex {
- _sortIndex = sortIndex;
-
- NSString *selectedImageName = @"";
- switch (sortIndex) {
- case 0:{
- selectedImageName = @"TX_22";
- }
- break;
- case 1:{
- selectedImageName = @"TS_22";
- }
- break;
- case 2:{
- selectedImageName = @"IX_22";
- }
- break;
- case 3:{
- selectedImageName = @"IS_22";
- }
- break;
- case 4:{
- selectedImageName = @"DX_22";
- }
- break;
- case 5: {
- selectedImageName = @"cs_22";
- }
-
- default:
- break;
- }
-
- self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
-
- }
- #pragma mark - rotation
- //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
- //
- // self.sortItemController.view.frame = self.view.bounds;
- //}
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- // what ever you want to prepare
- } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- self.sortItemController.view.frame = self.view.bounds;
- }];
- }
- //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // return YES;
- //}
- - (BOOL)shouldAutorotate{
- return YES;
- }
- //
- //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
- // self.sortItemController.view.frame = self.view.bounds;
- //}
- - (void)reRefreshView {
- [self.itemListTable reloadData];
- }
- #pragma mark - RA_NOTIFICAITON
- -(void) refresh_ui
- {
- [self.itemListTable reloadData];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.can_create_portfolio)
- {
-
- //#ifdef BUILD_UWAVER
- // self.btnCreatePort.title = @"Create Hang Tag";
- //#else
- [self.btnCreatePort setTitle:@"Create Portfolio"];
- //#endif
-
- self.btnCreatePort.enabled = true;
- }
- else
- {
- [self.btnCreatePort setTitle:@""];
- self.btnCreatePort.enabled = false;
- }
- }
- -(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"];
-
- [RANetwork request_portfoliolist:self.sortIndex completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* cart_json =result;
- [self.mum stopAnimating];
-
- int result_code=[[cart_json valueForKey:@"result"] intValue];
-
- if(result_code==2||result_code==1||result_code==0)
- {
- self.itemListTable.hidden=false;
- self.content_data = [cart_json mutableCopy];
- [self.itemListTable reloadData];
-
- [self initCheckedCount];
- [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_code==RESULT_NET_ERROR)
- {
- self.label_net_err.hidden=false;
- self.itemListTable.hidden=true;
- }
- else
- {
- [RAUtils message_box:@"Loading Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
- }
-
- self.isrefreshing=false;
- }];
- });
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.can_create_portfolio)
- {
-
-
- //#ifdef BUILD_UWAVER
- // self.btnCreatePort.title = @"Create Hang Tag";
- //#else
- [self.btnCreatePort setTitle:@"Create Portfolio"];
- //#endif
- self.btnCreatePort.enabled = true;
- }
- else
- {
- [self.btnCreatePort setTitle:@""];
- self.btnCreatePort.enabled = false;
- }
- }
- -(void) refresh_price
- {
- [self refresh_ui];
- }
- @end
|