feat[BE]: Add GetClosingKeuanganByKandang endpoint and related service methods

This commit is contained in:
aguhh18
2026-01-16 20:53:47 +07:00
parent 8ad11af9c9
commit 31c48ee1da
6 changed files with 255 additions and 169 deletions
@@ -563,16 +563,15 @@ func (r *RecordingRepositoryImpl) GetTotalWeightProducedFromUniformityByProjectF
err := r.DB().WithContext(ctx).
Table("project_flock_kandang_uniformity").
Select("COALESCE(SUM(mean_weight * chick_qty_of_weight / 1000), 0) as total_weight").
Select("COALESCE(SUM((mean_up / 1.10) * chick_qty_of_weight / 1000), 0) as total_weight").
Joins("JOIN ("+
" SELECT pfku.project_flock_kandang_id, MAX(pfku.id) as latest_id "+
" FROM project_flock_kandang_uniformity pfku "+
" JOIN project_flock_kandangs pfk ON pfk.id = pfku.project_flock_kandang_id "+
" WHERE pfk.project_flock_id = ? "+
" AND pfku.deleted_at IS NULL "+
" GROUP BY pfku.project_flock_kandang_id "+
") latest ON latest.project_flock_kandang_id = project_flock_kandang_uniformity.project_flock_kandang_id "+
"AND project_flock_kandang_uniformity.id = latest.latest_id").
"AND project_flock_kandang_uniformity.id = latest.latest_id", projectFlockID).
Scan(&result).Error
return result.TotalWeight, err