ScanOrderScanModelViewController.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // ScanOrderScanModelViewController.m
  3. // HMLG Scan Order
  4. //
  5. // Created by Rui Zhang on 3/8/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ScanOrderScanModelViewController.h"
  9. #import "RAConvertor.h"
  10. #import "RAUtils.h"
  11. #import "AppDelegate.h"
  12. #define NUMBERS @"0123456789\n"
  13. @interface ScanOrderScanModelViewController ()
  14. @end
  15. @implementation ScanOrderScanModelViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.qtyEdit.delegate = self;
  19. // Do any additional setup after loading the view.
  20. }
  21. - (BOOL)shouldAutorotate
  22. {
  23. return false;
  24. }
  25. - (void)viewWillAppear:(BOOL)animated
  26. {
  27. [super viewWillAppear:animated];
  28. NSMutableDictionary* jitem =(NSMutableDictionary*) self.scan_val;
  29. // jitem[@"product_id"]= item[0];
  30. // NSString* model =item[1];
  31. // NSString* description =item[2];
  32. // jitem[@"model"] =model;
  33. // jitem[@"description"] = [NSString stringWithFormat:@"%@ \r\n%@",model,description];
  34. // jitem[@"unit_price"] =@( [item[3] doubleValue]);
  35. // jitem[@"stockUom"] = @([item[4] intValue]);
  36. // jitem[@"count"] = @([item[4] intValue]);
  37. // jitem[@"subtotal_price"] = @([item[4] intValue]* [item[3] doubleValue]);
  38. //
  39. // jitem[@"check"]=@(true);
  40. // NSString* model =jitem[@"model"];
  41. NSString* description =jitem[@"description"];
  42. double unit_price = [jitem[@"unit_price"] doubleValue];
  43. // jitem[@"model"] =model;
  44. // jitem[@"description"] = [NSString stringWithFormat:@"%@ \r\n%@",model,description];
  45. // jitem[@"unit_price"] =@( [item[3] doubleValue]);
  46. // jitem[@"stockUom"] = @([item[4] intValue]);
  47. // jitem[@"count"] = @([item[4] intValue]);
  48. // jitem[@"subtotal_price"] = @([item[4] intValue]* [item[3] doubleValue]);
  49. //
  50. // jitem[@"check"]=@(true);
  51. //
  52. int stockUom =[jitem[@"stockUom"] intValue];
  53. [self init_Stepper:stockUom max:9999 min:stockUom value:stockUom];
  54. self.descriptionLabel.text = description;
  55. self.qtyEdit.text =[NSString stringWithFormat:@"%d",stockUom];
  56. self.priceLabel.text = [NSString stringWithFormat:@"%.2f",unit_price];
  57. self.mpackLabel.text = [NSString stringWithFormat:@"%d",stockUom];
  58. }
  59. -(void) init_Stepper:(int) step max:(int) max min:(int)min value:(int)value
  60. {
  61. // [self.stepper becomeFirstResponder];
  62. if(self.qtystepper!=nil)
  63. {
  64. if(min<=0)
  65. min=1;
  66. if(step<=0)
  67. step=1;
  68. self.qtystepper.minimumValue= min;
  69. self.qtystepper.stepValue= step;
  70. self.qtystepper.value= value;
  71. [self.qtystepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  72. }
  73. }
  74. - (void)valueChanged:(UIStepper *)sender {
  75. self.qtyEdit.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  76. // self.pre_val = (int)sender.value;
  77. // [self set_Count:(int)sender.value ];
  78. //
  79. // [celldelegate stepClicked:(int)sender.value];
  80. // -(void) stepClicked:(int) value;
  81. }
  82. #pragma mark textField delegate
  83. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  84. [textField resignFirstResponder];
  85. return NO;
  86. }
  87. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  88. // DebugLog(@"text:%@",textField.text);
  89. NSCharacterSet *cs;
  90. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
  91. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
  92. BOOL canChange = [string isEqualToString:filtered];
  93. return canChange;
  94. }
  95. - (void)textFieldDidEndEditing:(UITextField *)textField
  96. {
  97. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  98. int qty = [textField.text intValue];
  99. if(qty==0)
  100. qty=self.qtystepper.minimumValue;
  101. #ifdef MPACK
  102. if ((int)qty % (int)self.stepper.stepValue != 0) {
  103. UIViewController* vc=[RAUtils getViewController :self];
  104. [((CartViewController *)vc).itemListTable reloadData];
  105. [RAUtils message_alert:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] title:@"Change Model Count" controller:vc];
  106. return;
  107. }
  108. #endif
  109. int c=qty;
  110. int m=c%(int)(self.qtystepper.stepValue);
  111. if(m!=0)
  112. {
  113. [RAUtils message_alert:[NSString stringWithFormat:@"QTY must be a multiple of %d",(int)self.qtystepper.stepValue] title:@"Warrning" controller:self];
  114. textField.text = [NSString stringWithFormat:@"%d",self.pre_val];
  115. }
  116. self.pre_val = qty;
  117. }
  118. - (void)textFieldDidBeginEditing:(UITextField *)textField
  119. {
  120. NSString* text = textField.text;
  121. if(text.length==0)
  122. text=@"0";
  123. self.pre_val = [textField.text intValue];
  124. // self.last_edit = textField.text;
  125. }
  126. - (IBAction)onOK:(id)sender {
  127. [self dismissViewControllerAnimated:true completion:^{
  128. if(self.returnValue)
  129. self.returnValue(self.scan_val);
  130. }];
  131. }
  132. - (IBAction)onUpdate:(id)sender {
  133. NSMutableDictionary* jitem =(NSMutableDictionary*) self.scan_val;
  134. int qty = [self.qtyEdit.text intValue];
  135. jitem[@"count"] = @(qty);
  136. jitem[@"subtotal_price"] = @(qty* [jitem[@"unit_price"] doubleValue] );
  137. [self dismissViewControllerAnimated:true completion:^{
  138. if(self.returnValue)
  139. self.returnValue(self.scan_val);
  140. }];
  141. }
  142. /*
  143. #pragma mark - Navigation
  144. // In a storyboard-based application, you will often want to do a little preparation before navigation
  145. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  146. // Get the new view controller using [segue destinationViewController].
  147. // Pass the selected object to the new view controller.
  148. }
  149. */
  150. @end