mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
Fix[BE]: fixing and refactoring closing keuangan to use hpp service and repo for some getter data
This commit is contained in:
@@ -31,6 +31,7 @@ func (r *ProjectBudgetRepositoryImpl) GetByProjectFlockID(ctx context.Context, p
|
||||
Where("project_flock_id = ?", projectFlockID).
|
||||
Preload("Nonstock").
|
||||
Preload("Nonstock.Uom").
|
||||
Preload("Nonstock.Flags").
|
||||
Find(&budgets).Error
|
||||
return budgets, err
|
||||
}
|
||||
|
||||
@@ -47,8 +47,10 @@ type RecordingRepository interface {
|
||||
GetCumulativeEggQtyByProjectFlockKandang(tx *gorm.DB, projectFlockKandangId uint, recordTime time.Time) (float64, error)
|
||||
GetFcrStandardNumber(tx *gorm.DB, fcrId uint, currentWeightKg float64) (float64, bool, error)
|
||||
GetTotalWeightProducedFromUniformityByProjectFlockID(ctx context.Context, projectFlockID uint) (float64, error)
|
||||
GetTotalWeightProducedFromUniformityByProjectFlockKandangID(ctx context.Context, projectFlockKandangID uint) (float64, error)
|
||||
GetProductionWeightAndQtyByProjectFlockID(ctx context.Context, projectFlockID uint) (totalWeight float64, totalQty float64, err error)
|
||||
GetTotalDepletionByProjectFlockID(ctx context.Context, projectFlockID uint) (totalDepletion float64, err error)
|
||||
GetTotalDepletionByProjectFlockKandangID(ctx context.Context, projectFlockKandangID uint) (totalDepletion float64, err error)
|
||||
GetLatestAvgWeightByProjectFlockID(ctx context.Context, projectFlockID uint) (avgWeight float64, err error)
|
||||
GetTotalEggProductionWeightByProjectFlockID(ctx context.Context, projectFlockID uint) (totalWeightKg float64, err error)
|
||||
GetAverageTargetMetricsByProjectFlockKandangID(ctx context.Context, projectFlockKandangID uint, includeTargets bool) (RecordingTargetAverages, error)
|
||||
@@ -473,6 +475,17 @@ func (r *RecordingRepositoryImpl) GetTotalDepletionByProjectFlockID(ctx context.
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *RecordingRepositoryImpl) GetTotalDepletionByProjectFlockKandangID(ctx context.Context, projectFlockKandangID uint) (float64, error) {
|
||||
var result float64
|
||||
err := r.DB().WithContext(ctx).
|
||||
Table("recording_depletions").
|
||||
Select("COALESCE(SUM(recording_depletions.qty), 0)").
|
||||
Joins("JOIN recordings ON recordings.id = recording_depletions.recording_id").
|
||||
Where("recordings.project_flock_kandangs_id = ?", projectFlockKandangID).
|
||||
Scan(&result).Error
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *RecordingRepositoryImpl) GetLatestAvgWeightByProjectFlockID(ctx context.Context, projectFlockID uint) (float64, error) {
|
||||
// Body-weight tracking is removed; keep stub for report compatibility.
|
||||
return 0, nil
|
||||
@@ -609,3 +622,23 @@ func (r *RecordingRepositoryImpl) GetTotalWeightProducedFromUniformityByProjectF
|
||||
|
||||
return result.TotalWeight, err
|
||||
}
|
||||
|
||||
func (r *RecordingRepositoryImpl) GetTotalWeightProducedFromUniformityByProjectFlockKandangID(ctx context.Context, projectFlockKandangID uint) (float64, error) {
|
||||
if projectFlockKandangID == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var result struct {
|
||||
TotalWeight float64
|
||||
}
|
||||
|
||||
err := r.DB().WithContext(ctx).
|
||||
Table("project_flock_kandang_uniformity").
|
||||
Select("COALESCE((mean_up / 1.10) * chick_qty_of_weight / 1000, 0) as total_weight").
|
||||
Where("project_flock_kandang_id = ?", projectFlockKandangID).
|
||||
Order("id DESC").
|
||||
Limit(1).
|
||||
Scan(&result).Error
|
||||
|
||||
return result.TotalWeight, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user