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
@@ -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,
}