34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
package entities
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type OrderSequence struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
|
OrganizationID uuid.UUID `gorm:"type:uuid;not null;index" json:"organization_id"`
|
|
OutletID uuid.UUID `gorm:"type:uuid;not null;index" json:"outlet_id"`
|
|
Year int `gorm:"not null" json:"year"`
|
|
Month int `gorm:"not null" json:"month"`
|
|
SequenceNumber int `gorm:"not null;default:0" json:"sequence_number"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
Organization Organization `gorm:"foreignKey:OrganizationID" json:"organization,omitempty"`
|
|
Outlet Outlet `gorm:"foreignKey:OutletID" json:"outlet,omitempty"`
|
|
}
|
|
|
|
func (os *OrderSequence) BeforeCreate(tx *gorm.DB) error {
|
|
if os.ID == uuid.Nil {
|
|
os.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (OrderSequence) TableName() string {
|
|
return "order_sequences"
|
|
}
|