1.修复采购报表(按单)汇总金额和数量只是当前页的问题;
This commit is contained in:
parent
6c65d3940b
commit
973b77d5e9
|
@ -3833,10 +3833,6 @@ func getReportByOrderFromCommon(req *ErpPurchaseReportByOrderReq, c *gin.Context
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reportByOrderData.CommodityData == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
//if reportByOrderData.CommodityData == nil {
|
||||
// continue
|
||||
//}
|
||||
|
@ -3861,14 +3857,19 @@ func getReportByOrderFromCommon(req *ErpPurchaseReportByOrderReq, c *gin.Context
|
|||
}
|
||||
|
||||
resp.List = reportByOrderDataList[startIndex:endIndex]
|
||||
} else {
|
||||
resp.List = reportByOrderDataList
|
||||
}
|
||||
|
||||
nTotalAmount = math.Round(nTotalAmount*100) / 100
|
||||
resp.Amount = nTotalAmount
|
||||
resp.Count = nTotalCount
|
||||
//resp.Total = int(count)
|
||||
} else {
|
||||
resp.List = reportByOrderDataList
|
||||
// 查询订单总的执行金额和数量
|
||||
totalAmount, totalCount, err := getOrderInventorySumData(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Amount = totalAmount
|
||||
resp.Count = totalCount
|
||||
}
|
||||
|
||||
if req.IsExport == 1 {
|
||||
filePath, err := reportByOrderExport(resp)
|
||||
|
@ -3882,6 +3883,75 @@ func getReportByOrderFromCommon(req *ErpPurchaseReportByOrderReq, c *gin.Context
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
type OrderInventorySum struct {
|
||||
TotalAmount float64 `gorm:"column:totalAmount"`
|
||||
TotalCount int32 `gorm:"column:totalCount"`
|
||||
}
|
||||
|
||||
// 查询采购订单的汇总信息:总金额,总执行数量
|
||||
func getOrderInventorySumData(req *ErpPurchaseReportByOrderReq) (float64, int32, error) {
|
||||
qs := orm.Eloquent.Table("erp_purchase_order").Where("state != ?", ErpPurchaseOrderUnAudit) // 未审核订单不展示
|
||||
if req.SerialNumber != "" { // 单据编号
|
||||
qs = qs.Where("serial_number=?", req.SerialNumber)
|
||||
}
|
||||
if req.PurchaseType != "" { // 采购类型
|
||||
qs = qs.Where("purchase_type=?", req.PurchaseType)
|
||||
}
|
||||
if len(req.ErpSupplierId) > 0 { // 供应商复选
|
||||
var supplierIDs []uint32
|
||||
for _, supplier := range req.ErpSupplierId {
|
||||
supplierIDs = append(supplierIDs, supplier)
|
||||
}
|
||||
qs = qs.Where("erp_supplier_id IN (?)", supplierIDs)
|
||||
}
|
||||
if len(req.StoreId) > 0 { // 门店复选
|
||||
var storeIDs []uint32
|
||||
for _, store := range req.StoreId {
|
||||
storeIDs = append(storeIDs, store)
|
||||
}
|
||||
qs = qs.Where("store_id IN (?)", storeIDs)
|
||||
}
|
||||
if req.HandlerId != 0 { // 经手人id
|
||||
qs = qs.Where("handler_id=?", req.HandlerId)
|
||||
}
|
||||
if req.State != 0 { // 订单状态
|
||||
qs = qs.Where("state=?", req.State)
|
||||
}
|
||||
if req.AuditTimeStart != "" { // 审核开始时间
|
||||
parse, err := time.Parse(QueryTimeFormat, req.AuditTimeStart)
|
||||
if err != nil {
|
||||
logger.Errorf("erpPurchaseOrderList err:", err)
|
||||
return 0, 0, err
|
||||
}
|
||||
qs = qs.Where("audit_time > ?", parse)
|
||||
}
|
||||
if req.AuditTimeEnd != "" { // 审核结束时间
|
||||
parse, err := time.Parse(QueryTimeFormat, req.AuditTimeEnd)
|
||||
if err != nil {
|
||||
logger.Errorf("erpPurchaseOrderList err:", err)
|
||||
return 0, 0, err
|
||||
}
|
||||
qs = qs.Where("audit_time < ?", parse)
|
||||
}
|
||||
|
||||
var result OrderInventorySum
|
||||
|
||||
// 使用联表查询获取总金额和总执行数量
|
||||
err := qs.Joins("LEFT JOIN erp_purchase_inventory ON erp_purchase_inventory.erp_purchase_order_id = erp_purchase_order.id").
|
||||
Select("SUM(CASE WHEN erp_purchase_order.purchase_type = 'reject' THEN -erp_purchase_inventory.amount ELSE erp_purchase_inventory.amount END) as totalAmount, " +
|
||||
"SUM(CASE WHEN erp_purchase_order.purchase_type = 'reject' THEN -erp_purchase_inventory.count ELSE erp_purchase_inventory.count END) as totalCount").
|
||||
Scan(&result).Error
|
||||
if err != nil {
|
||||
logger.Errorf("getOrderInventorySumData err:", err)
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
// 四舍五入保留2位小数
|
||||
result.TotalAmount = math.Round(result.TotalAmount*100) / 100
|
||||
|
||||
return result.TotalAmount, result.TotalCount, nil
|
||||
}
|
||||
|
||||
// 查询采购订单的入库信息
|
||||
func getOrderInventoryInfo(req *ErpPurchaseReportByOrderReq, erpPurchaseOrderId uint32) ([]ErpPurchaseCommodityData, float64, int32, error) {
|
||||
var inventoryList []ErpPurchaseInventory
|
||||
|
|
Loading…
Reference in New Issue
Block a user