| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- //
- // NewInstallIItemModel.m
- // IBOSS
- //
- // Created by apple on 16/1/14.
- // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
- //
- // 功能描述:新增安装列表模型
- #import "NewInstallIItemModel.h"
- @implementation NewInstallIItemModel
- #pragma mark - 私有函数
- /*!
- * 1.该方法是 `字典里的属性Key` 和 `要转化为模型里的属性名` 不一样 而重写的
- * 前:模型的属性 后:字典里的属性
- */
- + (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper{
-
- return @{@"installationId":@"InstallationID",
- @"detailId":@"DetailID",
- @"salesDetailId":@"SalesDetailID",
- @"code":@"Code",
- @"onlyCode":@"OnlyCode",
- @"installQuantity":@"InstallationQuantity",
- @"completeQuantity":@"FinishQuantity",
- @"unitId":@"UnitID",
- @"unitName":@"UnitName",
- @"decimalPlaces":@"DecimalPlaces",
- @"circulateType":@"CirculateType",
- @"receiptType":@"ReceiptType",
- @"receiptTypeValue":@"ReceiptType",
- @"payStyle":@"PayStyle",
- @"payStyleValue":@"PayStyle",
- @"box":@"Box",
- @"mm":@"M2",
- @"piece":@"Piece",
- @"acreage":@"Acreage",
- @"package":@"Package",
- @"remarks":@"ReceiptRemarks",
- @"sourceFrom":@"SourceFrom",
- @"goodsName":@"GoodsName"
- };
- }
- /*!
- * 2. 下面的两个方法 `字典里值`与`模型的值`类型不一样`需要转换`而重写的方法
- * NSDate *time dic[@"t"]是double类型的的秒数
- */
- - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
- self.salesDetailType = [[dic objectForKey:@"SalesDetailType"] intValue];
- self.maxReceiptQuantity = [NSString stringWithFormat:@"%.6f",[[dic objectForKey:@"MaxReceiptQuantity"] doubleValue]];
- int decimalPlaces = [[dic objectForKey:@"DecimalPlaces"] intValue];
- NSString *str = [NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
- self.installationId = [[dic objectForKey:@"InstallationID"] stringValue];
- self.detailId = [[dic objectForKey:@"DetailID"] stringValue];
- self.salesDetailId = [[dic objectForKey:@"SalesDetailID"] stringValue];
- self.outQuantity =[dic objectForKey:@"OutQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"OutQuantity"]doubleValue]];
- self.installQuantity = [dic objectForKey:@"InstallationQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"InstallationQuantity"]doubleValue]];
- self.completeQuantity = [dic objectForKey:@"FinishQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"FinishQuantity"]doubleValue]];
- if ([dic objectForKey:@"DecimalPlaces"] == nil) {
- self.decimalPlaces = @"0";
- }
- else{
- self.decimalPlaces = [[dic objectForKey:@"DecimalPlaces"] stringValue];
- }
- self.circulateType = [[dic objectForKey:@"CirculateType"] stringValue];
- self.receiptType = [[dic objectForKey:@"ReceiptType"]stringValue];
- self.receiptTypeValue = [[dic objectForKey:@"ReceiptType"] stringValue];
- self.receiptQuantity = self.maxReceiptQuantity;
- self.box = [[dic objectForKey:@"Box"]stringValue];
- self.mm = [[dic objectForKey:@"M2"]stringValue];
- self.piece = [[dic objectForKey:@"Piece"]stringValue];
- self.acreage = [[dic objectForKey:@"Acreage"]stringValue];
- self.package = [[dic objectForKey:@"Package"]stringValue];
- [self boxAndPieceValue];
-
- return YES;
- }
- /**
- 设置箱和片
- */
- - (void)boxAndPieceValue{
- long box = 0;
- long piece = 0;
- double installQuantity = 0;
- int curculateType = 0;
- long long package = 0;
- double acreage = 0;
- double mm = 0;
-
- if (self.receiptQuantity == nil || [self.receiptQuantity isEqualToString:@""]) {
- self.receiptQuantity = @"0";
- }
- if (self.circulateType == nil|| [self.circulateType isEqualToString:@""]) {
- curculateType = 0;
- }
- else{
- curculateType = [self.circulateType intValue];
- }
-
- if (self.package == nil|| [self.package isEqualToString:@""]) {
- package = 0;
- }
- else{
- package = [self.package longLongValue];
- }
-
- if (self.acreage == nil|| [self.acreage isEqualToString:@""]) {
- acreage = 0;
- }
- else{
- acreage = [self.acreage doubleValue];
- }
-
- installQuantity = [self.receiptQuantity doubleValue];
-
- switch (curculateType) {
- case 1:
- //整数销售
- if (package > 0) {
- if (installQuantity >= 0) {
- box = round(floor(installQuantity / package));
- }
- else{
- box = round(ceil(installQuantity / package));
- }
- piece = (long)installQuantity % package;
- mm = installQuantity*acreage;
-
- }
- break;
-
- case 2:
- //平米销售
- if (package > 0 && acreage > 0) {
- long pieces = 0;
- if (installQuantity >= 0) {
- //计算总的片数
- pieces = round(ceil(installQuantity / acreage));
-
- box = round(floor(pieces / package));
-
- }
- else{
-
- pieces = round(floor(installQuantity / acreage));
-
- box = round(ceil(pieces / package));
- }
- piece = (long)pieces % package;
- mm = installQuantity;
-
- }
- break;
-
- default:
- box = 0;
- piece = 1;
- mm = installQuantity;
-
- break;
- }
-
- self.box = [NSString stringWithFormat:@"%ld",box] ;
- self.piece = [NSString stringWithFormat:@"%ld",piece] ;
- if (mm == 0.0) {
- self.mm = @"0";
- }else{
- self.mm = [NSString stringWithFormat:@"%f",mm];
- }
-
-
- }
- @end
|