ScanModelListCell.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. //
  2. // ScanModelListCell.m
  3. // HMLG Scan Order
  4. //
  5. // Created by Rui Zhang on 3/17/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ScanModelListCell.h"
  9. #import "RAConvertor.h"
  10. #import "RAUtils.h"
  11. #import "RASingleton.h"
  12. #import "AppDelegate.h"
  13. #define NUMBERS @"0123456789\n"
  14. @implementation ScanModelListCell
  15. //- (IBAction)stepChange:(id)sender {
  16. // self.editQTY.text = [NSString stringWithFormat:@"%d",(int)((UIStepper*)sender).value ];
  17. //// self.pre_val =(int)((UIStepper*)sender).value;
  18. //}
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. // self.editQTY.delegate = self;
  22. // _editQTY.delegate = self;
  23. // Initialization code
  24. }
  25. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  26. [super setSelected:selected animated:animated];
  27. // Configure the view for the selected state
  28. }
  29. - (void)setModelJson:(NSMutableDictionary *)modelJson
  30. {
  31. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  32. self.labelPrice0.text = appDelegate.price0_name;
  33. self.labelPrice1.text = appDelegate.price1_name;
  34. self.labelPrice2.text = appDelegate.price2_name;
  35. self.labelPrice3.text = appDelegate.price3_name;
  36. _modelJson = modelJson;
  37. _labelModel.text=_modelJson[@"model"];
  38. _labelDescription.text=_modelJson[@"description"];
  39. _labelDimension.text=_modelJson[@"dimension"];
  40. _labelCuft.text=_modelJson[@"unit_cuft"];
  41. _labelOrigin.text=_modelJson[@"origin"];
  42. _labelPort.text=_modelJson[@"port"];
  43. // NSString * cell_price;
  44. // if(RASingleton.sharedInstance.price_type==1)
  45. // {
  46. //// if(_modelJson [@"net_price"])
  47. // cell_price=_modelJson[@"price3"];
  48. //// jitem[@"unit_price"] =jitem[@"price3"];
  49. //// jitem[@"erp_unit_price"] =jitem[@"price3"];
  50. //// else if(_modelJson [@"special_price"])
  51. //// {
  52. //// unit_price= _modelJson[@"price2"];
  53. //// }
  54. //// else
  55. //// {
  56. //// unit_price= _modelJson[@"price1"];
  57. //// }
  58. // }
  59. // else
  60. // {
  61. // cell_price=_modelJson[@"price0"];
  62. //// jitem[@"unit_price"] =jitem[@"price0"];
  63. //// jitem[@"erp_unit_price"] =jitem[@"price0"];
  64. // }
  65. NSString* price0=_modelJson[@"price0"]; //DDP
  66. NSString* price1=_modelJson[@"price1"]; //WHSE
  67. NSString* price2=_modelJson[@"price2"]; //SHOW
  68. NSString* price3=_modelJson[@"price3"]; //%25
  69. if(![price0 isEqualToString: @"N/A"])
  70. price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price0"] doubleValue]];
  71. if(![price1 isEqualToString: @"N/A"])
  72. price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue]];
  73. if(![price2 isEqualToString: @"N/A"])
  74. {
  75. price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price2"] doubleValue]];
  76. // if(RASingleton.sharedInstance.price_type==1)
  77. _modelJson [@"special_price"] = @true;
  78. }
  79. if(![price3 isEqualToString: @"N/A"])
  80. price3 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price3"] doubleValue]];
  81. // if(![_modelJson [@"special_price"] boolValue]&& ![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])
  82. if((![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])||(![price2 isEqualToString: @"N/A"] && [price2 isEqual:price3]))
  83. {
  84. // if(RASingleton.sharedInstance.price_type==1)
  85. _modelJson [@"net_price"] = @true;
  86. }
  87. if([_modelJson[@"price0"] isEqualToString:@"N/A"])
  88. _labelPriceCTNR.text=@"";//_modelJson[@"price0"];
  89. else
  90. _labelPriceCTNR.text=[RAConvertor currencyNumber:[_modelJson[@"price0"] floatValue]];
  91. // if([price3 isEqualToString:@"N/A"])
  92. // _labelPriceNCA.text= price3;
  93. // else
  94. // _labelPriceNCA.text=[RAConvertor currencyNumber:[price3 floatValue]];
  95. if([_modelJson [@"special_price"] boolValue])
  96. {
  97. if([_modelJson[@"price2"] isEqualToString:@"N/A"])
  98. _labelPriceSpecial.text=@"";//_modelJson[@"price2"];
  99. else
  100. _labelPriceSpecial.text=[RAConvertor currencyNumber:[_modelJson[@"price2"] floatValue]];
  101. }
  102. else
  103. {
  104. _labelPriceSpecial.text=@"";//@"N/A";
  105. }
  106. if([_modelJson [@"net_price"] boolValue])
  107. {
  108. // if([_modelJson[@"price1"] isEqualToString:@"N/A"])
  109. // {
  110. // _labelPriceNet.text=_modelJson[@"price1"];
  111. //// _labelPriceNCA.text=@"N/A";
  112. // }
  113. // else
  114. // {
  115. // _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
  116. //// _labelPriceNCA.text=@"N/A";
  117. // }
  118. if([_modelJson[@"price3"] isEqualToString:@"N/A"])
  119. {
  120. _labelPriceNet.text=@"";//_modelJson[@"price3"];
  121. // _labelPriceNCA.text=@"N/A";
  122. }
  123. else
  124. {
  125. _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[@"price3"] floatValue]];
  126. // _labelPriceNCA.text=@"N/A";
  127. }
  128. }
  129. else
  130. {
  131. _labelPriceNet.text=@"";//@"N/A";
  132. }
  133. // {
  134. // if([_modelJson[@"price1"] isEqualToString:@"N/A"])
  135. // {
  136. // _labelPriceNCA.text=_modelJson[@"price1"];
  137. //// _labelPriceNCA.text=@"N/A";
  138. // }
  139. // else
  140. // {
  141. // _labelPriceNCA.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
  142. //// _labelPriceNet.text=@"N/A";
  143. // }
  144. // }
  145. {
  146. if([_modelJson[@"price1"] isEqualToString:@"N/A"])
  147. {
  148. _labelPriceNCA.text=@"";//_modelJson[@"price1"];
  149. // _labelPriceNCA.text=@"N/A";
  150. }
  151. else
  152. {
  153. _labelPriceNCA.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
  154. // _labelPriceNet.text=@"N/A";
  155. }
  156. }
  157. //
  158. // if([cell_price isEqualToString:@"N/A"])
  159. // _labelPriceNCA.text=cell_price;//_modelJson[@"unit_price"];
  160. // else
  161. // _labelPriceNCA.text=[RAConvertor currencyNumber:[cell_price floatValue]];
  162. // if([_modelJson[@"price1"] isEqualToString:@"N/A"])
  163. // {
  164. // _labelPrice25p.text=@"";//_modelJson[@"price2"];
  165. // }
  166. // else
  167. // {
  168. // _labelPrice25p.text=_modelJson[@"price2"];
  169. // }
  170. //
  171. _labelAvailable.text=_modelJson[@"available"];
  172. _editQTY.text=[_modelJson[@"count"] stringValue];
  173. int c =[_modelJson[@"count"] intValue];
  174. int s =[_modelJson[@"stockUom"] intValue];
  175. [self init_Stepper:s max:9999 min:0 value:c];
  176. }
  177. -(void) init_Stepper:(int) step max:(int) max min:(int)min value:(int)value
  178. {
  179. // [self.stepper becomeFirstResponder];
  180. if(self.steper!=nil)
  181. {
  182. // if(min<=0)
  183. // min=1;
  184. if(step<=0)
  185. step=1;
  186. self.steper.minimumValue= min;
  187. self.steper.stepValue= step;
  188. self.steper.value= value;
  189. // [self.qtystepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  190. }
  191. }
  192. //
  193. //#pragma mark textField delegate
  194. //
  195. //- (BOOL)textFieldShouldReturn:(UITextField *)textField {
  196. // [textField resignFirstResponder];
  197. // return NO;
  198. //}
  199. //-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  200. //
  201. //
  202. //// DebugLog(@"text:%@",textField.text);
  203. //
  204. //
  205. //
  206. // NSCharacterSet *cs;
  207. // cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
  208. //
  209. // NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
  210. //
  211. // BOOL canChange = [string isEqualToString:filtered];
  212. //
  213. //
  214. //
  215. //
  216. // return canChange;
  217. //}
  218. //- (void)textFieldDidEndEditing:(UITextField *)textField
  219. //{
  220. //
  221. //
  222. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  223. // int qty = [textField.text intValue];
  224. //
  225. // if(qty==0)
  226. // qty=self.steper.minimumValue;
  227. //
  228. //
  229. //// if ((int)qty % (int)self.stepper.stepValue != 0) {
  230. //// UIViewController* vc=[RAUtils getViewController :self];
  231. //// [((CartViewController *)vc).itemListTable reloadData];
  232. //// [RAUtils message_alert:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] title:@"Change Model Count" controller:vc];
  233. //// return;
  234. //// }
  235. ////
  236. //
  237. // int c=qty;
  238. //
  239. // int m=c%(int)(self.steper.stepValue);
  240. // if(m!=0)
  241. //
  242. // {
  243. // [RAUtils message_alert:[NSString stringWithFormat:@"QTY must be a multiple of %d",(int)self.steper.stepValue] title:@"Warrning" controller:[RAUtils getViewController:self]];
  244. // textField.text = [NSString stringWithFormat:@"%d",self.pre_val];
  245. // }
  246. //
  247. // self.pre_val = qty;
  248. //
  249. //
  250. //
  251. //
  252. //
  253. //
  254. //
  255. //
  256. //}
  257. //
  258. //- (void)textFieldDidBeginEditing:(UITextField *)textField
  259. //{
  260. // NSString* text = textField.text;
  261. // if(text.length==0)
  262. // text=@"0";
  263. // self.pre_val = [textField.text intValue];
  264. //
  265. // // self.last_edit = textField.text;
  266. //}
  267. @end