mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'fix/closing-sapronak-data-produksi' into 'development'
[FIX][BE]: api closing sapronak and data produksi See merge request mbugroup/lti-api!197
This commit is contained in:
@@ -111,13 +111,13 @@ type ClosingPerformanceDTO struct {
|
|||||||
FeedIntake float64 `json:"feed_intake"`
|
FeedIntake float64 `json:"feed_intake"`
|
||||||
FeedIntakeStd float64 `json:"feed_intake_std"`
|
FeedIntakeStd float64 `json:"feed_intake_std"`
|
||||||
HenDayAct *float64 `json:"hen_day_act,omitempty"`
|
HenDayAct *float64 `json:"hen_day_act,omitempty"`
|
||||||
HendayStd *float64 `json:"hen_day_std,omitempty"`
|
HendayStd float64 `json:"hen_day_std"`
|
||||||
EggMass *float64 `json:"egg_mass,omitempty"`
|
EggMass *float64 `json:"egg_mass,omitempty"`
|
||||||
EggMassStd *float64 `json:"egg_mass_std,omitempty"`
|
EggMassStd float64 `json:"egg_mass_std"`
|
||||||
EggWeight *float64 `json:"egg_weight,omitempty"`
|
EggWeight *float64 `json:"egg_weight,omitempty"`
|
||||||
EggWeightStd *float64 `json:"egg_weight_std,omitempty"`
|
EggWeightStd float64 `json:"egg_weight_std"`
|
||||||
HenHouseAct *float64 `json:"hen_housed_act,omitempty"`
|
HenHouseAct *float64 `json:"hen_housed_act,omitempty"`
|
||||||
HenHouseStd *float64 `json:"hen_housed_std,omitempty"`
|
HenHouseStd float64 `json:"hen_housed_std"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClosingSalesGroupDTO struct {
|
type ClosingSalesGroupDTO struct {
|
||||||
|
|||||||
@@ -473,8 +473,8 @@ SELECT
|
|||||||
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
|
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
|
||||||
), '') AS product_sub_category,
|
), '') AS product_sub_category,
|
||||||
COALESCE(fw.name, '') AS source_warehouse,
|
COALESCE(fw.name, '') AS source_warehouse,
|
||||||
'' AS destination_warehouse,
|
COALESCE(tw.name, '') AS destination_warehouse,
|
||||||
COALESCE(tw.name, '') AS destination,
|
'' AS destination,
|
||||||
std.usage_qty AS quantity,
|
std.usage_qty AS quantity,
|
||||||
u.name AS unit,
|
u.name AS unit,
|
||||||
'Transfer to other unit' AS notes
|
'Transfer to other unit' AS notes
|
||||||
@@ -522,8 +522,8 @@ SELECT
|
|||||||
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
|
WHERE f.flagable_type = 'products' AND f.flagable_id = prod.id
|
||||||
), '') AS product_sub_category,
|
), '') AS product_sub_category,
|
||||||
w.name AS source_warehouse,
|
w.name AS source_warehouse,
|
||||||
'' AS destination_warehouse,
|
'RETAIL CUSTOMER' AS destination_warehouse,
|
||||||
'RETAIL CUSTOMER' AS destination,
|
'' AS destination,
|
||||||
mp.qty AS quantity,
|
mp.qty AS quantity,
|
||||||
u.name AS unit,
|
u.name AS unit,
|
||||||
m.notes AS notes
|
m.notes AS notes
|
||||||
|
|||||||
@@ -337,8 +337,10 @@ func (s closingService) GetClosingSapronak(c *fiber.Ctx, projectFlockID uint, pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
var projectFlockKandangIDs []uint
|
var projectFlockKandangIDs []uint
|
||||||
if params.Type == validation.SapronakTypeOutgoing {
|
if params.KandangID != nil && *params.KandangID > 0 {
|
||||||
projectFlockKandangIDs, err = s.getProjectFlockKandangIDs(c.Context(), projectFlockID, params.KandangID)
|
projectFlockKandangIDs = []uint{*params.KandangID}
|
||||||
|
} else if params.Type == validation.SapronakTypeOutgoing {
|
||||||
|
projectFlockKandangIDs, err = s.getProjectFlockKandangIDs(c.Context(), projectFlockID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Log.Errorf("Failed to fetch project flock kandang IDs for project flock %d: %+v", projectFlockID, err)
|
s.Log.Errorf("Failed to fetch project flock kandang IDs for project flock %d: %+v", projectFlockID, err)
|
||||||
return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock kandang")
|
return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock kandang")
|
||||||
@@ -418,14 +420,11 @@ func (s closingService) getWarehouseIDsByProjectFlock(ctx context.Context, proje
|
|||||||
return ids, nil
|
return ids, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s closingService) getProjectFlockKandangIDs(ctx context.Context, projectFlockID uint, kandangID *uint) ([]uint, error) {
|
func (s closingService) getProjectFlockKandangIDs(ctx context.Context, projectFlockID uint) ([]uint, error) {
|
||||||
var ids []uint
|
var ids []uint
|
||||||
query := s.Repository.DB().WithContext(ctx).
|
query := s.Repository.DB().WithContext(ctx).
|
||||||
Model(&entity.ProjectFlockKandang{}).
|
Model(&entity.ProjectFlockKandang{}).
|
||||||
Where("project_flock_id = ?", projectFlockID)
|
Where("project_flock_id = ?", projectFlockID)
|
||||||
if kandangID != nil {
|
|
||||||
query = query.Where("kandang_id = ?", *kandangID)
|
|
||||||
}
|
|
||||||
err := query.Order("id ASC").Pluck("id", &ids).Error
|
err := query.Order("id ASC").Pluck("id", &ids).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -690,10 +689,16 @@ func (s closingService) GetClosingDataProduksi(c *fiber.Ctx, projectFlockID uint
|
|||||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Invalid project flock id")
|
return nil, fiber.NewError(fiber.StatusBadRequest, "Invalid project flock id")
|
||||||
}
|
}
|
||||||
|
|
||||||
projectFlockKandangIDs, err := s.getProjectFlockKandangIDs(c.Context(), projectFlockID, kandangID)
|
var projectFlockKandangIDs []uint
|
||||||
if err != nil {
|
if kandangID != nil && *kandangID > 0 {
|
||||||
s.Log.Errorf("Failed to fetch project flock kandangs for %d: %+v", projectFlockID, err)
|
projectFlockKandangIDs = []uint{*kandangID}
|
||||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock kandangs")
|
} else {
|
||||||
|
var err error
|
||||||
|
projectFlockKandangIDs, err = s.getProjectFlockKandangIDs(c.Context(), projectFlockID)
|
||||||
|
if err != nil {
|
||||||
|
s.Log.Errorf("Failed to fetch project flock kandangs for %d: %+v", projectFlockID, err)
|
||||||
|
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock kandangs")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(projectFlockKandangIDs) == 0 {
|
if len(projectFlockKandangIDs) == 0 {
|
||||||
@@ -954,16 +959,16 @@ func (s closingService) GetClosingDataProduksi(c *fiber.Ctx, projectFlockID uint
|
|||||||
}
|
}
|
||||||
if !isGrowing {
|
if !isGrowing {
|
||||||
if productionStandardDetail.TargetHenDayProduction != nil {
|
if productionStandardDetail.TargetHenDayProduction != nil {
|
||||||
performance.HendayStd = productionStandardDetail.TargetHenDayProduction
|
performance.HendayStd = *productionStandardDetail.TargetHenDayProduction
|
||||||
}
|
}
|
||||||
if productionStandardDetail.TargetHenHouseProduction != nil {
|
if productionStandardDetail.TargetHenHouseProduction != nil {
|
||||||
performance.HenHouseStd = productionStandardDetail.TargetHenHouseProduction
|
performance.HenHouseStd = *productionStandardDetail.TargetHenHouseProduction
|
||||||
}
|
}
|
||||||
if productionStandardDetail.TargetEggWeight != nil {
|
if productionStandardDetail.TargetEggWeight != nil {
|
||||||
performance.EggWeightStd = productionStandardDetail.TargetEggWeight
|
performance.EggWeightStd = *productionStandardDetail.TargetEggWeight
|
||||||
}
|
}
|
||||||
if productionStandardDetail.TargetEggMass != nil {
|
if productionStandardDetail.TargetEggMass != nil {
|
||||||
performance.EggMassStd = productionStandardDetail.TargetEggMass
|
performance.EggMassStd = *productionStandardDetail.TargetEggMass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user