mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-26 00:05:44 +00:00
codex/fix: recheck and fix purchase receive failed and farm stock not shown on recording
This commit is contained in:
@@ -2,12 +2,14 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -76,11 +78,53 @@ func resolvePurchaseFlagGroupByProductWarehouse(ctx context.Context, tx *gorm.DB
|
||||
Order("rr.id ASC").
|
||||
Limit(1).
|
||||
Take(&selected).Error
|
||||
if err == nil {
|
||||
return strings.TrimSpace(selected.FlagGroupCode), nil
|
||||
}
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
type categoryRow struct {
|
||||
CategoryCode string `gorm:"column:category_code"`
|
||||
}
|
||||
|
||||
var category categoryRow
|
||||
err = tx.WithContext(ctx).
|
||||
Table("product_warehouses pw").
|
||||
Select("pc.code AS category_code").
|
||||
Joins("JOIN products p ON p.id = pw.product_id").
|
||||
Joins("JOIN product_categories pc ON pc.id = p.product_category_id").
|
||||
Where("pw.id = ?", productWarehouseID).
|
||||
Limit(1).
|
||||
Take(&category).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimSpace(selected.FlagGroupCode), nil
|
||||
flagGroupCode := utils.LegacyFlagGroupCodeByProductCategoryCode(category.CategoryCode)
|
||||
if flagGroupCode == "" {
|
||||
return "", gorm.ErrRecordNotFound
|
||||
}
|
||||
|
||||
var matched int64
|
||||
err = tx.WithContext(ctx).
|
||||
Table("fifo_stock_v2_route_rules rr").
|
||||
Joins("JOIN fifo_stock_v2_flag_groups fg ON fg.code = rr.flag_group_code AND fg.is_active = TRUE").
|
||||
Where("rr.is_active = TRUE").
|
||||
Where("rr.lane = ?", purchaseStockableLane).
|
||||
Where("rr.function_code = ?", purchaseInFunctionCode).
|
||||
Where("rr.source_table = ?", purchaseSourceTable).
|
||||
Where("rr.flag_group_code = ?", flagGroupCode).
|
||||
Count(&matched).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if matched == 0 {
|
||||
return "", gorm.ErrRecordNotFound
|
||||
}
|
||||
|
||||
return flagGroupCode, nil
|
||||
}
|
||||
|
||||
func assignEarliestAsOf(m map[uint]time.Time, productWarehouseID uint, asOf time.Time) {
|
||||
|
||||
Reference in New Issue
Block a user