This commit is contained in:
2026-01-25 21:59:00 +08:00
parent 7fd537bef3
commit 4cad3f0250
118 changed files with 30473 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package models
import "gorm.io/gorm"
// SystemCategory represents system-level categories that cannot be deleted by users
// Feature: accounting-feature-upgrade
// Validates: Requirements 8.19, 8.20
type SystemCategory struct {
ID uint `gorm:"primarykey" json:"id"`
Code string `gorm:"size:50;uniqueIndex;not null" json:"code"` // refund, reimbursement
Name string `gorm:"size:100;not null" json:"name"`
Icon string `gorm:"size:100" json:"icon"`
Type string `gorm:"size:20;not null" json:"type"` // income, expense
IsSystem bool `gorm:"default:true" json:"is_system"`
}
// TableName specifies the table name for SystemCategory
func (SystemCategory) TableName() string {
return "system_categories"
}
// InitSystemCategories initializes the system categories (refund and reimbursement)
// This function should be called during application startup or migration
// Feature: accounting-feature-upgrade
// Validates: Requirements 8.19, 8.20
func InitSystemCategories(db *gorm.DB) error {
categories := []SystemCategory{
{Code: "refund", Name: "退款", Icon: "mdi:cash-refund", Type: "income", IsSystem: true},
{Code: "reimbursement", Name: "报销", Icon: "mdi:receipt-text-check", Type: "income", IsSystem: true},
}
for _, cat := range categories {
// Use FirstOrCreate to avoid duplicates
if err := db.FirstOrCreate(&cat, SystemCategory{Code: cat.Code}).Error; err != nil {
return err
}
}
return nil
}