ScanListCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. //
  2. // ScanListCell.m
  3. // HMLG Scan Order
  4. //
  5. // Created by Rui Zhang on 3/30/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ScanListCell.h"
  9. #import "RASingleton.h"
  10. #import "OLDataProvider.h"
  11. #import "ActiveViewController.h"
  12. #import "RAConvertor.h"
  13. #import "RAUtils.h"
  14. #import "AppDelegate.h"
  15. #import "RADataProvider.h"
  16. @implementation ScanListCell
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. }
  21. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  22. [super setSelected:selected animated:animated];
  23. // Configure the view for the selected state
  24. }
  25. - (IBAction)onAddToCart:(id)sender {
  26. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  27. if(RASingleton.sharedInstance.scan_cart ==nil)
  28. {
  29. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  30. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  31. RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  32. }
  33. // 初始化为 FOB CTNR;
  34. if(RASingleton.sharedInstance.scan_cart[@"price_type"] ==nil)
  35. {
  36. RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
  37. RASingleton.sharedInstance.price_type = 1;
  38. }
  39. NSMutableDictionary* section =[RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  40. int count =[section[@"count"] intValue];
  41. NSMutableDictionary* jitem = nil;
  42. jitem = [self.modelJson mutableCopy];
  43. int stockUom =[jitem[@"stockUom"] intValue];
  44. if(stockUom==0)
  45. stockUom=1;
  46. bool newitem = true;
  47. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  48. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  49. for(int i=0;i<count;i++)
  50. {
  51. NSMutableDictionary* litem = [section[[NSString stringWithFormat:@"item_%i",i]] mutableCopy];
  52. if([litem[@"product_id"] isEqualToString:jitem[@"product_id"]])
  53. {
  54. // int oldcount = [litem[@"stockUom"] intValue];
  55. newitem = false;
  56. litem[@"count"]=@([litem[@"count"] intValue] +[jitem[@"count"] intValue]);
  57. litem[@"cuft"]=@([litem[@"count"] intValue] * [litem[@"unit_cuft"] doubleValue]);
  58. section[[NSString stringWithFormat:@"item_%i",i]] = litem;
  59. break;
  60. }
  61. }
  62. if(newitem)
  63. {
  64. jitem[@"count"]=@(stockUom);
  65. jitem[@"check"]=@(true);
  66. jitem[@"cart_item_id"]=[NSUUID UUID].UUIDString;
  67. NSString * unit_price;
  68. if(RASingleton.sharedInstance.price_type==0)
  69. unit_price=_modelJson[price_group[@"price_0"][@"name"]];
  70. else if(_modelJson [@"special_price"])
  71. {
  72. unit_price= _modelJson[price_group[@"price_2"][@"name"]];
  73. }
  74. else if(_modelJson [@"net_price"])
  75. unit_price=_modelJson[price_group[@"price_3"][@"name"]];
  76. else
  77. {
  78. unit_price= _modelJson[price_group[@"price_1"][@"name"]];
  79. }
  80. if([unit_price isEqualToString:@"N/A"])
  81. unit_price = @"0";
  82. else
  83. {
  84. unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
  85. }
  86. jitem[@"unit_price"] = unit_price;
  87. jitem[@"erp_unit_price"] = unit_price;
  88. section[[NSString stringWithFormat:@"item_%i",count]] = jitem;
  89. section[@"count"]= @(count+1);
  90. count++;
  91. }
  92. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  93. //加list
  94. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  95. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  96. [RAUtils message_alert:@"Successfully" title:[NSString stringWithFormat: @"%@ added to cart",jitem[@"model"]] controller:[RAUtils getViewController:self]];
  97. }
  98. - (void)setModelJson:(NSMutableDictionary *)modelJson
  99. {
  100. _modelJson = modelJson;
  101. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  102. // self.labelPrice0.text = appDelegate.price0_name;
  103. // self.labelPrice1.text = appDelegate.price1_name;
  104. // self.labelPrice2.text = appDelegate.price2_name;
  105. // self.labelPrice3.text = appDelegate.price3_name;
  106. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  107. self.labelPrice0.text = price_group[@"price_0"][@"display"];//appDelegate.price0_name;
  108. self.labelPrice1.text = price_group[@"price_1"][@"display"];//appDelegate.price1_name;
  109. self.labelPrice2.text = price_group[@"price_2"][@"display"];//appDelegate.price2_name;
  110. self.labelPrice3.text = price_group[@"price_3"][@"display"];//appDelegate.price3_name;
  111. if(price_group[@"price_4"])
  112. {
  113. self.labelPrice3.text = price_group[@"price_4"][@"display"];
  114. }
  115. NSLog( [RAConvertor dict2string:modelJson]);
  116. NSString * port=_modelJson[@"port"];
  117. if(port.length==0)
  118. port = @"N/A";
  119. NSString * origin=_modelJson[@"origin"];
  120. if(origin.length==0)
  121. origin = @"N/A";
  122. NSString * dimension=_modelJson[@"dimension"];
  123. if(dimension.length==0)
  124. dimension = @"N/A";
  125. _labelModel.text=_modelJson[@"model"];
  126. _labelDescription.text=_modelJson[@"description"];
  127. _labelDimension.text=dimension;
  128. _labelCuft.text=_modelJson[@"unit_cuft"];
  129. _labelOrigin.text=origin;
  130. _labelPort.text=port;
  131. NSString* price0=_modelJson[price_group[@"price_0"][@"name"]]; //DDP
  132. NSString* price1=_modelJson[price_group[@"price_1"][@"name"]]; //WHSE
  133. NSString* price2=_modelJson[price_group[@"price_2"][@"name"]]; //SHOW
  134. NSString* price3=_modelJson[price_group[@"price_3"][@"name"]]; //NET
  135. if(![price0 isEqualToString: @"N/A"])
  136. price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_0"][@"name"]] doubleValue]];
  137. if(![price1 isEqualToString: @"N/A"])
  138. price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_1"][@"name"]] doubleValue]];
  139. if(![price2 isEqualToString: @"N/A"])
  140. {
  141. price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_2"][@"name"]] doubleValue]];
  142. // if(RASingleton.sharedInstance.price_type==1)
  143. _modelJson [@"special_price"] = @true;
  144. }
  145. if(![price3 isEqualToString: @"N/A"])
  146. price3 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_3"][@"name"]] doubleValue]];
  147. // if(![_modelJson [@"special_price"] boolValue]&& ![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])
  148. if((![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])||(![price2 isEqualToString: @"N/A"] && [price2 isEqual:price3]))
  149. {
  150. // if(RASingleton.sharedInstance.price_type==1)
  151. _modelJson [@"net_price"] = @true;
  152. }
  153. //
  154. // if(![price1 isEqualToString:@"N/A"])
  155. // {
  156. // price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue] *1.25];
  157. // _modelJson[@"price2"]= price2;
  158. // }
  159. // else
  160. // {
  161. // price2=@"N/A";
  162. // }
  163. //
  164. if([price0 isEqualToString:@"N/A"])
  165. _labelPriceCTNR.text= @"";//price0;
  166. else
  167. _labelPriceCTNR.text=[RAConvertor currencyNumber:[price0 floatValue]];
  168. //
  169. // if([price3 isEqualToString:@"N/A"])
  170. // _labelPriceNCA.text= price3;
  171. // else
  172. // _labelPriceNCA.text=[RAConvertor currencyNumber:[price3 floatValue]];
  173. // _labelPrice25p.text=price2;
  174. if([_modelJson [@"special_price"] boolValue])
  175. {
  176. if([_modelJson[price_group[@"price_2"][@"name"]] isEqualToString:@"N/A"])
  177. _labelPriceSpecial.text=@"";//_modelJson[@"price2"];
  178. else
  179. _labelPriceSpecial.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_2"][@"name"]] floatValue]];
  180. }
  181. else
  182. {
  183. _labelPriceSpecial.text=@"";//@"N/A";
  184. }
  185. if([_modelJson [@"net_price"] boolValue])
  186. {
  187. // if([_modelJson[@"price1"] isEqualToString:@"N/A"])
  188. // {
  189. // _labelPriceNet.text=_modelJson[@"price1"];
  190. //// _labelPriceNCA.text=@"N/A";
  191. // }
  192. // else
  193. // {
  194. // _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
  195. //// _labelPriceNCA.text=@"N/A";
  196. // }
  197. if([_modelJson[price_group[@"price_3"][@"name"]] isEqualToString:@"N/A"])
  198. {
  199. _labelPriceNet.text=@"";//_modelJson[@"price3"];
  200. // _labelPriceNCA.text=@"N/A";
  201. }
  202. else
  203. {
  204. _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_3"][@"name"]] floatValue]];
  205. // _labelPriceNCA.text=@"N/A";
  206. }
  207. }
  208. else
  209. {
  210. _labelPriceNet.text=@"";//@"N/A";
  211. }
  212. if(price_group[@"price_4"])
  213. {
  214. // price4 如果存在,会显示在price3的位置
  215. NSString* price4=_modelJson[price_group[@"price_4"][@"name"]]; //%25
  216. if(![price4 isEqualToString: @"N/A"])
  217. price4 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_4"][@"name"]] doubleValue]];
  218. else
  219. price4 =@"";
  220. _labelPriceNet.text=price4;
  221. }
  222. {
  223. if([_modelJson[price_group[@"price_1"][@"name"]] isEqualToString:@"N/A"])
  224. {
  225. _labelPriceNCA.text=@"";//_modelJson[@"price1"];
  226. // _labelPriceNCA.text=@"N/A";
  227. }
  228. else
  229. {
  230. _labelPriceNCA.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_1"][@"name"]] floatValue]];
  231. // _labelPriceNet.text=@"N/A";
  232. }
  233. }
  234. NSString * available=_modelJson[@"available"];
  235. if(available.length==0)
  236. available = @"N/A";
  237. _labelAvailable.text=available;
  238. NSString * unit_cuft=_modelJson[@"unit_cuft"];
  239. if(unit_cuft.length==0)
  240. unit_cuft = @"N/A";
  241. else
  242. {
  243. unit_cuft = [NSString stringWithFormat:@"%.2f", [_modelJson[@"unit_cuft"] doubleValue]];
  244. }
  245. NSString * cell_price;
  246. if(RASingleton.sharedInstance.price_type==1)
  247. {
  248. // if(_modelJson [@"net_price"])
  249. cell_price=_modelJson[price_group[@"price_3"][@"name"]];
  250. // else if(_modelJson [@"special_price"])
  251. // {
  252. // unit_price= _modelJson[@"price2"];
  253. // }
  254. // else
  255. // {
  256. // unit_price= _modelJson[@"price1"];
  257. // }
  258. }
  259. else
  260. {
  261. cell_price=_modelJson[price_group[@"price_0"][@"name"]];
  262. }
  263. NSString * mpack=_modelJson[@"stockUom"];
  264. if([mpack isEqualToString:@"N/A"])
  265. mpack=@"1";
  266. _modelJson[@"count"]=_modelJson[@"stockUom"];
  267. _modelJson[@"cuft"] = @([mpack intValue]* [unit_cuft doubleValue]);
  268. _modelJson[@"subtotal_price"] = @([mpack intValue]* [cell_price doubleValue]);
  269. }
  270. @end