| | |
| | | import ( |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | |
| | | ) |
| | | |
| | | 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 |
| | |
| | | return |
| | | } |
| | | |
| | | //查询出入库数量 |
| | | locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询仓库位置失败") |
| | |
| | | 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 { |
| | |
| | | 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)) |