transaction

package
v1.0.49 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(db *gorm.DB) error

Migrate runs the database migration for the transaction module. It creates the transactions table with the required columns and indexes.

Types

type TransactionService

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

func NewTransactionService

func NewTransactionService(db *gorm.DB, ctx *context.ERPContext, accountService *account.AccountService) *TransactionService

func (*TransactionService) CreateTransaction

func (s *TransactionService) CreateTransaction(transaction *models.TransactionModel, amount float64) error

CreateTransaction creates a new transaction in the database. If the transaction's AccountID is set, the transaction is associated with the specified account. If the transaction's SourceID is set, a transfer transaction is created.

func (*TransactionService) DeleteTransaction

func (s *TransactionService) DeleteTransaction(id string) error

DeleteTransaction deletes a transaction by its ID.

It returns an error if the deletion operation fails. Before deleting the transaction, it retrieves the transaction data to get the transaction code. After deleting the transaction, it deletes the counter-part transaction with the same code.

func (*TransactionService) GetByDateAndCompanyId

func (s *TransactionService) GetByDateAndCompanyId(from, to time.Time, companyId string, page, limit int) ([]models.TransactionModel, error)

GetByDateAndCompanyId retrieves a paginated list of transactions that occurred between the specified 'from' and 'to' dates for a given company ID. The function filters transactions by date and company ID, and returns a slice of TransactionModel and an error if the operation fails. The function uses pagination to manage the result set.

func (*TransactionService) GetTransactionByCode

func (s *TransactionService) GetTransactionByCode(code string) ([]models.TransactionModel, error)

GetTransactionByCode retrieves a transaction by its code.

It takes a code as input and returns a slice of TransactionModel and an error. The function uses GORM to retrieve the transaction data from the transactions table. If the operation fails, an error is returned. Otherwise, the error is nil.

func (*TransactionService) GetTransactionByDate

func (s *TransactionService) GetTransactionByDate(from, to time.Time, request http.Request) (paginate.Page, error)

func (*TransactionService) GetTransactionById

func (s *TransactionService) GetTransactionById(id string) (*models.TransactionModel, error)

GetTransactionById retrieves a transaction by its ID.

It takes the ID of the transaction as an argument and returns a pointer to a TransactionModel and an error. The function uses GORM to retrieve the transaction data from the transactions table. If the operation fails, an error is returned.

func (*TransactionService) GetTransactions

func (s *TransactionService) GetTransactions(request http.Request, search string) (paginate.Page, error)

GetTransactions retrieves a paginated list of transactions from the database.

It takes an HTTP request and a search query string as input. The method uses GORM to query the database for transactions, applying the search query to the account name, code, description, and various other fields. If the request contains a company ID header, the method filters the result by the company ID. The function utilizes pagination to manage the result set and includes any necessary request modifications using the utils.FixRequest utility. The function returns a paginated page of TransactionModel and an error if the operation fails.

func (*TransactionService) GetTransactionsByAccountID

func (s *TransactionService) GetTransactionsByAccountID(accountID string, startDate *time.Time, endDate *time.Time, companyID *string, request http.Request) (paginate.Page, error)

GetTransactionsByAccountID retrieves a paginated list of transactions for a given account ID.

It takes an account ID, optional start and end dates, and an optional company ID as input. The function filters transactions by account ID, company ID, and date range, and returns a paginated page of TransactionModel and an error if the operation fails. The function uses pagination to manage the result set. Each item in the result set has its balance calculated using the getBalance function.

func (*TransactionService) SetDB

func (s *TransactionService) SetDB(db *gorm.DB)

func (*TransactionService) UpdateCreditDebit

func (s *TransactionService) UpdateCreditDebit(transaction *models.TransactionModel, accountType models.AccountType) (*models.TransactionModel, error)

UpdateCreditDebit updates the debit and credit values of a transaction based on the given account type. It also sets the appropriate flags for expense, income, and equity transactions. The function returns the updated transaction, or an error if the account type is unrecognized.

func (*TransactionService) UpdateTransaction

func (s *TransactionService) UpdateTransaction(id string, transaction *models.TransactionModel) error

UpdateTransaction updates a transaction by its ID. It takes a string ID and a pointer to a TransactionModel as its arguments. The TransactionModel instance contains the updated values for the transaction.

The method returns an error if the update operation fails. If the update is successful, the error is nil.

The method is run inside a transaction. If the transaction has a counter-part transaction with the same code, the counter-part transaction is updated as well.

Jump to

Keyboard shortcuts

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