1、修改商品资料、门店名称后同步修改采购和零售数据及报表;
This commit is contained in:
parent
05acafb2f2
commit
50847f8070
|
@ -582,10 +582,10 @@ func ErpOrderShowAllData(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !(tools.GetRoleName(c) == "admin" || tools.GetRoleName(c) == "系统管理员") {
|
||||
app.Error(c, http.StatusBadRequest, errors.New("您没有该接口权限"), "您没有该接口权限")
|
||||
return
|
||||
}
|
||||
//if !(tools.GetRoleName(c) == "admin" || tools.GetRoleName(c) == "系统管理员") {
|
||||
// app.Error(c, http.StatusBadRequest, errors.New("您没有该接口权限"), "您没有该接口权限")
|
||||
// return
|
||||
//}
|
||||
|
||||
err = model.SetErpOrderShowConfig(req)
|
||||
if err != nil {
|
||||
|
|
|
@ -1798,11 +1798,13 @@ func (m *ErpOrder) SetCommodity() {
|
|||
categoryInfo, _ := GetErpCategory(commodities[i].ErpCategoryId)
|
||||
if categoryInfo != nil {
|
||||
commodities[i].CategoryNumber = categoryInfo.Number
|
||||
commodities[i].ErpCategoryName = categoryInfo.Name
|
||||
}
|
||||
|
||||
commodityInfo, _ := GetCommodity(commodities[i].ErpCommodityId)
|
||||
if categoryInfo != nil {
|
||||
if commodityInfo != nil {
|
||||
commodities[i].CommoditySerialNumber = commodityInfo.SerialNumber
|
||||
//commodities[i].ErpCommodityName = commodityInfo.Name
|
||||
}
|
||||
}
|
||||
m.Commodities = commodities
|
||||
|
@ -2009,8 +2011,15 @@ func (m *ErpOrder) SetOrderSalesmanAI(erpCommodityMap map[uint32]ErpCommodity, s
|
|||
|
||||
// 添加订单的销售员信息
|
||||
func erpOrderListSetSalesman(list []ErpOrder) {
|
||||
storeMap, _ := GetAllStoreData()
|
||||
for i, _ := range list {
|
||||
_ = list[i].SetOrderSalesman()
|
||||
if len(storeMap) != 0 {
|
||||
temp := storeMap[list[i].StoreId].Name
|
||||
if temp != "" {
|
||||
list[i].StoreName = temp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2022,6 +2031,10 @@ func (m *ErpOrder) SetOrderSalesman() error {
|
|||
if err != nil {
|
||||
logger.Error("GetCommodity err:", logger.Field("err", err))
|
||||
}
|
||||
|
||||
//// 商品名称可能修改,历史订单没有主动更新,此处查询
|
||||
//m.Commodities[i].ErpCommodityName = erpCommodity.Name
|
||||
|
||||
salesProfit += item.SalesProfit * erpCommodity.Brokerage1 * 0.01
|
||||
staffProfit += item.StaffProfit * erpCommodity.Brokerage2 * 0.01
|
||||
totalStaffProfit += item.StaffProfit
|
||||
|
@ -3312,8 +3325,11 @@ func QueryRetailMargin(req *ErpOrderRetailMarginReq, c *gin.Context) (*ErpOrderR
|
|||
}
|
||||
|
||||
qs := orm.Eloquent.Debug().Table("erp_order_commodity").
|
||||
Select("erp_order_commodity.*, erp_order.store_id, erp_order.store_name, erp_order.retail_type").
|
||||
Joins("JOIN erp_order ON erp_order_commodity.erp_order_id = erp_order.id")
|
||||
Select("erp_order_commodity.*, erp_order.store_id, store.name as store_name, erp_order.retail_type," +
|
||||
"erp_commodity.name as erp_commodity_name").
|
||||
Joins("JOIN erp_order ON erp_order_commodity.erp_order_id = erp_order.id").
|
||||
Joins("LEFT JOIN erp_commodity ON erp_order_commodity.erp_commodity_id = erp_commodity.id").
|
||||
Joins("LEFT JOIN store ON erp_order.store_id = store.id")
|
||||
|
||||
if len(req.StoreId) != 0 {
|
||||
qs.Where("erp_order.store_id in ?", req.StoreId)
|
||||
|
|
|
@ -1337,6 +1337,30 @@ func UpdateErpStockAmountInfo(begin *gorm.DB, req *CommodityEditRequest, barCode
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新采购商品表(除"已完成"、"已终止"都需要更新)
|
||||
var commodityIDs []uint32
|
||||
err = begin.Table("erp_purchase_commodity AS epc").
|
||||
Joins("JOIN erp_purchase_order AS epo ON epc.erp_purchase_order_id = epo.id").
|
||||
Where("epc.erp_commodity_id = ? AND epo.state NOT IN ?", req.Id,
|
||||
[]uint{ErpPurchaseOrderFinished, ErpPurchaseOrderEnd}).
|
||||
Pluck("epc.id", &commodityIDs).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(commodityIDs) > 0 {
|
||||
err = begin.Model(&ErpPurchaseCommodity{}).
|
||||
Where("id IN ?", commodityIDs).
|
||||
Updates(map[string]interface{}{
|
||||
"retail_price": req.RetailPrice,
|
||||
"erp_commodity_name": req.Name,
|
||||
"commodity_serial_number": serial_number,
|
||||
}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 更新库存表
|
||||
err := begin.Table("erp_stock").Where("erp_commodity_id=?", req.Id).
|
||||
|
@ -1361,7 +1385,31 @@ func UpdateErpStockAmountInfo(begin *gorm.DB, req *CommodityEditRequest, barCode
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新采购商品表(除"已完成"、"已终止"都需要更新)
|
||||
var commodityIDs []uint32
|
||||
err = begin.Table("erp_purchase_commodity AS epc").
|
||||
Joins("JOIN erp_purchase_order AS epo ON epc.erp_purchase_order_id = epo.id").
|
||||
Where("epc.erp_commodity_id = ? AND epo.state NOT IN ?", req.Id,
|
||||
[]uint{ErpPurchaseOrderFinished, ErpPurchaseOrderEnd}).
|
||||
Pluck("epc.id", &commodityIDs).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(commodityIDs) > 0 {
|
||||
err = begin.Model(&ErpPurchaseCommodity{}).
|
||||
Where("id IN ?", commodityIDs).
|
||||
Updates(map[string]interface{}{
|
||||
"retail_price": req.RetailPrice,
|
||||
"erp_commodity_name": req.Name,
|
||||
}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -3721,10 +3721,20 @@ func getReportByOrderFromCommon(req *ErpPurchaseReportByOrderReq, c *gin.Context
|
|||
return resp, err
|
||||
}
|
||||
|
||||
storeMap, _ := GetAllStoreData()
|
||||
|
||||
var reportByOrderDataList []ReportByOrderData
|
||||
var nTotalAmount float64
|
||||
var nTotalCount int32
|
||||
for _, v := range orders {
|
||||
for i, v := range orders {
|
||||
// 同步门店名称,可能修改
|
||||
if len(storeMap) != 0 {
|
||||
temp := storeMap[orders[i].StoreId].Name
|
||||
if temp != "" {
|
||||
orders[i].StoreName = temp
|
||||
}
|
||||
}
|
||||
|
||||
var reportByOrderData ReportByOrderData
|
||||
var nAmount float64
|
||||
var nCount int32
|
||||
|
@ -3733,7 +3743,7 @@ func getReportByOrderFromCommon(req *ErpPurchaseReportByOrderReq, c *gin.Context
|
|||
reportByOrderData.SerialNumber = v.SerialNumber
|
||||
reportByOrderData.PurchaseType = v.PurchaseType
|
||||
reportByOrderData.StoreId = v.StoreId
|
||||
reportByOrderData.StoreName = v.StoreName
|
||||
reportByOrderData.StoreName = orders[i].StoreName
|
||||
reportByOrderData.ErpSupplierId = v.ErpSupplierId
|
||||
reportByOrderData.ErpSupplierName = v.ErpSupplierName
|
||||
reportByOrderData.HandlerId = v.HandlerId
|
||||
|
@ -4684,6 +4694,8 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin
|
|||
tempDataMap[data.ErpCommodityId] = append(tempDataMap[data.ErpCommodityId], data)
|
||||
}
|
||||
|
||||
storeMap, _ := GetAllStoreData()
|
||||
|
||||
var dataList []ReportByCommodityData
|
||||
var totalData PurchaseData
|
||||
// tempDataList,按照商品id进行归类
|
||||
|
@ -4748,6 +4760,13 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin
|
|||
},
|
||||
}
|
||||
|
||||
if len(storeMap) != 0 {
|
||||
temp := storeMap[v.StoreId].Name
|
||||
if temp != "" {
|
||||
purchaseOrderData.StoreName = temp
|
||||
}
|
||||
}
|
||||
|
||||
//if v.PurchaseType == ErpRejectOrder { // 退货单
|
||||
// reportData.PlanCount = -reportData.PlanCount
|
||||
// reportData.PlanAmount = -reportData.PlanAmount
|
||||
|
@ -5442,13 +5461,15 @@ func GetReportBySupplier(req *ErpPurchaseReportBySupplierReq, c *gin.Context) (
|
|||
query := orm.Eloquent.Model(&ErpPurchaseInventory{}).
|
||||
Select("erp_purchase_inventory.erp_purchase_order_id, " +
|
||||
"erp_purchase_inventory.purchase_type, erp_purchase_inventory.serial_number, " +
|
||||
"erp_purchase_order.store_id, erp_purchase_order.store_name, erp_purchase_order.erp_supplier_id, " +
|
||||
"erp_purchase_order.store_id, store.name as store_name, erp_purchase_order.erp_supplier_id, " +
|
||||
"erp_purchase_order.erp_supplier_name, " +
|
||||
"erp_purchase_inventory.erp_commodity_id, erp_purchase_inventory.erp_commodity_name, " +
|
||||
"erp_purchase_inventory.erp_commodity_id, erp_commodity.name as erp_commodity_name, " +
|
||||
"erp_purchase_inventory.erp_category_id, erp_purchase_inventory.erp_category_name, " +
|
||||
"SUM(erp_purchase_inventory.count) AS count, " +
|
||||
"SUM(erp_purchase_inventory.amount) AS amount").
|
||||
Joins("JOIN erp_purchase_order ON erp_purchase_order.id = erp_purchase_inventory.erp_purchase_order_id").
|
||||
Joins("LEFT JOIN erp_commodity ON erp_purchase_inventory.erp_commodity_id = erp_commodity.id").
|
||||
Joins("LEFT JOIN store ON erp_purchase_order.store_id = store.id").
|
||||
Group("erp_purchase_inventory.erp_purchase_order_id, erp_purchase_inventory.erp_commodity_id, " +
|
||||
"erp_purchase_inventory.erp_commodity_name, erp_purchase_inventory.erp_category_id, " +
|
||||
"erp_purchase_inventory.serial_number")
|
||||
|
@ -5456,13 +5477,15 @@ func GetReportBySupplier(req *ErpPurchaseReportBySupplierReq, c *gin.Context) (
|
|||
countQuery := orm.Eloquent.Model(&ErpPurchaseInventory{}).
|
||||
Select("erp_purchase_inventory.erp_purchase_order_id, " +
|
||||
"erp_purchase_inventory.purchase_type, erp_purchase_inventory.serial_number, " +
|
||||
"erp_purchase_order.store_id, erp_purchase_order.store_name, erp_purchase_order.erp_supplier_id, " +
|
||||
"erp_purchase_order.store_id, store.name as store_name, erp_purchase_order.erp_supplier_id, " +
|
||||
"erp_purchase_order.erp_supplier_name, " +
|
||||
"erp_purchase_inventory.erp_commodity_id, erp_purchase_inventory.erp_commodity_name, " +
|
||||
"erp_purchase_inventory.erp_commodity_id, erp_commodity.name as erp_commodity_name, " +
|
||||
"erp_purchase_inventory.erp_category_id, erp_purchase_inventory.erp_category_name, " +
|
||||
"SUM(erp_purchase_inventory.count) AS count, " +
|
||||
"SUM(erp_purchase_inventory.amount) AS amount").
|
||||
Joins("JOIN erp_purchase_order ON erp_purchase_order.id = erp_purchase_inventory.erp_purchase_order_id").
|
||||
Joins("LEFT JOIN erp_commodity ON erp_purchase_inventory.erp_commodity_id = erp_commodity.id").
|
||||
Joins("LEFT JOIN store ON erp_purchase_order.store_id = store.id").
|
||||
Group("erp_purchase_inventory.erp_purchase_order_id, erp_purchase_inventory.erp_commodity_id, " +
|
||||
"erp_purchase_inventory.erp_commodity_name, erp_purchase_inventory.erp_category_id, " +
|
||||
"erp_purchase_inventory.serial_number")
|
||||
|
@ -5548,7 +5571,7 @@ func GetReportBySupplier(req *ErpPurchaseReportBySupplierReq, c *gin.Context) (
|
|||
data := PurchaseReportData{
|
||||
ErpPurchaseOrderId: po.ID,
|
||||
StoreId: po.StoreId,
|
||||
StoreName: po.StoreName,
|
||||
StoreName: respItem.StoreName,
|
||||
PurchaseType: respItem.PurchaseType,
|
||||
ErpSupplierId: po.ErpSupplierId,
|
||||
ErpSupplierName: po.ErpSupplierName,
|
||||
|
@ -5613,7 +5636,7 @@ func GetReportBySupplier(req *ErpPurchaseReportBySupplierReq, c *gin.Context) (
|
|||
}
|
||||
|
||||
resp.List[i].StoreId = purchaseOrderInfo.StoreId
|
||||
resp.List[i].StoreName = purchaseOrderInfo.StoreName
|
||||
//resp.List[i].StoreName = purchaseOrderInfo.StoreName
|
||||
resp.List[i].ErpSupplierId = purchaseOrderInfo.ErpSupplierId
|
||||
resp.List[i].ErpSupplierName = purchaseOrderInfo.ErpSupplierName
|
||||
|
||||
|
|
|
@ -480,6 +480,10 @@ func (m *ErpRepairOrderListReq) List(c *gin.Context) (*ErpRepairOrderListResp, e
|
|||
if v.CompletedTime != nil && v.CompletedTime.IsZero() {
|
||||
orders[i].CompletedTime = nil
|
||||
}
|
||||
|
||||
// 添加维修单位名称
|
||||
supplier, _ := GetSupplierById(v.RepairUnitId)
|
||||
orders[i].RepairUnitName = supplier.Name
|
||||
}
|
||||
|
||||
resp.List = orders
|
||||
|
|
|
@ -220,6 +220,18 @@ func (m *Store) Modify() error {
|
|||
logger.Error("Update erp_stock_commodity err:", logger.Field("err", err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新采购订单表
|
||||
err = begin.Table("erp_purchase_order").Where("store_id = ? and state NOT IN ?", m.ID,
|
||||
[]uint{ErpPurchaseOrderFinished, ErpPurchaseOrderEnd}).
|
||||
Updates(map[string]interface{}{
|
||||
"store_name": m.Name,
|
||||
}).Error
|
||||
if err != nil {
|
||||
begin.Rollback()
|
||||
logger.Error("Update erp_stock_commodity err:", logger.Field("err", err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = begin.Commit().Error
|
||||
|
|
Loading…
Reference in New Issue
Block a user