From 5a30b6d1fba23bd0e28c370d79693c34856590e6 Mon Sep 17 00:00:00 2001 From: chenlin Date: Tue, 14 Jan 2025 18:07:06 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E6=9C=88=E7=BB=93=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BC=80=E5=A7=8B=E6=97=A5=E6=9C=9F=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=E6=8A=A5=E9=94=99=E7=9A=84=E7=BC=BA=E9=99=B7=EF=BC=9B?= =?UTF-8?q?=202.=E8=BF=9B=E9=94=80=E5=AD=98=E6=8A=A5=E8=A1=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E8=B0=83=E6=95=B4=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/decision/month_end_closing.go | 5 +- app/admin/models/decision.go | 55 ++++++++++++-------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/app/admin/apis/decision/month_end_closing.go b/app/admin/apis/decision/month_end_closing.go index 848bc51..b5222e8 100644 --- a/app/admin/apis/decision/month_end_closing.go +++ b/app/admin/apis/decision/month_end_closing.go @@ -267,8 +267,9 @@ func ErpMonthEndClosingDate(c *gin.Context) { startDate = &nextDate } - resp := model.ErpMonthEndClosingDateResp{ - StartDate: startDate.Format(model.DateTimeFormat), + resp := model.ErpMonthEndClosingDateResp{} + if startDate != nil { + resp.StartDate = startDate.Format(model.DateTimeFormat) } app.OK(c, resp, "获取成功") diff --git a/app/admin/models/decision.go b/app/admin/models/decision.go index 2d94975..f4ed947 100644 --- a/app/admin/models/decision.go +++ b/app/admin/models/decision.go @@ -1693,31 +1693,31 @@ func getSumStartData(req *ErpDecisionReportReq) (DecisionReportData, error) { } // 查询库存汇总数据:采购退货数量、产品入库、系统入库、系统出库、在途库存(入库)数量 - sumStockData, err := getSumStockData(tempReq) + sumStockData, err := getSumStockData(tempReq, false) if err != nil { return DecisionReportData{}, err } // 查询采购进货数量 - sumPurchaseData, err := getSumPurchaseData(tempReq) + sumPurchaseData, err := getSumPurchaseData(tempReq, false) if err != nil { return DecisionReportData{}, err } // 查询零售汇总数据:零售销售数量、零售退货数量 - sumSalesData, err := getSumSalesData(tempReq) + sumSalesData, err := getSumSalesData(tempReq, false) if err != nil { return DecisionReportData{}, err } // 查询盘点汇总数据:盘点入库数量、盘点出库数量 - sumInventoryData, err := getSumInventoryData(tempReq) + sumInventoryData, err := getSumInventoryData(tempReq, false) if err != nil { return DecisionReportData{}, err } // 查询调拨汇总数据:在途库存(出库)数量、调拨入库数量、调拨出库数量 - sumAllotData, err := getSumAllotData(tempReq) + sumAllotData, err := getSumAllotData(tempReq, false) if err != nil { return DecisionReportData{}, err } @@ -2130,7 +2130,7 @@ func getSumEndCount(req *ErpDecisionReportReq) (DecisionReportData, error) { } // 查询库存汇总数据:采购退货数量、产品入库、系统入库、系统出库、在途库存(入库)数量 -func getSumStockData(req *ErpDecisionReportReq) (DecisionReportData, error) { +func getSumStockData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionReportData, error) { var reportData DecisionReportData qs := orm.Eloquent.Debug().Table("erp_stock_commodity") @@ -2143,7 +2143,7 @@ func getSumStockData(req *ErpDecisionReportReq) (DecisionReportData, error) { qs = qs.Where("created_at > ?", parse) } - if req.EndTime != "" { + if req.EndTime != "" && endTimeFlag { parse, err := time.Parse(QueryTimeFormat, req.EndTime) if err != nil { logger.Errorf("getStockData err:", err) @@ -2195,7 +2195,7 @@ func getSumStockData(req *ErpDecisionReportReq) (DecisionReportData, error) { SUM(CASE WHEN state = ? THEN wholesale_price ELSE 0 END) AS system_out_amount, SUM(CASE WHEN state = ? THEN count ELSE 0 END) AS allot_wait_in, SUM(CASE WHEN state = ? THEN wholesale_price ELSE 0 END) AS allot_wait_in_amount - `, PurchaseReturn, PurchaseReturn, ProductInventory, ProductInventory, SystemInventory, SystemInventory, + `, PurchaseCancel, PurchaseCancel, ProductInventory, ProductInventory, SystemInventory, SystemInventory, SystemOut, SystemOut, InAllot, InAllot) err := subQuery.Scan(&reportData).Error @@ -2208,7 +2208,7 @@ func getSumStockData(req *ErpDecisionReportReq) (DecisionReportData, error) { } // 查询采购进货数量 -func getSumPurchaseData(req *ErpDecisionReportReq) (DecisionReportData, error) { +func getSumPurchaseData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionReportData, error) { var reportData DecisionReportData qs := orm.Eloquent.Debug().Table("erp_purchase_inventory") @@ -2223,7 +2223,7 @@ func getSumPurchaseData(req *ErpDecisionReportReq) (DecisionReportData, error) { qs = qs.Where("erp_purchase_inventory.created_at > ?", parse) } - if req.EndTime != "" { // 出入库结束时间 + if req.EndTime != "" && endTimeFlag { // 出入库结束时间 parse, err := time.Parse(QueryTimeFormat, req.EndTime) if err != nil { logger.Errorf("getPurchaseCount err:", err) @@ -2279,7 +2279,7 @@ func getSumPurchaseData(req *ErpDecisionReportReq) (DecisionReportData, error) { } // 查询零售汇总数据:零售销售数量、零售退货数量 -func getSumSalesData(req *ErpDecisionReportReq) (DecisionReportData, error) { +func getSumSalesData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionReportData, error) { var reportData DecisionReportData qs := orm.Eloquent.Debug().Table("erp_order_commodity"). Joins("JOIN erp_order ON erp_order_commodity.erp_order_id = erp_order.id") @@ -2293,7 +2293,7 @@ func getSumSalesData(req *ErpDecisionReportReq) (DecisionReportData, error) { qs = qs.Where("erp_order.audit_time > ?", parse) } - if req.EndTime != "" { + if req.EndTime != "" && endTimeFlag { parse, err := time.Parse(QueryTimeFormat, req.EndTime) if err != nil { logger.Errorf("getSalesAndReturns err:", err) @@ -2354,7 +2354,7 @@ func getSumSalesData(req *ErpDecisionReportReq) (DecisionReportData, error) { } // 查询盘点汇总数据:盘点入库数量、盘点出库数量 -func getSumInventoryData(req *ErpDecisionReportReq) (DecisionReportData, error) { +func getSumInventoryData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionReportData, error) { var reportData DecisionReportData qs := orm.Eloquent.Debug().Table("erp_inventory_change_commodity"). Joins("JOIN erp_inventory_change_order " + @@ -2369,7 +2369,7 @@ func getSumInventoryData(req *ErpDecisionReportReq) (DecisionReportData, error) qs = qs.Where("erp_inventory_change_order.audit_time > ?", parse) } - if req.EndTime != "" { + if req.EndTime != "" && endTimeFlag { parse, err := time.Parse(QueryTimeFormat, req.EndTime) if err != nil { logger.Errorf("getInventoryChanges err:", err) @@ -2422,7 +2422,7 @@ THEN erp_inventory_change_commodity.price ELSE 0 END) AS check_out_amount } // 查询调拨汇总数据:在途库存(出库)数量、调拨入库数量、调拨出库数量 -func getSumAllotData(req *ErpDecisionReportReq) (DecisionReportData, error) { +func getSumAllotData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionReportData, error) { var reportData DecisionReportData qs := orm.Eloquent.Debug().Table("erp_inventory_allot_commodity"). Joins("JOIN erp_inventory_allot_order ON erp_inventory_allot_order.id = erp_inventory_allot_commodity.allot_order_id") @@ -2437,7 +2437,7 @@ func getSumAllotData(req *ErpDecisionReportReq) (DecisionReportData, error) { qs = qs.Where("erp_inventory_allot_order.receive_time > ?", parse) } - if req.EndTime != "" { + if req.EndTime != "" && endTimeFlag { parse, err := time.Parse(QueryTimeFormat, req.EndTime) if err != nil { logger.Errorf("getAllotCounts err:", err) @@ -2556,7 +2556,7 @@ func getSumDecisionReportData(req *ErpDecisionReportReq) (DecisionSumData, error sumData.TotalEndAmount = sumEndData.EndAmount // 查询库存汇总数据:采购退货数量、产品入库、系统入库、系统出库、在途库存(入库)数量 - sumStockData, err := getSumStockData(req) + sumStockData, err := getSumStockData(req, true) if err != nil { return DecisionSumData{}, err } @@ -2573,7 +2573,7 @@ func getSumDecisionReportData(req *ErpDecisionReportReq) (DecisionSumData, error sumData.TotalSystemOutAmount = sumStockData.SystemOutAmount // 查询采购进货数量 - sumPurchaseData, err := getSumPurchaseData(req) + sumPurchaseData, err := getSumPurchaseData(req, true) if err != nil { return DecisionSumData{}, err } @@ -2581,7 +2581,7 @@ func getSumDecisionReportData(req *ErpDecisionReportReq) (DecisionSumData, error sumData.TotalPurchaseAmount = sumPurchaseData.PurchaseStockAmount // 查询零售汇总数据:零售销售数量、零售退货数量 - sumSalesData, err := getSumSalesData(req) + sumSalesData, err := getSumSalesData(req, true) if err != nil { return DecisionSumData{}, err } @@ -2592,7 +2592,7 @@ func getSumDecisionReportData(req *ErpDecisionReportReq) (DecisionSumData, error sumData.TotalRejectAmount = sumSalesData.OrderRejectAmount // 查询盘点汇总数据:盘点入库数量、盘点出库数量 - sumInventoryData, err := getSumInventoryData(req) + sumInventoryData, err := getSumInventoryData(req, true) if err != nil { return DecisionSumData{}, err } @@ -2603,7 +2603,7 @@ func getSumDecisionReportData(req *ErpDecisionReportReq) (DecisionSumData, error sumData.TotalCheckOutAmount = sumInventoryData.CheckOutAmount // 查询调拨汇总数据:在途库存(出库)数量、调拨入库数量、调拨出库数量 - sumAllotData, err := getSumAllotData(req) + sumAllotData, err := getSumAllotData(req, true) if err != nil { return DecisionSumData{}, err } @@ -2648,6 +2648,19 @@ func roundFloat64(num float64, decimalPlaces int) float64 { // roundDecisionSumData rounds all float64 fields in DecisionSumData to 2 decimal places. func roundDecisionSumData(data *DecisionSumData) { data.TotalBeginAmount = roundFloat64(data.TotalBeginAmount, 2) + data.TotalPurchaseAmount = roundFloat64(data.TotalPurchaseAmount, 2) + data.TotalReturnAmount = roundFloat64(data.TotalReturnAmount, 2) + data.TotalSaleAmount = roundFloat64(data.TotalSaleAmount, 2) + data.TotalRejectAmount = roundFloat64(data.TotalRejectAmount, 2) + data.TotalAllotInAmount = roundFloat64(data.TotalAllotInAmount, 2) + data.TotalWaitInAmount = roundFloat64(data.TotalWaitInAmount, 2) + data.TotalAllotOutAmount = roundFloat64(data.TotalAllotOutAmount, 2) + data.TotalWaitOutAmount = roundFloat64(data.TotalWaitOutAmount, 2) + data.TotalProductInAmount = roundFloat64(data.TotalProductInAmount, 2) + data.TotalSystemInAmount = roundFloat64(data.TotalSystemInAmount, 2) + data.TotalSystemOutAmount = roundFloat64(data.TotalSystemOutAmount, 2) + data.TotalCheckInAmount = roundFloat64(data.TotalCheckInAmount, 2) + data.TotalCheckOutAmount = roundFloat64(data.TotalCheckOutAmount, 2) data.TotalEndAmount = roundFloat64(data.TotalEndAmount, 2) }