ScanModelListCell.m 8.6 KB

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