mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat[BE-384]: enhance closing reports by introducing calculation context and improving data handling; refactor related functions for better clarity and maintainability
This commit is contained in:
@@ -26,6 +26,7 @@ type PurchaseRepository interface {
|
||||
NextPoNumber(ctx context.Context, tx *gorm.DB) (string, error)
|
||||
BackfillProjectFlockKandang(ctx context.Context, purchaseID uint) error
|
||||
GetItemsByProjectFlockID(ctx context.Context, projectFlockID uint) ([]entity.PurchaseItem, error)
|
||||
GetItemsByWarehouseKandang(ctx context.Context, projectFlockID uint) ([]entity.PurchaseItem, error)
|
||||
}
|
||||
|
||||
type PurchaseRepositoryImpl struct {
|
||||
@@ -291,13 +292,34 @@ func (r *PurchaseRepositoryImpl) numberExists(ctx context.Context, db *gorm.DB,
|
||||
}
|
||||
|
||||
func (r *PurchaseRepositoryImpl) GetItemsByProjectFlockID(ctx context.Context, projectFlockID uint) ([]entity.PurchaseItem, error) {
|
||||
|
||||
return r.GetItemsByWarehouseKandang(ctx, projectFlockID)
|
||||
}
|
||||
|
||||
func (r *PurchaseRepositoryImpl) GetItemsByWarehouseKandang(ctx context.Context, projectFlockID uint) ([]entity.PurchaseItem, error) {
|
||||
var items []entity.PurchaseItem
|
||||
|
||||
var kandangIDs []uint
|
||||
err := r.DB().WithContext(ctx).
|
||||
Table("project_flock_kandangs").
|
||||
Where("project_flock_id = ?", projectFlockID).
|
||||
Pluck("kandang_id", &kandangIDs).Error
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(kandangIDs) == 0 {
|
||||
return []entity.PurchaseItem{}, nil
|
||||
}
|
||||
|
||||
err = r.DB().WithContext(ctx).
|
||||
Preload("Product").
|
||||
Preload("Product.Flags").
|
||||
Joins("JOIN project_flock_kandangs ON project_flock_kandangs.id = purchase_items.project_flock_kandang_id").
|
||||
Where("project_flock_kandangs.project_flock_id = ?", projectFlockID).
|
||||
Joins("JOIN warehouses ON warehouses.id = purchase_items.warehouse_id").
|
||||
Where("warehouses.kandang_id IN ?", kandangIDs).
|
||||
Find(&items).Error
|
||||
|
||||
return items, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user