| | |
| | | |
| | | type Purchase struct { |
| | | global.GVA_MODEL |
| | | PurchaseTypeId int `json:"purchaseTypeId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购类型id |
| | | PurchaseType PurchaseType `json:"purchaseType" gorm:"foreignKey:PurchaseTypeId"` |
| | | SupplierId int `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"` // 供应商id |
| | | Supplier test.Supplier `json:"supplier" gorm:"foreignKey:SupplierId"` |
| | | Number string `json:"number" form:"number" gorm:"unique;type:varchar(255);not null;default '';comment:采购编号"` // 采购编号 |
| | | Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:采购名称"` // 采购名称 |
| | | Quantity decimal.Decimal `json:"quantity" form:"quantity" gorm:"type:decimal(12,4);not null;comment:采购数量"` // 采购数量 |
| | | Contact string `json:"contact" form:"contact" gorm:"type:varchar(255);not null;default '';comment:联系人"` // 联系人 |
| | | Phone string `json:"phone" form:"phone" gorm:"type:varchar(255);not null;default '';comment:联系人电话"` // 联系人电话 |
| | | SigningDate string `json:"signingDate" form:"signingDate" gorm:"type:varchar(255);not null;default '';comment:签约日期"` // 签约日期 |
| | | DeliveryDate string `json:"deliveryDate" form:"deliveryDate" gorm:"type:varchar(255);not null;default '';comment:交付日期"` //交付日期 |
| | | Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null;default '';comment:备注"` //备注 |
| | | Status OrderStatus `json:"status" form:"status" gorm:"type:tinyint(1);not null;default 0;comment:状态"` //状态 |
| | | HandledBy string `json:"handledBy" form:"handledBy" gorm:"type:varchar(255);not null;default '';comment:经办人"` //经办人 |
| | | Creator string `json:"creator" form:"creator" gorm:"type:varchar(255);not null;default '';comment:制单人"` //制单人 |
| | | OrderType string `json:"orderType" form:"orderType" gorm:"type:varchar(255);not null;default '';comment:单据类型"` //单据类型 |
| | | Warehouse string `json:"warehouse" form:"warehouse" gorm:"type:varchar(255);not null;default '';comment:收货仓库"` //收货仓库 |
| | | PurchaseTypeId int `json:"purchaseTypeId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购类型id |
| | | PurchaseType PurchaseType `json:"purchaseType" gorm:"foreignKey:PurchaseTypeId"` |
| | | OrderSource string `json:"orderSource" gorm:"type:varchar(255);not null;default '';comment:单据来源"` // 单据来源 |
| | | SupplierId int `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"` // 供应商id |
| | | Supplier test.Supplier `json:"supplier" gorm:"foreignKey:SupplierId"` |
| | | Number string `json:"number" form:"number" gorm:"unique;type:varchar(255);not null;default '';comment:采购编号"` // 采购编号 |
| | | Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:采购名称"` // 采购名称 |
| | | Contact string `json:"contact" form:"contact" gorm:"type:varchar(255);not null;default '';comment:联系人"` // 联系人 |
| | | Phone string `json:"phone" form:"phone" gorm:"type:varchar(255);not null;default '';comment:联系人电话"` // 联系人电话 |
| | | SigningDate string `json:"signingDate" form:"signingDate" gorm:"type:varchar(255);not null;default '';comment:签约日期"` // 签约日期 |
| | | DeliveryDate string `json:"deliveryDate" form:"deliveryDate" gorm:"type:varchar(255);not null;default '';comment:交付日期"` //交付日期 |
| | | Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null;default '';comment:备注"` //备注 |
| | | Status OrderStatus `json:"status" form:"status" gorm:"type:tinyint(1);not null;default 0;comment:状态"` //状态 |
| | | HandledBy string `json:"handledBy" form:"handledBy" gorm:"type:varchar(255);not null;default '';comment:经办人"` //经办人 |
| | | Creator string `json:"creator" form:"creator" gorm:"type:varchar(255);not null;default '';comment:制单人"` //制单人 |
| | | OrderType string `json:"orderType" form:"orderType" gorm:"type:varchar(255);not null;default '';comment:单据类型"` //单据类型 |
| | | Warehouse string `json:"warehouse" form:"warehouse" gorm:"type:varchar(255);not null;default '';comment:收货仓库"` //收货仓库 |
| | | Quantity decimal.Decimal `json:"quantity" form:"quantity" gorm:"type:decimal(12,4);not null;comment:采购数量"` // 采购数量 |
| | | TotalPrice decimal.Decimal `json:"totalPrice" form:"totalPrice" gorm:"type:decimal(12,2);not null;default '';comment:价税合计"` //价税合计 |
| | | WholeDiscountType WholeDiscountType `json:"wholeDiscountType" form:"wholeDiscountType" gorm:"type:decimal(12,2);not null;default '';comment:整单折扣"` //整单折扣类型 |
| | | WholeDiscount decimal.Decimal `json:"wholeDiscount" form:"wholeDiscount" gorm:"type:decimal(12,2);not null;default '';comment:整单折扣"` //整单折扣值 |
| | | PriceAdjustmentType PriceAdjustmentType `json:"priceAdjustmentType" form:"priceAdjustmentType" gorm:"type:decimal(12,2);not null;default '';comment:价格调整"` //价格调整类型 |
| | | PriceAdjustment decimal.Decimal `json:"priceAdjustment" form:"priceAdjustment" gorm:"type:decimal(12,2);not null;default '';comment:价格调整"` //价格调整值 |
| | | RealTotalPrice decimal.Decimal `json:"realTotalPrice" form:"realTotalPrice" gorm:"type:decimal(12,2);not null;default '';comment:最终价格"` //最终价格 |
| | | } |
| | | |
| | | type OrderStatus int |
| | |
| | | OrderStatusStored OrderStatus = 3 //已入库 |
| | | OrderStatusCompleted OrderStatus = 4 //已完成 |
| | | ) |
| | | |
| | | type WholeDiscountType int |
| | | |
| | | const ( |
| | | WholeDiscountTypePercent WholeDiscountType = 1 //百分比降价 |
| | | WholeDiscountTypeDiscount WholeDiscountType = 2 //直接降价 |
| | | ) |
| | | |
| | | func (wdt WholeDiscountType) IsValid(totalPrice, value decimal.Decimal) bool { |
| | | if wdt != WholeDiscountTypePercent && wdt != WholeDiscountTypeDiscount { |
| | | return false |
| | | } |
| | | if wdt == WholeDiscountTypeDiscount && value.GreaterThanOrEqual(totalPrice) { |
| | | return false |
| | | } |
| | | if wdt == WholeDiscountTypePercent && totalPrice.Mul(value).Div(decimal.NewFromInt(100)).GreaterThanOrEqual(totalPrice) { |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | |
| | | type PriceAdjustmentType int |
| | | |
| | | const ( |
| | | PriceAdjustmentTypeAdd PriceAdjustmentType = 1 //增加 |
| | | PriceAdjustmentTypeSub PriceAdjustmentType = 2 //减少 |
| | | ) |
| | | |
| | | func (pat PriceAdjustmentType) IsValid(totalPrice, value decimal.Decimal) bool { |
| | | if pat != PriceAdjustmentTypeAdd && pat != PriceAdjustmentTypeSub { |
| | | return false |
| | | } |
| | | if pat == PriceAdjustmentTypeSub && value.GreaterThanOrEqual(totalPrice) { |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | |
| | | func (slf Purchase) CalcRealTotalPrice() decimal.Decimal { |
| | | totalPrice := slf.TotalPrice |
| | | if slf.WholeDiscountType == WholeDiscountTypePercent { |
| | | totalPrice = totalPrice.Mul(slf.WholeDiscount).Div(decimal.NewFromInt(100)) |
| | | } else if slf.WholeDiscountType == WholeDiscountTypeDiscount { |
| | | totalPrice = totalPrice.Sub(slf.WholeDiscount) |
| | | } |
| | | |
| | | if slf.PriceAdjustmentType == PriceAdjustmentTypeAdd { |
| | | totalPrice = totalPrice.Add(slf.PriceAdjustment) |
| | | } else if slf.PriceAdjustmentType == PriceAdjustmentTypeSub { |
| | | totalPrice = totalPrice.Sub(slf.PriceAdjustment) |
| | | } |
| | | return totalPrice.RoundCeil(2) |
| | | } |