NewDeliveryReceiptModel.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // NewDeliveryReceiptModel.m
  3. // IBOSS
  4. //
  5. // Created by Dongke on 16/1/15.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:新增配送回执模型
  9. #import "NewDeliveryReceiptModel.h"
  10. @implementation NewDeliveryReceiptModel
  11. #pragma mark - 私有函数
  12. /*!
  13. * 1.该方法是 `字典里的属性Key` 和 `要转化为模型里的属性名` 不一样 而重写的
  14. * 前:模型的属性 后:字典里的属性
  15. */
  16. + (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper{
  17. return @{@"code":@"Code",
  18. @"receiptType":@"ReceiptType",
  19. @"receiptRemarks":@"ReceiptRemarks",
  20. @"sourceFrom":@"SourceFrom",
  21. @"detailId":@"DetailID",
  22. @"invoiceId":@"InvoiceID",
  23. @"invoiceDetailId":@"InvoiceDetailID",
  24. @"circulateType":@"CirculateType",
  25. @"acreage":@"Acreage",
  26. @"onlyCode":@"OnlyCode"
  27. };
  28. }
  29. /*!
  30. * 2. 下面的两个方法 `字典里值`与`模型的值`类型不一样`需要转换`而重写的方法
  31. * NSDate *time dic[@"t"]是double类型的的秒数
  32. * Dic -> model
  33. */
  34. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  35. self.salesDetailType = [[dic objectForKey:@"SalesDetailType"] intValue];
  36. self.decimalPlaces = [[dic objectForKey:@"DecimalPlaces"] intValue];
  37. NSString *str = [NSString stringWithFormat:@"%@%d%@",@"%.",self.decimalPlaces,@"f"];
  38. double receiptQuantity = [[dic objectForKey:@"ReceiptQuantity"]doubleValue];
  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.completeReceiptQuantity = [[dic objectForKey:@"CompleteReceiptQuantity"]doubleValue];
  45. self.returnQuantity = [[dic objectForKey:@"ReturnQuantity"]doubleValue];
  46. self.noOutReturnQuantity = [[dic objectForKey:@"NoOutReturnQuantity"]doubleValue];
  47. self.receiptNotInQuantity = [[dic objectForKey:@"ReceiptNotInQuantity"]doubleValue];
  48. self.MNFManufactureQuantity = [[dic objectForKey:@"MNFManufactureQuantity"]doubleValue];
  49. self.sourceFromQuantity = [[dic objectForKey:@"SourceFromQuantity"]doubleValue];
  50. //允许进行回执的量
  51. double tempQuantity;
  52. if([self.sourceFrom doubleValue] == 1){
  53. if([self.outQuantity doubleValue] < self.MNFManufactureQuantity){
  54. tempQuantity = [self.outQuantity doubleValue] -self.receiptNotInQuantity -self.completeReceiptQuantity-self.returnQuantity;
  55. }else{
  56. tempQuantity = [self.outQuantity doubleValue] - self.MNFManufactureQuantity-self.receiptNotInQuantity-self.completeReceiptQuantity-self.returnQuantity;
  57. }
  58. if(self.salesDetailType == 2){
  59. tempQuantity = self.sourceFromQuantity - self.completeReceiptQuantity -self.noOutReturnQuantity;
  60. }
  61. tempQuantity = tempQuantity < 0 ? 0 :tempQuantity;
  62. self.maxReceiptQuantity = [self.deliveryQuantity doubleValue] > tempQuantity? tempQuantity:[self.deliveryQuantity doubleValue];
  63. }
  64. else{
  65. if(![[dic allKeys] containsObject:@"MaxReceiptQuantity"]){
  66. self.maxReceiptQuantity = [self.deliveryQuantity doubleValue] > [self.outQuantity doubleValue]? [self.outQuantity doubleValue]:[self.deliveryQuantity doubleValue];
  67. }
  68. else{
  69. double maximumReceiptQuantityValue=[[dic objectForKey:@"MaxReceiptQuantity"]doubleValue];
  70. self.maxReceiptQuantity=maximumReceiptQuantityValue;
  71. }
  72. }
  73. return YES;
  74. }
  75. @end