| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- //
- // ScanOrderScanModelViewController.m
- // HMLG Scan Order
- //
- // Created by Rui Zhang on 3/8/22.
- // Copyright © 2022 United Software Applications, Inc. All rights reserved.
- //
- #import "ScanOrderScanModelViewController.h"
- #import "RAConvertor.h"
- #import "RAUtils.h"
- #import "AppDelegate.h"
- #define NUMBERS @"0123456789\n"
- @interface ScanOrderScanModelViewController ()
- @end
- @implementation ScanOrderScanModelViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.qtyEdit.delegate = self;
-
-
-
- // Do any additional setup after loading the view.
- }
- - (BOOL)shouldAutorotate
- {
-
- return false;
-
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- NSMutableDictionary* jitem =(NSMutableDictionary*) self.scan_val;
-
- // jitem[@"product_id"]= item[0];
- // NSString* model =item[1];
- // NSString* description =item[2];
- // jitem[@"model"] =model;
- // jitem[@"description"] = [NSString stringWithFormat:@"%@ \r\n%@",model,description];
- // 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);
-
-
- // NSString* model =jitem[@"model"];
- NSString* description =jitem[@"description"];
- double unit_price = [jitem[@"unit_price"] doubleValue];
- // jitem[@"model"] =model;
- // jitem[@"description"] = [NSString stringWithFormat:@"%@ \r\n%@",model,description];
- // 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);
- //
- int stockUom =[jitem[@"stockUom"] intValue];
-
- [self init_Stepper:stockUom max:9999 min:stockUom value:stockUom];
-
- self.descriptionLabel.text = description;
-
- self.qtyEdit.text =[NSString stringWithFormat:@"%d",stockUom];
- self.priceLabel.text = [NSString stringWithFormat:@"%.2f",unit_price];
- self.mpackLabel.text = [NSString stringWithFormat:@"%d",stockUom];
- }
- -(void) init_Stepper:(int) step max:(int) max min:(int)min value:(int)value
- {
-
- // [self.stepper becomeFirstResponder];
- if(self.qtystepper!=nil)
- {
- if(min<=0)
- min=1;
- if(step<=0)
- step=1;
- self.qtystepper.minimumValue= min;
-
-
-
- self.qtystepper.stepValue= step;
-
- self.qtystepper.value= value;
-
-
-
- [self.qtystepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
-
-
- }
- }
- - (void)valueChanged:(UIStepper *)sender {
-
-
-
- self.qtyEdit.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
-
- // self.pre_val = (int)sender.value;
- // [self set_Count:(int)sender.value ];
-
-
- //
- // [celldelegate stepClicked:(int)sender.value];
- // -(void) stepClicked:(int) value;
- }
- #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)textFieldDidEndEditing:(UITextField *)textField
- {
-
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- int qty = [textField.text intValue];
-
- if(qty==0)
- qty=self.qtystepper.minimumValue;
-
- #ifdef MPACK
- if ((int)qty % (int)self.stepper.stepValue != 0) {
- UIViewController* vc=[RAUtils getViewController :self];
- [((CartViewController *)vc).itemListTable reloadData];
- [RAUtils message_alert:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] title:@"Change Model Count" controller:vc];
- return;
- }
- #endif
-
-
- int c=qty;
-
- int m=c%(int)(self.qtystepper.stepValue);
- if(m!=0)
-
- {
- [RAUtils message_alert:[NSString stringWithFormat:@"QTY must be a multiple of %d",(int)self.qtystepper.stepValue] title:@"Warrning" controller:self];
- textField.text = [NSString stringWithFormat:@"%d",self.pre_val];
- }
-
- self.pre_val = qty;
-
-
-
-
-
-
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField
- {
- NSString* text = textField.text;
- if(text.length==0)
- text=@"0";
- self.pre_val = [textField.text intValue];
-
- // self.last_edit = textField.text;
- }
- - (IBAction)onOK:(id)sender {
- [self dismissViewControllerAnimated:true completion:^{
- if(self.returnValue)
- self.returnValue(self.scan_val);
- }];
- }
- - (IBAction)onUpdate:(id)sender {
- NSMutableDictionary* jitem =(NSMutableDictionary*) self.scan_val;
- int qty = [self.qtyEdit.text intValue];
-
- jitem[@"count"] = @(qty);
- jitem[@"subtotal_price"] = @(qty* [jitem[@"unit_price"] doubleValue] );
-
- [self dismissViewControllerAnimated:true completion:^{
- if(self.returnValue)
- self.returnValue(self.scan_val);
- }];
- }
- /*
- #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.
- }
- */
- @end
|