income

package
v0.0.0-...-58f0064 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SourceUnSpecified source = iota
	SourceSalary
	SourceAllowance
	SourceCommission
	SourceBasicSalaryInterview
)

Variables

View Source
var ErrCalculationNotFound = fmt.Errorf("calculation not found")

ErrCalculationNotFound is returned when a calculation is not found in the database.

View Source
var ErrWordlistNotFound = errors.New("wordlist not found")

ErrWordlistNotFound is returned when a wordlist is not found in the database.

Functions

This section is empty.

Types

type Account

type Account struct {
	Number      string `json:"number"`
	DisplayName string `json:"displayName"`
	Currency    string `json:"currency"`
}

type Allowance

type Allowance struct {
	Title          string          `json:"title"`
	Months         decimal.Decimal `json:"months"`
	MonthlyAverage decimal.Decimal `json:"monthlyAverage"`
	Transactions   []Transaction   `json:"transactions"`
	Total          decimal.Decimal `json:"total"`
}

type AllowanceBreakdown

type AllowanceBreakdown struct {
	Allowances []Allowance     `json:"allowances"`
	Total      decimal.Decimal `json:"total"`
}

func (*AllowanceBreakdown) Bytes

func (l *AllowanceBreakdown) Bytes() []byte

type BatchGetCalculationsQuery

type BatchGetCalculationsQuery struct {
	ID                 int64     `query:"id"`
	Product            string    `query:"product"`
	Number             string    `query:"number"`
	AccountDisplayName string    `query:"accountDisplayName"`
	CreatedAfter       time.Time `query:"createdAfter"`
	CreatedBefore      time.Time `query:"createdBefore"`
	// contains filtered or unexported fields
}

func (*BatchGetCalculationsQuery) ToSQL

func (q *BatchGetCalculationsQuery) ToSQL() (string, []any, error)

type Breakdown

type Breakdown struct {
	MonthlyAverage decimal.Decimal `json:"monthlyAverage"`
	Total          decimal.Decimal `json:"total"`
}

type CalculateReq

type CalculateReq struct {
	Number            string            `json:"number"`
	Product           types.ProductType `json:"product"`
	StatementFileName string            `json:"statementFileName"`
}

func (*CalculateReq) Validate

func (r *CalculateReq) Validate() error

type Calculation

type Calculation struct {
	ID                                int64                `json:"id"`
	StatementFileName                 string               `json:"statementFileName"`
	Number                            string               `json:"number"`
	Product                           types.ProductType    `json:"product"`
	Account                           Account              `json:"account"`
	ExchangeRate                      decimal.Decimal      `json:"exchangeRate"`
	BasicSalaryFromInterview          decimal.Decimal      `json:"basicSalaryFromInterview"`
	MonthlyAverageIncome              decimal.Decimal      `json:"monthlyAverageIncome"`
	MonthlyNetIncome                  decimal.Decimal      `json:"monthlyNetIncome"`
	MonthlyOtherIncome                decimal.Decimal      `json:"monthlyOtherIncome"`
	EightyPercentOfMonthlyOtherIncome decimal.Decimal      `json:"eightyPercentOfMonthlyOtherIncome"`
	TotalOtherIncome                  decimal.Decimal      `json:"totalOtherIncome"`
	TotalBasicSalary                  decimal.Decimal      `json:"totalBasicSalary"`
	TotalIncome                       decimal.Decimal      `json:"totalIncome"`
	PeriodInMonth                     decimal.Decimal      `json:"periodInMonth"`
	StartedAt                         time.Time            `json:"startedAt"`
	EndedAt                           time.Time            `json:"endedAt"`
	Status                            types.AnalysisStatus `json:"status"`
	CreatedBy                         string               `json:"createdBy"`
	UpdatedBy                         string               `json:"updatedBy"`
	CreatedAt                         time.Time            `json:"createdAt"`
	UpdatedAt                         time.Time            `json:"updatedAt"`

	SalaryBreakdown     *SalaryBreakdown     `json:"salaryBreakdown"`
	AllowanceBreakdown  *AllowanceBreakdown  `json:"allowanceBreakdown"`
	CommissionBreakdown *CommissionBreakdown `json:"commissionBreakdown"`
	Source              *Source              `json:"source"`
}

func (*Calculation) Complete

func (c *Calculation) Complete(by string)

func (*Calculation) IsCompleted

func (c *Calculation) IsCompleted() bool

func (*Calculation) ReCalculate

func (c *Calculation) ReCalculate(by string, in *RecalculateReq) error

type CalculationQuery

type CalculationQuery struct {
	ID                 int64     `query:"id"`
	Product            string    `query:"product"`
	Number             string    `query:"number"`
	AccountDisplayName string    `query:"accountDisplayName"`
	CreatedAfter       time.Time `query:"createdAfter"`
	CreatedBefore      time.Time `query:"createdBefore"`
	PageSize           uint64    `query:"pageSize"`
	PageToken          string    `query:"pageToken"`
}

func (*CalculationQuery) ToSQL

func (q *CalculationQuery) ToSQL() (string, []any, error)

type Commission

type Commission struct {
	Month        string          `json:"month"`
	Transactions []Transaction   `json:"transactions"`
	Total        decimal.Decimal `json:"total"`
}

type CommissionBreakdown

type CommissionBreakdown struct {
	Commissions    []Commission    `json:"commissions"`
	MonthlyAverage decimal.Decimal `json:"monthlyAverage"`
	Total          decimal.Decimal `json:"total"`
}

func (*CommissionBreakdown) Bytes

func (l *CommissionBreakdown) Bytes() []byte

type GetTransactionReq

type GetTransactionReq struct {
	Number     string `json:"number" param:"number"`
	BillNumber string `json:"billNumber" param:"billNumber"`
}

func (*GetTransactionReq) Validate

func (r *GetTransactionReq) Validate() error

type ListCalculationsResult

type ListCalculationsResult struct {
	Calculations  []*Calculation `json:"calculations"`
	NextPageToken string         `json:"nextPageToken"`
}

type ListTransactionsResult

type ListTransactionsResult struct {
	Transactions []*Transaction `json:"transactions"`
}

type ListWordlistsResult

type ListWordlistsResult struct {
	Wordlists     []*Wordlist `json:"wordlists"`
	NextPageToken string      `json:"nextPageToken"`
}

type MonthlySalary

type MonthlySalary struct {
	Month         string          `json:"month"`
	TimesReceived decimal.Decimal `json:"timesReceived"`
	Transactions  []Transaction   `json:"transactions"`
	Total         decimal.Decimal `json:"total"`
}

type RecalculateReq

type RecalculateReq struct {
	Number                   string          `param:"number"`
	BasicSalaryFromInterview decimal.Decimal `json:"basicSalaryFromInterview"`
	MonthlySalaries          []MonthlySalary `json:"monthlySalaries"`
	Allowances               []Allowance     `json:"allowances"`
	Commissions              []Commission    `json:"commissions"`
}

type SalaryBreakdown

type SalaryBreakdown struct {
	MonthlySalaries []MonthlySalary `json:"monthlySalaries"`
	BasicSalary     decimal.Decimal `json:"basicSalary"`
	Total           decimal.Decimal `json:"total"`
}

func (*SalaryBreakdown) Bytes

func (l *SalaryBreakdown) Bytes() []byte

func (SalaryBreakdown) Length

func (s SalaryBreakdown) Length() decimal.Decimal

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(_ context.Context, db *sql.DB, currency *currency.Service, statement *statement.Service, zlog *zap.Logger) (*Service, error)

func (*Service) CalculateIncome

func (s *Service) CalculateIncome(ctx context.Context, in *CalculateReq) (*Calculation, error)

func (*Service) CompleteCalculation

func (s *Service) CompleteCalculation(ctx context.Context, number string) (*Calculation, error)

func (*Service) CreateWordlist

func (s *Service) CreateWordlist(ctx context.Context, in *WordlistReq) (*Wordlist, error)

func (*Service) ExportCalculationToExcelByNumber

func (s *Service) ExportCalculationToExcelByNumber(ctx context.Context, number string) (*bytes.Buffer, error)

func (*Service) ExportCalculationsToExcel

func (s *Service) ExportCalculationsToExcel(ctx context.Context, in *BatchGetCalculationsQuery) (*bytes.Buffer, error)

func (*Service) GetCalculationByNumber

func (s *Service) GetCalculationByNumber(ctx context.Context, number string) (*Calculation, error)

func (*Service) GetIncomeTransactionByBillNumber

func (s *Service) GetIncomeTransactionByBillNumber(ctx context.Context, in *GetTransactionReq) (*Transaction, error)

func (*Service) GetWordlistByID

func (s *Service) GetWordlistByID(ctx context.Context, id int64) (*Wordlist, error)

func (*Service) ListCalculations

func (s *Service) ListCalculations(ctx context.Context, in *CalculationQuery) (*ListCalculationsResult, error)

func (*Service) ListIncomeTransactionsByNumber

func (s *Service) ListIncomeTransactionsByNumber(ctx context.Context, in *TransactionReq) (*ListTransactionsResult, error)

func (*Service) ListWordlists

func (s *Service) ListWordlists(ctx context.Context, in *WordlistQuery) (*ListWordlistsResult, error)

func (*Service) ReCalculateIncome

func (s *Service) ReCalculateIncome(ctx context.Context, in *RecalculateReq) (*Calculation, error)

func (*Service) UpdateWordlist

func (s *Service) UpdateWordlist(ctx context.Context, in *WordlistReq) (*Wordlist, error)

type Source

type Source struct {
	BasicSalary Breakdown `json:"basicSalary"`
	Allowance   Breakdown `json:"allowance"`
	Commission  Breakdown `json:"commission"`
}

Source represents the source of income.

func (*Source) Bytes

func (s *Source) Bytes() []byte

type Transaction

type Transaction struct {
	Date       types.DDMMYYYY  `json:"date"`
	BillNumber string          `json:"billNumber"`
	Noted      string          `json:"noted"`
	Amount     decimal.Decimal `json:"amount"`
}

type TransactionReq

type TransactionReq struct {
	// The statement calculation number
	Number string `json:"number" param:"number"`

	// Category is the source of the income
	Category source `json:"category"`

	// Month in MMYYYY format
	Month types.MMYYY `json:"month"`
}

func (*TransactionReq) Validate

func (r *TransactionReq) Validate() error

type Wordlist

type Wordlist struct {
	ID        int64     `json:"id"`
	Word      string    `json:"word"`
	Category  source    `json:"category"`
	CreatedBy string    `json:"createdBy"`
	UpdatedBy string    `json:"updatedBy"` // Optional, can be used for updates
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

func (*Wordlist) Update

func (w *Wordlist) Update(by string, in *WordlistReq) bool

type WordlistQuery

type WordlistQuery struct {
	ID            int64     `json:"id" param:"id" query:"id"`
	Word          string    `json:"word"  query:"word"`
	Category      string    `json:"category"  query:"category"`
	PageToken     string    `json:"pageToken"  query:"pageToken"`
	PageSize      uint64    `json:"pageSize"  query:"pageSize"`
	CreatedAfter  time.Time `json:"createdAfter"  query:"createdAfter"`
	CreatedBefore time.Time `json:"createdBefore"  query:"createdBefore"`
	// contains filtered or unexported fields
}

func (*WordlistQuery) ToSql

func (q *WordlistQuery) ToSql() (string, []any, error)

type WordlistReq

type WordlistReq struct {
	// ID is used for updating an existing wordlist.
	ID int64 `json:"-" param:"id"`

	Word     string `json:"word"`
	Category source `json:"category"`
}

func (*WordlistReq) ToWordlist

func (r *WordlistReq) ToWordlist(by string) *Wordlist

func (*WordlistReq) Validate

func (r *WordlistReq) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL