mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix hpp harian kandang
This commit is contained in:
@@ -207,7 +207,7 @@ func (r *HppRepositoryImpl) GetEggProduksiPiecesAndWeightKgByProjectFlockKandang
|
||||
}
|
||||
err := r.db.WithContext(ctx).
|
||||
Table("recordings AS r").
|
||||
Select("COALESCE(SUM(re.qty), 0) AS total_pieces, COALESCE(SUM(re.weight), 0) / 1000 AS total_weight_kg").
|
||||
Select("COALESCE(SUM(re.qty), 0) AS total_pieces, COALESCE(SUM(re.weight), 0)AS total_weight_kg").
|
||||
Joins("JOIN recording_eggs AS re ON re.recording_id = r.id").
|
||||
Where("r.project_flock_kandangs_id IN (?)", projectFlockKandangIDs).
|
||||
Where("r.record_datetime <= ?", *date).
|
||||
|
||||
@@ -23,9 +23,9 @@ type HppPerKandangRow struct {
|
||||
// RemainingChickenBirds float64
|
||||
// RemainingChickenWeight float64
|
||||
EggProductionWeightKgRemaining float64
|
||||
EggProductionPiecesRemaining float64
|
||||
EggProductionTotalWeightKg float64
|
||||
EggProductionTotalPieces float64
|
||||
// EggProductionPiecesRemaining float64
|
||||
// EggProductionTotalWeightKg float64
|
||||
// EggProductionTotalPieces float64
|
||||
}
|
||||
|
||||
type HppPerKandangCostRow struct {
|
||||
@@ -49,7 +49,7 @@ type HppPerKandangSupplierRow struct {
|
||||
type HppPerKandangRepository interface {
|
||||
GetRowsByPeriod(ctx context.Context, start, end time.Time, areaIDs, locationIDs, kandangIDs []int64) ([]HppPerKandangRow, error)
|
||||
GetFeedOvkDocCostByPeriod(ctx context.Context, start, end time.Time, projectFlockKandangIDs []uint) ([]HppPerKandangCostRow, []HppPerKandangSupplierRow, error)
|
||||
GetEggProductionByProjectFlockKandangIDs(ctx context.Context, start, end time.Time, projectFlockKandangIDs []uint) (map[uint]HppPerKandangRow, error)
|
||||
GetWeightRemainingByProjectFlockKandangIDs(ctx context.Context, start, end time.Time, projectFlockKandangIDs []uint) (map[uint]HppPerKandangRow, error)
|
||||
}
|
||||
|
||||
type hppPerKandangRepository struct {
|
||||
@@ -210,7 +210,7 @@ func (r *hppPerKandangRepository) GetFeedOvkDocCostByPeriod(ctx context.Context,
|
||||
return rows, docSuppliers, nil
|
||||
}
|
||||
|
||||
func (r *hppPerKandangRepository) GetEggProductionByProjectFlockKandangIDs(ctx context.Context, start, end time.Time, projectFlockKandangIDs []uint) (map[uint]HppPerKandangRow, error) {
|
||||
func (r *hppPerKandangRepository) GetWeightRemainingByProjectFlockKandangIDs(ctx context.Context, start, end time.Time, projectFlockKandangIDs []uint) (map[uint]HppPerKandangRow, error) {
|
||||
if len(projectFlockKandangIDs) == 0 {
|
||||
return map[uint]HppPerKandangRow{}, nil
|
||||
}
|
||||
@@ -231,9 +231,9 @@ func (r *hppPerKandangRepository) GetEggProductionByProjectFlockKandangIDs(ctx c
|
||||
type eggRow struct {
|
||||
ProjectFlockKandangID uint
|
||||
EggProductionWeightKgRemaining float64
|
||||
EggProductionPiecesRemaining float64
|
||||
EggProductionTotalWeightKg float64
|
||||
EggProductionTotalPieces float64
|
||||
// EggProductionPiecesRemaining float64
|
||||
// EggProductionTotalWeightKg float64
|
||||
// EggProductionTotalPieces float64
|
||||
}
|
||||
|
||||
eggRows := make([]eggRow, 0)
|
||||
@@ -241,10 +241,7 @@ func (r *hppPerKandangRepository) GetEggProductionByProjectFlockKandangIDs(ctx c
|
||||
Table("recordings AS r").
|
||||
Select(`
|
||||
r.project_flock_kandangs_id AS project_flock_kandang_id,
|
||||
COALESCE(SUM((re.total_qty - re.total_used) * re.weight / 1000), 0) AS egg_production_weight_kg_remaining,
|
||||
COALESCE(SUM(re.total_qty - re.total_used), 0) AS egg_production_pieces_remaining,
|
||||
COALESCE(SUM(re.weight / 1000), 0) AS egg_production_total_weight_kg,
|
||||
COALESCE(SUM(re.total_qty), 0) AS egg_production_total_pieces`).
|
||||
COALESCE((SUM(re.weight) / NULLIF(SUM(re.total_qty), 0)) * SUM(re.total_qty - re.total_used), 0) AS egg_production_weight_kg_remaining`).
|
||||
Joins("LEFT JOIN (?) AS la ON la.approvable_id = r.id", latestApproval).
|
||||
Joins("LEFT JOIN recording_eggs AS re ON re.recording_id = r.id").
|
||||
Where("r.project_flock_kandangs_id IN ?", projectFlockKandangIDs).
|
||||
@@ -262,9 +259,9 @@ func (r *hppPerKandangRepository) GetEggProductionByProjectFlockKandangIDs(ctx c
|
||||
result[row.ProjectFlockKandangID] = HppPerKandangRow{
|
||||
ProjectFlockKandangID: row.ProjectFlockKandangID,
|
||||
EggProductionWeightKgRemaining: row.EggProductionWeightKgRemaining,
|
||||
EggProductionPiecesRemaining: row.EggProductionPiecesRemaining,
|
||||
EggProductionTotalWeightKg: row.EggProductionTotalWeightKg,
|
||||
EggProductionTotalPieces: row.EggProductionTotalPieces,
|
||||
// EggProductionPiecesRemaining: row.EggProductionPiecesRemaining,
|
||||
// EggProductionTotalWeightKg: row.EggProductionTotalWeightKg,
|
||||
// EggProductionTotalPieces: row.EggProductionTotalPieces,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1515,18 +1515,18 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// eggMap, err := s.HppPerKandangRepo.GetEggProductionByProjectFlockKandangIDs(ctx.Context(), startOfDay, endOfDay, validPfkIDs)
|
||||
// if err != nil {
|
||||
// return nil, nil, err
|
||||
// }
|
||||
// for pfkID, egg := range eggMap {
|
||||
// if rowIdx, ok := pfkIndex[pfkID]; ok {
|
||||
// repoRows[rowIdx].EggProductionWeightKgRemaining = egg.EggProductionWeightKgRemaining
|
||||
// repoRows[rowIdx].EggProductionPiecesRemaining = egg.EggProductionPiecesRemaining
|
||||
// repoRows[rowIdx].EggProductionTotalWeightKg = egg.EggProductionTotalWeightKg
|
||||
// repoRows[rowIdx].EggProductionTotalPieces = egg.EggProductionTotalPieces
|
||||
// }
|
||||
// }
|
||||
eggMap, err := s.HppPerKandangRepo.GetWeightRemainingByProjectFlockKandangIDs(ctx.Context(), startOfDay, endOfDay, validPfkIDs)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
for pfkID, egg := range eggMap {
|
||||
if rowIdx, ok := pfkIndex[pfkID]; ok {
|
||||
repoRows[rowIdx].EggProductionWeightKgRemaining = egg.EggProductionWeightKgRemaining
|
||||
// repoRows[rowIdx].EggProductionPiecesRemaining = egg.EggProductionPiecesRemaining
|
||||
// repoRows[rowIdx].EggProductionTotalWeightKg = egg.EggProductionTotalWeightKg
|
||||
// repoRows[rowIdx].EggProductionTotalPieces = egg.EggProductionTotalPieces
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
costMap := make(map[uint]HppCostAggregate, len(costRows))
|
||||
@@ -1612,7 +1612,7 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
}
|
||||
|
||||
var eggPiecesFloatRemaining float64
|
||||
var eggRemainingWeightFloatRemaining float64
|
||||
eggRemainingWeightFloatRemaining := row.EggProductionWeightKgRemaining
|
||||
var eggTotalPiecesFloat float64
|
||||
var eggWeightFloat float64
|
||||
eggHpp := 0.0
|
||||
@@ -1622,7 +1622,7 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
return nil, nil, err
|
||||
}
|
||||
if hppCost != nil {
|
||||
eggRemainingWeightFloatRemaining = hppCost.Estimation.Kg - hppCost.Real.Kg
|
||||
// eggRemainingWeightFloatRemaining = hppCost.Estimation.Kg - hppCost.Real.Kg
|
||||
eggPiecesFloatRemaining = hppCost.Estimation.Butir - hppCost.Real.Butir
|
||||
eggHpp = hppCost.Estimation.HargaKg
|
||||
eggTotalPiecesFloat = hppCost.Estimation.Butir
|
||||
|
||||
Reference in New Issue
Block a user