From b3a318b7f707ca49fa9127881bbe709654eaa761 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期三, 27 九月 2023 17:27:51 +0800
Subject: [PATCH] 报表功能开发

---
 controllers/operation.go |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index 8eca517..9a87ab0 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -7,6 +7,7 @@
 	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
 	"strconv"
+	"time"
 	"wms/constvar"
 	"wms/extend/code"
 	"wms/extend/util"
@@ -45,8 +46,15 @@
 		util.ResponseFormat(c, code.RequestParamError, err.Error())
 		return
 	}
+	operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
 
 	params.Status = constvar.OperationStatus_Ready
+	params.Number = strconv.FormatInt(time.Now().Unix(), 10)
+	params.BaseOperationType = operationType.BaseOperationType
 	if err := models.NewOperationSearch().Create(&params); err != nil {
 		logx.Errorf("Operation create err: %v", err)
 		util.ResponseFormat(c, code.SaveFail, "娣诲姞澶辫触锛�"+err.Error())
@@ -113,9 +121,9 @@
 		if v.ProductId == "" {
 			return errors.New("productID涓虹┖")
 		}
-		if v.ProductName == "" {
-			return errors.New("浜у搧鍚嶇О寮傚父")
-		}
+		//if v.ProductName == "" {
+		//	return errors.New("浜у搧鍚嶇О寮傚父")
+		//}
 		if v.Amount.IsNegative() {
 			return errors.New("浜у搧鏁伴噺鍑洪敊")
 		}
@@ -156,7 +164,6 @@
 	}
 
 	util.ResponseFormatListWithPage(c, code.Success, list, int(total), params.Page, params.PageSize)
-
 }
 
 func (slf OperationController) CheckListParams(params *request.OperationList) error {
@@ -318,12 +325,18 @@
 					if value, ok := mapProdt[v.ID]; !ok {
 						return errors.New("浜у搧绉嶇被寮傚父")
 					} else {
-						listProdt[k].Amount.Add(value)
+						listProdt[k].Amount = listProdt[k].Amount.Add(value)
 						if err := tx.Save(listProdt[k]).Error; err != nil {
 							return err
 						}
+						//TODO:鍑哄叆搴撶殑finish鍜屾姤搴熺殑finish閮借澧炲姞瀵筶ocation_product_amount琛ㄦ暟閲忕殑鏇存柊,鍥犱负姝よ〃鏈塒roductCategory瀛楁锛屾墍浠peration_details琛ㄤ腑瑕佸鍔燩roductCategoryId瀛楁
+						//var locAmount models.LocationProductAmount
+						//if err := models.NewLocationProductAmountSearch().Orm.Table("wms_location_produt_amount").Joins("inner join wms_location_product on wms_location_produt.id=wms_location_produt_amount.location_product_id").Where("wms_location_produt.product_id=? and wms_location_produt.location_id=?",operation.ToLocationID,v.ID).First(&locAmount).Error;err!=nil {
+						//	return err
+						//}
 					}
 				}
+
 			}
 			if operationType.BaseOperationType == constvar.BaseOperationTypeOutgoing {
 				for k, v := range listProdt {
@@ -333,7 +346,7 @@
 						if v.Amount.LessThan(value) {
 							return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
 						}
-						listProdt[k].Amount.Sub(value)
+						listProdt[k].Amount = listProdt[k].Amount.Sub(value)
 						if err := tx.Save(listProdt[k]).Error; err != nil {
 							return err
 						}
@@ -381,7 +394,5 @@
 		util.ResponseFormat(c, code.RequestError, "鏌ユ壘澶辫触:"+err.Error())
 		return
 	}
-
 	util.ResponseFormatListWithPage(c, code.Success, list, int(total), params.Page, params.PageSize)
-
 }

--
Gitblit v1.8.0