| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- //
- // 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"
- @interface ScanOrderModelListViewController ()
- @end
- @implementation ScanOrderModelListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.edit_check = true;
- // Do any additional setup after loading the view.
- }
- - (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];
-
-
- 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 = @"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 * port=item[6];
- // if(port.length==0)
- // port = @"N/A";
- //
- // NSString * origin=item[7];
- // if(origin.length==0)
- // origin = @"N/A";
- //
- // NSString * available=item[8];
- // if(available.length==0)
- // available = @"N/A";
- //
- // NSString* price0;
- // NSString* price1;
- // NSString* price2;
- // NSString* price3;
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
- if (addressDic) {
-
- int price_index =0;//[addressDic[ @"price_index"] intValue];
- // NSString* ia=addressDic[@"internalAddress"];
- // NSString* ea=addressDic[@"externalAddress"];
- // NSString* sa=addressDic[@"serverAddress"];
- // if(sa.length==0)
- // {
- // if(ea.length>0)
- // sa=ea;
- // else if(ia.length>0)
- // sa=ia;
- // }
- // NSString* server_name=[addressDic objectForKey:@"name"];
-
- int idx = 9+price_index;
- //
- // price0=item[idx];
- // if(price0.length==0)
- // price0 = @"N/A";
- // else
- // price0 = [NSString stringWithFormat:@"%.2f",[item[idx] doubleValue]];
- //
- // price1=item[idx+1];
- // if(price1.length==0)
- // price1 = @"N/A";
- // else
- // price1 = [NSString stringWithFormat:@"%.2f",[item[idx+1] doubleValue]];
- //
- // if(![price1 isEqualToString:@"N/A"])
- // {
- // price2 = [NSString stringWithFormat:@"%.2f",[item[idx+1] doubleValue] *1.25];
- // }
- // else
- // {
- // price2 = @"N/A";
- // }
- }
- //
- //
- //
- //
- // jitem[@"product_id"]= pid;
- // jitem[@"model"] =model;
- // jitem[@"description"] = description;
- //
-
- 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"];
- }
-
- // 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]* [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];
- int idx = [RASingleton.sharedInstance.scan_list indexOfObject:jitem];
- if(idx>=0)
- {
- //如果存在,移动到最前。
- [RASingleton.sharedInstance.scan_list removeObject:jitem];
-
- }
- 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];
-
-
- }
-
- [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 136.0f;
- }
- - (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;
-
- 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_alert:@"Successfully" title:[NSString stringWithFormat: @"%@ added to cart",models] controller:self action_handler:^(UIAlertAction * _Nonnull action) {
- [self dismissViewControllerAnimated:true completion:^{
- if(self.returnValue)
- self.returnValue(self.modellist);
- }];
- } completion:nil];
-
- // [RAUtils message_alert:@"Successful" title:[NSString stringWithFormat: @"%@ added to cart",models] controller:[RAUtils getViewController:self]];
-
-
-
-
-
- }
- }
- #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_alert:[NSString stringWithFormat:@"QTY must be a multiple of %d",mpack] title:@"Warrning" controller:self];
- 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
|