ScanModelListCell.m 11 KB

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