mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'fix/hasil-produksi' into 'development'
[FIX][BE]: fix hasil produksi deplesi std dan filter recording approved See merge request mbugroup/lti-api!305
This commit is contained in:
@@ -31,9 +31,25 @@ func (r *productionResultRepositoryImpl) GetRecordingsByProjectFlockKandang(
|
|||||||
return []entity.Recording{}, 0, nil
|
return []entity.Recording{}, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
latestApproval := r.db.WithContext(ctx).
|
||||||
|
Table("approvals AS a").
|
||||||
|
Select("a.approvable_id, a.action, a.step_number").
|
||||||
|
Joins(`
|
||||||
|
JOIN (
|
||||||
|
SELECT approvable_id, MAX(action_at) AS latest_action_at
|
||||||
|
FROM approvals
|
||||||
|
WHERE approvable_type = ?
|
||||||
|
GROUP BY approvable_id
|
||||||
|
) AS la ON la.approvable_id = a.approvable_id AND la.latest_action_at = a.action_at`,
|
||||||
|
string(utils.ApprovalWorkflowRecording),
|
||||||
|
)
|
||||||
|
|
||||||
countQuery := r.db.WithContext(ctx).
|
countQuery := r.db.WithContext(ctx).
|
||||||
Model(&entity.Recording{}).
|
Model(&entity.Recording{}).
|
||||||
Where("project_flock_kandangs_id = ?", projectFlockKandangID)
|
Joins("JOIN (?) AS la ON la.approvable_id = recordings.id", latestApproval).
|
||||||
|
Where("project_flock_kandangs_id = ?", projectFlockKandangID).
|
||||||
|
Where("la.step_number = ?", utils.RecordingStepDisetujui).
|
||||||
|
Where("la.action = ?", string(entity.ApprovalActionApproved))
|
||||||
|
|
||||||
var total int64
|
var total int64
|
||||||
if err := countQuery.Count(&total).Error; err != nil {
|
if err := countQuery.Count(&total).Error; err != nil {
|
||||||
@@ -59,7 +75,10 @@ func (r *productionResultRepositoryImpl) GetRecordingsByProjectFlockKandang(
|
|||||||
|
|
||||||
dataQuery := r.db.WithContext(ctx).
|
dataQuery := r.db.WithContext(ctx).
|
||||||
Model(&entity.Recording{}).
|
Model(&entity.Recording{}).
|
||||||
|
Joins("JOIN (?) AS la ON la.approvable_id = recordings.id", latestApproval).
|
||||||
Where("project_flock_kandangs_id = ?", projectFlockKandangID).
|
Where("project_flock_kandangs_id = ?", projectFlockKandangID).
|
||||||
|
Where("la.step_number = ?", utils.RecordingStepDisetujui).
|
||||||
|
Where("la.action = ?", string(entity.ApprovalActionApproved)).
|
||||||
Preload("Eggs", func(db *gorm.DB) *gorm.DB {
|
Preload("Eggs", func(db *gorm.DB) *gorm.DB {
|
||||||
return db.Select("recording_eggs.*, f.name AS product_flag_name").
|
return db.Select("recording_eggs.*, f.name AS product_flag_name").
|
||||||
Joins("LEFT JOIN product_warehouses pw ON pw.id = recording_eggs.product_warehouse_id").
|
Joins("LEFT JOIN product_warehouses pw ON pw.id = recording_eggs.product_warehouse_id").
|
||||||
|
|||||||
@@ -398,6 +398,9 @@ func (s *repportService) GetProductionResult(ctx *fiber.Ctx, params *validation.
|
|||||||
if detail != nil && detail.TargetMeanBw != nil {
|
if detail != nil && detail.TargetMeanBw != nil {
|
||||||
weeklyResults[i].StdBw = *detail.TargetMeanBw
|
weeklyResults[i].StdBw = *detail.TargetMeanBw
|
||||||
}
|
}
|
||||||
|
if detail != nil {
|
||||||
|
weeklyResults[i].DepStd = valueOrZero(detail.MaxDepletion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user