1.给采购订单、库存调拨、库存变动、产品入库等功能的反审核加上"财务月结"判断;

This commit is contained in:
chenlin 2025-01-03 18:14:17 +08:00
parent e4a634da65
commit ef20f7d319
8 changed files with 40 additions and 3 deletions

View File

@ -119,7 +119,7 @@ func InventoryAllotAudit(c *gin.Context) {
err := models.AuditAllotInventory(req, c)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, "审核失败:"+err.Error())
app.Error(c, http.StatusInternalServerError, err, "审核失败"+err.Error())
return
}

View File

@ -123,7 +123,7 @@ func InventoryChangeAudit(c *gin.Context) {
err := models.AuditChangeInventory(req, c)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, "审核失败:"+err.Error())
app.Error(c, http.StatusInternalServerError, err, "审核失败"+err.Error())
return
}

View File

@ -118,7 +118,7 @@ func ProductInventoryAudit(c *gin.Context) {
err := models.AuditProductInventory(req, c)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, "审核失败:"+err.Error())
app.Error(c, http.StatusInternalServerError, err, "审核失败"+err.Error())
return
}

View File

@ -372,6 +372,10 @@ func ErpPurchaseAudit(c *gin.Context) {
app.Error(c, http.StatusInternalServerError, err, "取消审核失败:[已终止]订单不能取消")
return
} else {
if model.IsMonthEndClosed(*erpPurchaseOrder.AuditTime) {
app.Error(c, http.StatusInternalServerError, errors.New("反审核失败,财务已月结"), "反审核失败,财务已月结")
return
}
orderState = model.ErpPurchaseOrderUnAudit
// 更新库存信息
err = model.CancelAuditUpdateStock(begin, erpPurchaseOrder)

View File

@ -596,6 +596,9 @@ func AuditAllotInventory(req *InventoryAllotAuditReq, c *gin.Context) error {
if inventoryAllotOrder.State == ErpInventoryAllotOrderUnAudit { // 订单未审核
return errors.New("订单是未审核状态,无需取消审核")
}
if IsMonthEndClosed(*inventoryAllotOrder.AuditTime) {
return errors.New("财务已月结")
}
// 更新商品的库存状态
err = cancelAllotAuditAndUpdateStock(begin, inventoryAllotOrder)
if err != nil {

View File

@ -573,6 +573,9 @@ func AuditChangeInventory(req *InventoryChangeAuditReq, c *gin.Context) error {
if inventoryChangeOrder.State == ErpInventoryChangeOrderUnAudit { // 订单未审核
return errors.New("订单是未审核状态,无需取消审核")
}
if IsMonthEndClosed(*inventoryChangeOrder.AuditTime) {
return errors.New("财务已月结")
}
orderState = ErpInventoryChangeOrderUnAudit
default:
logger.Error("order err, req.State is:", logger.Field("req.State", req.State))

View File

@ -485,6 +485,9 @@ func AuditProductInventory(req *ProductInventoryAuditReq, c *gin.Context) error
if inventoryProductOrder.State == ErpInventoryProductOrderUnAudit { // 订单未审核
return errors.New("订单是未审核状态,无需取消审核")
}
if IsMonthEndClosed(*inventoryProductOrder.AuditTime) {
return errors.New("财务已月结")
}
// 退库-更新库存信息
err = cancelProductAuditAndUpdateStock(begin, inventoryProductOrder)
if err != nil {

View File

@ -304,3 +304,27 @@ type ErpMonthEndClosingAuditReq struct {
type ErpMonthEndClosingDateResp struct {
StartDate string `json:"start_date"` // 月结开始时间
}
// IsMonthEndClosed 判断当前日期是否已月结
func IsMonthEndClosed(date time.Time) bool {
// 获取当前月份的第一天
firstDayOfMonth := time.Date(date.Year(), date.Month(), 1, 0, 0, 0, 0, date.Location())
// 查询已月结的记录,找到最新的月结记录
var erpMonthEndOrder ErpMonthEndClosing
err := orm.Eloquent.Table("erp_month_end_closing").
Where("closing_end_date >= ? AND state = ?", firstDayOfMonth, ErpMonthEndClosingAudited).
Order("closing_end_date desc").
First(&erpMonthEndOrder).Error
if err != nil {
// 如果没有找到已月结记录,直接返回 false
if err == RecordNotFound {
return false
}
logger.Error("Query month end closing record error:", logger.Field("err", err))
return false
}
// 判断传入的时间是否早于已月结记录的截止日期
return date.Before(erpMonthEndOrder.ClosingEndDate)
}