This commit is contained in:
Aditya Siregar
2025-09-12 16:37:16 +07:00
parent 91f51d129e
commit 75ec5274d2
8 changed files with 45 additions and 46 deletions
@@ -12,7 +12,6 @@ import (
"github.com/google/uuid"
)
type ChartOfAccountProcessor interface {
CreateChartOfAccount(ctx context.Context, req *models.CreateChartOfAccountRequest) (*models.ChartOfAccountResponse, error)
GetChartOfAccountByID(ctx context.Context, id uuid.UUID) (*models.ChartOfAccountResponse, error)
@@ -91,7 +90,7 @@ func (p *ChartOfAccountProcessorImpl) UpdateChartOfAccount(ctx context.Context,
// Check if new code already exists (if code is being updated)
if req.Code != nil && *req.Code != entity.Code {
existing, err := p.chartOfAccountRepo.GetByCode(ctx, entity.OrganizationID, *req.Code, entity.OutletID)
existing, err := p.chartOfAccountRepo.GetByCode(ctx, entity.OrganizationID, *req.Code, &entity.OutletID)
if err == nil && existing != nil {
return nil, fmt.Errorf("chart of account with code %s already exists", *req.Code)
}
@@ -142,19 +141,15 @@ func (p *ChartOfAccountProcessorImpl) DeleteChartOfAccount(ctx context.Context,
}
func (p *ChartOfAccountProcessorImpl) ListChartOfAccounts(ctx context.Context, req *models.ListChartOfAccountsRequest) ([]models.ChartOfAccountResponse, int, error) {
// Get organization and outlet from context
appCtx := appcontext.FromGinContext(ctx)
organizationID := appCtx.OrganizationID
var outletID *uuid.UUID
if appCtx.OutletID != uuid.Nil {
outletID = &appCtx.OutletID
filterEntity := &entities.ChartOfAccount{
OrganizationID: req.OrganizationID,
OutletID: req.OutletID,
ParentID: req.ParentID,
}
filterEntity := &entities.ChartOfAccount{
OrganizationID: organizationID,
OutletID: outletID,
ChartOfAccountTypeID: *req.ChartOfAccountTypeID,
ParentID: req.ParentID,
// Apply optional filter for ChartOfAccountTypeID
if req.ChartOfAccountTypeID != nil {
filterEntity.ChartOfAccountTypeID = *req.ChartOfAccountTypeID
}
entities, total, err := p.chartOfAccountRepo.List(ctx, filterEntity)