From 7236a0a5b966313ddefdd89df7fa6bf2370dd12f Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期六, 23 三月 2024 17:21:09 +0800 Subject: [PATCH] 采购单修改 --- service/purchase/purchase.go | 45 ++++++++++++++++++++++++--------------------- 1 files changed, 24 insertions(+), 21 deletions(-) diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go index 045ff67..e6b6cb9 100644 --- a/service/purchase/purchase.go +++ b/service/purchase/purchase.go @@ -299,7 +299,7 @@ return int(total), err } -func (slf *PurchaseService) SavePurchaseProductConfirm(list []*purchase.PurchaseProductConfirm) (err error) { +func (slf *PurchaseService) SavePurchaseProductConfirm(list []*purchase.PurchaseProductConfirm, first bool) (err error) { if len(list) == 0 { return errors.New("浜у搧鍒楄〃涓嶈兘涓虹┖") } @@ -311,26 +311,29 @@ } m := make(map[string]interface{}) - now := int64(0) - yu := int64(0) - for _, confirm := range list { - if !confirm.NowReceiveAmount.IsZero() { - now = confirm.NowReceiveAmount.IntPart() - } - if !confirm.SurplusReceiveAmount.IsZero() { - yu = confirm.SurplusReceiveAmount.IntPart() - } - confirm.OverReceiveAmount = confirm.OverReceiveAmount.Add(confirm.NowReceiveAmount) - confirm.NotReceiveAmount = confirm.Amount.Sub(confirm.OverReceiveAmount) - } - if now == 0 && yu > 0 { + newList := make([]*purchase.PurchaseProductConfirm, 0) + if first { m["status"] = purchase.OrderStatusWaitReceive - } - if now > 0 && yu > 0 { - m["status"] = purchase.OrderStatusPartReceive - } - if now > 0 && yu == 0 { - m["status"] = purchase.OrderStatusWaitQuality + newList = list + } else { + yu := int64(0) + for _, confirm := range list { + confirm.OverReceiveAmount = confirm.OverReceiveAmount.Add(confirm.NowReceiveAmount) + confirm.NotReceiveAmount = confirm.Amount.Sub(confirm.OverReceiveAmount) + if !confirm.SurplusReceiveAmount.IsZero() { + yu = confirm.SurplusReceiveAmount.IntPart() + } + //杩囨护鏈鏀惰揣鏁伴噺涓�0鐨勬暟鎹� + if !confirm.NowReceiveAmount.IsZero() { + newList = append(newList, confirm) + } + } + if yu > 0 { + m["status"] = purchase.OrderStatusPartReceive + } + if yu == 0 { + m["status"] = purchase.OrderStatusWaitQuality + } } err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { @@ -339,7 +342,7 @@ return err } - err = tx.Create(list).Error + err = tx.Create(newList).Error if err != nil { return err } -- Gitblit v1.8.0