| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- //
- // ScanOrderModelListViewController.m
- // HMLG Scan Order
- //
- // Created by Rui Zhang on 3/17/22.
- // Copyright © 2022 United Software Applications, Inc. All rights reserved.
- //
- #import "ScanOrderModelListViewController.h"
- #import "ScanModelListCell.h"
- #define NUMBERS @"0123456789\n"
- #import "RASingleton.h"
- #import "ActiveViewController.h"
- #import "RAUtils.h"
- #import "RAConvertor.h"
- #import "RADataProvider.h"
- #import "ScanRefreshStock.h"
- @interface ScanOrderModelListViewController ()<IScanRefreshStock>
- @end
- @implementation ScanOrderModelListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.edit_check = true;
-
- // [self refreshStock];
- // Do any additional setup after loading the view.
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- self.labelStock.text = [RADataProvider queryStockUpdateTime];
- }
- - (IBAction)onUpdateStock:(id)sender {
- [RADataProvider updateStock:self];
- }
- -(void) refreshStock
- {
-
-
- // NSDictionary *addressDic1 = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanStock"];
- // if (addressDic1) {
- // NSString* updatetime=addressDic1[@"updatetime"];
- // self.labelStock.text = updatetime;
- // }
- self.labelStock.text = [RADataProvider queryStockUpdateTime];
-
- [self.tableView reloadData];
- }
- - (IBAction)stepChange:(id)sender {
-
- UIStepper * stepper = (UIStepper *) sender;
- UITableViewCell *cell = (UITableViewCell *) stepper.superview.superview;
- NSIndexPath * indexPath = [self.tableView indexPathForCell:cell];
- ScanModelListCell * scancell = (ScanModelListCell*)cell;
- NSMutableDictionary* item= self.modellist[indexPath.row];
- int qty = (int)((UIStepper*)sender).value;
- scancell.editQTY.text = [NSString stringWithFormat:@"%d",qty ];
- item[@"count"] = @(qty);
- item[@"subtotal_price"] = @(qty*[item[@"unit_price"] doubleValue]);
-
- self.modellist[indexPath.row] = item;
-
-
- }
- - (void)setScan_val:(id)scan_val
- {
- [super setScan_val:scan_val];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
- self.modellist = [NSMutableArray new];
-
- NSArray* arr = (NSArray*) self.scan_val;
- bool iscollection=false;
- if(arr.count>1)
- iscollection = true;
- for(int i=0;i<arr.count;i++)
- {
- // NSArray* item = arr[i];
-
- NSMutableDictionary* jitem = [arr[i] mutableCopy];
-
-
- //
- // NSString* pid = item[0];
- // NSString * model =item[1];
- // if(model.length==0)
- // model = @"";
- // NSString * description=item[2];
- // if(description.length==0)
- // description = @"";
- //
- // NSString * dimension=item[3];
- // if(dimension.length==0)
- // dimension = @"N/A";
-
- NSString * mpack=jitem[@"stockUom"];
- if(mpack.length==0||[mpack isEqualToString:@"N/A"])
- mpack = @"1";
-
- NSString * unit_cuft=jitem[@"unit_cuft"];
- if(unit_cuft.length==0)
- unit_cuft = @"N/A";
- else
- {
-
- unit_cuft = [NSString stringWithFormat:@"%.2f", [jitem[@"unit_cuft"] doubleValue]];
- }
-
- NSString* price0=jitem[price_group[@"price_0"][@"name"]]; //DDP
- NSString* price1=jitem[price_group[@"price_1"][@"name"]]; //WHSE
- NSString* price2=jitem[price_group[@"price_2"][@"name"]]; //SHOW
- NSString* price3=jitem[price_group[@"price_3"][@"name"]]; //%25
- // NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
- // if (addressDic) {
- //
- // int price_index =0;//[addressDic[ @"price_index"] intValue];
- //
- //
- // int idx = 9+price_index;
- //
- //
- // }
-
- if(![price0 isEqualToString: @"N/A"])
- price0 = [NSString stringWithFormat:@"%.2f",[jitem[price_group[@"price_0"][@"name"]] doubleValue]];
- if(![price1 isEqualToString: @"N/A"])
- price1 = [NSString stringWithFormat:@"%.2f",[jitem[price_group[@"price_1"][@"name"]] doubleValue]];
- if(![price2 isEqualToString: @"N/A"])
- {
- price2 = [NSString stringWithFormat:@"%.2f",[jitem[price_group[@"price_2"][@"name"]] doubleValue]];
- jitem [@"special_price"] = @true;
- }
- if(![price3 isEqualToString: @"N/A"])
- price3 = [NSString stringWithFormat:@"%.2f",[jitem[price_group[@"price_3"][@"name"]] doubleValue]];
- if(![jitem [@"special_price"] boolValue]&& ![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])
- {
- jitem [@"net_price"] = @true;
- // remove net price
- jitem [@"net_price"] = @false;
- }
-
-
- // if(RASingleton.sharedInstance.price_type==3)
- // {
- // jitem[@"unit_price"] =jitem[@"price3"];
- // }
- // if(RASingleton.sharedInstance.price_type==2)
- // {
- // jitem[@"unit_price"] =jitem[@"price2"];
- // }
- // else if(RASingleton.sharedInstance.price_type==1)
- // {
- // jitem[@"unit_price"] =jitem[@"price1"];
- // }
- // else
- // {
- // jitem[@"unit_price"] =jitem[@"price0"];
- // }
-
- NSString * cell_price;
- if(RASingleton.sharedInstance.price_type==1)
- {
- // if(_modelJson [@"net_price"])
- cell_price=jitem[price_group[@"price_3"][@"name"]];
- // jitem[@"unit_price"] =jitem[@"price3"];
- // jitem[@"erp_unit_price"] =jitem[@"price3"];
- // else if(_modelJson [@"special_price"])
- // {
- // unit_price= _modelJson[@"price2"];
- // }
- // else
- // {
- // unit_price= _modelJson[@"price1"];
- // }
- }
- else
- {
- cell_price=jitem[price_group[@"price_0"][@"name"]];
- // jitem[@"unit_price"] =jitem[@"price0"];
- // jitem[@"erp_unit_price"] =jitem[@"price0"];
- }
-
- NSString * unit_price;
- if(RASingleton.sharedInstance.price_type==0)
- unit_price=jitem[price_group[@"price_0"][@"name"]];
- else if(jitem [@"special_price"])
- {
- unit_price= jitem[price_group[@"price_2"][@"name"]];
- }
- else if(jitem [@"net_price"])
- unit_price=jitem[price_group[@"price_3"][@"name"]];
- else
- {
- unit_price= jitem[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;
-
- // jitem[@"price0"] =price0;
- // jitem[@"price1"] =price1;
- // jitem[@"price2"] =price2;
- // jitem[@"stockUom"] = mpack;
- if(iscollection)
- jitem[@"count"]=@"0";
- else
- jitem[@"count"] = mpack;
- jitem[@"subtotal_price"] = @([mpack intValue]* [unit_price doubleValue]);//@([mpack intValue]* [jitem[@"unit_price"] doubleValue]);
- // jitem[@"dimension"] = dimension;
- // jitem[@"unit_cuft"] = unit_cuft;
- jitem[@"cuft"] = @([mpack intValue]* [unit_cuft doubleValue]);
- // jitem[@"origin"] = origin;
- // jitem[@"port"] = port;
- // jitem[@"available"] = available;
- // jitem[@"iscollection"]= @(iscollection);
-
- // jitem[@"unit_price"] =@( [item[3] doubleValue]);
- // jitem[@"stockUom"] = @([item[4] intValue]);
- // jitem[@"count"] = @([item[4] intValue]);
- // jitem[@"subtotal_price"] = @([item[4] intValue]* [item[3] doubleValue]);
-
- jitem[@"check"]=@(true);
-
-
- [self.modellist addObject:jitem];
-
- if(RASingleton.sharedInstance.scan_list == nil)
- RASingleton.sharedInstance.scan_list = [NSMutableArray new];
-
- for(int sli=0;sli<RASingleton.sharedInstance.scan_list.count;sli++)
- {
- if([RASingleton.sharedInstance.scan_list[sli][@"product_id"] isEqualToString:jitem[@"product_id"]])
- {
- [RASingleton.sharedInstance.scan_list removeObject:RASingleton.sharedInstance.scan_list[sli]];
- }
- }
- if(RASingleton.sharedInstance.scan_list.count>=200)
- [RASingleton.sharedInstance.scan_list removeLastObject];
- [RASingleton.sharedInstance.scan_list insertObject:jitem atIndex:0];
- [ActiveViewController Notify:@"ScanHistoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- // int idx = [RASingleton.sharedInstance.scan_list indexOfObject:jitem];
- // if(idx>=0)
- // {
- // //如果存在,移动到最前。
- //
- //
- // }
-
-
-
-
- }
-
- [self.tableView reloadData];
- }
- #pragma mark - TableView DataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- NSMutableArray* arr = (NSMutableArray*) self.scan_val;
- return arr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
- // return 166.0f;
- UILabel * label = [UILabel new];
-
-
- NSMutableArray* arr = self.modellist;
-
- NSMutableDictionary* model = arr[indexPath.row];
- label.frame = CGRectMake(0, 0, tableView.frame.size.width-32-30, 0);
- label.text = model[@"description"];
- label.font = [UIFont systemFontOfSize:15];
- label.numberOfLines=0;
- label.lineBreakMode = NSLineBreakByWordWrapping;
- double s = label.font.pointSize;
-
-
- // NSLog(label.text);
- // CGSize s=[label sizeThatFits:CGSizeMake(tableView.frame.size.width-32, 0)];
- [label sizeToFit];
-
- return label.frame.size.height+107.5;
-
-
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- ScanModelListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScanModelListCell"];
- if (!cell) {
- cell = [[ScanModelListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ScanModelListCell"];
- }
- NSMutableArray* arr = (NSMutableArray*) self.modellist;
-
- [cell setModelJson:arr[indexPath.row]];
- cell.editQTY.delegate = self;
-
- cell.labelStock.text = [RADataProvider queryStock:cell.labelModel.text];
-
- return cell;
- }
- //#pragma mark - TableView Delegate
- /*
- #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.
- }
- */
- - (IBAction)onScanNext:(id)sender {
- [self dismissViewControllerAnimated:true completion:^{
- if(self.returnValue)
- self.returnValue(nil);
- }];
- }
- - (IBAction)onAddToCart:(id)sender {
-
- // [self.lastedit endEditing:true];
- if(self.lastedit)
- [self textFieldDidEndEditing:self.lastedit];
-
- if(self.edit_check)
- {
- NSMutableArray* arrname = [NSMutableArray new];
-
- for(int j=0;j<self.modellist.count;j++)
- {
-
- if([self.modellist[j][@"count"] intValue]==0)
- continue;
- NSMutableDictionary* jitem = nil;
- jitem = [self.modellist[j] mutableCopy];
-
-
- [arrname addObject:jitem[@"model"]];
-
-
-
-
- }
-
- NSString* models=[RAConvertor arr2string:arrname separator:@"," trim:false];
-
-
- [RAUtils message_box:[NSString stringWithFormat: @"%@ added to cart",models] message:@"Successfully" completion:^{
- [self dismissViewControllerAnimated:true completion:^{
- if(self.returnValue)
- self.returnValue(self.modellist);
- }];
- }];
-
-
-
- }
- }
- #pragma mark textField delegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return NO;
- }
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
-
- // DebugLog(@"text:%@",textField.text);
-
-
-
- NSCharacterSet *cs;
- cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
-
- NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
-
- BOOL canChange = [string isEqualToString:filtered];
-
-
-
-
- return canChange;
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField
- {
- self.lastedit = textField;
-
- // self.lastedit = textField;
- // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- // ScanModelListCell * scancell = (ScanModelListCell*)cell;
-
- // scancell.pre_val=[textField.text intValue];
-
- // self.lastedit_from = [self.editorTable indexPathForCell:cell];
- //
- // NSDictionary* item_json =((NSMutableArray*)self.content_data_control[self.lastedit_from.section])[self.lastedit_from.row];
- //
- // if ([item_json valueForKey:@"clear"]) {
- // //开始编辑时清掉旧内容
- // BOOL clear = [[item_json valueForKey:@"clear"] doubleValue] == [textField.text doubleValue];
- //
- // if (clear) {
- // textField.text = nil;
- // }
- // }
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
-
- self.lastedit = nil;
- UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- NSIndexPath * indexPath = [self.tableView indexPathForCell:cell];
- ScanModelListCell * scancell = (ScanModelListCell*)cell;
-
- NSMutableDictionary* item= self.modellist[indexPath.row];
- int qty = [textField.text intValue];
-
- int c=qty;
-
- int mpack= [item[@"stockUom"] intValue];
-
- int m=c%mpack;
- if(m!=0)
-
- {
- [RAUtils message_box:@"Warrning" message:[NSString stringWithFormat:@"QTY must be a multiple of %d",mpack] completion:nil];
- textField.text = [NSString stringWithFormat:@"%d",[item[@"count"] intValue]];
- self.edit_check = false;
- return;
- }
- //self.pre_val = qty;
-
-
-
-
- self.edit_check=true;
-
-
- scancell.steper.value = qty;
-
-
-
- item[@"count"] = @(qty);
- item[@"subtotal_price"] = @(qty*[item[@"unit_price"] doubleValue]);
-
- self.modellist[indexPath.row] = item;
-
- // NSMutableArray* item_arr=arr[indexPath.row] mutableCopy;
-
-
-
-
- // NSIndexPath * indexPath = self.lastedit_from;
- //
- // NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- // if ([item_json objectForKey:@"fill"]) {
- // NSString *fillText = [item_json objectForKey:@"fill"];
- //
- // if (fillText && textField.text.length == 0) {
- // textField.text = fillText;
- // }
- // }
- //
- // [self textfieldSetValue:indexPath value:textField.text];
- //
- //
- }
- @end
|