Add account balance
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
||||
"apskel-pos-be/internal/entities"
|
||||
"apskel-pos-be/internal/models"
|
||||
"apskel-pos-be/internal/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type AnalyticsProcessor interface {
|
||||
@@ -669,6 +671,11 @@ func (p *AnalyticsProcessorImpl) GetExclusiveSummaryMonthly(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bankBalance, err := p.buildExclusiveSummaryBankBalances(ctx, req.OrganizationID, req.OutletID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buckets := buildExclusiveSummaryMonthlyBuckets(monthStart)
|
||||
periods := make([]models.ExclusiveSummaryMonthlyPeriod, 0, len(buckets))
|
||||
for _, bucket := range buckets {
|
||||
@@ -706,14 +713,39 @@ func (p *AnalyticsProcessorImpl) GetExclusiveSummaryMonthly(ctx context.Context,
|
||||
NetProfit: fullPeriod.Summary.NetProfit,
|
||||
NetProfitMargin: percentage(fullPeriod.Summary.NetProfit, fullPeriod.Summary.Sales),
|
||||
},
|
||||
Periods: periods,
|
||||
BankBalance: []models.ExclusiveSummaryBankBalance{
|
||||
{Bank: "BCA"},
|
||||
{Bank: "BRI"},
|
||||
},
|
||||
Periods: periods,
|
||||
BankBalance: bankBalance,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *AnalyticsProcessorImpl) buildExclusiveSummaryBankBalances(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID) ([]models.ExclusiveSummaryBankBalance, error) {
|
||||
balances, err := p.analyticsRepo.GetExclusiveSummaryBankBalances(ctx, organizationID, outletID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get exclusive summary bank balances: %w", err)
|
||||
}
|
||||
|
||||
result := make([]models.ExclusiveSummaryBankBalance, len(balances))
|
||||
for i, balance := range balances {
|
||||
openingBalance := balance.OpeningBalance
|
||||
closingBalance := balance.ClosingBalance
|
||||
notes := strings.TrimSpace(balance.AccountType)
|
||||
if balance.Description != nil && strings.TrimSpace(*balance.Description) != "" {
|
||||
notes = strings.TrimSpace(*balance.Description)
|
||||
}
|
||||
|
||||
result[i] = models.ExclusiveSummaryBankBalance{
|
||||
Bank: balance.Bank,
|
||||
OpeningBalance: &openingBalance,
|
||||
ClosingBalance: &closingBalance,
|
||||
}
|
||||
if notes != "" {
|
||||
result[i].Notes = ¬es
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p *AnalyticsProcessorImpl) buildExclusiveSummaryPeriod(ctx context.Context, req *models.ExclusiveSummaryPeriodRequest) (*models.ExclusiveSummaryPeriodResponse, error) {
|
||||
result, err := p.analyticsRepo.GetExclusiveSummaryAnalytics(ctx, req.OrganizationID, req.OutletID, req.DateFrom, req.DateTo)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user