ProcurementApplyListDetailModel.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // ProcurementApplyListDetailModel.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2018/7/24.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "ProcurementApplyListDetailModel.h"
  9. @implementation ProcurementApplyListDetailModel
  10. /*!
  11. * 1.该方法是 `字典里的属性Key` 和 `要转化为模型里的属性名` 不一样 而重写的
  12. * 前:模型的属性 后:字典里的属性
  13. */
  14. + (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper{
  15. return @{@"orderNo":@"OrderNo",
  16. @"code":@"Code",
  17. @"onlyCode":@"OnlyCode",
  18. @"goodsSpecification":@"Specification",
  19. @"gradeName":@"GradeName",
  20. @"organizationName":@"OrganizationName",
  21. @"applyQuantity":@"ApplyQuantity",
  22. @"approvedQuantity":@"ApprovedQuantity",
  23. @"applyNo":@"ApplyNo",
  24. @"contractNo":@"ContractNumber",
  25. @"brandName":@"BrandName",
  26. @"kindName":@"KindName",
  27. @"varietyName":@"VarietyName",
  28. @"seriesName":@"SeriesName",
  29. @"unitName":@"UnitName",
  30. @"decimalPlaces":@"DecimalPlaces",
  31. @"goodsRemarks":@"GoodsRemarks",
  32. @"colorNo":@"ColorNo",
  33. @"toOrderQuantity":@"ToOrderQuantity",
  34. @"verificationQuantity":@"VerificationQuantity",
  35. @"applicant":@"ApplicantName",
  36. @"staffName":@"StaffName",
  37. @"remarks":@"Remarks",
  38. @"package":@"Package",
  39. @"acreage":@"Acreage",
  40. @"weight":@"Weight",
  41. @"circulateType":@"CirculateType",
  42. @"goodsName":@"GoodsName",
  43. @"box":@"Box",
  44. @"piece":@"Piece",
  45. @"M2":@"M2"
  46. };
  47. }
  48. /*!
  49. * 2. 下面的两个方法 `字典里值`与`模型的值`类型不一样`需要转换`而重写的方法
  50. * NSDate *time dic[@"t"]是double类型的的秒数
  51. */
  52. /// Dic -> model
  53. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  54. double acreageValue= [[dic objectForKey:@"Acreage"]doubleValue];
  55. double weightValue= [[dic objectForKey:@"Weight"]doubleValue];
  56. int circulateTypeValue=[[dic objectForKey:@"CirculateType"]intValue];
  57. double approvedQuantityValue= [[dic objectForKey:@"ApprovedQuantity"]doubleValue];
  58. double applyQuantityValue=[[dic objectForKey:@"ApplyQuantity"]doubleValue];
  59. int decimalPlacesValue=[[dic objectForKey:@"DecimalPlaces"]intValue];
  60. double toOrderQuantityValue=[[dic objectForKey:@"ToOrderQuantity"]doubleValue];
  61. double verificationQuantityValue=[[dic objectForKey:@"VerificationQuantity"]doubleValue];
  62. _orderNo=[dic objectForKey:@"OrderNo"];
  63. _applyNo=[dic objectForKey:@"ApplyNo"];
  64. _acreage=[NSString stringWithFormat:@"%.6f",acreageValue];
  65. _weight=[NSString stringWithFormat:@"%.6f",weightValue];
  66. if([_orderNo isEqualToString:@"小计"]||[_applyNo isEqualToString:@"小计"]){
  67. _approvedQuantity=[NSString stringWithFormat:@"%.6f",approvedQuantityValue];
  68. _applyQuantity=[NSString stringWithFormat:@"%.6f",applyQuantityValue];
  69. }
  70. else{
  71. if(decimalPlacesValue>0){
  72. NSString *format=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlacesValue,@"f" ];
  73. _approvedQuantity=[NSString stringWithFormat:format,approvedQuantityValue];
  74. _applyQuantity=[NSString stringWithFormat:format,applyQuantityValue];
  75. _toOrderQuantity=[NSString stringWithFormat:format,toOrderQuantityValue];
  76. _verificationQuantity=[NSString stringWithFormat:format,verificationQuantityValue];
  77. }
  78. }
  79. if(circulateTypeValue==1){
  80. if([_package integerValue]>0){
  81. if(approvedQuantityValue>=0){
  82. _box = [NSString stringWithFormat:@"%ld",(long)floor(approvedQuantityValue/[_package integerValue])];
  83. }
  84. else{
  85. _box=[NSString stringWithFormat:@"%ld",(long)ceil(approvedQuantityValue/[_package integerValue])];
  86. }
  87. _piece = [NSString stringWithFormat:@"%d",(int)approvedQuantityValue%[_package integerValue]];
  88. }
  89. }
  90. else if(circulateTypeValue==2){
  91. if([_package integerValue]>0&&[_acreage doubleValue]>0){
  92. long pieces=0;
  93. if(approvedQuantityValue>=0){
  94. pieces=ceil(approvedQuantityValue/[_acreage doubleValue]);
  95. _box=[NSString stringWithFormat:@"%ld",(long)floor(pieces/[_package integerValue])];
  96. }
  97. else{
  98. pieces=floor(approvedQuantityValue/[_acreage doubleValue]);
  99. _box=[NSString stringWithFormat:@"%ld",(long)ceil(pieces/[_package integerValue])];
  100. }
  101. _piece=[NSString stringWithFormat:@"%d",(int)pieces%[_package intValue]];
  102. }
  103. }
  104. else{
  105. _box=@"0";
  106. _piece=@"1";
  107. }
  108. double M2Value;
  109. if(_acreage!=nil&&_acreage.length>0){
  110. if(circulateTypeValue==1){
  111. M2Value=acreageValue*approvedQuantityValue;
  112. _M2=[NSString stringWithFormat:@"%.6f",M2Value];
  113. }
  114. else{
  115. _M2=_approvedQuantity;
  116. }
  117. }
  118. return YES;
  119. }
  120. @end