ScanListCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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"] = @0;
  35. RASingleton.sharedInstance.price_type = 0;
  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. bool newitem = true;
  42. for(int i=0;i<count;i++)
  43. {
  44. NSMutableDictionary* litem = [section[[NSString stringWithFormat:@"item_%i",i]] mutableCopy];
  45. if([litem[@"product_id"] isEqualToString:jitem[@"product_id"]])
  46. {
  47. // int oldcount = [litem[@"stockUom"] intValue];
  48. newitem = false;
  49. litem[@"count"]=@([litem[@"count"] intValue] +[jitem[@"count"] intValue]);
  50. litem[@"cuft"]=@([litem[@"count"] intValue] * [litem[@"unit_cuft"] doubleValue]);
  51. section[[NSString stringWithFormat:@"item_%i",i]] = litem;
  52. break;
  53. }
  54. }
  55. if(newitem)
  56. {
  57. jitem[@"check"]=@(true);
  58. jitem[@"cart_item_id"]=[NSUUID UUID].UUIDString;
  59. section[[NSString stringWithFormat:@"item_%i",count]] = jitem;
  60. section[@"count"]= @(count+1);
  61. count++;
  62. }
  63. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  64. //加list
  65. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  66. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  67. [RAUtils message_alert:@"Successful" title:@"Add to cart" controller:[RAUtils getViewController:self]];
  68. }
  69. - (void)setModelJson:(NSMutableDictionary *)modelJson
  70. {
  71. _modelJson = modelJson;
  72. NSLog( [RAConvertor dict2string:modelJson]);
  73. _labelModel.text=_modelJson[@"model"];
  74. _labelDescription.text=_modelJson[@"description"];
  75. _labelDimension.text=_modelJson[@"dimension"];
  76. _labelCuft.text=_modelJson[@"unit_cuft"];
  77. _labelOrigin.text=_modelJson[@"origin"];
  78. _labelPort.text=_modelJson[@"port"];
  79. NSString* price0=_modelJson[@"price0"];
  80. NSString* price1=_modelJson[@"price1"];
  81. NSString* price2;
  82. if(price0.length==0)
  83. price0 = @"N/A";
  84. else
  85. price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price0"] doubleValue]];
  86. if(price1.length==0)
  87. price1 = @"N/A";
  88. else
  89. price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue]];
  90. if(![price1 isEqualToString:@"N/A"])
  91. {
  92. price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue] *1.25];
  93. _modelJson[@"price2"]= price2;
  94. }
  95. else
  96. {
  97. price2=@"N/A";
  98. }
  99. _labelPriceCTNR.text=price0;
  100. _labelPriceNCA.text=price1;
  101. _labelPrice25p.text=price2;
  102. _labelAvailable.text=_modelJson[@"available"];
  103. NSString * unit_cuft=_modelJson[@"unit_cuft"];
  104. if(unit_cuft.length==0)
  105. unit_cuft = @"N/A";
  106. else
  107. {
  108. unit_cuft = [NSString stringWithFormat:@"%.2f", [_modelJson[@"unit_cuft"] doubleValue]];
  109. }
  110. NSString * unit_price;
  111. if(RASingleton.sharedInstance.price_type==2)
  112. {
  113. unit_price=_modelJson[@"price2"];
  114. }
  115. else if(RASingleton.sharedInstance.price_type==1)
  116. {
  117. unit_price=_modelJson[@"price1"];
  118. }
  119. else
  120. {
  121. unit_price=_modelJson[@"price0"];
  122. }
  123. if(unit_price.length==0)
  124. unit_price = @"N/A";
  125. else
  126. {
  127. unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
  128. }
  129. NSString * mpack=_modelJson[@"stockUom"];
  130. _modelJson[@"cuft"] = @([mpack intValue]* [unit_cuft doubleValue]);
  131. _modelJson[@"subtotal_price"] = @([mpack intValue]* [unit_price doubleValue]);
  132. }
  133. @end