[FIX][BE]: LSS390

This commit is contained in:
giovanni
2026-01-19 16:19:47 +07:00
parent eda50930e7
commit 71c62c5e02
4 changed files with 121 additions and 73 deletions
@@ -1,6 +1,7 @@
package dto package dto
import ( import (
"strconv"
"time" "time"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities" entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
@@ -53,6 +54,7 @@ type ProjectFlockKandangListDTO struct {
ProjectFlockKandangRelationDTO ProjectFlockKandangRelationDTO
ProjectFlock *ProjectFlockDTO `json:"project_flock,omitempty"` ProjectFlock *ProjectFlockDTO `json:"project_flock,omitempty"`
Kandang *kandangDTO.KandangRelationDTO `json:"kandang,omitempty"` Kandang *kandangDTO.KandangRelationDTO `json:"kandang,omitempty"`
NameWithPeriod string `json:"name_with_period"`
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"` CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
Approval *approvalDTO.ApprovalRelationDTO `json:"approval,omitempty"` Approval *approvalDTO.ApprovalRelationDTO `json:"approval,omitempty"`
@@ -104,6 +106,7 @@ func ToProjectFlockKandangDetailDTOWithAvailableQty(e entity.ProjectFlockKandang
ProjectFlockKandangRelationDTO: ToProjectFlockKandangRelationDTO(e), ProjectFlockKandangRelationDTO: ToProjectFlockKandangRelationDTO(e),
ProjectFlock: toProjectFlockDTO(projectFlockSummary), ProjectFlock: toProjectFlockDTO(projectFlockSummary),
Kandang: toKandangRelation(e.Kandang), Kandang: toKandangRelation(e.Kandang),
NameWithPeriod: toNameWithPeriod(e.Kandang, e.Period),
CreatedAt: e.CreatedAt, CreatedAt: e.CreatedAt,
CreatedUser: toCreatedUserDTO(e.ProjectFlock), CreatedUser: toCreatedUserDTO(e.ProjectFlock),
Approval: toApprovalDTOSelector(e, func(x entity.ProjectFlockKandang) *entity.Approval { return x.LatestProjectFlockApproval }), Approval: toApprovalDTOSelector(e, func(x entity.ProjectFlockKandang) *entity.Approval { return x.LatestProjectFlockApproval }),
@@ -126,6 +129,16 @@ func toKandangRelation(kandang entity.Kandang) *kandangDTO.KandangRelationDTO {
return &mapped return &mapped
} }
func toNameWithPeriod(kandang entity.Kandang, period int) string {
if kandang.Name == "" {
return ""
}
if period == 0 {
return kandang.Name
}
return kandang.Name + " Period " + strconv.Itoa(period)
}
func toApprovalDTOSelector( func toApprovalDTOSelector(
e entity.ProjectFlockKandang, selector func(entity.ProjectFlockKandang) *entity.Approval) *approvalDTO.ApprovalRelationDTO { e entity.ProjectFlockKandang, selector func(entity.ProjectFlockKandang) *entity.Approval) *approvalDTO.ApprovalRelationDTO {
approval := selector(e) approval := selector(e)
@@ -147,6 +160,7 @@ func ToProjectFlockKandangListDTO(e entity.ProjectFlockKandang) ProjectFlockKand
ProjectFlockKandangRelationDTO: ToProjectFlockKandangRelationDTO(e), ProjectFlockKandangRelationDTO: ToProjectFlockKandangRelationDTO(e),
ProjectFlock: toProjectFlockDTO(projectFlockSummary), ProjectFlock: toProjectFlockDTO(projectFlockSummary),
Kandang: toKandangRelation(e.Kandang), Kandang: toKandangRelation(e.Kandang),
NameWithPeriod: toNameWithPeriod(e.Kandang, e.Period),
CreatedAt: e.CreatedAt, CreatedAt: e.CreatedAt,
CreatedUser: toCreatedUserDTO(e.ProjectFlock), CreatedUser: toCreatedUserDTO(e.ProjectFlock),
Approval: toApprovalDTOSelector(e, func(x entity.ProjectFlockKandang) *entity.Approval { return x.LatestProjectFlockApproval }), Approval: toApprovalDTOSelector(e, func(x entity.ProjectFlockKandang) *entity.Approval { return x.LatestProjectFlockApproval }),
@@ -31,6 +31,8 @@ type HppPerKandangRowDTO struct {
AvgWeightKg float64 `json:"avg_weight_kg"` AvgWeightKg float64 `json:"avg_weight_kg"`
EggProductionPieces int64 `json:"egg_production_pieces"` EggProductionPieces int64 `json:"egg_production_pieces"`
EggProductionKg float64 `json:"egg_production_kg"` EggProductionKg float64 `json:"egg_production_kg"`
// EggProductionTotalWeightKg float64 `json:"egg_production_total_weight_kg"`
// EggProductionTotalPieces int64 `json:"egg_production_total_pieces"`
// FeedCostRp float64 `json:"feed_cost_rp"` // FeedCostRp float64 `json:"feed_cost_rp"`
// OvkCostRp float64 `json:"ovk_cost_rp"` // OvkCostRp float64 `json:"ovk_cost_rp"`
EggHppRpPerKg float64 `json:"egg_hpp_rp_per_kg"` EggHppRpPerKg float64 `json:"egg_hpp_rp_per_kg"`
@@ -38,8 +40,8 @@ type HppPerKandangRowDTO struct {
FeedSuppliers []HppPerKandangSupplierDTO `json:"feed_suppliers"` FeedSuppliers []HppPerKandangSupplierDTO `json:"feed_suppliers"`
DocSuppliers []HppPerKandangSupplierDTO `json:"doc_suppliers"` DocSuppliers []HppPerKandangSupplierDTO `json:"doc_suppliers"`
AverageDocPriceRp int64 `json:"average_doc_price_rp"` AverageDocPriceRp int64 `json:"average_doc_price_rp"`
HppRp float64 `json:"hpp_rp"` // HppRp float64 `json:"hpp_rp"`
RemainingValueRp int64 `json:"remaining_value_rp"` // RemainingValueRp int64 `json:"remaining_value_rp"`
} }
type HppPerKandangRowKandangDTO struct { type HppPerKandangRowKandangDTO struct {
@@ -11,19 +11,21 @@ import (
) )
type HppPerKandangRow struct { type HppPerKandangRow struct {
ProjectFlockKandangID uint ProjectFlockKandangID uint
KandangID uint KandangID uint
KandangName string KandangName string
KandangStatus string KandangStatus string
LocationID uint LocationID uint
LocationName string LocationName string
PicID uint PicID uint
PicName string PicName string
RecordingCount int64 RecordingCount int64
RemainingChickenBirds float64 // RemainingChickenBirds float64
RemainingChickenWeight float64 // RemainingChickenWeight float64
EggProductionWeightKg float64 EggProductionWeightKgRemaining float64
EggProductionPieces float64 EggProductionPiecesRemaining float64
EggProductionTotalWeightKg float64
EggProductionTotalPieces float64
} }
type HppPerKandangCostRow struct { type HppPerKandangCostRow struct {
@@ -97,13 +99,22 @@ func (r *hppPerKandangRepository) GetRowsByPeriod(ctx context.Context, start, en
COALESCE(MAX(vr.total_chick_qty), 0) AS remaining_chicken_birds, COALESCE(MAX(vr.total_chick_qty), 0) AS remaining_chicken_birds,
0 AS remaining_chicken_weight, 0 AS remaining_chicken_weight,
0 AS egg_production_weight_kg, 0 AS egg_production_weight_kg,
0 AS egg_production_pieces`). 0 AS egg_production_pieces,
0 AS egg_production_total_weight_kg,
0 AS egg_production_total_pieces`).
Joins("JOIN project_flock_kandangs AS pfk ON pfk.project_flock_id = pf.id"). Joins("JOIN project_flock_kandangs AS pfk ON pfk.project_flock_id = pf.id").
Joins(`
LEFT JOIN (
SELECT project_flock_kandang_id, MIN(chick_in_date) AS chick_in_date
FROM project_chickins
GROUP BY project_flock_kandang_id
) AS pc ON pc.project_flock_kandang_id = pfk.id`).
Joins("JOIN kandangs AS k ON k.id = pfk.kandang_id"). Joins("JOIN kandangs AS k ON k.id = pfk.kandang_id").
Joins("JOIN locations AS loc ON loc.id = k.location_id"). Joins("JOIN locations AS loc ON loc.id = k.location_id").
Joins("JOIN users AS pic ON pic.id = k.pic_id"). Joins("JOIN users AS pic ON pic.id = k.pic_id").
Joins("LEFT JOIN (?) AS vr ON vr.project_flock_kandangs_id = pfk.id", validRecordings). Joins("LEFT JOIN (?) AS vr ON vr.project_flock_kandangs_id = pfk.id", validRecordings).
Where("pfk.closed_at IS NULL") Where("pf.category = ?", utils.ProjectFlockCategoryLaying).
Where("(pfk.closed_at IS NULL OR ? BETWEEN pc.chick_in_date AND pfk.closed_at)", start)
query = applyLocationFilters(query, areaIDs, locationIDs, kandangIDs) query = applyLocationFilters(query, areaIDs, locationIDs, kandangIDs)
@@ -164,7 +175,7 @@ func (r *hppPerKandangRepository) GetFeedOvkDocCostByPeriod(ctx context.Context,
Joins("LEFT JOIN flags AS f ON f.flagable_id = pi.product_id AND f.flagable_type = ?", entity.FlagableTypeProduct). Joins("LEFT JOIN flags AS f ON f.flagable_id = pi.product_id AND f.flagable_type = ?", entity.FlagableTypeProduct).
Joins("LEFT JOIN flags AS tf ON tf.flagable_id = std.product_id AND tf.flagable_type = ?", entity.FlagableTypeProduct). Joins("LEFT JOIN flags AS tf ON tf.flagable_id = std.product_id AND tf.flagable_type = ?", entity.FlagableTypeProduct).
Where("r.project_flock_kandangs_id IN ?", projectFlockKandangIDs). Where("r.project_flock_kandangs_id IN ?", projectFlockKandangIDs).
// Where("r.record_datetime >= ? AND r.record_datetime < ?", start, end). Where("r.record_datetime < ?", end).
Where("r.deleted_at IS NULL"). Where("r.deleted_at IS NULL").
Where("(la.action IS NULL OR la.action != ?)", string(entity.ApprovalActionRejected)) Where("(la.action IS NULL OR la.action != ?)", string(entity.ApprovalActionRejected))
@@ -349,7 +360,7 @@ func (r *hppPerKandangRepository) GetFeedOvkDocCostByPeriod(ctx context.Context,
Joins("LEFT JOIN flags AS f ON f.flagable_id = pi.product_id AND f.flagable_type = ?", entity.FlagableTypeProduct). Joins("LEFT JOIN flags AS f ON f.flagable_id = pi.product_id AND f.flagable_type = ?", entity.FlagableTypeProduct).
Where("f.name IN ?", []utils.FlagType{utils.FlagPakan, utils.FlagOVK}). Where("f.name IN ?", []utils.FlagType{utils.FlagPakan, utils.FlagOVK}).
Where("r.project_flock_kandangs_id IN (?)", projectFlockKandangIDs). Where("r.project_flock_kandangs_id IN (?)", projectFlockKandangIDs).
// Where("r.record_datetime >= ? AND r.record_datetime < ?", start, end). Where("r.record_datetime < ?", end).
Where("r.deleted_at IS NULL") Where("r.deleted_at IS NULL")
// feedQuery = applyLocationFilters(feedQuery, areaIDs, locationIDs, kandangIDs) // feedQuery = applyLocationFilters(feedQuery, areaIDs, locationIDs, kandangIDs)
@@ -391,9 +402,11 @@ func (r *hppPerKandangRepository) GetEggProductionByProjectFlockKandangIDs(ctx c
) )
type eggRow struct { type eggRow struct {
ProjectFlockKandangID uint ProjectFlockKandangID uint
EggProductionWeightKg float64 EggProductionWeightKgRemaining float64
EggProductionPieces float64 EggProductionPiecesRemaining float64
EggProductionTotalWeightKg float64
EggProductionTotalPieces float64
} }
eggRows := make([]eggRow, 0) eggRows := make([]eggRow, 0)
@@ -401,12 +414,14 @@ func (r *hppPerKandangRepository) GetEggProductionByProjectFlockKandangIDs(ctx c
Table("recordings AS r"). Table("recordings AS r").
Select(` Select(`
r.project_flock_kandangs_id AS project_flock_kandang_id, r.project_flock_kandangs_id AS project_flock_kandang_id,
COALESCE(SUM(re.weight), 0) AS egg_production_weight_kg, COALESCE(SUM((re.total_qty - re.total_used) * re.weight / 1000), 0) AS egg_production_weight_kg_remaining,
COALESCE(SUM(re.qty), 0) AS egg_production_pieces`). 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`).
Joins("LEFT JOIN (?) AS la ON la.approvable_id = r.id", latestApproval). 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"). Joins("LEFT JOIN recording_eggs AS re ON re.recording_id = r.id").
Where("r.project_flock_kandangs_id IN ?", projectFlockKandangIDs). Where("r.project_flock_kandangs_id IN ?", projectFlockKandangIDs).
// Where("r.record_datetime >= ? AND r.record_datetime < ?", start, end). Where("r.record_datetime < ?", end).
Where("r.deleted_at IS NULL"). Where("r.deleted_at IS NULL").
Where("(la.action IS NULL OR la.action != ?)", string(entity.ApprovalActionRejected)). Where("(la.action IS NULL OR la.action != ?)", string(entity.ApprovalActionRejected)).
Group("r.project_flock_kandangs_id") Group("r.project_flock_kandangs_id")
@@ -418,9 +433,11 @@ func (r *hppPerKandangRepository) GetEggProductionByProjectFlockKandangIDs(ctx c
result := make(map[uint]HppPerKandangRow, len(eggRows)) result := make(map[uint]HppPerKandangRow, len(eggRows))
for _, row := range eggRows { for _, row := range eggRows {
result[row.ProjectFlockKandangID] = HppPerKandangRow{ result[row.ProjectFlockKandangID] = HppPerKandangRow{
ProjectFlockKandangID: row.ProjectFlockKandangID, ProjectFlockKandangID: row.ProjectFlockKandangID,
EggProductionWeightKg: row.EggProductionWeightKg, EggProductionWeightKgRemaining: row.EggProductionWeightKgRemaining,
EggProductionPieces: row.EggProductionPieces, EggProductionPiecesRemaining: row.EggProductionPiecesRemaining,
EggProductionTotalWeightKg: row.EggProductionTotalWeightKg,
EggProductionTotalPieces: row.EggProductionTotalPieces,
} }
} }
@@ -435,7 +452,7 @@ func applyLocationFilters(query *gorm.DB, areaIDs, locationIDs, kandangIDs []int
query = query.Where("k.location_id IN ?", locationIDs) query = query.Where("k.location_id IN ?", locationIDs)
} }
if len(kandangIDs) > 0 { if len(kandangIDs) > 0 {
query = query.Where("k.id IN ?", kandangIDs) query = query.Where("pfk.id IN ?", kandangIDs)
} }
return query return query
} }
@@ -1370,8 +1370,10 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
} }
for pfkID, egg := range eggMap { for pfkID, egg := range eggMap {
if rowIdx, ok := pfkIndex[pfkID]; ok { if rowIdx, ok := pfkIndex[pfkID]; ok {
repoRows[rowIdx].EggProductionWeightKg = egg.EggProductionWeightKg repoRows[rowIdx].EggProductionWeightKgRemaining = egg.EggProductionWeightKgRemaining
repoRows[rowIdx].EggProductionPieces = egg.EggProductionPieces repoRows[rowIdx].EggProductionPiecesRemaining = egg.EggProductionPiecesRemaining
repoRows[rowIdx].EggProductionTotalWeightKg = egg.EggProductionTotalWeightKg
repoRows[rowIdx].EggProductionTotalPieces = egg.EggProductionTotalPieces
} }
} }
} }
@@ -1442,12 +1444,12 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
dataRows := make([]dto.HppPerKandangRowDTO, 0, len(repoRows)) dataRows := make([]dto.HppPerKandangRowDTO, 0, len(repoRows))
perRangeMap := make(map[weightRangeKey]*weightRangeAggregate) perRangeMap := make(map[weightRangeKey]*weightRangeAggregate)
var totalBirds int64 var totalBirds int64
var totalWeight float64 // var totalWeight float64
var totalEggPieces int64 var totalEggPieces int64
var totalEggKg float64 var totalEggKg float64
var totalRemainingValueRp int64 // var totalRemainingValueRp int64
var totalEggValueRp int64 var totalEggValueRp int64
var totalHppSum float64 // var totalHppSum float64
var totalHppCount int var totalHppCount int
var totalDocPriceSum float64 var totalDocPriceSum float64
var totalDocPriceCount int var totalDocPriceCount int
@@ -1461,26 +1463,34 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
continue continue
} }
birdsFloat := row.RemainingChickenBirds // birdsFloat := row.RemainingChickenBirds
if math.IsNaN(birdsFloat) || math.IsInf(birdsFloat, 0) { // if math.IsNaN(birdsFloat) || math.IsInf(birdsFloat, 0) {
birdsFloat = 0 // birdsFloat = 0
// }
// weightFloat := row.RemainingChickenWeight
// if math.IsNaN(weightFloat) || math.IsInf(weightFloat, 0) {
// weightFloat = 0
// }
eggPiecesFloatRemaining := row.EggProductionPiecesRemaining
if math.IsNaN(eggPiecesFloatRemaining) || math.IsInf(eggPiecesFloatRemaining, 0) {
eggPiecesFloatRemaining = 0
} }
weightFloat := row.RemainingChickenWeight eggTotalPiecesFloat := row.EggProductionTotalPieces
if math.IsNaN(weightFloat) || math.IsInf(weightFloat, 0) { if math.IsNaN(eggTotalPiecesFloat) || math.IsInf(eggTotalPiecesFloat, 0) {
weightFloat = 0 eggTotalPiecesFloat = 0
} }
eggPiecesFloat := row.EggProductionPieces eggRemainingWeightFloatRemaining := row.EggProductionWeightKgRemaining
if math.IsNaN(eggPiecesFloat) || math.IsInf(eggPiecesFloat, 0) { if math.IsNaN(eggRemainingWeightFloatRemaining) || math.IsInf(eggRemainingWeightFloatRemaining, 0) {
eggPiecesFloat = 0 eggRemainingWeightFloatRemaining = 0
} }
eggWeightFloat := row.EggProductionWeightKg eggWeightFloat := row.EggProductionTotalWeightKg
if math.IsNaN(eggWeightFloat) || math.IsInf(eggWeightFloat, 0) { if math.IsNaN(eggWeightFloat) || math.IsInf(eggWeightFloat, 0) {
eggWeightFloat = 0 eggWeightFloat = 0
} }
avgWeight := 0.0 avgWeight := 0.0
if eggPiecesFloat > 0 { if eggTotalPiecesFloat > 0 {
avgWeight = eggWeightFloat / eggPiecesFloat avgWeight = eggWeightFloat / eggTotalPiecesFloat
} }
if params.WeightMin != nil && avgWeight < *params.WeightMin { if params.WeightMin != nil && avgWeight < *params.WeightMin {
continue continue
@@ -1496,21 +1506,21 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
weightMax := weightMin + 0.09 weightMax := weightMin + 0.09
rangeKey := weightRangeKey{Min: weightMin, Max: weightMax} rangeKey := weightRangeKey{Min: weightMin, Max: weightMax}
rowBirds := int64(math.Round(birdsFloat)) // rowBirds := int64(math.Round(birdsFloat))
costEntry := costMap[row.KandangID] costEntry := costMap[row.KandangID]
totalCost := costEntry.FeedCost + costEntry.OvkCost + costEntry.DocCost + costEntry.BudgetCost + costEntry.ExpenseCost totalCost := costEntry.FeedCost + costEntry.OvkCost + costEntry.DocCost + costEntry.BudgetCost + costEntry.ExpenseCost
hppRp := 0.0 // hppRp := 0.0
if weightFloat > 0 { // if weightFloat > 0 {
hppRp = totalCost / weightFloat // hppRp = totalCost / weightFloat
} // }
eggHpp := 0.0 eggHpp := 0.0
if eggWeightFloat > 0 { if eggWeightFloat > 0 {
eggHpp = totalCost / eggWeightFloat eggHpp = (totalCost / eggWeightFloat) / 1000
} }
rowEggPieces := int64(math.Round(eggPiecesFloat)) rowEggPieces := int64(math.Round(eggPiecesFloatRemaining))
rowEggValue := int64(eggHpp * eggWeightFloat) rowEggValue := int64(eggHpp * eggRemainingWeightFloatRemaining)
rowRemainingValue := int64(hppRp * weightFloat) // rowRemainingValue := int64(hppRp * weightFloat)
avgDocPrice := int64(0) avgDocPrice := int64(0)
if costEntry.DocQty > 0 { if costEntry.DocQty > 0 {
avgDocPrice = int64(math.Round(costEntry.DocCost / costEntry.DocQty)) avgDocPrice = int64(math.Round(costEntry.DocCost / costEntry.DocQty))
@@ -1540,27 +1550,29 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
// OvkCostRp: costEntry.OvkCost, // OvkCostRp: costEntry.OvkCost,
DocSuppliers: docSupplierMap[row.KandangID], DocSuppliers: docSupplierMap[row.KandangID],
FeedSuppliers: feedSupplierMap[row.KandangID], FeedSuppliers: feedSupplierMap[row.KandangID],
EggProductionPieces: rowEggPieces, EggProductionPieces: int64(math.Round(eggPiecesFloatRemaining)),
EggProductionKg: eggWeightFloat, EggProductionKg: eggRemainingWeightFloatRemaining,
AverageDocPriceRp: avgDocPrice, // EggProductionTotalWeightKg: eggWeightFloat,
// EggProductionTotalPieces: int64(math.Round(eggTotalPiecesFloat)),
AverageDocPriceRp: avgDocPrice,
// HppRp: hppRp, // HppRp: hppRp,
EggHppRpPerKg: eggHpp, EggHppRpPerKg: eggHpp,
RemainingValueRp: rowRemainingValue, // RemainingValueRp: rowRemainingValue,
EggValueRp: rowEggValue, EggValueRp: rowEggValue,
}) })
totalBirds += rowBirds // totalBirds += rowBirds
totalWeight += weightFloat // totalWeight += weightFloat
totalEggPieces += rowEggPieces totalEggPieces += rowEggPieces
totalEggKg += eggWeightFloat totalEggKg += eggRemainingWeightFloatRemaining
totalRemainingValueRp += rowRemainingValue // totalRemainingValueRp += rowRemainingValue
totalEggValueRp += rowEggValue totalEggValueRp += rowEggValue
totalAvgWeightSum += avgWeight totalAvgWeightSum += avgWeight
totalAvgWeightCount++ totalAvgWeightCount++
if weightFloat > 0 { // if weightFloat > 0 {
totalHppSum += hppRp // totalHppSum += hppRp
totalHppCount++ // totalHppCount++
} // }
if avgDocPrice > 0 { if avgDocPrice > 0 {
totalDocPriceSum += float64(avgDocPrice) totalDocPriceSum += float64(avgDocPrice)
totalDocPriceCount++ totalDocPriceCount++
@@ -1587,8 +1599,8 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
} }
rangeSummary := rangeAgg.Summary rangeSummary := rangeAgg.Summary
rangeAgg.RemainingBirds += rowBirds // rangeAgg.RemainingBirds += rowBirds
rangeAgg.RemainingWeightKg += row.RemainingChickenWeight // rangeAgg.RemainingWeightKg += row.RemainingChickenWeight
rangeAgg.AvgWeightSum += avgWeight rangeAgg.AvgWeightSum += avgWeight
rangeAgg.AvgWeightCount++ rangeAgg.AvgWeightCount++
for _, supplier := range feedSupplierMap[row.KandangID] { for _, supplier := range feedSupplierMap[row.KandangID] {
@@ -1602,8 +1614,8 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
} }
} }
rangeSummary.EggProductionPieces += rowEggPieces rangeSummary.EggProductionPieces += rowEggPieces
rangeSummary.EggProductionKg += eggWeightFloat rangeSummary.EggProductionKg += eggRemainingWeightFloatRemaining
rangeSummary.RemainingValueRp += rowRemainingValue // rangeSummary.RemainingValueRp += rowRemainingValue
rangeSummary.EggValueRp += rowEggValue rangeSummary.EggValueRp += rowEggValue
if eggWeightFloat > 0 { if eggWeightFloat > 0 {
rangeAgg.EggHppSum += eggHpp rangeAgg.EggHppSum += eggHpp
@@ -1750,6 +1762,9 @@ func (s *repportService) parseHppPerKandangQuery(ctx *fiber.Ctx) (*validation.Hp
if err != nil { if err != nil {
return nil, dto.HppPerKandangFiltersDTO{}, fiber.NewError(fiber.StatusBadRequest, err.Error()) return nil, dto.HppPerKandangFiltersDTO{}, fiber.NewError(fiber.StatusBadRequest, err.Error())
} }
if weightMin != nil && weightMax != nil && *weightMin > *weightMax {
return nil, dto.HppPerKandangFiltersDTO{}, fiber.NewError(fiber.StatusBadRequest, "weight_min must be less than or equal to weight_max")
}
params := &validation.HppPerKandangQuery{ params := &validation.HppPerKandangQuery{
Page: page, Page: page,