mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
Feat[BE]: implement FIFO stock management for marketing delivery products, including migration scripts and updates to related services and DTOs
This commit is contained in:
@@ -17,6 +17,9 @@ type MarketingDeliveryProductRepository interface {
|
||||
GetByMarketingId(ctx context.Context, marketingId uint) ([]entity.MarketingDeliveryProduct, error)
|
||||
GetByMarketingProductID(ctx context.Context, marketingProductID uint) (*entity.MarketingDeliveryProduct, error)
|
||||
GetAllWithFilters(ctx context.Context, offset, limit int, filters *validation.MarketingQuery) ([]entity.MarketingDeliveryProduct, int64, error)
|
||||
UpdateFifoFields(ctx context.Context, id uint, usageQty, pendingQty float64) error
|
||||
GetUsageQty(ctx context.Context, id uint) (float64, error)
|
||||
ResetFifoFields(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
type MarketingDeliveryProductRepositoryImpl struct {
|
||||
@@ -241,3 +244,33 @@ func containsJoin(db *gorm.DB, tableName string) bool {
|
||||
joinSQL := statement.SQL.String()
|
||||
return strings.Contains(joinSQL, "JOIN "+tableName)
|
||||
}
|
||||
|
||||
func (r *MarketingDeliveryProductRepositoryImpl) UpdateFifoFields(ctx context.Context, id uint, usageQty, pendingQty float64) error {
|
||||
return r.DB().WithContext(ctx).
|
||||
Model(&entity.MarketingDeliveryProduct{}).
|
||||
Where("id = ?", id).
|
||||
Updates(map[string]interface{}{
|
||||
"usage_qty": usageQty,
|
||||
"pending_qty": pendingQty,
|
||||
}).Error
|
||||
}
|
||||
|
||||
func (r *MarketingDeliveryProductRepositoryImpl) GetUsageQty(ctx context.Context, id uint) (float64, error) {
|
||||
var usageQty float64
|
||||
err := r.DB().WithContext(ctx).
|
||||
Model(&entity.MarketingDeliveryProduct{}).
|
||||
Where("id = ?", id).
|
||||
Select("usage_qty").
|
||||
Scan(&usageQty).Error
|
||||
return usageQty, err
|
||||
}
|
||||
|
||||
func (r *MarketingDeliveryProductRepositoryImpl) ResetFifoFields(ctx context.Context, id uint) error {
|
||||
return r.DB().WithContext(ctx).
|
||||
Model(&entity.MarketingDeliveryProduct{}).
|
||||
Where("id = ?", id).
|
||||
Updates(map[string]interface{}{
|
||||
"usage_qty": 0,
|
||||
"pending_qty": 0,
|
||||
}).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user