InventoryDetailModel.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // InventoryDetailModel.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2018/12/11.
  6. // Copyright © 2018 elongtian. All rights reserved.
  7. //
  8. #import "InventoryDetailModel.h"
  9. @implementation InventoryDetailModel
  10. /*!
  11. * 1.该方法是 `字典里的属性Key` 和 `要转化为模型里的属性名` 不一样 而重写的
  12. * 前:模型的属性 后:字典里的属性
  13. */
  14. + (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper{
  15. return @{@"code":@"Code",
  16. @"onlyCode":@"OnlyCode",
  17. @"wareHouseName":@"WarehouseName",
  18. @"goodName":@"GoodsName",
  19. @"specification":@"Specification",
  20. @"colorNumber":@"ColorNumber",
  21. @"brandName":@"BrandName",
  22. @"gradeName":@"GradeName",
  23. @"positionNumber":@"PositionNumber",
  24. @"inventoryQuantity":@"InventoryQuantity",
  25. @"canSaleQuantity":@"CanSaleQuantity",
  26. @"price":@"jzj",
  27. @"costPrice":@"EnterPrice",
  28. @"circulateType":@"CirculateType",
  29. @"package":@"Package",
  30. @"occupyQuantity":@"OccupyQuantity",
  31. @"decimalPlaces":@"DecimalPlaces",
  32. @"noBookOccupyQuantity":@"NoBookOccupyQuantity",
  33. @"freezeQuantity":@"FreezeQuantity",
  34. @"noDeliveryQuantity":@"NoDeliveryQuantity",
  35. @"noEnterQuantity":@"NoEnterQuantity",
  36. @"ceaseFlag":@"CeaseFlag",
  37. @"deliveryQuantity":@"DeliveryQuantity",
  38. @"seriesName":@"SeriesName",
  39. @"unitName":@"UnitName",
  40. @"weight":@"Weight",
  41. @"varietyName":@"VarietyName",
  42. @"acreage":@"Acreage",
  43. @"photo":@"Photo",
  44. @"expandAttribute":@"ExpandAttribute",
  45. @"expandAttribute2":@"ExpandAttribute2"
  46. };
  47. }
  48. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  49. if(dic!=nil){
  50. if([[dic allKeys]containsObject:@"CirculateType"]){
  51. int circulateTypeValue= [[dic objectForKey:@"CirculateType"]intValue];
  52. if(circulateTypeValue==1){
  53. int inventoryQuantityValue=[[dic objectForKey:@"InventoryQuantity"]intValue];
  54. _inventoryQuantity=[NSString stringWithFormat:@"%d",inventoryQuantityValue];
  55. int canSalesQuantityValue= [[dic objectForKey:@"CanSaleQuantity"]intValue];
  56. _canSaleQuantity=[NSString stringWithFormat:@"%d",canSalesQuantityValue];
  57. int occupyQuantityValue=[[dic objectForKey:@"OccupyQuantity"]intValue];
  58. int freezeQuantityValue=[[dic objectForKey:@"FreezeQuantity"]intValue];
  59. int noOccupyQuantityValue=[[dic objectForKey:@"NoBookOccupyQuantity"]intValue];
  60. int noDeliveryQuantityValue=[[dic objectForKey:@"NoDeliveryQuantity"]intValue];
  61. int noEnterQuantityValue=[[dic objectForKey:@"NoEnterQuantity"]intValue];
  62. int estimatedShortageQuantityValue=inventoryQuantityValue-occupyQuantityValue-freezeQuantityValue-noOccupyQuantityValue-noDeliveryQuantityValue+noEnterQuantityValue;
  63. _estimatedShortageQuantity=[NSString stringWithFormat:@"%d",estimatedShortageQuantityValue];
  64. }
  65. else{
  66. int decimalPlacesValue=[[dic objectForKey:@"DecimalPlaces"]intValue];
  67. if(decimalPlacesValue==0){
  68. int inventoryQuantityValue=[[dic objectForKey:@"InventoryQuantity"]intValue];
  69. _inventoryQuantity=[NSString stringWithFormat:@"%d",inventoryQuantityValue];
  70. int canSalesQuantityValue= [[dic objectForKey:@"CanSaleQuantity"]intValue];
  71. _canSaleQuantity=[NSString stringWithFormat:@"%d",canSalesQuantityValue];
  72. int occupyQuantityValue=[[dic objectForKey:@"OccupyQuantity"]intValue];
  73. int freezeQuantityValue=[[dic objectForKey:@"FreezeQuantity"]intValue];
  74. int noOccupyQuantityValue=[[dic objectForKey:@"NoBookOccupyQuantity"]intValue];
  75. int noDeliveryQuantityValue=[[dic objectForKey:@"NoDeliveryQuantity"]intValue];
  76. int noEnterQuantityValue=[[dic objectForKey:@"NoEnterQuantity"]intValue];
  77. int estimatedShortageQuantityValue=inventoryQuantityValue-occupyQuantityValue-freezeQuantityValue-noOccupyQuantityValue-noDeliveryQuantityValue+noEnterQuantityValue;
  78. _estimatedShortageQuantity=[NSString stringWithFormat:@"%d",estimatedShortageQuantityValue];
  79. }
  80. else{
  81. double inventoryQuantityValue=[[dic objectForKey:@"InventoryQuantity"]doubleValue];
  82. NSString* decimalFormat = [NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlacesValue,@"f" ];
  83. _inventoryQuantity=[NSString stringWithFormat:decimalFormat,inventoryQuantityValue];
  84. double canSalesQuantityValue=[[dic objectForKey:@"CanSaleQuantity"]doubleValue];
  85. _canSaleQuantity=[NSString stringWithFormat:decimalFormat,canSalesQuantityValue];
  86. double occupyQuantityValue=[[dic objectForKey:@"OccupyQuantity"]doubleValue];
  87. double freezeQuantityValue=[[dic objectForKey:@"FreezeQuantity"]doubleValue];
  88. double noOccupyQuantityValue=[[dic objectForKey:@"NoBookOccupyQuantity"]doubleValue];
  89. double noDeliveryQuantityValue=[[dic objectForKey:@"NoDeliveryQuantity"]doubleValue];
  90. double noEnterQuantityValue=[[dic objectForKey:@"NoEnterQuantity"]doubleValue];
  91. double estimatedShortageQuantityValue=inventoryQuantityValue-occupyQuantityValue-freezeQuantityValue-noOccupyQuantityValue-noDeliveryQuantityValue+noEnterQuantityValue;
  92. _estimatedShortageQuantity=[NSString stringWithFormat:decimalFormat,estimatedShortageQuantityValue];
  93. }
  94. }
  95. }
  96. else{
  97. int decimalPlacesValue=[[dic objectForKey:@"DecimalPlaces"]intValue];
  98. if(decimalPlacesValue==0){
  99. int inventoryQuantityValue=[[dic objectForKey:@"InventoryQuantity"]intValue];
  100. _inventoryQuantity=[NSString stringWithFormat:@"%d",inventoryQuantityValue];
  101. int canSalesQuantityValue= [[dic objectForKey:@"CanSaleQuantity"]intValue];
  102. _canSaleQuantity=[NSString stringWithFormat:@"%d",canSalesQuantityValue];
  103. int occupyQuantityValue=[[dic objectForKey:@"OccupyQuantity"]intValue];
  104. int freezeQuantityValue=[[dic objectForKey:@"FreezeQuantity"]intValue];
  105. int noOccupyQuantityValue=[[dic objectForKey:@"NoBookOccupyQuantity"]intValue];
  106. int noDeliveryQuantityValue=[[dic objectForKey:@"NoDeliveryQuantity"]intValue];
  107. int noEnterQuantityValue=[[dic objectForKey:@"NoEnterQuantity"]intValue];
  108. int estimatedShortageQuantityValue=inventoryQuantityValue-occupyQuantityValue-freezeQuantityValue-noOccupyQuantityValue-noDeliveryQuantityValue+noEnterQuantityValue;
  109. _estimatedShortageQuantity=[NSString stringWithFormat:@"%d",estimatedShortageQuantityValue];
  110. }
  111. else{
  112. double inventoryQuantityValue=[[dic objectForKey:@"InventoryQuantity"]doubleValue];
  113. NSString* decimalFormat = [NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlacesValue,@"f" ];
  114. _inventoryQuantity=[NSString stringWithFormat:decimalFormat,inventoryQuantityValue];
  115. double canSalesQuantityValue=[[dic objectForKey:@"CanSaleQuantity"]doubleValue];
  116. _canSaleQuantity=[NSString stringWithFormat:decimalFormat,canSalesQuantityValue];
  117. double occupyQuantityValue=[[dic objectForKey:@"OccupyQuantity"]doubleValue];
  118. double freezeQuantityValue=[[dic objectForKey:@"FreezeQuantity"]doubleValue];
  119. double noOccupyQuantityValue=[[dic objectForKey:@"NoBookOccupyQuantity"]doubleValue];
  120. double noDeliveryQuantityValue=[[dic objectForKey:@"NoDeliveryQuantity"]doubleValue];
  121. double noEnterQuantityValue=[[dic objectForKey:@"NoEnterQuantity"]doubleValue];
  122. double estimatedShortageQuantityValue=inventoryQuantityValue-occupyQuantityValue-freezeQuantityValue-noOccupyQuantityValue-noDeliveryQuantityValue+noEnterQuantityValue;
  123. _estimatedShortageQuantity=[NSString stringWithFormat:decimalFormat,estimatedShortageQuantityValue];
  124. }
  125. }
  126. }
  127. return YES;
  128. }
  129. @end