ScanListCell.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. // remove net price
  112. // if(price_group[@"price_4"])
  113. // {
  114. // self.labelPrice3.text = price_group[@"price_4"][@"display"];
  115. // }
  116. //
  117. NSLog( [RAConvertor dict2string:modelJson]);
  118. NSString * port=_modelJson[@"port"];
  119. if(port.length==0)
  120. port = @"N/A";
  121. NSString * origin=_modelJson[@"origin"];
  122. if(origin.length==0)
  123. origin = @"N/A";
  124. NSString * dimension=_modelJson[@"dimension"];
  125. if(dimension.length==0)
  126. dimension = @"N/A";
  127. _labelModel.text=_modelJson[@"model"];
  128. _labelDescription.text=_modelJson[@"description"];
  129. _labelDimension.text=dimension;
  130. _labelCuft.text=_modelJson[@"unit_cuft"];
  131. _labelOrigin.text=origin;
  132. _labelPort.text=port;
  133. NSString* price0=_modelJson[price_group[@"price_0"][@"name"]]; //DDP
  134. NSString* price1=_modelJson[price_group[@"price_1"][@"name"]]; //WHSE
  135. NSString* price2=_modelJson[price_group[@"price_2"][@"name"]]; //SHOW
  136. NSString* price3=_modelJson[price_group[@"price_3"][@"name"]]; //NET
  137. if(![price0 isEqualToString: @"N/A"])
  138. price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_0"][@"name"]] doubleValue]];
  139. if(![price1 isEqualToString: @"N/A"])
  140. price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_1"][@"name"]] doubleValue]];
  141. if(![price2 isEqualToString: @"N/A"])
  142. {
  143. price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_2"][@"name"]] doubleValue]];
  144. // if(RASingleton.sharedInstance.price_type==1)
  145. _modelJson [@"special_price"] = @true;
  146. }
  147. if(![price3 isEqualToString: @"N/A"])
  148. price3 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_3"][@"name"]] doubleValue]];
  149. // if(![_modelJson [@"special_price"] boolValue]&& ![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])
  150. if((![price1 isEqualToString: @"N/A"] && [price1 isEqualToString:price3])||(![price2 isEqualToString: @"N/A"] && [price2 isEqualToString:price3]))
  151. {
  152. // if(RASingleton.sharedInstance.price_type==1)
  153. _modelJson [@"net_price"] = @true;
  154. // remove net price
  155. _modelJson [@"net_price"] = @false;
  156. }
  157. //
  158. // if(![price1 isEqualToString:@"N/A"])
  159. // {
  160. // price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue] *1.25];
  161. // _modelJson[@"price2"]= price2;
  162. // }
  163. // else
  164. // {
  165. // price2=@"N/A";
  166. // }
  167. //
  168. if([price0 isEqualToString:@"N/A"])
  169. _labelPriceCTNR.text= @"";//price0;
  170. else
  171. _labelPriceCTNR.text=[RAConvertor currencyNumber:[price0 floatValue]];
  172. //
  173. // if([price3 isEqualToString:@"N/A"])
  174. // _labelPriceNCA.text= price3;
  175. // else
  176. // _labelPriceNCA.text=[RAConvertor currencyNumber:[price3 floatValue]];
  177. // _labelPrice25p.text=price2;
  178. if([_modelJson [@"special_price"] boolValue])
  179. {
  180. if([_modelJson[price_group[@"price_2"][@"name"]] isEqualToString:@"N/A"])
  181. _labelPriceSpecial.text=@"";//_modelJson[@"price2"];
  182. else
  183. _labelPriceSpecial.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_2"][@"name"]] floatValue]];
  184. }
  185. else
  186. {
  187. _labelPriceSpecial.text=@"";//@"N/A";
  188. }
  189. // remove net price
  190. // if([_modelJson [@"net_price"] boolValue])
  191. // {
  192. //// if([_modelJson[@"price1"] isEqualToString:@"N/A"])
  193. //// {
  194. //// _labelPriceNet.text=_modelJson[@"price1"];
  195. ////// _labelPriceNCA.text=@"N/A";
  196. //// }
  197. //// else
  198. //// {
  199. //// _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
  200. ////// _labelPriceNCA.text=@"N/A";
  201. //// }
  202. //
  203. // if([_modelJson[price_group[@"price_3"][@"name"]] isEqualToString:@"N/A"])
  204. // {
  205. // _labelPriceNet.text=@"";//_modelJson[@"price3"];
  206. //// _labelPriceNCA.text=@"N/A";
  207. // }
  208. // else
  209. // {
  210. // _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_3"][@"name"]] floatValue]];
  211. //// _labelPriceNCA.text=@"N/A";
  212. // }
  213. //
  214. // }
  215. // else
  216. // {
  217. // _labelPriceNet.text=@"";//@"N/A";
  218. // }
  219. if([_modelJson[price_group[@"price_3"][@"name"]] isEqualToString:@"N/A"])
  220. {
  221. _labelPriceNet.text=@"";//_modelJson[@"price3"];
  222. // _labelPriceNCA.text=@"N/A";
  223. }
  224. else
  225. {
  226. _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_3"][@"name"]] floatValue]];
  227. // _labelPriceNCA.text=@"N/A";
  228. }
  229. // remove net price
  230. // if(price_group[@"price_4"])
  231. // {
  232. // // price4 如果存在,会显示在price3的位置
  233. // NSString* price4=_modelJson[price_group[@"price_4"][@"name"]]; //%25
  234. //
  235. // if(![price4 isEqualToString: @"N/A"])
  236. // price4 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_4"][@"name"]] doubleValue]];
  237. // else
  238. // price4 =@"";
  239. // _labelPriceNet.text=price4;
  240. // }
  241. {
  242. if([_modelJson[price_group[@"price_1"][@"name"]] isEqualToString:@"N/A"])
  243. {
  244. _labelPriceNCA.text=@"";//_modelJson[@"price1"];
  245. // _labelPriceNCA.text=@"N/A";
  246. }
  247. else
  248. {
  249. _labelPriceNCA.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_1"][@"name"]] floatValue]];
  250. // _labelPriceNet.text=@"N/A";
  251. }
  252. }
  253. NSString * available=_modelJson[@"available"];
  254. if(available.length==0)
  255. available = @"N/A";
  256. _labelAvailable.text=available;
  257. NSString * unit_cuft=_modelJson[@"unit_cuft"];
  258. if(unit_cuft.length==0)
  259. unit_cuft = @"N/A";
  260. else
  261. {
  262. unit_cuft = [NSString stringWithFormat:@"%.2f", [_modelJson[@"unit_cuft"] doubleValue]];
  263. }
  264. NSString * cell_price;
  265. if(RASingleton.sharedInstance.price_type==1)
  266. {
  267. // if(_modelJson [@"net_price"])
  268. cell_price=_modelJson[price_group[@"price_3"][@"name"]];
  269. // else if(_modelJson [@"special_price"])
  270. // {
  271. // unit_price= _modelJson[@"price2"];
  272. // }
  273. // else
  274. // {
  275. // unit_price= _modelJson[@"price1"];
  276. // }
  277. }
  278. else
  279. {
  280. cell_price=_modelJson[price_group[@"price_0"][@"name"]];
  281. }
  282. NSString * mpack=_modelJson[@"stockUom"];
  283. if([mpack isEqualToString:@"N/A"])
  284. mpack=@"1";
  285. _modelJson[@"count"]=_modelJson[@"stockUom"];
  286. _modelJson[@"cuft"] = @([mpack intValue]* [unit_cuft doubleValue]);
  287. _modelJson[@"subtotal_price"] = @([mpack intValue]* [cell_price doubleValue]);
  288. }
  289. @end