feat[BE]: enhance expense management with location and project flock integration, including updates to migrations, entities, services, and validations

This commit is contained in:
aguhh18
2025-12-28 08:13:50 +07:00
parent 85dc0ecd13
commit ec6da57510
10 changed files with 197 additions and 69 deletions
@@ -19,6 +19,7 @@ type ProjectflockRepository interface {
GetNextPeriodsForKandangs(ctx context.Context, kandangIDs []uint) (map[uint]int, error)
GetCurrentProjectPeriod(ctx context.Context, projectFlockID uint) (int, error)
GetKandangPeriodSummaryRows(ctx context.Context, locationID uint) ([]KandangPeriodRow, error)
GetActiveByLocationID(ctx context.Context, locationID uint64) ([]entity.ProjectFlock, error)
AreaExists(ctx context.Context, id uint) (bool, error)
FcrExists(ctx context.Context, id uint) (bool, error)
LocationExists(ctx context.Context, id uint) (bool, error)
@@ -295,3 +296,17 @@ func (r *ProjectflockRepositoryImpl) ExistsByFlockName(ctx context.Context, floc
}
return count > 0, nil
}
func (r *ProjectflockRepositoryImpl) GetActiveByLocationID(ctx context.Context, locationID uint64) ([]entity.ProjectFlock, error) {
var projectFlocks []entity.ProjectFlock
err := r.DB().WithContext(ctx).
Joins("JOIN project_flock_kandangs ON project_flock_kandangs.project_flock_id = project_flocks.id").
Where("project_flocks.location_id = ?", locationID).
Where("project_flock_kandangs.closed_at IS NULL").
Group("project_flocks.id").
Find(&projectFlocks).Error
if err != nil {
return nil, err
}
return projectFlocks, nil
}