| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- //
- // 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"
- @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;
- 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[@"price0"];
- else if(_modelJson [@"net_price"])
- unit_price=_modelJson[@"price3"];
- else if(_modelJson [@"special_price"])
- {
- unit_price= _modelJson[@"price2"];
- }
- else
- {
- unit_price= _modelJson[@"price1"];
- }
- 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_alert:@"Successfully" title:[NSString stringWithFormat: @"%@ added to cart",jitem[@"model"]] controller:[RAUtils getViewController:self]];
-
-
- }
- - (void)setModelJson:(NSMutableDictionary *)modelJson
- {
- _modelJson = modelJson;
- NSLog( [RAConvertor dict2string:modelJson]);
-
- 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[@"price0"]; //DDP
- NSString* price1=_modelJson[@"price1"]; //WHSE
- NSString* price2=_modelJson[@"price2"]; //SHOW
- NSString* price3=_modelJson[@"price3"]; //%25
-
-
-
- if(![price0 isEqualToString: @"N/A"])
- price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price0"] doubleValue]];
- if(![price1 isEqualToString: @"N/A"])
- price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue]];
- if(![price2 isEqualToString: @"N/A"])
- {
- price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price2"] doubleValue]];
- // if(RASingleton.sharedInstance.price_type==1)
- _modelJson [@"special_price"] = @true;
- }
- if(![price3 isEqualToString: @"N/A"])
- price3 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price3"] doubleValue]];
- if(![_modelJson [@"special_price"] boolValue]&& ![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])
- {
- // if(RASingleton.sharedInstance.price_type==1)
- _modelJson [@"net_price"] = @true;
- }
-
-
- //
- // 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[@"price2"] isEqualToString:@"N/A"])
- _labelPriceSpecial.text=_modelJson[@"price2"];
- else
- _labelPriceSpecial.text=[RAConvertor currencyNumber:[_modelJson[@"price2"] floatValue]];
- }
- else
- {
- _labelPriceSpecial.text=@"N/A";
- }
-
-
- 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";
- }
- }
- else
- {
- if([_modelJson[@"price1"] isEqualToString:@"N/A"])
- {
- _labelPriceNet.text=_modelJson[@"price1"];
- _labelPriceNCA.text=@"N/A";
- }
- else
- {
- _labelPriceNCA.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] 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[@"price3"];
- // else if(_modelJson [@"special_price"])
- // {
- // unit_price= _modelJson[@"price2"];
- // }
- // else
- // {
- // unit_price= _modelJson[@"price1"];
- // }
- }
- else
- {
- cell_price=_modelJson[@"price0"];
- }
-
-
-
-
-
- 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
|