| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- //
- // 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"] = @0;
- RASingleton.sharedInstance.price_type = 0;
- }
- 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==2)
- {
- unit_price=jitem[@"price2"];
- }
- else if(RASingleton.sharedInstance.price_type==1)
- {
- unit_price=jitem[@"price1"];
- }
- else
- {
- unit_price=jitem[@"price0"];
- }
- if(unit_price.length==0)
- unit_price = @"0";
- else
- {
-
- unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
- }
-
-
- jitem[@"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:@"Successful" title:@"Add to cart" 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"];
- NSString* price1=_modelJson[@"price1"];
- NSString* price2;
-
- if(price0.length==0)
- price0 = @"N/A";
- else
- price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price0"] doubleValue]];
-
-
- if(price1.length==0)
- price1 = @"N/A";
- else
- price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue]];
-
- if(![price1 isEqualToString:@"N/A"])
- {
- price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue] *1.25];
- _modelJson[@"price2"]= price2;
- }
- else
- {
- price2=@"N/A";
- }
-
-
-
- _labelPriceCTNR.text=price0;
- _labelPriceNCA.text=price1;
- _labelPrice25p.text=price2;
-
-
- 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 * unit_price;
- if(RASingleton.sharedInstance.price_type==2)
- {
- unit_price=_modelJson[@"price2"];
- }
- else if(RASingleton.sharedInstance.price_type==1)
- {
- unit_price=_modelJson[@"price1"];
- }
- else
- {
- unit_price=_modelJson[@"price0"];
- }
- if(unit_price.length==0)
- unit_price = @"N/A";
- else
- {
-
- unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
- }
-
-
-
-
-
- NSString * mpack=_modelJson[@"stockUom"];
- _modelJson[@"cuft"] = @([mpack intValue]* [unit_cuft doubleValue]);
- _modelJson[@"subtotal_price"] = @([mpack intValue]* [unit_price doubleValue]);
- }
- @end
|