NewDeliveryRequirementModel.m 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // NewDeliveryRequirementModel.m
  3. // IBOSSHSH
  4. //
  5. // Created by ssl on 2018/1/15.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewDeliveryRequirementModel.h"
  9. @implementation NewDeliveryRequirementModel
  10. #pragma mark - 私有函数
  11. /*!
  12. * 1.该方法是 `字典里的属性Key` 和 `要转化为模型里的属性名` 不一样 而重写的
  13. * 前:模型的属性 后:字典里的属性
  14. */
  15. + (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper{
  16. return @{@"code":@"Code",
  17. @"receiptType":@"ReceiptType",
  18. @"receiptRemarks":@"ReceiptRemarks",
  19. @"sourceFrom":@"SourceFrom",
  20. @"detailId":@"DetailID",
  21. @"invoiceId":@"InvoiceID",
  22. @"invoiceDetailId":@"InvoiceDetailID",
  23. @"circulateType":@"CirculateType",
  24. @"acreage":@"Acreage"
  25. };
  26. }
  27. /*!
  28. * 2. 下面的两个方法 `字典里值`与`模型的值`类型不一样`需要转换`而重写的方法
  29. * NSDate *time dic[@"t"]是double类型的的秒数
  30. * Dic -> model
  31. */
  32. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  33. self.salesDetailType = [[dic objectForKey:@"SalesDetailType"] intValue];
  34. self.decimalPlaces = [[dic objectForKey:@"DecimalPlaces"] intValue];
  35. NSString *str = [NSString stringWithFormat:@"%@%d%@",@"%.",self.decimalPlaces,@"f"];
  36. double receiptQuantity = [[dic objectForKey:@"ReceiptQuantity"]doubleValue];
  37. self.receiptType = @"1";
  38. self.installReceiptType = @"1";
  39. if(receiptQuantity){
  40. self.receiptQuantity = [NSString stringWithFormat:str,receiptQuantity];
  41. }
  42. self.outQuantity = [NSString stringWithFormat:str,[[dic objectForKey:@"OutQuantity"]doubleValue]];
  43. self.deliveryQuantity = [NSString stringWithFormat:str,[[dic objectForKey:@"DeliveryQuantity"]doubleValue]];
  44. self.finishQuantity = [[dic objectForKey:@"FinishQuantity"]doubleValue];
  45. self.completeReceiptQuantity = [[dic objectForKey:@"CompleteReceiptQuantity"]doubleValue];
  46. self.returnQuantity = [[dic objectForKey:@"ReturnQuantity"]doubleValue];
  47. self.noOutReturnQuantity = [[dic objectForKey:@"NoOutReturnQuantity"]doubleValue];
  48. self.receiptNotInQuantity = [[dic objectForKey:@"ReceiptNotInQuantity"]doubleValue];
  49. self.MNFManufactureQuantity = [[dic objectForKey:@"MNFManufactureQuantity"]doubleValue];
  50. self.sourceFromQuantity = [[dic objectForKey:@"SourceFromQuantity"]doubleValue];
  51. //允许进行回执的量
  52. double tempQuantity;
  53. if([self.sourceFrom doubleValue] == 1){
  54. if([self.outQuantity doubleValue] < self.MNFManufactureQuantity){
  55. tempQuantity = [self.outQuantity doubleValue] -self.receiptNotInQuantity -self.completeReceiptQuantity-self.returnQuantity;
  56. }else{
  57. tempQuantity = [self.outQuantity doubleValue] - self.MNFManufactureQuantity-self.receiptNotInQuantity-self.completeReceiptQuantity-self.returnQuantity;
  58. }
  59. if(self.salesDetailType == 2){
  60. tempQuantity = self.sourceFromQuantity - self.completeReceiptQuantity -self.noOutReturnQuantity;
  61. }
  62. tempQuantity = tempQuantity < 0 ? 0 :tempQuantity;
  63. self.maxReceiptQuantity = [self.deliveryQuantity doubleValue] > tempQuantity? tempQuantity:[self.deliveryQuantity doubleValue];
  64. }else{
  65. self.maxReceiptQuantity = [self.deliveryQuantity doubleValue] > [self.outQuantity doubleValue]? [self.outQuantity doubleValue]:[self.deliveryQuantity doubleValue];
  66. }
  67. //安装
  68. self.installQuantity = [dic objectForKey:@"InstallationQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"InstallationQuantity"]doubleValue]];
  69. self.maxInstallReceiptQuantity = [NSString stringWithFormat:str,[[dic objectForKey:@"MaxInstallationReceiptQuantity"]doubleValue]];
  70. self.installReceiptQuantity = self.maxInstallReceiptQuantity;
  71. return YES;
  72. }
  73. @end