mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cb37e481b |
@@ -409,7 +409,14 @@ func (s *recordingService) CreateOne(c *fiber.Ctx, req *validation.Create) (*ent
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := s.ChickinSvc.EnsureChickInExists(ctx, pfk.Id); err != nil {
|
if err := s.ChickinSvc.EnsureChickInExists(ctx, pfk.Id); err != nil {
|
||||||
return nil, err
|
if !isLaying {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// LAYING fallback: kandang laying tidak punya project_chickins sendiri —
|
||||||
|
// populasinya dari laying transfer. Cek apakah ada executed laying transfer.
|
||||||
|
if fallbackErr := s.ensureLayingTransferExecutedForKandang(ctx, pfk.Id); fallbackErr != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if s.ProductionStandardSvc != nil {
|
if s.ProductionStandardSvc != nil {
|
||||||
if err := s.ProductionStandardSvc.EnsureWeekStart(ctx, pfk.ProjectFlock.ProductionStandardId, category); err != nil {
|
if err := s.ProductionStandardSvc.EnsureWeekStart(ctx, pfk.ProjectFlock.ProductionStandardId, category); err != nil {
|
||||||
@@ -3998,6 +4005,27 @@ func (s *recordingService) reflowRollbackRecordingInventory(ctx context.Context,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *recordingService) ensureLayingTransferExecutedForKandang(ctx context.Context, pfkID uint) error {
|
||||||
|
var count int64
|
||||||
|
err := s.Repository.DB().WithContext(ctx).
|
||||||
|
Table("laying_transfer_targets ltt").
|
||||||
|
Joins("JOIN laying_transfers lt ON lt.id = ltt.laying_transfer_id").
|
||||||
|
Where("ltt.target_project_flock_kandang_id = ?", pfkID).
|
||||||
|
Where("ltt.deleted_at IS NULL").
|
||||||
|
Where("lt.deleted_at IS NULL").
|
||||||
|
Where("lt.executed_at IS NOT NULL").
|
||||||
|
Where("ltt.total_qty > 0").
|
||||||
|
Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
s.Log.Errorf("Failed to check executed laying transfer for pfk_id=%d: %+v", pfkID, err)
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, "Gagal memeriksa transfer laying")
|
||||||
|
}
|
||||||
|
if count == 0 {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, "Kandang laying belum memiliki transfer laying yang telah dieksekusi sehingga belum dapat membuat recording")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *recordingService) requireFIFO() error {
|
func (s *recordingService) requireFIFO() error {
|
||||||
if s.FifoStockV2Svc == nil {
|
if s.FifoStockV2Svc == nil {
|
||||||
s.Log.Errorf("FIFO v2 service is not available for recording operations")
|
s.Log.Errorf("FIFO v2 service is not available for recording operations")
|
||||||
|
|||||||
Reference in New Issue
Block a user