| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- //
- // ScanListCell.m
- // HMLG Scan Order
- //
- // Created by Rui Zhang on 3/30/22.
- // Copyright © 2022 United Software Applications, Inc. All rights reserved.
- //
- #import "ScanListCell.h"
- #import "RASingleton.h"
- #import "OLDataProvider.h"
- #import "ActiveViewController.h"
- #import "RAConvertor.h"
- #import "RAUtils.h"
- #import "AppDelegate.h"
- #import "RADataProvider.h"
- @implementation ScanListCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (IBAction)onAddToCart:(id)sender {
- // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
-
-
-
-
-
- if(RASingleton.sharedInstance.scan_cart ==nil)
- {
- // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
- NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
- RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
- }
- // 初始化为 FOB CTNR;
- if(RASingleton.sharedInstance.scan_cart[@"price_type"] ==nil)
- {
- RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
- RASingleton.sharedInstance.price_type = 1;
- }
- NSMutableDictionary* section =[RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
- int count =[section[@"count"] intValue];
-
-
-
- NSMutableDictionary* jitem = nil;
- jitem = [self.modelJson mutableCopy];
- int stockUom =[jitem[@"stockUom"] intValue];
- if(stockUom==0)
- stockUom=1;
- bool newitem = true;
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
- for(int i=0;i<count;i++)
- {
-
- NSMutableDictionary* litem = [section[[NSString stringWithFormat:@"item_%i",i]] mutableCopy];
-
- if([litem[@"product_id"] isEqualToString:jitem[@"product_id"]])
- {
-
- // int oldcount = [litem[@"stockUom"] intValue];
- newitem = false;
-
- litem[@"count"]=@([litem[@"count"] intValue] +[jitem[@"count"] intValue]);
- litem[@"cuft"]=@([litem[@"count"] intValue] * [litem[@"unit_cuft"] doubleValue]);
-
- section[[NSString stringWithFormat:@"item_%i",i]] = litem;
- break;
-
-
- }
-
- }
- if(newitem)
- {
- jitem[@"count"]=@(stockUom);
- jitem[@"check"]=@(true);
- jitem[@"cart_item_id"]=[NSUUID UUID].UUIDString;
-
- NSString * unit_price;
- if(RASingleton.sharedInstance.price_type==0)
- unit_price=_modelJson[price_group[@"price_0"][@"name"]];
- else if(_modelJson [@"special_price"])
- {
- unit_price= _modelJson[price_group[@"price_2"][@"name"]];
- }
- else if(_modelJson [@"net_price"])
- unit_price=_modelJson[price_group[@"price_3"][@"name"]];
- else
- {
- unit_price= _modelJson[price_group[@"price_1"][@"name"]];
- }
- if([unit_price isEqualToString:@"N/A"])
- unit_price = @"0";
- else
- {
-
- unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
- }
-
-
- jitem[@"unit_price"] = unit_price;
- jitem[@"erp_unit_price"] = unit_price;
-
-
- section[[NSString stringWithFormat:@"item_%i",count]] = jitem;
- section[@"count"]= @(count+1);
- count++;
-
- }
-
-
- RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
-
- //加list
-
-
-
-
-
- [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-
- [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
-
- [RAUtils message_box:[NSString stringWithFormat: @"%@ added to cart",jitem[@"model"]] message:@"Successfully" completion:nil];
- }
- - (void)setModelJson:(NSMutableDictionary *)modelJson
- {
- _modelJson = modelJson;
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- // self.labelPrice0.text = appDelegate.price0_name;
- // self.labelPrice1.text = appDelegate.price1_name;
- // self.labelPrice2.text = appDelegate.price2_name;
- // self.labelPrice3.text = appDelegate.price3_name;
- NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
- self.labelPrice0.text = price_group[@"price_0"][@"display"];//appDelegate.price0_name;
- self.labelPrice1.text = price_group[@"price_1"][@"display"];//appDelegate.price1_name;
- self.labelPrice2.text = price_group[@"price_2"][@"display"];//appDelegate.price2_name;
- self.labelPrice3.text = price_group[@"price_3"][@"display"];//appDelegate.price3_name;
- // remove net price
- // if(price_group[@"price_4"])
- // {
- // self.labelPrice3.text = price_group[@"price_4"][@"display"];
- // }
- //
-
- #ifdef DEBUG
-
- NSLog(@"%@",[RAConvertor dict2string:modelJson]);
-
- #endif
- // NSString* s=[RAConvertor dict2string:modelJson];
- // @try {
- //
- //// NSLog( s);
- //
- // NSLog([RAConvertor dict2string:modelJson]);
- //
- // }
- // @catch (NSException * e) {
- // NSLog(@"Exception: %@", e);
- // [RAUtils message_box:@"exception" message:[NSString stringWithFormat:@"%@ %@",e,modelJson] completion:nil];
- // }
-
-
- NSString * port=_modelJson[@"port"];
- if(port.length==0)
- port = @"N/A";
-
- NSString * origin=_modelJson[@"origin"];
- if(origin.length==0)
- origin = @"N/A";
- NSString * dimension=_modelJson[@"dimension"];
- if(dimension.length==0)
- dimension = @"N/A";
-
- _labelModel.text=_modelJson[@"model"];
- _labelDescription.text=_modelJson[@"description"];
- _labelDimension.text=dimension;
- _labelCuft.text=_modelJson[@"unit_cuft"];
- _labelOrigin.text=origin;
- _labelPort.text=port;
- NSString* price0=_modelJson[price_group[@"price_0"][@"name"]]; //DDP
- NSString* price1=_modelJson[price_group[@"price_1"][@"name"]]; //WHSE
- NSString* price2=_modelJson[price_group[@"price_2"][@"name"]]; //SHOW
- NSString* price3=_modelJson[price_group[@"price_3"][@"name"]]; //NET
-
-
-
- if(![price0 isEqualToString: @"N/A"])
- price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_0"][@"name"]] doubleValue]];
- if(![price1 isEqualToString: @"N/A"])
- price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_1"][@"name"]] doubleValue]];
- if(![price2 isEqualToString: @"N/A"])
- {
- price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_2"][@"name"]] doubleValue]];
- // if(RASingleton.sharedInstance.price_type==1)
- _modelJson [@"special_price"] = @true;
- }
- if(![price3 isEqualToString: @"N/A"])
- price3 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_3"][@"name"]] doubleValue]];
- // if(![_modelJson [@"special_price"] boolValue]&& ![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])
- if((![price1 isEqualToString: @"N/A"] && [price1 isEqualToString:price3])||(![price2 isEqualToString: @"N/A"] && [price2 isEqualToString:price3]))
- {
- // if(RASingleton.sharedInstance.price_type==1)
- _modelJson [@"net_price"] = @true;
- // remove net price
- _modelJson [@"net_price"] = @false;
- }
-
-
- //
- // if(![price1 isEqualToString:@"N/A"])
- // {
- // price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue] *1.25];
- // _modelJson[@"price2"]= price2;
- // }
- // else
- // {
- // price2=@"N/A";
- // }
- //
-
-
- if([price0 isEqualToString:@"N/A"])
- _labelPriceCTNR.text= @"";//price0;
- else
- _labelPriceCTNR.text=[RAConvertor currencyNumber:[price0 floatValue]];
-
- //
- // if([price3 isEqualToString:@"N/A"])
- // _labelPriceNCA.text= price3;
- // else
- // _labelPriceNCA.text=[RAConvertor currencyNumber:[price3 floatValue]];
- // _labelPrice25p.text=price2;
-
-
-
-
- if([_modelJson [@"special_price"] boolValue])
- {
- if([_modelJson[price_group[@"price_2"][@"name"]] isEqualToString:@"N/A"])
- _labelPriceSpecial.text=@"";//_modelJson[@"price2"];
- else
- _labelPriceSpecial.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_2"][@"name"]] floatValue]];
- }
- else
- {
- _labelPriceSpecial.text=@"";//@"N/A";
- }
-
- // remove net price
- // if([_modelJson [@"net_price"] boolValue])
- // {
- //// if([_modelJson[@"price1"] isEqualToString:@"N/A"])
- //// {
- //// _labelPriceNet.text=_modelJson[@"price1"];
- ////// _labelPriceNCA.text=@"N/A";
- //// }
- //// else
- //// {
- //// _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
- ////// _labelPriceNCA.text=@"N/A";
- //// }
- //
- // if([_modelJson[price_group[@"price_3"][@"name"]] isEqualToString:@"N/A"])
- // {
- // _labelPriceNet.text=@"";//_modelJson[@"price3"];
- //// _labelPriceNCA.text=@"N/A";
- // }
- // else
- // {
- // _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_3"][@"name"]] floatValue]];
- //// _labelPriceNCA.text=@"N/A";
- // }
- //
- // }
- // else
- // {
- // _labelPriceNet.text=@"";//@"N/A";
- // }
-
-
-
- if([_modelJson[price_group[@"price_3"][@"name"]] isEqualToString:@"N/A"])
- {
- _labelPriceNet.text=@"";//_modelJson[@"price3"];
- // _labelPriceNCA.text=@"N/A";
- }
- else
- {
- _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_3"][@"name"]] floatValue]];
- // _labelPriceNCA.text=@"N/A";
- }
-
- // remove net price
- // if(price_group[@"price_4"])
- // {
- // // price4 如果存在,会显示在price3的位置
- // NSString* price4=_modelJson[price_group[@"price_4"][@"name"]]; //%25
- //
- // if(![price4 isEqualToString: @"N/A"])
- // price4 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_4"][@"name"]] doubleValue]];
- // else
- // price4 =@"";
- // _labelPriceNet.text=price4;
- // }
-
- {
- if([_modelJson[price_group[@"price_1"][@"name"]] isEqualToString:@"N/A"])
- {
- _labelPriceNCA.text=@"";//_modelJson[@"price1"];
- // _labelPriceNCA.text=@"N/A";
- }
- else
- {
- _labelPriceNCA.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_1"][@"name"]] floatValue]];
- // _labelPriceNet.text=@"N/A";
- }
- }
-
-
- NSString * available=_modelJson[@"available"];
- if(available.length==0)
- available = @"N/A";
-
- _labelAvailable.text=available;
- NSString * unit_cuft=_modelJson[@"unit_cuft"];
- if(unit_cuft.length==0)
- unit_cuft = @"N/A";
- else
- {
-
- unit_cuft = [NSString stringWithFormat:@"%.2f", [_modelJson[@"unit_cuft"] doubleValue]];
- }
-
- NSString * cell_price;
- if(RASingleton.sharedInstance.price_type==1)
- {
- // if(_modelJson [@"net_price"])
- cell_price=_modelJson[price_group[@"price_3"][@"name"]];
- // else if(_modelJson [@"special_price"])
- // {
- // unit_price= _modelJson[@"price2"];
- // }
- // else
- // {
- // unit_price= _modelJson[@"price1"];
- // }
- }
- else
- {
- cell_price=_modelJson[price_group[@"price_0"][@"name"]];
- }
-
-
-
-
-
- NSString * mpack=_modelJson[@"stockUom"];
- if([mpack isEqualToString:@"N/A"])
- mpack=@"1";
- _modelJson[@"count"]=_modelJson[@"stockUom"];
- _modelJson[@"cuft"] = @([mpack intValue]* [unit_cuft doubleValue]);
- _modelJson[@"subtotal_price"] = @([mpack intValue]* [cell_price doubleValue]);
- }
- @end
|