Commit c63ff51b authored by Sandy's avatar Sandy

修复计算精度问题

parent 95c407fd
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
04B4A3871B9CAAD700D88D68 /* ShopDetail.m in Sources */ = {isa = PBXBuildFile; fileRef = 04B4A3861B9CAAD700D88D68 /* ShopDetail.m */; }; 04B4A3871B9CAAD700D88D68 /* ShopDetail.m in Sources */ = {isa = PBXBuildFile; fileRef = 04B4A3861B9CAAD700D88D68 /* ShopDetail.m */; };
04E721E31BA755FD008F9158 /* ProductUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 04E721E21BA755FD008F9158 /* ProductUnit.m */; }; 04E721E31BA755FD008F9158 /* ProductUnit.m in Sources */ = {isa = PBXBuildFile; fileRef = 04E721E21BA755FD008F9158 /* ProductUnit.m */; };
04F6E70A1B9B08A500550849 /* PurchaseNoticeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04F6E7091B9B08A500550849 /* PurchaseNoticeViewController.m */; }; 04F6E70A1B9B08A500550849 /* PurchaseNoticeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04F6E7091B9B08A500550849 /* PurchaseNoticeViewController.m */; };
19605F981D377CA500C20590 /* CalculateHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 19605F971D377CA500C20590 /* CalculateHelper.m */; };
19D20B8B1D1BC11000BF7FE2 /* NSDictionary+Category.m in Sources */ = {isa = PBXBuildFile; fileRef = 19D20B8A1D1BC11000BF7FE2 /* NSDictionary+Category.m */; }; 19D20B8B1D1BC11000BF7FE2 /* NSDictionary+Category.m in Sources */ = {isa = PBXBuildFile; fileRef = 19D20B8A1D1BC11000BF7FE2 /* NSDictionary+Category.m */; };
300DD94A1B184B450080EE12 /* ICRPatrolPlan.m in Sources */ = {isa = PBXBuildFile; fileRef = 300DD9491B184B450080EE12 /* ICRPatrolPlan.m */; }; 300DD94A1B184B450080EE12 /* ICRPatrolPlan.m in Sources */ = {isa = PBXBuildFile; fileRef = 300DD9491B184B450080EE12 /* ICRPatrolPlan.m */; };
300DD94B1B184B450080EE12 /* ICRPatrolPlan.m in Sources */ = {isa = PBXBuildFile; fileRef = 300DD9491B184B450080EE12 /* ICRPatrolPlan.m */; }; 300DD94B1B184B450080EE12 /* ICRPatrolPlan.m in Sources */ = {isa = PBXBuildFile; fileRef = 300DD9491B184B450080EE12 /* ICRPatrolPlan.m */; };
...@@ -544,6 +545,8 @@ ...@@ -544,6 +545,8 @@
04E721E21BA755FD008F9158 /* ProductUnit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProductUnit.m; sourceTree = "<group>"; }; 04E721E21BA755FD008F9158 /* ProductUnit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProductUnit.m; sourceTree = "<group>"; };
04F6E7081B9B08A500550849 /* PurchaseNoticeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurchaseNoticeViewController.h; sourceTree = "<group>"; }; 04F6E7081B9B08A500550849 /* PurchaseNoticeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurchaseNoticeViewController.h; sourceTree = "<group>"; };
04F6E7091B9B08A500550849 /* PurchaseNoticeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PurchaseNoticeViewController.m; sourceTree = "<group>"; }; 04F6E7091B9B08A500550849 /* PurchaseNoticeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PurchaseNoticeViewController.m; sourceTree = "<group>"; };
19605F961D377CA500C20590 /* CalculateHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CalculateHelper.h; sourceTree = "<group>"; };
19605F971D377CA500C20590 /* CalculateHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CalculateHelper.m; sourceTree = "<group>"; };
19D20B891D1BC11000BF7FE2 /* NSDictionary+Category.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+Category.h"; sourceTree = "<group>"; }; 19D20B891D1BC11000BF7FE2 /* NSDictionary+Category.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+Category.h"; sourceTree = "<group>"; };
19D20B8A1D1BC11000BF7FE2 /* NSDictionary+Category.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+Category.m"; sourceTree = "<group>"; }; 19D20B8A1D1BC11000BF7FE2 /* NSDictionary+Category.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+Category.m"; sourceTree = "<group>"; };
1B0B22845F5CD40B5CF655F2 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; }; 1B0B22845F5CD40B5CF655F2 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
...@@ -2143,6 +2146,8 @@ ...@@ -2143,6 +2146,8 @@
C142D2911AC3A154000109A7 /* Categories */, C142D2911AC3A154000109A7 /* Categories */,
C142D2901AC3A12C000109A7 /* Classes */, C142D2901AC3A12C000109A7 /* Classes */,
C142D28F1AC3A10F000109A7 /* Views */, C142D28F1AC3A10F000109A7 /* Views */,
19605F961D377CA500C20590 /* CalculateHelper.h */,
19605F971D377CA500C20590 /* CalculateHelper.m */,
); );
path = General; path = General;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -3178,6 +3183,7 @@ ...@@ -3178,6 +3183,7 @@
C123A9221B26ED85003C0C36 /* ICRQuestionManager.m in Sources */, C123A9221B26ED85003C0C36 /* ICRQuestionManager.m in Sources */,
C15918801AC4362D0013B391 /* UIApplication+CheckFirstRun.m in Sources */, C15918801AC4362D0013B391 /* UIApplication+CheckFirstRun.m in Sources */,
72A814001BCD3B0A003631F3 /* NewReceiveViewController.m in Sources */, 72A814001BCD3B0A003631F3 /* NewReceiveViewController.m in Sources */,
19605F981D377CA500C20590 /* CalculateHelper.m in Sources */,
0460F6711BA8B3FC004A073D /* FollowUpRecordViewController.m in Sources */, 0460F6711BA8B3FC004A073D /* FollowUpRecordViewController.m in Sources */,
049957E51C8C1CFD003388D3 /* BottomPurchaseView.m in Sources */, 049957E51C8C1CFD003388D3 /* BottomPurchaseView.m in Sources */,
C1F696091AB870B400F9F5DD /* main.m in Sources */, C1F696091AB870B400F9F5DD /* main.m in Sources */,
......
...@@ -259,7 +259,7 @@ static NSString * const ICRHTTPInterface[] = { ...@@ -259,7 +259,7 @@ static NSString * const ICRHTTPInterface[] = {
//版本升级 //版本升级
[XFFHttp_getVersionId] = @"ipapk", [XFFHttp_getVersionId] = @"ipapk",
//报表 //报表
[XFFHttp_Getweekbyday] = @"salesdata/getweekbyday", [XFFHttp_Getweekbyday] = @"salesdata/getweekbyday",
[XFFHttp_QueryHomepage] = @"salesdata/query", [XFFHttp_QueryHomepage] = @"salesdata/query",
[XFFHttp_QueryLowerOrgs] = @"organization/queryLowerOrgs", [XFFHttp_QueryLowerOrgs] = @"organization/queryLowerOrgs",
......
//
// CalculateHelper.h
// XFFruit
//
// Created by Z on 16/7/14.
// Copyright © 2016年 Xummer. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, CalculateType) {
CalculateTypeAdd = 0, //加
CalculateTypeSub, //减
CalculateTypeMul, //乘
CalculateTypeDiv //除
};
@interface CalculateHelper : NSObject
/*
NSRoundPlain, // Round up on a tie //貌似取整
NSRoundDown, // Always down == truncate //只舍不入
NSRoundUp, // Always up // 只入不舍
NSRoundBankers // on a tie round so last digit is even 貌似四舍五入
*/
/**
* 计算
*
* @param num1 第一个数字
* @param num2 第二个数字
* @param type 计算类型(加减乘除)
* @param roundingType 四舍五入类型
* @param coutLenth 小数点后面保留几位
*
* @return 结算结果
*/
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type roundingType:(NSRoundingMode)roundingType cutLenth:(NSInteger)coutLenth;
+ (NSString *)getMoneyStringFrom:(id)num Lenth:(NSInteger)cutLenth;
+ (NSString *)getMoneyStringFrom:(id)num;
@end
//
// CalculateHelper.m
// XFFruit
//
// Created by Z on 16/7/14.
// Copyright © 2016年 Xummer. All rights reserved.
//
#import "CalculateHelper.h"
@implementation CalculateHelper
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type roundingType:(NSRoundingMode)roundingType cutLenth:(NSInteger)coutLenth {
NSDecimalNumberHandler *roundUp = [NSDecimalNumberHandler
decimalNumberHandlerWithRoundingMode:roundingType
scale:coutLenth
raiseOnExactness:NO
raiseOnOverflow:NO
raiseOnUnderflow:NO
raiseOnDivideByZero:YES];
NSDecimalNumber *decimalNum1 = [self changeType:num1];
NSDecimalNumber *decimalNum2 = [self changeType:num2];
NSDecimalNumber *decimalResult;
NSString *result;
switch (type) {
case CalculateTypeAdd: {
decimalResult = [decimalNum1 decimalNumberByAdding:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
break;
}
case CalculateTypeSub: {
decimalResult = [decimalNum1 decimalNumberBySubtracting:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
break;
}
case CalculateTypeMul: {
decimalResult = [decimalNum1 decimalNumberByMultiplyingBy:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
break;
}
case CalculateTypeDiv: {
decimalResult = [decimalNum1 decimalNumberByDividingBy:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
break;
}
}
return decimalResult;
}
+ (NSDecimalNumber *)changeType:(id)num1 {
NSDecimalNumber *decimalNum1;
if ([num1 isKindOfClass:[NSDecimalNumber class]]) {
decimalNum1 = num1;
}else if([num1 isKindOfClass:[NSString class]]){
decimalNum1 = [NSDecimalNumber decimalNumberWithString:num1];
}else if ([num1 isKindOfClass:[NSNumber class]]){
decimalNum1 = [NSDecimalNumber decimalNumberWithDecimal:[num1 decimalValue]];
}else if(num1 == nil){
decimalNum1 = [NSDecimalNumber decimalNumberWithString:@"0"];
}
return decimalNum1;
}
+ (NSString *)getMoneyStringFrom:(id)num Lenth:(NSInteger)cutLenth {
NSDecimalNumberHandler *roundUp = [NSDecimalNumberHandler
decimalNumberHandlerWithRoundingMode:NSRoundBankers
scale:cutLenth ? cutLenth : 2
raiseOnExactness:NO
raiseOnOverflow:NO
raiseOnUnderflow:NO
raiseOnDivideByZero:YES];
NSDecimalNumber *decimal = [self changeType:num];
NSDecimalNumber *result = [decimal decimalNumberByAdding:[NSDecimalNumber decimalNumberWithString:@"0"] withBehavior:roundUp];
return [result stringValue];
}
+ (NSString *)getMoneyStringFrom:(id)num{
NSString *originString = [self getMoneyStringFrom:num Lenth:2];
NSArray *array = [originString componentsSeparatedByString:@"."];
NSString *top = array[0];
NSString *result;
if (array.count == 1) {
result = [NSString stringWithFormat:@"%@.00",top];
}else if(array.count == 2){
NSString *bottom = array[1];
if (bottom.length == 2) {
result = originString;
}
NSString *chr;
for (NSInteger i = bottom.length; i < 2; i++) {
chr =[bottom substringWithRange:NSMakeRange(i, 1)];
if ([chr isEqualToString:@"0"]) {
result = [top stringByAppendingString:chr];
}
}
}
return result;
}
@end
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.2.6</string> <string>1.2.8</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#import "BottomPurchaseView.h" #import "BottomPurchaseView.h"
#import "NewCostViewController.h" #import "NewCostViewController.h"
#import "FeeAcountDetail.h" #import "FeeAcountDetail.h"
#import "CalculateHelper.h"
#define TopHeight 328 #define TopHeight 328
#define BottomHeight 300 #define BottomHeight 300
#define SpaceHeight 20 #define SpaceHeight 20
...@@ -111,7 +112,6 @@ typedef enum : NSUInteger { ...@@ -111,7 +112,6 @@ typedef enum : NSUInteger {
//赋值 //赋值
- (void)prepareDataInCell{ - (void)prepareDataInCell{
_purchaseView.bill = self.purchaseBill; _purchaseView.bill = self.purchaseBill;
NSMutableArray *arr = [NSMutableArray array]; NSMutableArray *arr = [NSMutableArray array];
for (NSDictionary *productDict in self.purchaseBill.products) { for (NSDictionary *productDict in self.purchaseBill.products) {
...@@ -191,26 +191,27 @@ typedef enum : NSUInteger { ...@@ -191,26 +191,27 @@ typedef enum : NSUInteger {
//添加商品明细,更新上部显示的费用 //添加商品明细,更新上部显示的费用
- (void)setProductTotalPrice:(NSNotification *)fication{ - (void)setProductTotalPrice:(NSNotification *)fication{
//计算总金额 //计算总金额
float otherPrice = 0; NSDecimalNumber *otherPrice = [NSDecimalNumber decimalNumberWithString:@"0"];
// if (_aBottomView.costVC.costArr.count == 0) { // if (_aBottomView.costVC.costArr.count == 0) {
// otherPrice = [_purchaseView.otherPriceFiled.text floatValue]; // otherPrice = [_purchaseView.otherPriceFiled.text floatValue];
// }else{ // }else{
for (FeeAcountDetail *cost in _aBottomView.costVC.costArr) { for (FeeAcountDetail *cost in _aBottomView.costVC.costArr) {
otherPrice += [cost.leftmoney floatValue]; otherPrice = [CalculateHelper calculateNum1:otherPrice num2:cost.leftmoney type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:10];
} }
_purchaseView.otherPriceFiled.text = [NSString stringWithFormat:@"%.2f", otherPrice]; _purchaseView.otherPriceFiled.text = [NSString stringWithFormat:@"%@", otherPrice];
// } // }
//其他费用 + 商品总金额 //其他费用 + 商品总金额
NSMutableArray *purchaseProduct = _aBottomView.productVC.productArr; NSMutableArray *purchaseProduct = _aBottomView.productVC.productArr;
float totalPrice = 0; NSDecimalNumber *totalPrice = [NSDecimalNumber decimalNumberWithString:@"0"];
for (PurchaseBillProduct *billProduct in purchaseProduct) { for (PurchaseBillProduct *billProduct in purchaseProduct) {
totalPrice += [billProduct.total floatValue]; totalPrice = [CalculateHelper calculateNum1:totalPrice num2:billProduct.total type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:10];
} }
_purchaseView.purchasePriceLabel.text = [NSString stringWithFormat:@"%.2f",totalPrice + otherPrice]; NSDecimalNumber *all = [CalculateHelper calculateNum1:totalPrice num2:otherPrice type:CalculateTypeAdd roundingType:NSRoundBankers cutLenth:2];
_purchaseView.total = [NSNumber numberWithFloat:totalPrice+otherPrice]; _purchaseView.purchasePriceLabel.text = [NSString stringWithFormat:@"%@",[all stringValue]];
_purchaseView.chargePurchase = [NSNumber numberWithFloat:otherPrice]; _purchaseView.total = all;
_purchaseView.chargePurchase = otherPrice;
...@@ -415,13 +416,13 @@ typedef enum : NSUInteger { ...@@ -415,13 +416,13 @@ typedef enum : NSUInteger {
billProduct.product_uuid = shopDetail.product_uuid; billProduct.product_uuid = shopDetail.product_uuid;
billProduct.product_code = shopDetail.product_code; billProduct.product_code = shopDetail.product_code;
billProduct.product_name = shopDetail.merchandise; billProduct.product_name = shopDetail.merchandise;
billProduct.qpc = [NSNumber numberWithFloat:[shopDetail.packageSpecification floatValue]]; billProduct.qpc = [NSDecimalNumber decimalNumberWithString:shopDetail.packageSpecification];
billProduct.unit = shopDetail.packageUnit; billProduct.unit = shopDetail.packageUnit;
billProduct.qty = [NSNumber numberWithFloat:[shopDetail.packageQuantity floatValue]]; billProduct.qty = [NSDecimalNumber decimalNumberWithString:shopDetail.packageQuantity];
billProduct.price = [NSNumber numberWithFloat:[shopDetail.packageUnitPrice floatValue]]; billProduct.price = shopDetail.packageUnitPrice;
billProduct.baseQty = [NSNumber numberWithFloat:[shopDetail.foundationQuantity floatValue]]; billProduct.baseQty = [NSDecimalNumber decimalNumberWithString:shopDetail.foundationQuantity];
billProduct.basePrice = [NSNumber numberWithFloat:[shopDetail.foundationUnitPrice floatValue]]; billProduct.basePrice = shopDetail.foundationUnitPrice;
billProduct.total = [NSNumber numberWithFloat:[shopDetail.totalMoney floatValue]]; billProduct.total = shopDetail.totalMoney;
billProduct.remark = shopDetail.remark; billProduct.remark = shopDetail.remark;
billProduct.qpcStr = shopDetail.packageQpcStr ? shopDetail.packageQpcStr : @"无"; billProduct.qpcStr = shopDetail.packageQpcStr ? shopDetail.packageQpcStr : @"无";
billProduct.baseUnit = shopDetail.packageQpcUnit; billProduct.baseUnit = shopDetail.packageQpcUnit;
...@@ -433,11 +434,11 @@ typedef enum : NSUInteger { ...@@ -433,11 +434,11 @@ typedef enum : NSUInteger {
shopDetail.product_uuid = billProduct.product_uuid; shopDetail.product_uuid = billProduct.product_uuid;
shopDetail.product_code = billProduct.product_code; shopDetail.product_code = billProduct.product_code;
shopDetail.merchandise = billProduct.product_name; shopDetail.merchandise = billProduct.product_name;
shopDetail.packageSpecification = [billProduct.qpc stringValue]; shopDetail.packageSpecification = [CalculateHelper getMoneyStringFrom:billProduct.qpc Lenth:0];
shopDetail.packageUnit = billProduct.unit; shopDetail.packageUnit = billProduct.unit;
shopDetail.packageQuantity = [billProduct.qty stringValue]; shopDetail.packageQuantity = [CalculateHelper getMoneyStringFrom:billProduct.qty Lenth:0];
shopDetail.packageUnitPrice = billProduct.price; shopDetail.packageUnitPrice = billProduct.price;
shopDetail.foundationQuantity= [billProduct.baseQty stringValue]; shopDetail.foundationQuantity= [CalculateHelper getMoneyStringFrom:billProduct.baseQty Lenth:0];
shopDetail.foundationUnitPrice= billProduct.basePrice; shopDetail.foundationUnitPrice= billProduct.basePrice;
shopDetail.totalMoney= billProduct.total; shopDetail.totalMoney= billProduct.total;
shopDetail.remark = billProduct.remark; shopDetail.remark = billProduct.remark;
......
...@@ -152,11 +152,11 @@ ...@@ -152,11 +152,11 @@
self.showNameLabel.text = [NSString stringWithFormat:@"商品:%@[%@]",billProduct.product_name,billProduct.product_code]; self.showNameLabel.text = [NSString stringWithFormat:@"商品:%@[%@]",billProduct.product_name,billProduct.product_code];
self.showStandLabel.text = [NSString stringWithFormat:@"包装规格:1*%@%@",[billProduct.qpc stringValue],billProduct.baseUnit]; self.showStandLabel.text = [NSString stringWithFormat:@"包装规格:1*%@%@",[billProduct.qpc stringValue],billProduct.baseUnit];
self.showCountLabel.text = [NSString stringWithFormat:@"包装数量:%@%@",[billProduct.qty stringValue],billProduct.unit]; self.showCountLabel.text = [NSString stringWithFormat:@"包装数量:%@%@",billProduct.qty,billProduct.unit];
self.showBaseCountLabel.text =[NSString stringWithFormat:@"基础数量:%@%@",[billProduct.baseQty stringValue],billProduct.baseUnit]; self.showBaseCountLabel.text =[NSString stringWithFormat:@"基础数量:%@%@",billProduct.baseQty ,billProduct.baseUnit];
self.showPriceLabel.text = [NSString stringWithFormat:@"包装单价:%.2f元",[billProduct.price floatValue]]; self.showPriceLabel.text = [NSString stringWithFormat:@"包装单价:%.2f元",[billProduct.price floatValue]];
self.showBasePriceLabel.text = [NSString stringWithFormat:@"基础单价:%.2f元",[billProduct.basePrice floatValue]]; self.showBasePriceLabel.text = [NSString stringWithFormat:@"基础单价:%.2f元",[billProduct.basePrice floatValue]];
self.showTotalLabel.text = [NSString stringWithFormat:@"总金额:%.2f元",[billProduct.total floatValue]]; self.showTotalLabel.text = [NSString stringWithFormat:@"总金额:%@元",[billProduct.total stringValue]];
self.showNoteLabel.text =[NSString stringWithFormat:@"备注:%@",billProduct.remark ? billProduct.remark :@"无" ]; self.showNoteLabel.text =[NSString stringWithFormat:@"备注:%@",billProduct.remark ? billProduct.remark :@"无" ];
[self isShowShippingQty:billProduct]; [self isShowShippingQty:billProduct];
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import "ChooseProductUnitViewController.h" #import "ChooseProductUnitViewController.h"
#import "GXFSearchVendorViewController.h" #import "GXFSearchVendorViewController.h"
#import "GXFProductUnit.h" #import "GXFProductUnit.h"
#import "CalculateHelper.h"
#define LeftMargin 15 #define LeftMargin 15
#define BtnHeight 44 #define BtnHeight 44
#define TableHeight 46 #define TableHeight 46
...@@ -131,20 +132,20 @@ typedef enum : NSUInteger { ...@@ -131,20 +132,20 @@ typedef enum : NSUInteger {
foundationQuantity.text=self.shopDetail.foundationQuantity; foundationQuantity.text=self.shopDetail.foundationQuantity;
//基础单价 //基础单价
if ([self.shopDetail.foundationUnitPrice floatValue] > 0) { if ([self.shopDetail.foundationUnitPrice floatValue] > 0) {
foundationUnitPrice.text= [NSString stringWithFormat:@"%.2f",[self.shopDetail.foundationUnitPrice floatValue]]; foundationUnitPrice.text= [self.shopDetail.foundationUnitPrice stringValue];
} }
self.basePrice = self.shopDetail.foundationUnitPrice; self.basePrice = self.shopDetail.foundationUnitPrice;
//包装单价 //包装单价
if ([self.shopDetail.packageUnitPrice floatValue] > 0) { if ([self.shopDetail.packageUnitPrice floatValue] > 0) {
packageUnitPrice.text=[NSString stringWithFormat:@"%.2f",[self.shopDetail.packageUnitPrice floatValue]]; packageUnitPrice.text=[self.shopDetail.packageUnitPrice stringValue];
} }
self.packPrice = self.shopDetail.packageUnitPrice; self.packPrice = self.shopDetail.packageUnitPrice;
//总金额 //总金额
if ([self.shopDetail.totalMoney floatValue] <= 0) { if ([self.shopDetail.totalMoney floatValue] <= 0) {
totalMoney.text=@"0.0000"; totalMoney.text=@"0.0000";
}else{ }else{
totalMoney.text=[NSString stringWithFormat:@"%.2f",[self.shopDetail.totalMoney floatValue]]; totalMoney.text=[self.shopDetail.totalMoney stringValue];
} }
self.totalPrice = self.shopDetail.totalMoney; self.totalPrice = self.shopDetail.totalMoney;
//备注 //备注
...@@ -240,8 +241,8 @@ typedef enum : NSUInteger { ...@@ -240,8 +241,8 @@ typedef enum : NSUInteger {
self.shopDetail.foundationQuantity = foundationQuantity.text; self.shopDetail.foundationQuantity = foundationQuantity.text;
self.shopDetail.foundationUnitPrice = self.basePrice; self.shopDetail.foundationUnitPrice = self.basePrice;
NSString *totalPrices = totalMoney.text;
self.shopDetail.totalMoney = self.totalPrice; self.shopDetail.totalMoney = [NSDecimalNumber decimalNumberWithString:totalPrices];
self.shopDetail.remark = remark.text; self.shopDetail.remark = remark.text;
if (self.productNameStr.length == 0 ) { if (self.productNameStr.length == 0 ) {
...@@ -490,15 +491,24 @@ typedef enum : NSUInteger { ...@@ -490,15 +491,24 @@ typedef enum : NSUInteger {
- (void)setPacktAndTotalPrice{ - (void)setPacktAndTotalPrice{
if (self.basePrice && foundationUnitPrice.text.length > 0) { if (self.basePrice && foundationUnitPrice.text.length > 0) {
if (foundationQuantity.text.length > 0) { if (foundationQuantity.text.length > 0) {
float basePrice = [self.basePrice doubleValue]; // float basePrice = [self.basePrice floatValue] * 100;
float foundationQtt = [foundationQuantity.text doubleValue]; // int intBasePrice = (int)basePrice;
float totalPrice = basePrice * 1000 * foundationQtt; // int foundationQtt = [foundationQuantity.text intValue];
totalMoney.text = [NSString stringWithFormat:@"%.2f",totalPrice / 1000]; // double price = (intBasePrice * foundationQtt * 1.0);
self.totalPrice = [NSNumber numberWithFloat:totalPrice]; // double totalPrice = price / 100;
// NSDecimalNumber *basePrice = [NSDecimalNumber decimalNumberWithDecimal:[self.basePrice decimalValue]];
// NSDecimalNumber *foundationQty = [NSDecimalNumber decimalNumberWithString:foundationQuantity.text];
// NSDecimalNumber *multiplyResult = [basePrice decimalNumberByMultiplyingBy:foundationQty];
NSDecimalNumber *multiplyResult = [CalculateHelper calculateNum1:self.basePrice num2:foundationQuantity.text type:CalculateTypeMul roundingType:NSRoundBankers cutLenth:2];
totalMoney.text = [multiplyResult stringValue];
self.totalPrice = multiplyResult;
if (packageQuantity.text.length > 0 && [packageQuantity.text floatValue] > 0) { if (packageQuantity.text.length > 0 && [packageQuantity.text floatValue] > 0) {
float packagePrice = totalPrice / [packageQuantity.text floatValue] / 1000;
packageUnitPrice.text = [NSString stringWithFormat:@"%.2f",packagePrice]; NSDecimalNumber *packagePrice = [CalculateHelper calculateNum1:multiplyResult num2:packageQuantity.text type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2] ;
self.packPrice = [NSNumber numberWithFloat:packagePrice];
packageUnitPrice.text = [packagePrice stringValue];
self.packPrice = packagePrice;
} }
} }
} }
...@@ -507,13 +517,21 @@ typedef enum : NSUInteger { ...@@ -507,13 +517,21 @@ typedef enum : NSUInteger {
- (void)setUnitAndTotalPrice{ - (void)setUnitAndTotalPrice{
if (self.packPrice&&packageUnitPrice.text.length > 0) { if (self.packPrice&&packageUnitPrice.text.length > 0) {
if (packageQuantity.text.length > 0) { if (packageQuantity.text.length > 0) {
float totalPrice = [self.packPrice floatValue] * [packageQuantity.text floatValue]; // float pakePrice = [self.packPrice floatValue] * 100;
totalMoney.text = [NSString stringWithFormat:@"%.2f",totalPrice]; // int intPakePrice = (int)pakePrice;
self.totalPrice = [NSNumber numberWithFloat:totalPrice]; // int pakageQty = [packageQuantity.text intValue];
//
// double price = (intPakePrice * pakageQty * 1.0);
// double totalPrice = price / 100;
// float totalPrice = pakePrice * 100 * pakageQty / 100;
NSDecimalNumber *totalPrice = [CalculateHelper calculateNum1:self.packPrice num2:packageQuantity.text type:CalculateTypeMul roundingType:NSRoundBankers cutLenth:2];
totalMoney.text = [totalPrice stringValue];
self.totalPrice = totalPrice;
if (foundationQuantity.text.length > 0 && [foundationQuantity.text integerValue] > 0) { if (foundationQuantity.text.length > 0 && [foundationQuantity.text integerValue] > 0) {
float packagePrice = totalPrice / [foundationQuantity.text floatValue]; NSDecimalNumber *packagePrice = [CalculateHelper calculateNum1:totalPrice num2:foundationQuantity.text type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2];
foundationUnitPrice.text = [NSString stringWithFormat:@"%.2f",packagePrice]; // float packagePrice = totalPrice / [foundationQuantity.text floatValue];
self.basePrice = [NSNumber numberWithFloat:packagePrice]; } foundationUnitPrice.text = packagePrice.stringValue;
self.basePrice = packagePrice; }
} }
} }
} }
...@@ -521,14 +539,18 @@ typedef enum : NSUInteger { ...@@ -521,14 +539,18 @@ typedef enum : NSUInteger {
- (void)setUnitAndPackPrice{ - (void)setUnitAndPackPrice{
if (totalMoney.text.length > 0) { if (totalMoney.text.length > 0) {
if (packageQuantity.text.length > 0 && [packageQuantity.text floatValue] > 0) { if (packageQuantity.text.length > 0 && [packageQuantity.text floatValue] > 0) {
float packagePrice = [self.totalPrice floatValue] / [packageQuantity.text floatValue];
packageUnitPrice.text = [NSString stringWithFormat:@"%.2f",packagePrice]; // float packagePrice = [self.totalPrice floatValue] / [packageQuantity.text floatValue];
self.packPrice = [NSNumber numberWithFloat:packagePrice]; NSDecimalNumber *packagePrice = [CalculateHelper calculateNum1:self.totalPrice num2:packageQuantity.text type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2];
packageUnitPrice.text = packagePrice.stringValue;
self.packPrice = packagePrice;
} }
if (foundationQuantity.text.length > 0 && [foundationQuantity.text floatValue] > 0) { if (foundationQuantity.text.length > 0 && [foundationQuantity.text floatValue] > 0) {
float packagePrice = [self.totalPrice floatValue] / [foundationQuantity.text floatValue]; // float packagePrice = [self.totalPrice floatValue] / [foundationQuantity.text floatValue];
foundationUnitPrice.text = [NSString stringWithFormat:@"%.2f",packagePrice]; NSDecimalNumber *packagePrice = [CalculateHelper calculateNum1:self.totalPrice num2:foundationQuantity.text type:CalculateTypeDiv roundingType:NSRoundBankers cutLenth:2];
self.basePrice = [NSNumber numberWithFloat:packagePrice]; foundationUnitPrice.text = packagePrice.stringValue;
self.basePrice = packagePrice;
} }
} }
} }
......
...@@ -240,6 +240,7 @@ ...@@ -240,6 +240,7 @@
@"pageNumber":@0, @"pageNumber":@0,
@"pageSize":@100 @"pageSize":@100
}; };
CLog(@"%@", dict);
[[ICRHTTPController sharedController] queryHomepageWith:dict success:succ failure:fail]; [[ICRHTTPController sharedController] queryHomepageWith:dict success:succ failure:fail];
} }
...@@ -285,13 +286,13 @@ ...@@ -285,13 +286,13 @@
#pragma mark - 刷新所有的tableView #pragma mark - 刷新所有的tableView
- (void)refreshAllTable{ - (void)refreshAllTable{
svc.count = self.storeCount; svc.count = self.storeCount;
svc.typeStr = self.dayType; svc.typeStr = self.dayType;
pvc.count = self.storeCount; pvc.count = self.storeCount;
pvc.typeStr = self.dayType; pvc.typeStr = self.dayType;
ppvc.count = self.storeCount; ppvc.count = self.storeCount;
ppvc.typeStr = self.dayType; ppvc.typeStr = self.dayType;
gvc.count = self.storeCount; gvc.count = self.storeCount;
gvc.typeStr = self.dayType; gvc.typeStr = self.dayType;
svc.dataArr = self.dataArr; svc.dataArr = self.dataArr;
pvc.dataArr = self.dataArr; pvc.dataArr = self.dataArr;
ppvc.dataArr = self.dataArr; ppvc.dataArr = self.dataArr;
...@@ -355,10 +356,10 @@ ...@@ -355,10 +356,10 @@
NSDate *date ; NSDate *date ;
if (!_selectDay) { if (!_selectDay) {
self.selectDay = [[NSDate date]localYMDString]; self.selectDay = [[NSDate date]localYMDString];
// //
} }
date = [IBTCommon dateFromStringWithFormat:_selectDay format:@"yyyy-MM-dd" ]; date = [IBTCommon dateFromStringWithFormat:_selectDay format:@"yyyy-MM-dd" ];
// NSString *strDate = [_selectDay substringToIndex:_selectDay.length - 3]; // NSString *strDate = [_selectDay substringToIndex:_selectDay.length - 3];
//日周年切换 //日周年切换
NSString *dayType = @""; NSString *dayType = @"";
if ([title isEqualToString:SaleWeek]) { if ([title isEqualToString:SaleWeek]) {
...@@ -368,16 +369,16 @@ ...@@ -368,16 +369,16 @@
[self getWeekbydayFromServer]; [self getWeekbydayFromServer];
return; return;
} }
if ([title isEqualToString:SaleDay]) { if ([title isEqualToString:SaleDay]) {
dayType = @"day"; dayType = @"day";
self.scopeType = _selectDay;//[IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM-dd"]; self.scopeType = _selectDay;//[IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM-dd"];
// }else if ([title isEqualToString:SaleWeek]) { // }else if ([title isEqualToString:SaleWeek]) {
// dayType = @"week"; // dayType = @"week";
// self.scopeType = [IBTCommon getWeekFromDateWithDate:date]; // self.scopeType = [IBTCommon getWeekFromDateWithDate:date];
}else if ([title isEqualToString:SaleMonth]) { }else if ([title isEqualToString:SaleMonth]) {
dayType = @"month"; dayType = @"month";
// date = [IBTCommon dateFromStringWithFormat:strDate format:@"yyyy-MM" ]; // date = [IBTCommon dateFromStringWithFormat:strDate format:@"yyyy-MM" ];
self.scopeType = [IBTCommon stringFromDateWithFormat:date format:@"yyyy-MM"]; self.scopeType = [IBTCommon stringFromDateWithFormat:date format:@"yyyy-MM"];
} else { } else {
return; return;
...@@ -387,7 +388,7 @@ ...@@ -387,7 +388,7 @@
self.orgScope = nil; self.orgScope = nil;
[self getDataFromServer]; [self getDataFromServer];
} }
- (void)customSegTwoClick:(NSString *)title{ - (void)customSegTwoClick:(NSString *)title{
...@@ -401,6 +402,7 @@ ...@@ -401,6 +402,7 @@
} }
} }
//日期选择器开始的初始时间
- (void)startDatePickView:(NSString *)type{ - (void)startDatePickView:(NSString *)type{
if (!self.startTimeView) { if (!self.startTimeView) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment