mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fixing filter product warehouse transfer, cannot take from population
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
fifoV2 "gitlab.com/mbugroup/lti-api.git/internal/common/service/fifo_stock_v2"
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
||||
@@ -22,7 +21,6 @@ import (
|
||||
projectFlockKandangRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
|
||||
rStockLogs "gitlab.com/mbugroup/lti-api.git/internal/modules/shared/repositories"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils/fifo"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -513,18 +511,6 @@ func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferReques
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Stok tidak mencukupi untuk produk %d di gudang asal", product.ProductID))
|
||||
}
|
||||
|
||||
if strings.EqualFold(flagGroupCode, "AYAM") && outUsageQty > 0 {
|
||||
if err := s.allocatePopulationForStockTransferOut(
|
||||
c.Context(),
|
||||
tx,
|
||||
detail,
|
||||
uint(*detail.SourceProductWarehouseID),
|
||||
outUsageQty,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
stockLogDecrease := &entity.StockLog{
|
||||
ProductWarehouseId: uint(*detail.SourceProductWarehouseID),
|
||||
CreatedBy: uint(actorID),
|
||||
@@ -633,57 +619,6 @@ func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferReques
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *transferService) allocatePopulationForStockTransferOut(
|
||||
ctx context.Context,
|
||||
tx *gorm.DB,
|
||||
detail *entity.StockTransferDetail,
|
||||
sourceProductWarehouseID uint,
|
||||
consumeQty float64,
|
||||
) error {
|
||||
if consumeQty <= 0 {
|
||||
return nil
|
||||
}
|
||||
if tx == nil {
|
||||
return errors.New("transaction is required")
|
||||
}
|
||||
if detail == nil || detail.Id == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Data transfer detail tidak valid")
|
||||
}
|
||||
if sourceProductWarehouseID == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Gudang sumber tidak valid")
|
||||
}
|
||||
|
||||
pw, err := s.ProductWarehouseRepo.WithTx(tx).GetByID(ctx, sourceProductWarehouseID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if pw.ProjectFlockKandangId == nil || *pw.ProjectFlockKandangId == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
populations, err := s.ProjectFlockPopulationRepo.WithTx(tx).GetByProjectFlockKandangIDAndProductWarehouseID(
|
||||
ctx,
|
||||
*pw.ProjectFlockKandangId,
|
||||
sourceProductWarehouseID,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(populations) == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Populasi tidak ditemukan untuk transfer")
|
||||
}
|
||||
|
||||
return fifoV2.AllocatePopulationConsumption(
|
||||
ctx,
|
||||
tx,
|
||||
populations,
|
||||
sourceProductWarehouseID,
|
||||
fifo.UsableKeyStockTransferOut.String(),
|
||||
uint(detail.Id),
|
||||
consumeQty,
|
||||
)
|
||||
}
|
||||
|
||||
func (s *transferService) resolveTransferFlagGroup(
|
||||
ctx context.Context,
|
||||
tx *gorm.DB,
|
||||
|
||||
Reference in New Issue
Block a user