saving

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: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SavingService

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

func NewSavingService

func NewSavingService(db *gorm.DB, ctx *context.ERPContext, cooperativeSettingService *cooperative_setting.CooperativeSettingService) *SavingService

func (*SavingService) CreateSaving

func (c *SavingService) CreateSaving(saving *models.SavingModel) error

CreateSaving creates a new saving in the database.

It takes a pointer to a SavingModel as a parameter and returns an error if the operation fails. It generates a number for the saving and saves it to the database.

func (*SavingService) CreateTransaction

func (s *SavingService) CreateTransaction(saving models.SavingModel, forceVoluntry bool) error

CreateTransaction creates a new transaction for the given saving.

The transaction is created according to the type of saving and the cooperative setting. The saving amount must match the cooperative setting for principal and mandatory savings. For voluntary savings, the amount must be higher than the cooperative setting unless the forceVoluntry parameter is set to true.

The transaction is created with a secondary transaction reference to the saving.

The function returns an error if the saving amount does not match the cooperative setting, if the saving type is invalid, or if there is an error creating the transaction.

func (*SavingService) DeleteSaving

func (c *SavingService) DeleteSaving(id string) error

DeleteSaving deletes a saving and its related transactions from the database.

It takes a string id as a parameter and returns an error if the operation fails. The function first deletes all transactions related to the saving, then deletes the saving itself.

func (*SavingService) GenNumber

func (c *SavingService) GenNumber(saving *models.SavingModel, companyID *string) error

GenNumber generates the next number for a new saving. It queries the database to get the latest saving number for the given company, and then uses the invoice bill setting to generate the next number. If the query fails, it falls back to generating the number from the invoice bill setting with a prefix of "00".

func (*SavingService) GetSavingByID

func (s *SavingService) GetSavingByID(id string, memberID *string) (*models.SavingModel, error)

func (*SavingService) GetSavings

func (s *SavingService) GetSavings(request http.Request, search string, memberID *string) (paginate.Page, error)

GetSavings retrieves a paginated list of savings from the database.

It takes an HTTP request and a search query string as parameters. The search query is applied to the savings description field. If a company ID is present in the request header, the result is filtered by the company ID. The function uses pagination to manage the result set and includes any necessary request modifications using the utils.FixRequest utility.

The function returns a paginated page of SavingModel and an error if the operation fails.

func (*SavingService) SetDB

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

SetDB sets the database instance for this service.

This can be used to set a specific database instance for testing or in scenarios where the service is used with a different database than the one provided in the constructor.

func (*SavingService) UpdateSaving

func (c *SavingService) UpdateSaving(id string, loan *models.SavingModel) error

UpdateSaving updates an existing saving in the database.

It takes the ID of the saving and a pointer to a SavingModel as parameters. It returns an error if the operation fails.

Jump to

Keyboard shortcuts

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