feat(BE): add standard_fcr column to production_standard_details and update related services and validations

This commit is contained in:
aguhh18
2025-12-30 10:27:12 +07:00
parent db4e8232b9
commit e4acd9a21e
7 changed files with 35 additions and 10 deletions
@@ -0,0 +1,3 @@
-- Remove standard_fcr column from production_standard_details table
ALTER TABLE production_standard_details
DROP COLUMN IF EXISTS standard_fcr;
@@ -0,0 +1,3 @@
-- Add standard_fcr column to production_standard_details table
ALTER TABLE production_standard_details
ADD COLUMN standard_fcr NUMERIC(15, 3);
+22 -10
View File
@@ -891,14 +891,14 @@ func seedProductWarehouse(tx *gorm.DB, createdBy uint) error {
WarehouseName string
Quantity float64
}{
{ProductName: "DOC Broiler", WarehouseName: "Gudang Priangan", Quantity: 100},
{ProductName: "281 SPECIAL STARTER", WarehouseName: "Gudang Singaparna", Quantity: 200},
{ProductName: "281 SPECIAL STARTER", WarehouseName: "Gudang Banten", Quantity: 300},
{ProductName: "DOC Broiler", WarehouseName: "Gudang Singaparna 1", Quantity: 5000},
{ProductName: "Telur Konsumsi Baik", WarehouseName: "Gudang Singaparna 1", Quantity: 600},
{ProductName: "Telur Pecah", WarehouseName: "Gudang Singaparna 1", Quantity: 80},
{ProductName: "Telur Konsumsi Baik", WarehouseName: "Gudang Cikaum 1", Quantity: 450},
{ProductName: "Telur Pecah", WarehouseName: "Gudang Cikaum 1", Quantity: 60},
{ProductName: "DOC Broiler", WarehouseName: "Gudang Priangan", Quantity: 0},
{ProductName: "281 SPECIAL STARTER", WarehouseName: "Gudang Singaparna", Quantity: 0},
{ProductName: "281 SPECIAL STARTER", WarehouseName: "Gudang Banten", Quantity: 0},
{ProductName: "DOC Broiler", WarehouseName: "Gudang Singaparna 1", Quantity: 0},
{ProductName: "Telur Konsumsi Baik", WarehouseName: "Gudang Singaparna 1", Quantity: 0},
{ProductName: "Telur Pecah", WarehouseName: "Gudang Singaparna 1", Quantity: 0},
{ProductName: "Telur Konsumsi Baik", WarehouseName: "Gudang Cikaum 1", Quantity: 0},
{ProductName: "Telur Pecah", WarehouseName: "Gudang Cikaum 1", Quantity: 0},
}
for _, seed := range seeds {
@@ -962,12 +962,24 @@ func seedTransferStock(tx *gorm.DB) error {
{
StockTransferId: transfer.Id,
ProductId: 1,
Quantity: 10,
SourceProductWarehouseID: func() *uint64 { id := uint64(1); return &id }(),
DestProductWarehouseID: func() *uint64 { id := uint64(2); return &id }(),
UsageQty: 10,
PendingQty: 0,
TotalQty: 10,
TotalUsed: 0,
},
{
StockTransferId: transfer.Id,
ProductId: 2,
Quantity: 5,
SourceProductWarehouseID: func() *uint64 { id := uint64(1); return &id }(),
DestProductWarehouseID: func() *uint64 { id := uint64(2); return &id }(),
UsageQty: 5,
PendingQty: 0,
TotalQty: 5,
TotalUsed: 0,
},
}
for i := range details {
@@ -12,6 +12,7 @@ type ProductionStandardDetail struct {
TargetHenHouseProduction *float64 `gorm:"type:numeric(15,3)"`
TargetEggWeight *float64 `gorm:"type:numeric(15,3)"`
TargetEggMass *float64 `gorm:"type:numeric(15,3)"`
StandardFCR *float64 `gorm:"type:numeric(15,3)"`
CreatedAt time.Time `gorm:"type:timestamptz;not null"`
UpdatedAt time.Time `gorm:"type:timestamptz;not null"`
@@ -33,6 +33,7 @@ type EggProductionStandardDetailDTO struct {
TargetHenHouseProduction *float64 `json:"target_hen_house_production"`
TargetEggWeight *float64 `json:"target_egg_weight"`
TargetEggMass *float64 `json:"target_egg_mass"`
StandardFCR *float64 `json:"standard_fcr"`
}
type WeeklyProductionStandardDTO struct {
@@ -87,6 +88,7 @@ func ToWeeklyProductionStandardDTOWithDetails(growth entity.StandardGrowthDetail
TargetHenHouseProduction: detail.TargetHenHouseProduction,
TargetEggWeight: detail.TargetEggWeight,
TargetEggMass: detail.TargetEggMass,
StandardFCR: detail.StandardFCR,
}
return WeeklyProductionStandardDTO{
@@ -140,6 +142,7 @@ func ToEggProductionStandardDetailDTO(e entity.ProductionStandardDetail) EggProd
TargetHenHouseProduction: e.TargetHenHouseProduction,
TargetEggWeight: e.TargetEggWeight,
TargetEggMass: e.TargetEggMass,
StandardFCR: e.StandardFCR,
}
}
@@ -142,6 +142,7 @@ func (s *productionStandardService) CreateOne(c *fiber.Ctx, req *validation.Crea
TargetHenHouseProduction: detailReq.ProductionStandardDetails.TargetHenHouseProduction,
TargetEggWeight: detailReq.ProductionStandardDetails.TargetEggWeight,
TargetEggMass: detailReq.ProductionStandardDetails.TargetEggMass,
StandardFCR: detailReq.ProductionStandardDetails.StandardFCR,
}
if err := productionStandardDetailRepoTx.CreateOne(c.Context(), productionStandardDetail, nil); err != nil {
@@ -255,6 +256,7 @@ func (s productionStandardService) UpdateOne(c *fiber.Ctx, req *validation.Updat
TargetHenHouseProduction: detailReq.ProductionStandardDetails.TargetHenHouseProduction,
TargetEggWeight: detailReq.ProductionStandardDetails.TargetEggWeight,
TargetEggMass: detailReq.ProductionStandardDetails.TargetEggMass,
StandardFCR: detailReq.ProductionStandardDetails.StandardFCR,
}
if err := productionStandardDetailRepoTx.CreateOne(c.Context(), productionStandardDetail, nil); err != nil {
@@ -5,6 +5,7 @@ type ProductionStandardDetailItem struct {
TargetHenHouseProduction *float64 `json:"target_hen_house_production" validate:"omitempty,gte=0"`
TargetEggWeight *float64 `json:"target_egg_weight" validate:"omitempty,gte=0"`
TargetEggMass *float64 `json:"target_egg_mass" validate:"omitempty,gte=0"`
StandardFCR *float64 `json:"standard_fcr" validate:"omitempty,gte=0"`
}
type StandardGrowthDetailItem struct {