1.修复月结获取开始日期为空时报错的缺陷;
2.进销存报表逻辑调整;
This commit is contained in:
parent
e984a0a646
commit
5a30b6d1fb
|
@ -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, "获取成功")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user