From d1cb09e7a23e7221b6c090ad33e4481a5b79f615 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 29 十一月 2023 17:44:29 +0800
Subject: [PATCH] 出入库报表搜索增加几个字段

---
 proto/product_inventory/server.go |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/proto/product_inventory/server.go b/proto/product_inventory/server.go
index 1dfaf74..1b624b7 100644
--- a/proto/product_inventory/server.go
+++ b/proto/product_inventory/server.go
@@ -17,9 +17,12 @@
 }
 
 type ProductAndLocationInfo struct {
-	ProductId  string          `json:"productId"`
-	Amount     decimal.Decimal `json:"amount"`
-	LocationId int             `json:"locationId"`
+	ProductId     string          `json:"productId"`
+	Amount        decimal.Decimal `json:"amount"`
+	LocationId    int             `json:"locationId"`
+	Number        string          `json:"number"`
+	WaybillNumber string          `json:"waybillNumber"`
+	Name          string          `json:"name"`
 }
 
 func (s *Server) GetInventoryProductInfo(ctx context.Context, req *GetInventoryProductInfoRequest) (*GetInventoryProductInfoResponse, error) {
@@ -29,12 +32,18 @@
 	//鏌ヨ浜у搧id
 	var details []ProductAndLocationInfo
 	var productIds []string
+	resp := new(GetInventoryProductInfoResponse)
 	err := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}).
-		Select("wms_operation_details.product_id,wms_operation_details.amount,wms_operation.from_location_id as location_id").
+		Select("wms_operation_details.product_id,wms_operation_details.amount,wms_operation.from_location_id as location_id,"+
+			"wms_operation.number,wms_operation.waybill_number, logistic_company.name").
 		Joins("left join wms_operation on wms_operation.id = wms_operation_details.operation_id").
+		Joins("left join logistic_company on logistic_company.id = wms_operation.logistic_company_id").
 		Where("wms_operation.source_number = ?", req.Number).Find(&details).Error
 	if err != nil {
 		return nil, err
+	}
+	if len(details) == 0 {
+		return resp, nil
 	}
 	var locationId int
 	for _, detail := range details {
@@ -84,7 +93,7 @@
 		Joins("left join wms_operation on wms_operation_details.operation_id = wms_operation.id").
 		Where("wms_operation_details.product_id in (?)", productIds).
 		Where("wms_operation.from_location_id in (?)", locationIds).Where("wms_operation.status = ?", constvar.OperationStatus_Ready).
-		Where("wms_operation.base_operation_type in (?)", []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal}).
+		Where("wms_operation.base_operation_type in (?)", []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal, constvar.BaseOperationTypeDisuse}).
 		Find(&canUse).Error
 	if err != nil {
 		return nil, err
@@ -97,6 +106,10 @@
 		for _, detail := range details {
 			if material.ID == detail.ProductId {
 				p.OrderAmount = detail.Amount.String()
+				p.Valorem = detail.Amount.Mul(material.SalePrice).String()
+				p.Invoice = detail.Number
+				p.Carrier = detail.Name
+				p.Waybill = detail.WaybillNumber
 				break
 			}
 		}
@@ -116,11 +129,11 @@
 				cu = cu.Add(info.Amount)
 			}
 		}
+		cu = at.Sub(cu)
 		p.AvailableNumber = cu.String()
 
 		products = append(products, &p)
 	}
-	resp := new(GetInventoryProductInfoResponse)
 	resp.ProductList = products
 	return resp, nil
 }
@@ -143,7 +156,7 @@
 	}
 	operation.OperationTypeName = operationType.Name
 	operation.OperationTypeId = operationType.Id
-	location, err := models.NewLocationSearch().SetJointNames([]string{warehouse.Code}).First()
+	location, err := models.NewLocationSearch().SetID(warehouse.LocationId).First()
 	if err != nil {
 		return nil, err
 	}
@@ -154,6 +167,9 @@
 	}
 	operation.ToLocationID = first.Id
 	operation.BaseOperationType = constvar.BaseOperationTypeOutgoing
+	operation.ReceiverName = req.Addressee
+	operation.ReceiverPhone = req.Phone
+	operation.ReceiverAddr = req.Address
 	if req.DeliverType == 1 {
 		for _, product := range req.ProductList {
 			var detail models.OperationDetails

--
Gitblit v1.8.0