mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
Merge branch 'fix/LSS390' into 'development'
[FIX][BE]: LSS390 See merge request mbugroup/lti-api!208
This commit is contained in:
@@ -1426,15 +1426,17 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
}
|
||||
for pfkID, egg := range eggMap {
|
||||
if rowIdx, ok := pfkIndex[pfkID]; ok {
|
||||
repoRows[rowIdx].EggProductionWeightKg = egg.EggProductionWeightKg
|
||||
repoRows[rowIdx].EggProductionPieces = egg.EggProductionPieces
|
||||
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))
|
||||
for _, row := range costRows {
|
||||
costMap[row.KandangID] = HppCostAggregate{
|
||||
costMap[row.ProjectFlockKandangID] = HppCostAggregate{
|
||||
FeedCost: row.FeedCost,
|
||||
OvkCost: row.OvkCost,
|
||||
DocCost: row.DocCost,
|
||||
@@ -1463,15 +1465,15 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
category = "DOC"
|
||||
}
|
||||
|
||||
if seen[sup.KandangID] == nil {
|
||||
seen[sup.KandangID] = make(map[uint]bool)
|
||||
if seen[sup.ProjectFlockKandangID] == nil {
|
||||
seen[sup.ProjectFlockKandangID] = make(map[uint]bool)
|
||||
}
|
||||
if seen[sup.KandangID][sup.SupplierID] {
|
||||
if seen[sup.ProjectFlockKandangID][sup.SupplierID] {
|
||||
continue
|
||||
}
|
||||
seen[sup.KandangID][sup.SupplierID] = true
|
||||
seen[sup.ProjectFlockKandangID][sup.SupplierID] = true
|
||||
|
||||
targetMap[sup.KandangID] = append(targetMap[sup.KandangID], dto.HppPerKandangSupplierDTO{
|
||||
targetMap[sup.ProjectFlockKandangID] = append(targetMap[sup.ProjectFlockKandangID], dto.HppPerKandangSupplierDTO{
|
||||
ID: int64(sup.SupplierID),
|
||||
Name: sup.SupplierName,
|
||||
Alias: sup.SupplierAlias,
|
||||
@@ -1498,12 +1500,12 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
dataRows := make([]dto.HppPerKandangRowDTO, 0, len(repoRows))
|
||||
perRangeMap := make(map[weightRangeKey]*weightRangeAggregate)
|
||||
var totalBirds int64
|
||||
var totalWeight float64
|
||||
// var totalWeight float64
|
||||
var totalEggPieces int64
|
||||
var totalEggKg float64
|
||||
var totalRemainingValueRp int64
|
||||
// var totalRemainingValueRp int64
|
||||
var totalEggValueRp int64
|
||||
var totalHppSum float64
|
||||
// var totalHppSum float64
|
||||
var totalHppCount int
|
||||
var totalDocPriceSum float64
|
||||
var totalDocPriceCount int
|
||||
@@ -1517,26 +1519,34 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
continue
|
||||
}
|
||||
|
||||
birdsFloat := row.RemainingChickenBirds
|
||||
if math.IsNaN(birdsFloat) || math.IsInf(birdsFloat, 0) {
|
||||
birdsFloat = 0
|
||||
// birdsFloat := row.RemainingChickenBirds
|
||||
// if math.IsNaN(birdsFloat) || math.IsInf(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
|
||||
if math.IsNaN(weightFloat) || math.IsInf(weightFloat, 0) {
|
||||
weightFloat = 0
|
||||
eggTotalPiecesFloat := row.EggProductionTotalPieces
|
||||
if math.IsNaN(eggTotalPiecesFloat) || math.IsInf(eggTotalPiecesFloat, 0) {
|
||||
eggTotalPiecesFloat = 0
|
||||
}
|
||||
eggPiecesFloat := row.EggProductionPieces
|
||||
if math.IsNaN(eggPiecesFloat) || math.IsInf(eggPiecesFloat, 0) {
|
||||
eggPiecesFloat = 0
|
||||
eggRemainingWeightFloatRemaining := row.EggProductionWeightKgRemaining
|
||||
if math.IsNaN(eggRemainingWeightFloatRemaining) || math.IsInf(eggRemainingWeightFloatRemaining, 0) {
|
||||
eggRemainingWeightFloatRemaining = 0
|
||||
}
|
||||
eggWeightFloat := row.EggProductionWeightKg
|
||||
eggWeightFloat := row.EggProductionTotalWeightKg
|
||||
if math.IsNaN(eggWeightFloat) || math.IsInf(eggWeightFloat, 0) {
|
||||
eggWeightFloat = 0
|
||||
}
|
||||
|
||||
avgWeight := 0.0
|
||||
if eggPiecesFloat > 0 {
|
||||
avgWeight = eggWeightFloat / eggPiecesFloat
|
||||
if eggTotalPiecesFloat > 0 {
|
||||
avgWeight = eggWeightFloat / eggTotalPiecesFloat
|
||||
}
|
||||
if params.WeightMin != nil && avgWeight < *params.WeightMin {
|
||||
continue
|
||||
@@ -1552,28 +1562,30 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
weightMax := weightMin + 0.09
|
||||
rangeKey := weightRangeKey{Min: weightMin, Max: weightMax}
|
||||
|
||||
rowBirds := int64(math.Round(birdsFloat))
|
||||
costEntry := costMap[row.KandangID]
|
||||
// rowBirds := int64(math.Round(birdsFloat))
|
||||
costEntry := costMap[row.ProjectFlockKandangID]
|
||||
totalCost := costEntry.FeedCost + costEntry.OvkCost + costEntry.DocCost + costEntry.BudgetCost + costEntry.ExpenseCost
|
||||
hppRp := 0.0
|
||||
if weightFloat > 0 {
|
||||
hppRp = totalCost / weightFloat
|
||||
}
|
||||
// hppRp := 0.0
|
||||
// if weightFloat > 0 {
|
||||
// hppRp = totalCost / weightFloat
|
||||
// }
|
||||
eggHpp := 0.0
|
||||
if eggWeightFloat > 0 {
|
||||
eggHpp = totalCost / eggWeightFloat
|
||||
eggHpp = (totalCost / eggWeightFloat) / 1000
|
||||
}
|
||||
|
||||
rowEggPieces := int64(math.Round(eggPiecesFloat))
|
||||
rowEggValue := int64(eggHpp * eggWeightFloat)
|
||||
rowRemainingValue := int64(hppRp * weightFloat)
|
||||
rowEggPieces := int64(math.Round(eggPiecesFloatRemaining))
|
||||
rowEggValue := int64(eggHpp * eggRemainingWeightFloatRemaining)
|
||||
// rowRemainingValue := int64(hppRp * weightFloat)
|
||||
avgDocPrice := int64(0)
|
||||
if costEntry.DocQty > 0 {
|
||||
avgDocPrice = int64(math.Round(costEntry.DocCost / costEntry.DocQty))
|
||||
}
|
||||
|
||||
nameWithPeriod := fmt.Sprintf("%s Period %d", row.KandangName, row.ProjectFlockPeriod)
|
||||
|
||||
dataRows = append(dataRows, dto.HppPerKandangRowDTO{
|
||||
ID: int(row.KandangID),
|
||||
ID: int(row.ProjectFlockKandangID),
|
||||
Kandang: dto.HppPerKandangRowKandangDTO{
|
||||
ID: int64(row.KandangID),
|
||||
Name: row.KandangName,
|
||||
@@ -1591,32 +1603,35 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
WeightMin: weightMin,
|
||||
WeightMax: weightMax,
|
||||
},
|
||||
AvgWeightKg: avgWeight,
|
||||
AvgWeightKg: avgWeight,
|
||||
NameWithPeriode: nameWithPeriod,
|
||||
// FeedCostRp: costEntry.FeedCost,
|
||||
// OvkCostRp: costEntry.OvkCost,
|
||||
DocSuppliers: docSupplierMap[row.KandangID],
|
||||
FeedSuppliers: feedSupplierMap[row.KandangID],
|
||||
EggProductionPieces: rowEggPieces,
|
||||
EggProductionKg: eggWeightFloat,
|
||||
AverageDocPriceRp: avgDocPrice,
|
||||
DocSuppliers: docSupplierMap[row.ProjectFlockKandangID],
|
||||
FeedSuppliers: feedSupplierMap[row.ProjectFlockKandangID],
|
||||
EggProductionPieces: int64(math.Round(eggPiecesFloatRemaining)),
|
||||
EggProductionKg: eggRemainingWeightFloatRemaining,
|
||||
// EggProductionTotalWeightKg: eggWeightFloat,
|
||||
// EggProductionTotalPieces: int64(math.Round(eggTotalPiecesFloat)),
|
||||
AverageDocPriceRp: avgDocPrice,
|
||||
// HppRp: hppRp,
|
||||
EggHppRpPerKg: eggHpp,
|
||||
RemainingValueRp: rowRemainingValue,
|
||||
EggValueRp: rowEggValue,
|
||||
EggHppRpPerKg: eggHpp,
|
||||
// RemainingValueRp: rowRemainingValue,
|
||||
EggValueRp: rowEggValue,
|
||||
})
|
||||
|
||||
totalBirds += rowBirds
|
||||
totalWeight += weightFloat
|
||||
// totalBirds += rowBirds
|
||||
// totalWeight += weightFloat
|
||||
totalEggPieces += rowEggPieces
|
||||
totalEggKg += eggWeightFloat
|
||||
totalRemainingValueRp += rowRemainingValue
|
||||
totalEggKg += eggRemainingWeightFloatRemaining
|
||||
// totalRemainingValueRp += rowRemainingValue
|
||||
totalEggValueRp += rowEggValue
|
||||
totalAvgWeightSum += avgWeight
|
||||
totalAvgWeightCount++
|
||||
if weightFloat > 0 {
|
||||
totalHppSum += hppRp
|
||||
totalHppCount++
|
||||
}
|
||||
// if weightFloat > 0 {
|
||||
// totalHppSum += hppRp
|
||||
// totalHppCount++
|
||||
// }
|
||||
if avgDocPrice > 0 {
|
||||
totalDocPriceSum += float64(avgDocPrice)
|
||||
totalDocPriceCount++
|
||||
@@ -1643,23 +1658,23 @@ func (s *repportService) GetHppPerKandang(ctx *fiber.Ctx) (*dto.HppPerKandangRes
|
||||
}
|
||||
|
||||
rangeSummary := rangeAgg.Summary
|
||||
rangeAgg.RemainingBirds += rowBirds
|
||||
rangeAgg.RemainingWeightKg += row.RemainingChickenWeight
|
||||
// rangeAgg.RemainingBirds += rowBirds
|
||||
// rangeAgg.RemainingWeightKg += row.RemainingChickenWeight
|
||||
rangeAgg.AvgWeightSum += avgWeight
|
||||
rangeAgg.AvgWeightCount++
|
||||
for _, supplier := range feedSupplierMap[row.KandangID] {
|
||||
for _, supplier := range feedSupplierMap[row.ProjectFlockKandangID] {
|
||||
if _, ok := rangeAgg.FeedSuppliers[supplier.ID]; !ok {
|
||||
rangeAgg.FeedSuppliers[supplier.ID] = supplier
|
||||
}
|
||||
}
|
||||
for _, supplier := range docSupplierMap[row.KandangID] {
|
||||
for _, supplier := range docSupplierMap[row.ProjectFlockKandangID] {
|
||||
if _, ok := rangeAgg.DocSuppliers[supplier.ID]; !ok {
|
||||
rangeAgg.DocSuppliers[supplier.ID] = supplier
|
||||
}
|
||||
}
|
||||
rangeSummary.EggProductionPieces += rowEggPieces
|
||||
rangeSummary.EggProductionKg += eggWeightFloat
|
||||
rangeSummary.RemainingValueRp += rowRemainingValue
|
||||
rangeSummary.EggProductionKg += eggRemainingWeightFloatRemaining
|
||||
// rangeSummary.RemainingValueRp += rowRemainingValue
|
||||
rangeSummary.EggValueRp += rowEggValue
|
||||
if eggWeightFloat > 0 {
|
||||
rangeAgg.EggHppSum += eggHpp
|
||||
@@ -1806,6 +1821,9 @@ func (s *repportService) parseHppPerKandangQuery(ctx *fiber.Ctx) (*validation.Hp
|
||||
if err != nil {
|
||||
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{
|
||||
Page: page,
|
||||
|
||||
Reference in New Issue
Block a user