FIX[BE]: fixing bug transfer to laying, delet biaya, nominal expesen e, chickin

This commit is contained in:
aguhh18
2026-01-07 09:27:39 +07:00
parent a08466a28e
commit 0a84e427c1
21 changed files with 432 additions and 126 deletions
@@ -552,6 +552,7 @@ func (s projectFlockKandangService) Closing(c *fiber.Ctx, id uint, req *validati
}
func (s projectFlockKandangService) calculateAvailableQuantityForProductWarehouse(c *fiber.Ctx, projectFlockKandang *entity.ProjectFlockKandang, productWarehouse *entity.ProductWarehouse) (float64, error) {
availableQty := productWarehouse.Quantity
if projectFlockKandang.ProjectFlock.Category == string(utils.ProjectFlockCategoryGrowing) {
@@ -564,7 +565,17 @@ func (s projectFlockKandangService) calculateAvailableQuantityForProductWarehous
}
}
availableQty = productWarehouse.Quantity - totalPendingQty
totalPopulationQty := 0.0
if s.PopulationRepo != nil {
popQty, err := s.PopulationRepo.GetTotalQtyByProductWarehouseID(c.Context(), productWarehouse.Id)
if err != nil {
s.Log.Errorf("Failed to get population qty for PW %d: %+v", productWarehouse.Id, err)
} else {
totalPopulationQty = popQty
}
}
availableQty = productWarehouse.Quantity - totalPendingQty - totalPopulationQty
if availableQty < 0 {
availableQty = 0
}
@@ -578,7 +589,17 @@ func (s projectFlockKandangService) calculateAvailableQuantityForProductWarehous
}
}
availableQty = productWarehouse.Quantity - totalPendingQty
totalPopulationQty := 0.0
if s.PopulationRepo != nil {
popQty, err := s.PopulationRepo.GetTotalQtyByProductWarehouseID(c.Context(), productWarehouse.Id)
if err != nil {
s.Log.Errorf("Failed to get population qty for PW %d: %+v", productWarehouse.Id, err)
} else {
totalPopulationQty = popQty
}
}
availableQty = productWarehouse.Quantity - totalPendingQty - totalPopulationQty
if availableQty < 0 {
availableQty = 0
}