feat(purchasae): added team with category parent and central

This commit is contained in:
efrilm
2026-08-11 21:00:39 +07:00
parent a230199ce0
commit 9ae5be2c33
18 changed files with 566 additions and 32 deletions
@@ -48,6 +48,26 @@ func (r *CategoryRepositoryImpl) GetByOrganization(ctx context.Context, organiza
return categories, err
}
// ListParentCategories returns the top-level categories of an organization. These are
// the buckets the parent category reports roll up to via COALESCE(parent_id, id), so
// the list is deliberately every top-level category, not only those with children —
// otherwise a team could show up in a report but not be selectable on a purchase.
// Categories with no outlet of their own are shared, so they are always included.
func (r *CategoryRepositoryImpl) ListParentCategories(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID) ([]*entities.Category, error) {
var categories []*entities.Category
query := r.db.WithContext(ctx).
Where("organization_id = ?", organizationID).
Where("parent_id IS NULL")
if outletID != nil {
query = query.Where("outlet_id = ? OR outlet_id IS NULL", *outletID)
}
err := query.Order("\"order\" ASC, name ASC").Find(&categories).Error
return categories, err
}
func (r *CategoryRepositoryImpl) GetByBusinessType(ctx context.Context, businessType string) ([]*entities.Category, error) {
var categories []*entities.Category
err := r.db.WithContext(ctx).Where("business_type = ?", businessType).Find(&categories).Error