ScanModelListCell.m 11 KB

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