1.优化InventoryErpPurchaseUpdateRejectStock接口,采购入库订单反审核后对应库存状态改为3;
2、进销存报表优化,新增查询采购退货数量接口getSumPurchaseReturnData,根据库存状态为3查询不准确,跨月退货有问题,改为直接查询采购订单表;
This commit is contained in:
parent
3a663ae449
commit
52d1a32215
|
@ -1692,7 +1692,7 @@ func getSumStartData(req *ErpDecisionReportReq) (DecisionReportData, error) {
|
||||||
return DecisionReportData{}, err
|
return DecisionReportData{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询库存汇总数据:采购退货数量、产品入库、系统入库、系统出库、在途库存(入库)数量
|
// 查询库存汇总数据:产品入库、系统入库、系统出库、在途库存(入库)数量
|
||||||
sumStockData, err := getSumStockData(tempReq, false)
|
sumStockData, err := getSumStockData(tempReq, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DecisionReportData{}, err
|
return DecisionReportData{}, err
|
||||||
|
@ -1704,6 +1704,12 @@ func getSumStartData(req *ErpDecisionReportReq) (DecisionReportData, error) {
|
||||||
return DecisionReportData{}, err
|
return DecisionReportData{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询采购退货数量
|
||||||
|
sumPurchaseReturnData, err := getSumPurchaseReturnData(tempReq, false)
|
||||||
|
if err != nil {
|
||||||
|
return DecisionReportData{}, err
|
||||||
|
}
|
||||||
|
|
||||||
// 查询零售汇总数据:零售销售数量、零售退货数量
|
// 查询零售汇总数据:零售销售数量、零售退货数量
|
||||||
sumSalesData, err := getSumSalesData(tempReq, false)
|
sumSalesData, err := getSumSalesData(tempReq, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1724,12 +1730,12 @@ func getSumStartData(req *ErpDecisionReportReq) (DecisionReportData, error) {
|
||||||
|
|
||||||
respData.BeginStock = sumEndData.EndStock + (sumSalesData.OrderSale - sumSalesData.OrderReject) +
|
respData.BeginStock = sumEndData.EndStock + (sumSalesData.OrderSale - sumSalesData.OrderReject) +
|
||||||
sumAllotData.AllotOut + sumStockData.SystemOut + sumInventoryData.CheckOut -
|
sumAllotData.AllotOut + sumStockData.SystemOut + sumInventoryData.CheckOut -
|
||||||
(sumPurchaseData.PurchaseStock - sumStockData.PurchaseReturn) - sumAllotData.AllotIn -
|
(sumPurchaseData.PurchaseStock - sumPurchaseReturnData.PurchaseReturn) - sumAllotData.AllotIn -
|
||||||
sumStockData.ProductIn - sumInventoryData.CheckIn
|
sumStockData.ProductIn - sumInventoryData.CheckIn
|
||||||
|
|
||||||
respData.BeginAmount = sumEndData.EndAmount + ((sumSalesData.OrderSaleAmount - sumSalesData.OrderRejectAmount) +
|
respData.BeginAmount = sumEndData.EndAmount + ((sumSalesData.OrderSaleAmount - sumSalesData.OrderRejectAmount) +
|
||||||
sumAllotData.AllotOutAmount + sumStockData.SystemOutAmount + sumInventoryData.CheckOutAmount) -
|
sumAllotData.AllotOutAmount + sumStockData.SystemOutAmount + sumInventoryData.CheckOutAmount) -
|
||||||
((sumPurchaseData.PurchaseStockAmount - sumStockData.PurchaseReturnAmount) + sumAllotData.AllotInAmount +
|
((sumPurchaseData.PurchaseStockAmount - sumPurchaseReturnData.PurchaseReturnAmount) + sumAllotData.AllotInAmount +
|
||||||
sumStockData.ProductInAmount + sumInventoryData.CheckInAmount)
|
sumStockData.ProductInAmount + sumInventoryData.CheckInAmount)
|
||||||
|
|
||||||
return respData, nil
|
return respData, nil
|
||||||
|
@ -2185,8 +2191,6 @@ func getSumStockData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionRepor
|
||||||
}
|
}
|
||||||
|
|
||||||
subQuery := qs.Select(`
|
subQuery := qs.Select(`
|
||||||
SUM(CASE WHEN state = ? THEN count ELSE 0 END) AS purchase_return,
|
|
||||||
SUM(CASE WHEN state = ? THEN wholesale_price ELSE 0 END) AS purchase_return_amount,
|
|
||||||
SUM(CASE WHEN storage_type = ? THEN count ELSE 0 END) AS product_in,
|
SUM(CASE WHEN storage_type = ? THEN count ELSE 0 END) AS product_in,
|
||||||
SUM(CASE WHEN storage_type = ? THEN wholesale_price ELSE 0 END) AS product_in_amount,
|
SUM(CASE WHEN storage_type = ? THEN wholesale_price ELSE 0 END) AS product_in_amount,
|
||||||
SUM(CASE WHEN storage_type = ? THEN count ELSE 0 END) AS system_in,
|
SUM(CASE WHEN storage_type = ? THEN count ELSE 0 END) AS system_in,
|
||||||
|
@ -2195,7 +2199,7 @@ func getSumStockData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionRepor
|
||||||
SUM(CASE WHEN state = ? THEN wholesale_price ELSE 0 END) AS system_out_amount,
|
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 count ELSE 0 END) AS allot_wait_in,
|
||||||
SUM(CASE WHEN state = ? THEN wholesale_price ELSE 0 END) AS allot_wait_in_amount
|
SUM(CASE WHEN state = ? THEN wholesale_price ELSE 0 END) AS allot_wait_in_amount
|
||||||
`, PurchaseReturn, PurchaseReturn, ProductInventory, ProductInventory, SystemInventory, SystemInventory,
|
`, ProductInventory, ProductInventory, SystemInventory, SystemInventory,
|
||||||
SystemOut, SystemOut, InAllot, InAllot)
|
SystemOut, SystemOut, InAllot, InAllot)
|
||||||
|
|
||||||
err := subQuery.Scan(&reportData).Error
|
err := subQuery.Scan(&reportData).Error
|
||||||
|
@ -2278,6 +2282,77 @@ func getSumPurchaseData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionRe
|
||||||
return reportData, nil
|
return reportData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询采购退货货数量
|
||||||
|
func getSumPurchaseReturnData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionReportData, error) {
|
||||||
|
var reportData DecisionReportData
|
||||||
|
|
||||||
|
qs := orm.Eloquent.Debug().Table("erp_purchase_inventory")
|
||||||
|
|
||||||
|
// 进行条件查询
|
||||||
|
if req.StartTime != "" { // 出入库开始时间
|
||||||
|
parse, err := time.Parse(QueryTimeFormat, req.StartTime)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("getPurchaseCount err:", err)
|
||||||
|
return DecisionReportData{}, err
|
||||||
|
}
|
||||||
|
qs = qs.Where("erp_purchase_inventory.created_at > ?", parse)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.EndTime != "" && endTimeFlag { // 出入库结束时间
|
||||||
|
parse, err := time.Parse(QueryTimeFormat, req.EndTime)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("getPurchaseCount err:", err)
|
||||||
|
return DecisionReportData{}, err
|
||||||
|
}
|
||||||
|
qs = qs.Where("erp_purchase_inventory.created_at <= ?", parse)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.StoreId) > 0 {
|
||||||
|
if len(req.StoreId) == 1 {
|
||||||
|
qs = qs.Where("store_id = ?", req.StoreId[0])
|
||||||
|
} else {
|
||||||
|
qs = qs.Where("store_id IN (?)", req.StoreId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.CommodityName) > 0 { // 商品名称
|
||||||
|
var commodityNames []string
|
||||||
|
for _, commodityName := range req.CommodityName {
|
||||||
|
commodityNames = append(commodityNames, commodityName)
|
||||||
|
}
|
||||||
|
if len(commodityNames) == 1 {
|
||||||
|
qs = qs.Where("erp_commodity_name = ?", commodityNames[0])
|
||||||
|
} else {
|
||||||
|
qs = qs.Where("erp_commodity_name IN (?)", commodityNames)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.CategoryID) > 0 { // 商品分类id
|
||||||
|
var categoryIDs []uint32
|
||||||
|
for _, category := range req.CategoryID {
|
||||||
|
categoryIDs = append(categoryIDs, category)
|
||||||
|
}
|
||||||
|
if len(categoryIDs) == 1 {
|
||||||
|
qs = qs.Where("erp_category_id = ?", categoryIDs[0])
|
||||||
|
} else {
|
||||||
|
qs = qs.Where("erp_category_id IN (?)", categoryIDs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
err = qs.Select("SUM(erp_purchase_inventory.count) AS purchase_return,"+
|
||||||
|
"SUM(erp_purchase_inventory.amount) AS purchase_return_amount").
|
||||||
|
Joins("JOIN erp_purchase_order ON erp_purchase_order.id = erp_purchase_inventory.erp_purchase_order_id").
|
||||||
|
Where("erp_purchase_inventory.purchase_type = ?", ErpRejectOrder).
|
||||||
|
Find(&reportData).Error
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return DecisionReportData{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return reportData, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 查询零售汇总数据:零售销售数量、零售退货数量
|
// 查询零售汇总数据:零售销售数量、零售退货数量
|
||||||
func getSumSalesData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionReportData, error) {
|
func getSumSalesData(req *ErpDecisionReportReq, endTimeFlag bool) (DecisionReportData, error) {
|
||||||
var reportData DecisionReportData
|
var reportData DecisionReportData
|
||||||
|
@ -2555,18 +2630,16 @@ func getSumDecisionReportData(req *ErpDecisionReportReq) (DecisionSumData, error
|
||||||
sumData.TotalEndStock = sumEndData.EndStock
|
sumData.TotalEndStock = sumEndData.EndStock
|
||||||
sumData.TotalEndAmount = sumEndData.EndAmount
|
sumData.TotalEndAmount = sumEndData.EndAmount
|
||||||
|
|
||||||
// 查询库存汇总数据:采购退货数量、产品入库、系统入库、系统出库、在途库存(入库)数量
|
// 查询库存汇总数据:产品入库、系统入库、系统出库、在途库存(入库)数量
|
||||||
sumStockData, err := getSumStockData(req, true)
|
sumStockData, err := getSumStockData(req, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DecisionSumData{}, err
|
return DecisionSumData{}, err
|
||||||
}
|
}
|
||||||
sumData.TotalPurchaseReturn = sumStockData.PurchaseReturn
|
|
||||||
sumData.TotalAllotWaitIn = sumStockData.AllotWaitIn
|
sumData.TotalAllotWaitIn = sumStockData.AllotWaitIn
|
||||||
sumData.TotalProductIn = sumStockData.ProductIn
|
sumData.TotalProductIn = sumStockData.ProductIn
|
||||||
sumData.TotalSystemIn = sumStockData.SystemIn
|
sumData.TotalSystemIn = sumStockData.SystemIn
|
||||||
sumData.TotalSystemOut = sumStockData.SystemOut
|
sumData.TotalSystemOut = sumStockData.SystemOut
|
||||||
|
|
||||||
sumData.TotalReturnAmount = sumStockData.PurchaseReturnAmount
|
|
||||||
sumData.TotalWaitInAmount = sumStockData.AllotWaitInAmount
|
sumData.TotalWaitInAmount = sumStockData.AllotWaitInAmount
|
||||||
sumData.TotalProductInAmount = sumStockData.ProductInAmount
|
sumData.TotalProductInAmount = sumStockData.ProductInAmount
|
||||||
sumData.TotalSystemInAmount = sumStockData.SystemInAmount
|
sumData.TotalSystemInAmount = sumStockData.SystemInAmount
|
||||||
|
@ -2580,6 +2653,14 @@ func getSumDecisionReportData(req *ErpDecisionReportReq) (DecisionSumData, error
|
||||||
sumData.TotalPurchaseStock = sumPurchaseData.PurchaseStock
|
sumData.TotalPurchaseStock = sumPurchaseData.PurchaseStock
|
||||||
sumData.TotalPurchaseAmount = sumPurchaseData.PurchaseStockAmount
|
sumData.TotalPurchaseAmount = sumPurchaseData.PurchaseStockAmount
|
||||||
|
|
||||||
|
// 查询采购退货数量
|
||||||
|
sumPurchaseReturnData, err := getSumPurchaseReturnData(req, true)
|
||||||
|
if err != nil {
|
||||||
|
return DecisionSumData{}, err
|
||||||
|
}
|
||||||
|
sumData.TotalPurchaseReturn = sumPurchaseReturnData.PurchaseReturn
|
||||||
|
sumData.TotalReturnAmount = sumPurchaseReturnData.PurchaseReturnAmount
|
||||||
|
|
||||||
// 查询零售汇总数据:零售销售数量、零售退货数量
|
// 查询零售汇总数据:零售销售数量、零售退货数量
|
||||||
sumSalesData, err := getSumSalesData(req, true)
|
sumSalesData, err := getSumSalesData(req, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1248,7 +1248,7 @@ func InventoryErpPurchase(req *ErpPurchaseInventoryReq, c *gin.Context) error {
|
||||||
if purchaseOrder.PurchaseType == ErpProcureOrder { //采购入库订单
|
if purchaseOrder.PurchaseType == ErpProcureOrder { //采购入库订单
|
||||||
err = InventoryErpPurchaseUpdateStock(begin, inventoryList, purchaseOrder)
|
err = InventoryErpPurchaseUpdateStock(begin, inventoryList, purchaseOrder)
|
||||||
} else if purchaseOrder.PurchaseType == ErpRejectOrder { // 采购退货订单
|
} else if purchaseOrder.PurchaseType == ErpRejectOrder { // 采购退货订单
|
||||||
err = InventoryErpPurchaseUpdateRejectStock(begin, inventoryList, purchaseOrder)
|
err = InventoryErpPurchaseUpdateRejectStock(begin, inventoryList, purchaseOrder, false)
|
||||||
} else {
|
} else {
|
||||||
return errors.New("订单类型有误")
|
return errors.New("订单类型有误")
|
||||||
}
|
}
|
||||||
|
@ -1478,7 +1478,8 @@ func combineStocks(waitCreateStockList []ErpStock) []ErpStock {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InventoryErpPurchaseUpdateRejectStock 采购退货更新库存信息
|
// InventoryErpPurchaseUpdateRejectStock 采购退货更新库存信息
|
||||||
func InventoryErpPurchaseUpdateRejectStock(gdb *gorm.DB, list []ErpPurchaseInventory, purchaseOrder ErpPurchaseOrder) error {
|
func InventoryErpPurchaseUpdateRejectStock(gdb *gorm.DB, list []ErpPurchaseInventory, purchaseOrder ErpPurchaseOrder,
|
||||||
|
cancelFlag bool) error {
|
||||||
usedStockCommodityIdList := make(map[uint32]bool)
|
usedStockCommodityIdList := make(map[uint32]bool)
|
||||||
for i, _ := range list {
|
for i, _ := range list {
|
||||||
if list[i].IMEIType == 2 || list[i].IMEIType == 3 { // 串码商品
|
if list[i].IMEIType == 2 || list[i].IMEIType == 3 { // 串码商品
|
||||||
|
@ -1501,9 +1502,14 @@ func InventoryErpPurchaseUpdateRejectStock(gdb *gorm.DB, list []ErpPurchaseInven
|
||||||
// return fmt.Errorf("商品[%s]在销售锁定中,不能退货", stockCommodityInfo.ErpCommodityName)
|
// return fmt.Errorf("商品[%s]在销售锁定中,不能退货", stockCommodityInfo.ErpCommodityName)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
orderState := PurchaseReturn
|
||||||
|
if cancelFlag { // 反审核取消即可
|
||||||
|
orderState = PurchaseCancel
|
||||||
|
}
|
||||||
|
|
||||||
err = gdb.Table("erp_stock_commodity").Where("imei = ?", list[i].IMEI).
|
err = gdb.Table("erp_stock_commodity").Where("imei = ?", list[i].IMEI).
|
||||||
Updates(&map[string]interface{}{
|
Updates(&map[string]interface{}{
|
||||||
"state": PurchaseCancel,
|
"state": orderState,
|
||||||
"stock_sn": list[i].SerialNumber,
|
"stock_sn": list[i].SerialNumber,
|
||||||
"updated_at": time.Now(),
|
"updated_at": time.Now(),
|
||||||
}).Error // 状态更新为采购退货
|
}).Error // 状态更新为采购退货
|
||||||
|
@ -6313,7 +6319,7 @@ func CancelAuditUpdateStock(begin *gorm.DB, req ErpPurchaseOrder) error {
|
||||||
purchaseOrder.RejectedSerialNumber = purchaseOrder.SerialNumber
|
purchaseOrder.RejectedSerialNumber = purchaseOrder.SerialNumber
|
||||||
|
|
||||||
// 按照采购退货更新库存
|
// 按照采购退货更新库存
|
||||||
err = InventoryErpPurchaseUpdateRejectStock(begin, inventoryList, purchaseOrder)
|
err = InventoryErpPurchaseUpdateRejectStock(begin, inventoryList, purchaseOrder, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("取消审核失败:%s", err.Error())
|
return fmt.Errorf("取消审核失败:%s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user