From 821b6a55dc8f64fce65e51a4d6aaf5511a88855e Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期六, 15 六月 2024 10:19:27 +0800
Subject: [PATCH] 库存内部调拨验证后先生成出库单,出库单验证后生成入库单
---
models/operation.go | 2 +
models/operation_details.go | 1
service/operation.go | 106 ++++++++++++++++++++++++++++++++++-------------------
3 files changed, 71 insertions(+), 38 deletions(-)
diff --git a/models/operation.go b/models/operation.go
index 1d84f86..a3ab05e 100644
--- a/models/operation.go
+++ b/models/operation.go
@@ -59,6 +59,8 @@
Custodian string `json:"custodian" gorm:"type:varchar(255);comment:淇濈鍛樺悕绉�"`
CreatedBy string `json:"createBy" gorm:"type:varchar(255);comment:鍒涘缓鑰匲serId"`
CheckedBy string `json:"checkedBy" gorm:"type:varchar(255);comment:楠岃瘉鑰匲serId"`
+
+ IsInternalOutput bool `json:"isInternalOutput"` //鏄惁璋冩嫧浜х敓鐨勫嚭搴�
}
OperationSearch struct {
diff --git a/models/operation_details.go b/models/operation_details.go
index 278a259..22b9de5 100644
--- a/models/operation_details.go
+++ b/models/operation_details.go
@@ -28,6 +28,7 @@
AuxiliaryAmount decimal.Decimal `json:"auxiliaryAmount" gorm:"type:decimal(20,3);comment:杈呭姪鏁伴噺"`
AuxiliaryUnit string `json:"auxiliaryUnit" gorm:"type:varchar(191);comment:杈呭姪鍗曚綅"`
Remark string `gorm:"type:varchar(1024);comment:澶囨敞" json:"remark"`
+ IsInternalOutput bool `json:"isInternalOutput"` //鏄惁璋冩嫧浜х敓鐨勫嚭搴�
}
OperationDetailsSearch struct {
diff --git a/service/operation.go b/service/operation.go
index 33cc24d..8133d97 100644
--- a/service/operation.go
+++ b/service/operation.go
@@ -224,6 +224,7 @@
// FinishOperationOutput 瀹屾垚鍑哄簱鎴栨姤搴�
func FinishOperationOutput(tx *gorm.DB, listDetails []*models.OperationDetails, mapLocAmount map[string]*models.LocationProductAmount) (err error) {
+ var internalInputDetails []*models.OperationDetails //鍐呴儴璋冩嫧浜х敓鐨勫嚭搴撻獙璇佸悗锛岀敓鎴愬叆搴撳崟
for k, v := range listDetails {
if v.Product.Amount.LessThan(v.Amount) {
return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Product.Name, v.Product.Amount.String(), v.Amount.String()))
@@ -244,39 +245,57 @@
} else {
return errors.New("褰撳墠浠撳簱娌℃湁璇ヤ骇鍝�,璇峰厛鍏ュ簱")
}
+ if v.IsInternalOutput {
+ internalInputDetails = append(internalInputDetails, v)
+ }
+ }
+ if len(internalInputDetails) > 0 {
+ operation := &models.Operation{
+ Number: strconv.FormatInt(time.Now().Unix(), 10),
+ Status: constvar.OperationStatus_Ready,
+ OperationDate: time.Now().Format("2006-01-02 15:04:05"),
+ Comment: "搴撳瓨璋冩嫧鍏ュ簱",
+ BaseOperationType: constvar.BaseOperationTypeIncoming,
+ Details: internalInputDetails,
+ LocationID: internalInputDetails[0].ToLocationID,
+ OperationTypeName: "搴撳瓨璋冩嫧鍏ュ簱",
+ }
+ if err := models.NewOperationSearch().SetOrm(tx).Create(operation); err != nil {
+ return err
+ }
}
return nil
}
-// FinishOperationInternal 瀹屾垚鍐呴儴璋冩嫧
-func FinishOperationInternal(tx *gorm.DB, listDetails []*models.OperationDetails, mapLocAmount map[string]*models.LocationProductAmount) (err error) {
+// FinishOperationInternal 楠岃瘉鍐呴儴璋冩嫧鐢熸垚鍑哄簱鍗�
+func FinishOperationInternal(tx *gorm.DB, listDetails []*models.OperationDetails) (err error) {
+ var outputDetails []*models.OperationDetails
for _, v := range listDetails {
- if fromLocAmount, aok := mapLocAmount[strconv.Itoa(v.FromLocationID)+v.ProductId]; aok {
- if fromLocAmount.Amount.LessThan(v.Amount) {
- return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Product.Name, fromLocAmount.Amount.String(), v.Amount.String()))
+ outputDetails = append(outputDetails, &models.OperationDetails{
+ FromLocationID: v.FromLocationID,
+ ToLocationID: v.ToLocationID,
+ Amount: v.Amount,
+ TotalGrossWeight: v.TotalGrossWeight,
+ TotalNetWeight: v.TotalNetWeight,
+ AuxiliaryAmount: v.AuxiliaryAmount,
+ AuxiliaryUnit: v.AuxiliaryUnit,
+ Remark: v.Remark,
+ IsInternalOutput: true,
+ })
+ if len(outputDetails) > 0 {
+ operation := &models.Operation{
+ Number: strconv.FormatInt(time.Now().Unix(), 10),
+ Status: constvar.OperationStatus_Ready,
+ OperationDate: time.Now().Format("2006-01-02 15:04:05"),
+ Comment: "搴撳瓨璋冩嫧鍑哄簱",
+ BaseOperationType: constvar.BaseOperationTypeOutgoing,
+ Details: outputDetails,
+ LocationID: outputDetails[0].FromLocationID,
+ OperationTypeName: "搴撳瓨璋冩嫧鍑哄簱",
+ IsInternalOutput: true,
}
- fromLocAmount.Amount = fromLocAmount.Amount.Sub(v.Amount)
- if err := models.NewLocationProductAmountSearch().SetOrm(tx).SetID(fromLocAmount.Id).Update(fromLocAmount); err != nil {
- return err
- }
- } else {
- return errors.New("褰撳墠浠撳簱娌℃湁璇ヤ骇鍝�,璇峰厛鍏ュ簱")
- }
-
- if toLocAmount, aok := mapLocAmount[strconv.Itoa(v.ToLocationID)+v.ProductId]; aok {
- toLocAmount.Amount = toLocAmount.Amount.Add(v.Amount)
- if err := models.NewLocationProductAmountSearch().SetOrm(tx).SetID(toLocAmount.Id).Update(toLocAmount); err != nil {
- return err
- }
- } else {
- if err := models.NewLocationProductAmountSearch().SetOrm(tx).Create(&models.LocationProductAmount{
- LocationId: v.ToLocationID,
- ProductCategoryID: v.Product.CategoryId,
- ProductId: v.ProductId,
- Amount: v.Amount,
- CreateDate: time.Now().Format("2006-01-02 15:04:05"),
- }); err != nil {
+ if err := models.NewOperationSearch().SetOrm(tx).Create(operation); err != nil {
return err
}
}
@@ -297,17 +316,27 @@
}
if v.Amount.GreaterThan(locAmount.Amount) {
inputDetails = append(inputDetails, &models.OperationDetails{
- ProductId: v.ProductId,
- Amount: v.Amount.Sub(locAmount.Amount),
- FromLocationID: v.FromLocationID,
- ToLocationID: v.ToLocationID,
+ ProductId: v.ProductId,
+ Amount: v.Amount.Sub(locAmount.Amount),
+ FromLocationID: v.FromLocationID,
+ ToLocationID: v.ToLocationID,
+ TotalGrossWeight: v.TotalGrossWeight,
+ TotalNetWeight: v.TotalNetWeight,
+ AuxiliaryAmount: v.AuxiliaryAmount,
+ AuxiliaryUnit: v.AuxiliaryUnit,
+ Remark: v.Remark,
})
} else {
outputDetails = append(outputDetails, &models.OperationDetails{
- ProductId: v.ProductId,
- Amount: locAmount.Amount.Sub(v.Amount),
- FromLocationID: v.ToLocationID,
- ToLocationID: v.FromLocationID,
+ ProductId: v.ProductId,
+ Amount: locAmount.Amount.Sub(v.Amount),
+ FromLocationID: v.ToLocationID,
+ ToLocationID: v.FromLocationID,
+ TotalGrossWeight: v.TotalGrossWeight,
+ TotalNetWeight: v.TotalNetWeight,
+ AuxiliaryAmount: v.AuxiliaryAmount,
+ AuxiliaryUnit: v.AuxiliaryUnit,
+ Remark: v.Remark,
})
}
} else {
@@ -316,6 +345,7 @@
Amount: v.Amount,
FromLocationID: v.FromLocationID,
ToLocationID: v.ToLocationID,
+ Remark: v.Remark,
})
}
//if locAmount, aok := mapLocAmount[strconv.Itoa(v.ToLocationID)+v.ProductId]; aok {
@@ -340,11 +370,11 @@
Number: strconv.FormatInt(time.Now().Unix(), 10),
Status: constvar.OperationStatus_Ready,
OperationDate: time.Now().Format("2006-01-02 15:04:05"),
- Comment: "搴撳瓨鐩樼偣",
+ Comment: "搴撳瓨璋冩暣鍏ュ簱",
BaseOperationType: constvar.BaseOperationTypeIncoming,
Details: inputDetails,
LocationID: inputDetails[0].FromLocationID,
- OperationTypeName: "搴撳瓨璋冩暣",
+ OperationTypeName: "搴撳瓨璋冩暣鍏ュ簱",
}
if err := models.NewOperationSearch().SetOrm(tx).Create(operation); err != nil {
return err
@@ -355,11 +385,11 @@
Number: strconv.FormatInt(time.Now().Unix(), 10),
Status: constvar.OperationStatus_Ready,
OperationDate: time.Now().Format("2006-01-02 15:04:05"),
- Comment: "搴撳瓨鐩樼偣",
+ Comment: "搴撳瓨璋冩暣鍑哄簱",
BaseOperationType: constvar.BaseOperationTypeOutgoing,
Details: outputDetails,
LocationID: outputDetails[0].FromLocationID,
- OperationTypeName: "搴撳瓨璋冩暣",
+ OperationTypeName: "搴撳瓨璋冩暣鍑哄簱",
}
if err := models.NewOperationSearch().SetOrm(tx).Create(operation); err != nil {
return err
--
Gitblit v1.8.0