mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +00:00
[FEAT/BE] wiring recording,transfer_stock,transfer_laying,marketing for consumer chick in project flock population
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
fifoV2 "gitlab.com/mbugroup/lti-api.git/internal/common/service/fifo_stock_v2"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/config"
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
@@ -1005,6 +1006,9 @@ func (s *transferLayingService) executeApprovedTransferMovement(
|
||||
}
|
||||
|
||||
movedQty := usageDelta
|
||||
if err := s.allocatePopulationForTransfer(ctx, tx, source, movedQty); err != nil {
|
||||
return err
|
||||
}
|
||||
targetShares := distributeProportionalWithRounding(targets, totalTargetQty, movedQty)
|
||||
for i, target := range targets {
|
||||
roundedQty := math.Round(targetShares[i])
|
||||
@@ -1104,6 +1108,45 @@ func (s *transferLayingService) executeApprovedTransferMovement(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *transferLayingService) allocatePopulationForTransfer(
|
||||
ctx context.Context,
|
||||
tx *gorm.DB,
|
||||
source entity.LayingTransferSource,
|
||||
consumeQty float64,
|
||||
) error {
|
||||
if consumeQty <= 0 {
|
||||
return nil
|
||||
}
|
||||
if tx == nil {
|
||||
return errors.New("transaction is required")
|
||||
}
|
||||
if source.SourceProjectFlockKandangId == 0 || source.ProductWarehouseId == nil || *source.ProductWarehouseId == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Project flock kandang sumber atau product warehouse tidak valid")
|
||||
}
|
||||
|
||||
populations, err := s.ProjectFlockPopulationRepo.GetByProjectFlockKandangIDAndProductWarehouseID(
|
||||
ctx,
|
||||
source.SourceProjectFlockKandangId,
|
||||
*source.ProductWarehouseId,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(populations) == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Populasi tidak ditemukan untuk transfer laying")
|
||||
}
|
||||
|
||||
return fifoV2.AllocatePopulationConsumption(
|
||||
ctx,
|
||||
tx,
|
||||
populations,
|
||||
*source.ProductWarehouseId,
|
||||
fifo.UsableKeyTransferToLayingOut.String(),
|
||||
source.Id,
|
||||
consumeQty,
|
||||
)
|
||||
}
|
||||
|
||||
func (s *transferLayingService) calculateEffectiveMoveDate(ctx context.Context, sources []entity.LayingTransferSource) (time.Time, error) {
|
||||
if len(sources) == 0 {
|
||||
return time.Time{}, fiber.NewError(fiber.StatusBadRequest, "Sumber transfer laying tidak ditemukan")
|
||||
|
||||
Reference in New Issue
Block a user