mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'dev/gio' into 'feat/BE/Sprint-7'
adjust age closing data produksi See merge request mbugroup/lti-api!103
This commit is contained in:
@@ -204,3 +204,20 @@ func ToClosingDetailDTO(e entity.ProjectFlock) ClosingDetailDTO {
|
|||||||
ClosingListDTO: ToClosingListDTO(e),
|
ClosingListDTO: ToClosingListDTO(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CalculateAgeFromChickinDataProduksi(projectFlockKandang *entity.ProjectFlockKandang, deliveryDate *time.Time) int {
|
||||||
|
if projectFlockKandang == nil || deliveryDate == nil || len(projectFlockKandang.Chickins) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
earliestChickinDate := projectFlockKandang.Chickins[0].ChickInDate
|
||||||
|
for _, chickin := range projectFlockKandang.Chickins {
|
||||||
|
if chickin.ChickInDate.Before(earliestChickinDate) {
|
||||||
|
earliestChickinDate = chickin.ChickInDate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ageInDays := int(deliveryDate.Sub(earliestChickinDate).Hours() / 24)
|
||||||
|
ageInWeeks := ageInDays / 7
|
||||||
|
return ageInWeeks
|
||||||
|
}
|
||||||
|
|||||||
@@ -561,8 +561,11 @@ func (s closingService) GetClosingDataProduksi(c *fiber.Ctx, projectFlockID uint
|
|||||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch FCR standard data")
|
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch FCR standard data")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// masih dummy, karena tab penjualan agenya masih dummy
|
age, err := s.calculateAverageSalesAge(c.Context(), projectFlockID)
|
||||||
age := 1.0
|
if err != nil {
|
||||||
|
s.Log.Errorf("Failed to calculate sales age for project flock %d: %+v", projectFlockID, err)
|
||||||
|
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch sales age data")
|
||||||
|
}
|
||||||
|
|
||||||
feedUsedPerHead := 0.0
|
feedUsedPerHead := 0.0
|
||||||
if population > 0 {
|
if population > 0 {
|
||||||
@@ -691,6 +694,40 @@ func (s closingService) GetClosingDataProduksi(c *fiber.Ctx, projectFlockID uint
|
|||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s closingService) calculateAverageSalesAge(ctx context.Context, projectFlockID uint) (float64, error) {
|
||||||
|
deliveryProducts, err := s.MarketingDeliveryProductRepo.GetDeliveryProductsByProjectFlockID(ctx, projectFlockID, func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.
|
||||||
|
Preload("MarketingProduct").
|
||||||
|
Preload("MarketingProduct.ProductWarehouse").
|
||||||
|
Preload("MarketingProduct.ProductWarehouse.ProjectFlockKandang").
|
||||||
|
Preload("MarketingProduct.ProductWarehouse.ProjectFlockKandang.Chickins")
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
totalQty float64
|
||||||
|
totalAgeWeeks float64
|
||||||
|
)
|
||||||
|
|
||||||
|
for _, product := range deliveryProducts {
|
||||||
|
if product.Qty == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
projectFlockKandang := product.MarketingProduct.ProductWarehouse.ProjectFlockKandang
|
||||||
|
ageWeeks := dto.CalculateAgeFromChickinDataProduksi(projectFlockKandang, product.DeliveryDate)
|
||||||
|
totalAgeWeeks += float64(ageWeeks) * product.Qty
|
||||||
|
totalQty += product.Qty
|
||||||
|
}
|
||||||
|
|
||||||
|
if totalQty == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalAgeWeeks / totalQty, nil
|
||||||
|
}
|
||||||
|
|
||||||
func calculatePerformanceMetrics(averageWeight, totalWeight, feedUsed, basePopulation, depletion, age float64, standards []entity.FcrStandard) dto.ClosingPerformanceDTO {
|
func calculatePerformanceMetrics(averageWeight, totalWeight, feedUsed, basePopulation, depletion, age float64, standards []entity.FcrStandard) dto.ClosingPerformanceDTO {
|
||||||
mortalityStd, fcrStd := closestFcrValues(standards, averageWeight)
|
mortalityStd, fcrStd := closestFcrValues(standards, averageWeight)
|
||||||
|
|
||||||
@@ -704,8 +741,8 @@ func calculatePerformanceMetrics(averageWeight, totalWeight, feedUsed, basePopul
|
|||||||
mortalityAct = (depletion / basePopulation) * 100
|
mortalityAct = (depletion / basePopulation) * 100
|
||||||
}
|
}
|
||||||
|
|
||||||
deffMortality := mortalityStd - mortalityAct
|
deffMortality := mortalityAct - mortalityStd
|
||||||
deffFcr := fcrStd - fcrAct
|
deffFcr := fcrAct - fcrStd
|
||||||
|
|
||||||
awg := 0.0
|
awg := 0.0
|
||||||
if age > 0 {
|
if age > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user