ScanListCell.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. @implementation ScanListCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. // Initialization code
  18. }
  19. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  20. [super setSelected:selected animated:animated];
  21. // Configure the view for the selected state
  22. }
  23. - (IBAction)onAddToCart:(id)sender {
  24. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  25. if(RASingleton.sharedInstance.scan_cart ==nil)
  26. {
  27. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  28. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  29. RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  30. }
  31. // 初始化为 FOB CTNR;
  32. if(RASingleton.sharedInstance.scan_cart[@"price_type"] ==nil)
  33. {
  34. RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
  35. RASingleton.sharedInstance.price_type = 1;
  36. }
  37. NSMutableDictionary* section =[RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  38. int count =[section[@"count"] intValue];
  39. NSMutableDictionary* jitem = nil;
  40. jitem = [self.modelJson mutableCopy];
  41. int stockUom =[jitem[@"stockUom"] intValue];
  42. if(stockUom==0)
  43. stockUom=1;
  44. bool newitem = true;
  45. for(int i=0;i<count;i++)
  46. {
  47. NSMutableDictionary* litem = [section[[NSString stringWithFormat:@"item_%i",i]] mutableCopy];
  48. if([litem[@"product_id"] isEqualToString:jitem[@"product_id"]])
  49. {
  50. // int oldcount = [litem[@"stockUom"] intValue];
  51. newitem = false;
  52. litem[@"count"]=@([litem[@"count"] intValue] +[jitem[@"count"] intValue]);
  53. litem[@"cuft"]=@([litem[@"count"] intValue] * [litem[@"unit_cuft"] doubleValue]);
  54. section[[NSString stringWithFormat:@"item_%i",i]] = litem;
  55. break;
  56. }
  57. }
  58. if(newitem)
  59. {
  60. jitem[@"count"]=@(stockUom);
  61. jitem[@"check"]=@(true);
  62. jitem[@"cart_item_id"]=[NSUUID UUID].UUIDString;
  63. NSString * unit_price;
  64. if(RASingleton.sharedInstance.price_type==0)
  65. unit_price=_modelJson[@"price0"];
  66. else if(_modelJson [@"net_price"])
  67. unit_price=_modelJson[@"price3"];
  68. else if(_modelJson [@"special_price"])
  69. {
  70. unit_price= _modelJson[@"price2"];
  71. }
  72. else
  73. {
  74. unit_price= _modelJson[@"price1"];
  75. }
  76. if([unit_price isEqualToString:@"N/A"])
  77. unit_price = @"0";
  78. else
  79. {
  80. unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
  81. }
  82. jitem[@"unit_price"] = unit_price;
  83. jitem[@"erp_unit_price"] = unit_price;
  84. section[[NSString stringWithFormat:@"item_%i",count]] = jitem;
  85. section[@"count"]= @(count+1);
  86. count++;
  87. }
  88. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  89. //加list
  90. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  91. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  92. [RAUtils message_alert:@"Successfully" title:[NSString stringWithFormat: @"%@ added to cart",jitem[@"model"]] controller:[RAUtils getViewController:self]];
  93. }
  94. - (void)setModelJson:(NSMutableDictionary *)modelJson
  95. {
  96. _modelJson = modelJson;
  97. NSLog( [RAConvertor dict2string:modelJson]);
  98. NSString * port=_modelJson[@"port"];
  99. if(port.length==0)
  100. port = @"N/A";
  101. NSString * origin=_modelJson[@"origin"];
  102. if(origin.length==0)
  103. origin = @"N/A";
  104. NSString * dimension=_modelJson[@"dimension"];
  105. if(dimension.length==0)
  106. dimension = @"N/A";
  107. _labelModel.text=_modelJson[@"model"];
  108. _labelDescription.text=_modelJson[@"description"];
  109. _labelDimension.text=dimension;
  110. _labelCuft.text=_modelJson[@"unit_cuft"];
  111. _labelOrigin.text=origin;
  112. _labelPort.text=port;
  113. NSString* price0=_modelJson[@"price0"]; //DDP
  114. NSString* price1=_modelJson[@"price1"]; //WHSE
  115. NSString* price2=_modelJson[@"price2"]; //SHOW
  116. NSString* price3=_modelJson[@"price3"]; //%25
  117. if(![price0 isEqualToString: @"N/A"])
  118. price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price0"] doubleValue]];
  119. if(![price1 isEqualToString: @"N/A"])
  120. price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue]];
  121. if(![price2 isEqualToString: @"N/A"])
  122. {
  123. price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price2"] doubleValue]];
  124. // if(RASingleton.sharedInstance.price_type==1)
  125. _modelJson [@"special_price"] = @true;
  126. }
  127. if(![price3 isEqualToString: @"N/A"])
  128. price3 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price3"] doubleValue]];
  129. if(![_modelJson [@"special_price"] boolValue]&& ![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])
  130. {
  131. // if(RASingleton.sharedInstance.price_type==1)
  132. _modelJson [@"net_price"] = @true;
  133. }
  134. //
  135. // if(![price1 isEqualToString:@"N/A"])
  136. // {
  137. // price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue] *1.25];
  138. // _modelJson[@"price2"]= price2;
  139. // }
  140. // else
  141. // {
  142. // price2=@"N/A";
  143. // }
  144. //
  145. if([price0 isEqualToString:@"N/A"])
  146. _labelPriceCTNR.text= price0;
  147. else
  148. _labelPriceCTNR.text=[RAConvertor currencyNumber:[price0 floatValue]];
  149. //
  150. // if([price3 isEqualToString:@"N/A"])
  151. // _labelPriceNCA.text= price3;
  152. // else
  153. // _labelPriceNCA.text=[RAConvertor currencyNumber:[price3 floatValue]];
  154. // _labelPrice25p.text=price2;
  155. if([_modelJson [@"special_price"] boolValue])
  156. {
  157. if([_modelJson[@"price2"] isEqualToString:@"N/A"])
  158. _labelPriceSpecial.text=_modelJson[@"price2"];
  159. else
  160. _labelPriceSpecial.text=[RAConvertor currencyNumber:[_modelJson[@"price2"] floatValue]];
  161. }
  162. else
  163. {
  164. _labelPriceSpecial.text=@"N/A";
  165. }
  166. if([_modelJson [@"net_price"] boolValue])
  167. {
  168. if([_modelJson[@"price1"] isEqualToString:@"N/A"])
  169. {
  170. _labelPriceNet.text=_modelJson[@"price1"];
  171. _labelPriceNCA.text=@"N/A";
  172. }
  173. else
  174. {
  175. _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
  176. _labelPriceNCA.text=@"N/A";
  177. }
  178. }
  179. else
  180. {
  181. if([_modelJson[@"price1"] isEqualToString:@"N/A"])
  182. {
  183. _labelPriceNet.text=_modelJson[@"price1"];
  184. _labelPriceNCA.text=@"N/A";
  185. }
  186. else
  187. {
  188. _labelPriceNCA.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
  189. _labelPriceNet.text=@"N/A";
  190. }
  191. }
  192. NSString * available=_modelJson[@"available"];
  193. if(available.length==0)
  194. available = @"N/A";
  195. _labelAvailable.text=available;
  196. NSString * unit_cuft=_modelJson[@"unit_cuft"];
  197. if(unit_cuft.length==0)
  198. unit_cuft = @"N/A";
  199. else
  200. {
  201. unit_cuft = [NSString stringWithFormat:@"%.2f", [_modelJson[@"unit_cuft"] doubleValue]];
  202. }
  203. NSString * cell_price;
  204. if(RASingleton.sharedInstance.price_type==1)
  205. {
  206. // if(_modelJson [@"net_price"])
  207. cell_price=_modelJson[@"price3"];
  208. // else if(_modelJson [@"special_price"])
  209. // {
  210. // unit_price= _modelJson[@"price2"];
  211. // }
  212. // else
  213. // {
  214. // unit_price= _modelJson[@"price1"];
  215. // }
  216. }
  217. else
  218. {
  219. cell_price=_modelJson[@"price0"];
  220. }
  221. NSString * mpack=_modelJson[@"stockUom"];
  222. if([mpack isEqualToString:@"N/A"])
  223. mpack=@"1";
  224. _modelJson[@"count"]=_modelJson[@"stockUom"];
  225. _modelJson[@"cuft"] = @([mpack intValue]* [unit_cuft doubleValue]);
  226. _modelJson[@"subtotal_price"] = @([mpack intValue]* [cell_price doubleValue]);
  227. }
  228. @end