NewInstallIItemModel.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // NewInstallIItemModel.m
  3. // IBOSS
  4. //
  5. // Created by apple on 16/1/14.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:新增安装列表模型
  9. #import "NewInstallIItemModel.h"
  10. @implementation NewInstallIItemModel
  11. #pragma mark - 私有函数
  12. /*!
  13. * 1.该方法是 `字典里的属性Key` 和 `要转化为模型里的属性名` 不一样 而重写的
  14. * 前:模型的属性 后:字典里的属性
  15. */
  16. + (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper{
  17. return @{@"installationId":@"InstallationID",
  18. @"detailId":@"DetailID",
  19. @"salesDetailId":@"SalesDetailID",
  20. @"code":@"Code",
  21. @"onlyCode":@"OnlyCode",
  22. @"installQuantity":@"InstallationQuantity",
  23. @"completeQuantity":@"FinishQuantity",
  24. @"unitId":@"UnitID",
  25. @"unitName":@"UnitName",
  26. @"decimalPlaces":@"DecimalPlaces",
  27. @"circulateType":@"CirculateType",
  28. @"receiptType":@"ReceiptType",
  29. @"receiptTypeValue":@"ReceiptType",
  30. @"payStyle":@"PayStyle",
  31. @"payStyleValue":@"PayStyle",
  32. @"box":@"Box",
  33. @"mm":@"M2",
  34. @"piece":@"Piece",
  35. @"acreage":@"Acreage",
  36. @"package":@"Package",
  37. @"remarks":@"ReceiptRemarks",
  38. @"sourceFrom":@"SourceFrom",
  39. @"goodsName":@"GoodsName"
  40. };
  41. }
  42. /*!
  43. * 2. 下面的两个方法 `字典里值`与`模型的值`类型不一样`需要转换`而重写的方法
  44. * NSDate *time dic[@"t"]是double类型的的秒数
  45. */
  46. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  47. self.salesDetailType = [[dic objectForKey:@"SalesDetailType"] intValue];
  48. self.maxReceiptQuantity = [NSString stringWithFormat:@"%.6f",[[dic objectForKey:@"MaxReceiptQuantity"] doubleValue]];
  49. int decimalPlaces = [[dic objectForKey:@"DecimalPlaces"] intValue];
  50. NSString *str = [NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
  51. self.installationId = [[dic objectForKey:@"InstallationID"] stringValue];
  52. self.detailId = [[dic objectForKey:@"DetailID"] stringValue];
  53. self.salesDetailId = [[dic objectForKey:@"SalesDetailID"] stringValue];
  54. self.outQuantity =[dic objectForKey:@"OutQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"OutQuantity"]doubleValue]];
  55. self.installQuantity = [dic objectForKey:@"InstallationQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"InstallationQuantity"]doubleValue]];
  56. self.completeQuantity = [dic objectForKey:@"FinishQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"FinishQuantity"]doubleValue]];
  57. if ([dic objectForKey:@"DecimalPlaces"] == nil) {
  58. self.decimalPlaces = @"0";
  59. }
  60. else{
  61. self.decimalPlaces = [[dic objectForKey:@"DecimalPlaces"] stringValue];
  62. }
  63. self.circulateType = [[dic objectForKey:@"CirculateType"] stringValue];
  64. self.receiptType = [[dic objectForKey:@"ReceiptType"]stringValue];
  65. self.receiptTypeValue = [[dic objectForKey:@"ReceiptType"] stringValue];
  66. self.receiptQuantity = self.maxReceiptQuantity;
  67. self.box = [[dic objectForKey:@"Box"]stringValue];
  68. self.mm = [[dic objectForKey:@"M2"]stringValue];
  69. self.piece = [[dic objectForKey:@"Piece"]stringValue];
  70. self.acreage = [[dic objectForKey:@"Acreage"]stringValue];
  71. self.package = [[dic objectForKey:@"Package"]stringValue];
  72. [self boxAndPieceValue];
  73. return YES;
  74. }
  75. /**
  76. 设置箱和片
  77. */
  78. - (void)boxAndPieceValue{
  79. long box = 0;
  80. long piece = 0;
  81. double installQuantity = 0;
  82. int curculateType = 0;
  83. long long package = 0;
  84. double acreage = 0;
  85. double mm = 0;
  86. if (self.receiptQuantity == nil || [self.receiptQuantity isEqualToString:@""]) {
  87. self.receiptQuantity = @"0";
  88. }
  89. if (self.circulateType == nil|| [self.circulateType isEqualToString:@""]) {
  90. curculateType = 0;
  91. }
  92. else{
  93. curculateType = [self.circulateType intValue];
  94. }
  95. if (self.package == nil|| [self.package isEqualToString:@""]) {
  96. package = 0;
  97. }
  98. else{
  99. package = [self.package longLongValue];
  100. }
  101. if (self.acreage == nil|| [self.acreage isEqualToString:@""]) {
  102. acreage = 0;
  103. }
  104. else{
  105. acreage = [self.acreage doubleValue];
  106. }
  107. installQuantity = [self.receiptQuantity doubleValue];
  108. switch (curculateType) {
  109. case 1:
  110. //整数销售
  111. if (package > 0) {
  112. if (installQuantity >= 0) {
  113. box = round(floor(installQuantity / package));
  114. }
  115. else{
  116. box = round(ceil(installQuantity / package));
  117. }
  118. piece = (long)installQuantity % package;
  119. mm = installQuantity*acreage;
  120. }
  121. break;
  122. case 2:
  123. //平米销售
  124. if (package > 0 && acreage > 0) {
  125. long pieces = 0;
  126. if (installQuantity >= 0) {
  127. //计算总的片数
  128. pieces = round(ceil(installQuantity / acreage));
  129. box = round(floor(pieces / package));
  130. }
  131. else{
  132. pieces = round(floor(installQuantity / acreage));
  133. box = round(ceil(pieces / package));
  134. }
  135. piece = (long)pieces % package;
  136. mm = installQuantity;
  137. }
  138. break;
  139. default:
  140. box = 0;
  141. piece = 1;
  142. mm = installQuantity;
  143. break;
  144. }
  145. self.box = [NSString stringWithFormat:@"%ld",box] ;
  146. self.piece = [NSString stringWithFormat:@"%ld",piece] ;
  147. if (mm == 0.0) {
  148. self.mm = @"0";
  149. }else{
  150. self.mm = [NSString stringWithFormat:@"%f",mm];
  151. }
  152. }
  153. @end