37 lines
1.3 KiB
Go
37 lines
1.3 KiB
Go
package entities
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ExpenseItem struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
|
ExpenseID uuid.UUID `gorm:"type:uuid;not null;index" json:"expense_id"`
|
|
ChartOfAccountID uuid.UUID `gorm:"type:uuid;not null;index" json:"chart_of_account_id"`
|
|
PurchaseCategoryID uuid.UUID `gorm:"type:uuid;not null;index" json:"purchase_category_id"`
|
|
Item string `gorm:"not null;size:255" json:"item"`
|
|
Description *string `gorm:"type:text" json:"description"`
|
|
Amount float64 `gorm:"type:decimal(15,2);not null;default:0" json:"amount"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
Expense *Expense `gorm:"foreignKey:ExpenseID" json:"expense,omitempty"`
|
|
ChartOfAccount *ChartOfAccount `gorm:"foreignKey:ChartOfAccountID" json:"chart_of_account,omitempty"`
|
|
PurchaseCategory *PurchaseCategory `gorm:"foreignKey:PurchaseCategoryID" json:"purchase_category,omitempty"`
|
|
}
|
|
|
|
func (e *ExpenseItem) BeforeCreate(tx *gorm.DB) error {
|
|
if e.ID == uuid.Nil {
|
|
e.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (ExpenseItem) TableName() string {
|
|
return "expense_items"
|
|
}
|