liujiandao
2023-11-13 eb3a28fa790ee41bb3755b2b4aa789996c4365ca
在库与可用查询修改
4个文件已修改
68 ■■■■ 已修改文件
controllers/operation.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/reorder_rule_controller.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/report_forms_controller.go 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
proto/product_inventory/server.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/operation.go
@@ -1,6 +1,7 @@
package controllers
import (
    "context"
    "encoding/json"
    "errors"
    "fmt"
@@ -684,7 +685,7 @@
        return
    }
    if operation.SourceNumber != "" {
        go UpdateSalesDetailStatus(c, operation.SourceNumber)
        go UpdateSalesDetailStatus(operation.SourceNumber)
    }
    util.ResponseFormat(c, code.Success, "操作成功")
}
@@ -706,9 +707,9 @@
    }
}
func UpdateSalesDetailStatus(ctx *gin.Context, number string) {
func UpdateSalesDetailStatus(number string) {
    client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn)
    _, err := client.UpdateSalesDetailStatus(ctx, &product_inventory.UpdateSalesDetailStatusRequest{
    _, err := client.UpdateSalesDetailStatus(context.Background(), &product_inventory.UpdateSalesDetailStatusRequest{
        Number:            number,
        SalesDetailStatus: "已出库",
    })
controllers/reorder_rule_controller.go
@@ -119,7 +119,7 @@
        rule.Prediction = rule.Amount.Add(rule.Prediction)
    }
    //出库就绪
    operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal}
    operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal, constvar.BaseOperationTypeDisuse}
    amount, err = GetProductAmount(productIds, nil, locationIds, status, operationType)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询重订货规则列表失败")
@@ -221,7 +221,7 @@
    }
    prediction = amount.Add(prediction)
    //出库就绪
    operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal}
    operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal, constvar.BaseOperationTypeDisuse}
    list, err = GetProductAmount(productIds, nil, locationIds, status, operationType)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询重订货规则列表失败")
controllers/report_forms_controller.go
@@ -3,6 +3,7 @@
import (
    "fmt"
    "github.com/gin-gonic/gin"
    "github.com/shopspring/decimal"
    "wms/constvar"
    "wms/extend/code"
    "wms/extend/util"
@@ -12,6 +13,13 @@
)
type ReportFormsController struct {
}
type Detail struct {
    ProductId string                   `json:"productId"`
    Amount    decimal.Decimal          `json:"amount"`
    Status    constvar.OperationStatus `json:"status"`
    //ProductName string                   `json:"productName"`
}
// GetInventoryForms
@@ -54,7 +62,6 @@
        return
    }
    //查询出入库数量
    locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询仓库位置失败")
@@ -64,19 +71,37 @@
    for _, location := range locations {
        locationIds = append(locationIds, location.Id)
    }
    var inHouse []models.OperationDetails
    var outHouse []models.OperationDetails
    //查询在库数量
    productIds := make([]string, 0)
    for _, material := range materials {
        productIds = append(productIds, material.ID)
    }
    productAmounts, err := models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询在库数量失败")
        return
    }
    //查询出入库就绪数量
    var inHouse []Detail
    var outHouse []Detail
    dbIn := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}).
        Select("wms_operation_details.product_id,wms_operation_details.amount,wms_operation.status as status").
        Joins("left join wms_operation ON wms_operation_details.operation_id=wms_operation.id").
        Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeIncoming).
        Where("wms_operation.status = ?", constvar.OperationStatus_Finish)
        Where("wms_operation.base_operation_type in (?)", []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeInternal}).
        Where("wms_operation.status in (?)", []constvar.OperationStatus{constvar.OperationStatus_Finish})
    dbOut := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}).
        Select("wms_operation_details.product_id,wms_operation_details.amount,wms_operation.status as status").
        Joins("left join wms_operation ON wms_operation_details.operation_id=wms_operation.id").
        Where("wms_operation.base_operation_type in (?)", []int{2, 4}).
        Where("wms_operation.status = ?", constvar.OperationStatus_Finish)
        Where("wms_operation.base_operation_type in (?)", []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal, constvar.BaseOperationTypeDisuse}).
        Where("wms_operation.status in (?)", []constvar.OperationStatus{constvar.OperationStatus_Ready, constvar.OperationStatus_Finish})
    if len(locationIds) > 0 {
        dbIn.Where("wms_operation.to_location_id in (?)", locationIds)
        dbOut.Where("wms_operation.from_location_id in (?)", locationIds)
    }
    if len(productIds) > 0 {
        dbIn.Where("wms_operation_details.product_id in (?)", productIds)
        dbOut.Where("wms_operation_details.product_id in (?)", productIds)
    }
    err = dbIn.Find(&inHouse).Error
    if err != nil {
@@ -97,18 +122,27 @@
        resp.Unit = material.Unit
        resp.Value = material.Amount.Mul(material.Cost)
        resp.ProductType = material.CategoryName
        for _, amount := range productAmounts {
            if material.ID == amount.ProductId {
                resp.Amount = resp.Amount.Add(amount.Amount)
            }
        }
        for _, details := range inHouse {
            if material.ID == details.ProductId {
                resp.In = resp.In.Add(details.Amount)
            }
        }
        available := decimal.NewFromInt(0)
        for _, details := range outHouse {
            if material.ID == details.ProductId {
                resp.Out = resp.Out.Add(details.Amount)
                if details.Status == constvar.OperationStatus_Ready {
                    available = available.Add(details.Amount)
                } else {
                    resp.Out = resp.Out.Add(details.Amount)
                }
            }
        }
        resp.Amount = resp.In.Sub(resp.Out)
        resp.AvailableNumber = resp.Amount
        resp.AvailableNumber = resp.Amount.Sub(available)
        result = append(result, resp)
    }
    util.ResponseFormatList(c, code.Success, result, int(total))
proto/product_inventory/server.go
@@ -93,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
@@ -129,6 +129,7 @@
                cu = cu.Add(info.Amount)
            }
        }
        cu = at.Sub(cu)
        p.AvailableNumber = cu.String()
        products = append(products, &p)