Fix adjusment stock chickin, transfer to laying and chickin

This commit is contained in:
ragilap
2026-03-08 23:31:04 +07:00
parent fca96df3d9
commit 45cc057dd4
23 changed files with 1905 additions and 525 deletions
@@ -208,6 +208,28 @@ func (u *TransferLayingController) Execute(c *fiber.Ctx) error {
})
}
func (u *TransferLayingController) Unexecute(c *fiber.Ctx) error {
param := c.Params("id")
id, err := strconv.Atoi(param)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, "Invalid Id")
}
result, err := u.TransferLayingService.Unexecute(c, uint(id))
if err != nil {
return err
}
return c.Status(fiber.StatusOK).
JSON(response.Success{
Code: fiber.StatusOK,
Status: "success",
Message: "Unexecute transfer laying successfully",
Data: dto.ToTransferLayingDetailDTOWithSingleApproval(*result, result.LatestApproval),
})
}
func (u *TransferLayingController) GetAvailableQtyPerKandang(c *fiber.Ctx) error {
projectFlockID, err := strconv.ParseUint(c.Params("project_flock_id"), 10, 32)
if err != nil {
@@ -152,6 +152,46 @@ func ToLayingTransferSourceDTOs(sources []entity.LayingTransferSource) []LayingT
return result
}
func toLayingTransferSourceDTOsFromTransfer(e entity.LayingTransfer) []LayingTransferSourceDTO {
if len(e.Sources) > 0 {
return ToLayingTransferSourceDTOs(e.Sources)
}
if e.SourceProjectFlockKandangId == nil || *e.SourceProjectFlockKandangId == 0 {
return []LayingTransferSourceDTO{}
}
displayQty := e.SourceRequestedQty
if e.SourceUsageQty > 0 {
displayQty = e.SourceUsageQty
}
pfkDTO := &ProjectFlockKandangWithKandangDTO{
Id: *e.SourceProjectFlockKandangId,
}
if e.SourceProjectFlockKandang != nil && e.SourceProjectFlockKandang.Id != 0 {
pfkDTO.KandangId = e.SourceProjectFlockKandang.KandangId
pfkDTO.ProjectFlockId = e.SourceProjectFlockKandang.ProjectFlockId
if e.SourceProjectFlockKandang.Kandang.Id != 0 {
kandangMapped := kandangDTO.ToKandangRelationDTO(e.SourceProjectFlockKandang.Kandang)
pfkDTO.Kandang = &kandangMapped
}
}
var pwDTO *productWarehouseDTO.ProductWarehouseRelationDTO
if e.SourceProductWarehouse != nil && e.SourceProductWarehouse.Id != 0 {
mapped := productWarehouseDTO.ToProductWarehouseRelationDTO(*e.SourceProductWarehouse)
pwDTO = &mapped
}
return []LayingTransferSourceDTO{
{
SourceProjectFlockKandang: pfkDTO,
Qty: displayQty,
ProductWarehouse: pwDTO,
},
}
}
func ToLayingTransferTargetDTO(target entity.LayingTransferTarget) LayingTransferTargetDTO {
var pfkDTO *ProjectFlockKandangWithKandangDTO
if target.TargetProjectFlockKandang != nil && target.TargetProjectFlockKandang.Id != 0 {
@@ -256,7 +296,7 @@ func ToTransferLayingDetailDTO(e entity.LayingTransfer, approvals []entity.Appro
return TransferLayingDetailDTO{
TransferLayingListDTO: ToTransferLayingListDTO(e),
Sources: ToLayingTransferSourceDTOs(e.Sources),
Sources: toLayingTransferSourceDTOsFromTransfer(e),
Targets: ToLayingTransferTargetDTOs(e.Targets),
Approval: latestApproval,
}
@@ -278,7 +318,7 @@ func ToTransferLayingDetailDTOWithSingleApproval(e entity.LayingTransfer, approv
return TransferLayingDetailDTO{
TransferLayingListDTO: ToTransferLayingListDTO(e),
Sources: ToLayingTransferSourceDTOs(e.Sources),
Sources: toLayingTransferSourceDTOsFromTransfer(e),
Targets: ToLayingTransferTargetDTOs(e.Targets),
Approval: mappedApproval,
}
@@ -10,11 +10,11 @@ import (
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
"gitlab.com/mbugroup/lti-api.git/internal/utils/fifo"
rProjectFlock "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
rTransferLaying "gitlab.com/mbugroup/lti-api.git/internal/modules/production/transfer_layings/repositories"
sTransferLaying "gitlab.com/mbugroup/lti-api.git/internal/modules/production/transfer_layings/services"
"gitlab.com/mbugroup/lti-api.git/internal/utils"
"gitlab.com/mbugroup/lti-api.git/internal/utils/fifo"
rInventory "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
@@ -60,12 +60,12 @@ func (TransferLayingModule) RegisterRoutes(router fiber.Router, db *gorm.DB, val
// daftarin jadi usable
if err := fifoService.RegisterUsable(fifo.UsableConfig{
Key: fifo.UsableKeyTransferToLayingOut,
Table: "laying_transfer_sources",
Table: "laying_transfers",
Columns: fifo.UsableColumns{
ID: "id",
ProductWarehouseID: "product_warehouse_id",
UsageQuantity: "usage_qty",
PendingQuantity: "pending_usage_qty",
ProductWarehouseID: "source_product_warehouse_id",
UsageQuantity: "source_usage_qty",
PendingQuantity: "source_pending_usage_qty",
CreatedAt: "created_at",
},
OrderBy: []string{"created_at ASC", "id ASC"},
@@ -166,6 +166,9 @@ func (r *TransferLayingRepositoryImpl) GetAllWithFilters(ctx context.Context, of
q = q.Offset(offset).Limit(limit).
Preload("FromProjectFlock").
Preload("ToProjectFlock").
Preload("SourceProjectFlockKandang").
Preload("SourceProjectFlockKandang.Kandang").
Preload("SourceProductWarehouse").
Preload("CreatedUser").
Preload("ExecutedUser").
Preload("Sources").
@@ -193,11 +196,12 @@ func (r *TransferLayingRepositoryImpl) GetLatestApprovedBySourceKandang(ctx cont
var transfer entity.LayingTransfer
err := r.db.WithContext(ctx).
Model(&entity.LayingTransfer{}).
Joins("JOIN laying_transfer_sources lts ON lts.laying_transfer_id = laying_transfers.id AND lts.deleted_at IS NULL").
Where("lts.source_project_flock_kandang_id = ?", sourceProjectFlockKandangID).
Distinct("laying_transfers.*").
Joins("LEFT JOIN laying_transfer_sources lts ON lts.laying_transfer_id = laying_transfers.id AND lts.deleted_at IS NULL").
Where("(laying_transfers.source_project_flock_kandang_id = ? OR lts.source_project_flock_kandang_id = ?)", sourceProjectFlockKandangID, sourceProjectFlockKandangID).
Where("laying_transfers.deleted_at IS NULL").
Where(`(
SELECT a.action
SELECT a.action
FROM approvals a
WHERE a.approvable_type = ?
AND a.approvable_id = laying_transfers.id
@@ -28,6 +28,7 @@ func TransferLayingRoutes(v1 fiber.Router, u user.UserService, s transferLaying.
route.Delete("/:id", m.RequirePermissions(m.P_TransferToLaying_DeleteOne), ctrl.DeleteOne)
route.Post("/approvals", m.RequirePermissions(m.P_TransferToLaying_Approval), ctrl.Approval)
route.Post("/:id/execute", m.RequirePermissions(m.P_TransferToLaying_Approval), ctrl.Execute)
route.Post("/:id/unexecute", m.RequirePermissions(m.P_TransferToLaying_Approval), ctrl.Unexecute)
route.Get("/project-flocks/:project_flock_id/available-qty", m.RequirePermissions(m.P_TransferToLaying_GetAvailableQty), ctrl.GetAvailableQtyPerKandang)
route.Get("/project-flocks/:project_flock_id/max-target-qty", m.RequirePermissions(m.P_TransferToLaying_CreateOne), ctrl.GetMaxTargetQtyPerKandang)
}
File diff suppressed because it is too large Load Diff
@@ -14,7 +14,7 @@ type Create struct {
TransferDate string `json:"transfer_date" validate:"required,datetime=2006-01-02"`
SourceProjectFlockId uint `json:"source_project_flock_id" validate:"required"`
TargetProjectFlockId uint `json:"target_project_flock_id" validate:"required"`
SourceKandangs []SourceKandangDetail `json:"source_kandangs" validate:"required,min=1,dive,required"`
SourceKandangs []SourceKandangDetail `json:"source_kandangs" validate:"required,min=1,max=1,dive,required"`
TargetKandangs []TargetKandangDetail `json:"target_kandangs" validate:"required,min=1,dive,required"`
Reason string `json:"reason" validate:"omitempty,max=1000"`
}
@@ -23,7 +23,7 @@ type Update struct {
TransferDate string `json:"transfer_date" validate:"required,datetime=2006-01-02"`
SourceProjectFlockId uint `json:"source_project_flock_id" validate:"required"`
TargetProjectFlockId uint `json:"target_project_flock_id" validate:"required"`
SourceKandangs []SourceKandangDetail `json:"source_kandangs" validate:"required,min=1,dive,required"`
SourceKandangs []SourceKandangDetail `json:"source_kandangs" validate:"required,min=1,max=1,dive,required"`
TargetKandangs []TargetKandangDetail `json:"target_kandangs" validate:"required,min=1,dive,required"`
Reason string `json:"reason" validate:"omitempty,max=1000"`
}