Files
MyClub/internal/models/invoice.go
T
Tomas Dvorak dfc079288f hot fix #1
2026-01-26 08:13:18 +01:00

281 lines
12 KiB
Go

package models
import (
"time"
)
// Invoice represents a complete invoice with auto-fill capabilities
type Invoice struct {
ID uint `json:"id" gorm:"primaryKey"`
// Invoice identification
InvoiceNumber string `json:"invoice_number" gorm:"size:50;uniqueIndex;not null"`
InvoiceType string `json:"invoice_type" gorm:"size:20;default:'faktura'"` // "faktura", "zalohova_faktura", "proforma_faktura", "dobropis"
VariableSymbol string `json:"variable_symbol" gorm:"size:20"`
ConstantSymbol string `json:"constant_symbol" gorm:"size:20"`
SpecificSymbol string `json:"specific_symbol" gorm:"size:20"`
// Invoice dates
IssueDate time.Time `json:"issue_date" gorm:"not null"`
DueDate time.Time `json:"due_date" gorm:"not null"`
TaxableSupplyDate time.Time `json:"taxable_supply_date"`
// Supplier information (auto-filled from club settings)
SupplierName string `json:"supplier_name" gorm:"size:255;not null"`
SupplierICO string `json:"supplier_ico" gorm:"size:20"`
SupplierDIC string `json:"supplier_dic" gorm:"size:20"`
SupplierAddress string `json:"supplier_address" gorm:"type:text"`
SupplierCity string `json:"supplier_city" gorm:"size:100"`
SupplierZIP string `json:"supplier_zip" gorm:"size:10"`
SupplierCountry string `json:"supplier_country" gorm:"size:100;default:'Česká republika'"`
// Supplier bank information (auto-filled)
BankName string `json:"bank_name" gorm:"size:255"`
BankAccount string `json:"bank_account" gorm:"size:50"`
BankIBAN string `json:"bank_iban" gorm:"size:50"`
BankSWIFT string `json:"bank_swift" gorm:"size:20"`
// Customer information (manual or auto-fill from database)
CustomerID *uint `json:"customer_id" gorm:"index"`
CustomerName string `json:"customer_name" gorm:"size:255;not null"`
CustomerICO string `json:"customer_ico" gorm:"size:20"`
CustomerDIC string `json:"customer_dic" gorm:"size:20"`
CustomerAddress string `json:"customer_address" gorm:"type:text"`
CustomerCity string `json:"customer_city" gorm:"size:100"`
CustomerZIP string `json:"customer_zip" gorm:"size:10"`
CustomerCountry string `json:"customer_country" gorm:"size:100;default:'Česká republika'"`
CustomerEmail string `json:"customer_email" gorm:"size:255"`
CustomerPhone string `json:"customer_phone" gorm:"size:50"`
// Financial summary
TotalAmount float64 `json:"total_amount" gorm:"type:decimal(15,2);not null"`
TotalVAT float64 `json:"total_vat" gorm:"type:decimal(15,2);not null"`
TotalAmountVAT float64 `json:"total_amount_vat" gorm:"type:decimal(15,2);not null"`
TotalAmountWithoutVAT float64 `json:"total_amount_without_vat" gorm:"type:decimal(15,2);not null"`
Currency string `json:"currency" gorm:"size:3;default:'CZK'"`
// Invoice status and workflow
Status string `json:"status" gorm:"size:20;default:'draft'"` // "draft", "sent", "paid", "overdue", "cancelled"
PaymentStatus string `json:"payment_status" gorm:"size:20;default:'unpaid'"` // "unpaid", "partially_paid", "paid", "overdue"
PaymentDate *time.Time `json:"payment_date"`
PaidAmount float64 `json:"paid_amount" gorm:"type:decimal(15,2);default:0"`
// Additional information
Note string `json:"note" gorm:"type:text"`
PaymentNote string `json:"payment_note" gorm:"type:text"`
InternalNote string `json:"internal_note" gorm:"type:text"`
// PDF and sending
PDFPath string `json:"pdf_path" gorm:"size:500"`
PDFGeneratedAt *time.Time `json:"pdf_generated_at"`
SentAt *time.Time `json:"sent_at"`
SentTo string `json:"sent_to" gorm:"type:text"` // JSON array of emails
// Metadata
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy uint `json:"created_by"`
UpdatedBy uint `json:"updated_by"`
// Relations
Items []InvoiceItem `json:"items,omitempty" gorm:"foreignKey:InvoiceID;constraint:OnDelete:CASCADE"`
Payments []InvoicePayment `json:"payments,omitempty" gorm:"foreignKey:InvoiceID;constraint:OnDelete:CASCADE"`
Customer *InvoiceCustomer `json:"customer,omitempty" gorm:"foreignKey:CustomerID"`
}
// InvoiceItem represents individual line items in an invoice
type InvoiceItem struct {
ID uint `json:"id" gorm:"primaryKey"`
InvoiceID uint `json:"invoice_id" gorm:"not null;index"`
// Item details
Description string `json:"description" gorm:"type:text;not null"`
Quantity float64 `json:"quantity" gorm:"type:decimal(12,3);not null"`
Unit string `json:"unit" gorm:"size:20;default:'ks'"` // "ks", "hod", "m", "kg", etc.
UnitPrice float64 `json:"unit_price" gorm:"type:decimal(15,2);not null"`
TotalPrice float64 `json:"total_price" gorm:"type:decimal(15,2);not null"`
// VAT information
VATRate float64 `json:"vat_rate" gorm:"type:decimal(5,2);not null"` // 0, 10, 21
VATAmount float64 `json:"vat_amount" gorm:"type:decimal(15,2);not null"`
TotalWithVAT float64 `json:"total_with_vat" gorm:"type:decimal(15,2);not null"`
// Additional fields
Code string `json:"code" gorm:"size:100"` // Product code or service code
Note string `json:"note" gorm:"type:text"`
// Metadata
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Relations
Invoice Invoice `json:"invoice,omitempty" gorm:"foreignKey:InvoiceID"`
}
// InvoicePayment represents payments received for invoices
type InvoicePayment struct {
ID uint `json:"id" gorm:"primaryKey"`
InvoiceID uint `json:"invoice_id" gorm:"not null;index"`
// Payment details
Amount float64 `json:"amount" gorm:"type:decimal(15,2);not null"`
Currency string `json:"currency" gorm:"size:3;default:'CZK'"`
PaymentDate time.Time `json:"payment_date" gorm:"not null"`
PaymentMethod string `json:"payment_method" gorm:"size:50"` // "bank_transfer", "cash", "card", "other"
// Bank transfer details
VariableSymbol string `json:"variable_symbol" gorm:"size:20"`
ConstantSymbol string `json:"constant_symbol" gorm:"size:20"`
SpecificSymbol string `json:"specific_symbol" gorm:"size:20"`
BankAccount string `json:"bank_account" gorm:"size:50"`
// Additional information
Note string `json:"note" gorm:"type:text"`
ReferenceNumber string `json:"reference_number" gorm:"size:255"`
// Metadata
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy uint `json:"created_by"`
// Relations
Invoice Invoice `json:"invoice,omitempty" gorm:"foreignKey:InvoiceID"`
}
// InvoiceCustomer represents customer database for auto-fill
type InvoiceCustomer struct {
ID uint `json:"id" gorm:"primaryKey"`
// Basic information
Name string `json:"name" gorm:"size:255;not null"`
ICO string `json:"ico" gorm:"size:20;uniqueIndex"`
DIC string `json:"dic" gorm:"size:20"`
// Address
Address string `json:"address" gorm:"type:text"`
City string `json:"city" gorm:"size:100"`
ZIP string `json:"zip" gorm:"column:zip;size:10"`
Country string `json:"country" gorm:"size:100;default:'Česká republika'"`
// Contact information
Email string `json:"email" gorm:"size:255"`
Phone string `json:"phone" gorm:"size:50"`
Website string `json:"website" gorm:"size:255"`
// Business information
BusinessType string `json:"business_type" gorm:"size:100"` // "individual", "company", "non_profit"
VATPayer bool `json:"vat_payer" gorm:"default:true"`
// Notes and metadata
Notes string `json:"notes" gorm:"type:text"`
Active bool `json:"active" gorm:"default:true"`
// Metadata
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy uint `json:"created_by"`
UpdatedBy uint `json:"updated_by"`
// Relations
Invoices []Invoice `json:"invoices,omitempty" gorm:"foreignKey:CustomerID"`
}
// InvoiceTemplate represents invoice templates for different types
type InvoiceTemplate struct {
ID uint `json:"id" gorm:"primaryKey"`
// Template identification
Name string `json:"name" gorm:"size:255;not null"`
Type string `json:"type" gorm:"size:50;not null"` // "standard", "proforma", "credit_note"
Description string `json:"description" gorm:"type:text"`
// Template content (HTML with placeholders)
HeaderHTML string `json:"header_html" gorm:"type:text"`
BodyHTML string `json:"body_html" gorm:"type:text"`
FooterHTML string `json:"footer_html" gorm:"type:text"`
// CSS styling
CSS string `json:"css" gorm:"type:text"`
// Default settings
DefaultVATRate float64 `json:"default_vat_rate" gorm:"type:decimal(5,2);default:21"`
DefaultPaymentTerm int `json:"default_payment_term" gorm:"default:14"` // days
// Status
Active bool `json:"active" gorm:"default:true"`
Default bool `json:"default" gorm:"default:false"`
// Metadata
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy uint `json:"created_by"`
UpdatedBy uint `json:"updated_by"`
}
// InvoiceSettings represents global invoice settings
type InvoiceSettings struct {
ID uint `json:"id" gorm:"primaryKey"`
// Company information (auto-fill source)
CompanyName string `json:"company_name" gorm:"size:255;not null"`
CompanyICO string `json:"company_ico" gorm:"size:20;not null"`
CompanyDIC string `json:"company_dic" gorm:"size:20"`
CompanyAddress string `json:"company_address" gorm:"type:text"`
CompanyCity string `json:"company_city" gorm:"size:100"`
CompanyZIP string `json:"company_zip" gorm:"size:10"`
CompanyCountry string `json:"company_country" gorm:"size:100;default:'Česká republika'"`
// Bank information
BankName string `json:"bank_name" gorm:"size:255"`
BankAccount string `json:"bank_account" gorm:"size:50"`
BankIBAN string `json:"bank_iban" gorm:"size:50"`
BankSWIFT string `json:"bank_swift" gorm:"size:20"`
// Invoice numbering
InvoiceNumberFormat string `json:"invoice_number_format" gorm:"size:100;default:'F{year}{seq:6}'"` // Format with placeholders
NextInvoiceNumber int `json:"next_invoice_number" gorm:"default:1"`
CurrentYear int `json:"current_year"`
// Default settings
DefaultPaymentTerm int `json:"default_payment_term" gorm:"default:14"` // days
DefaultVATRate float64 `json:"default_vat_rate" gorm:"type:decimal(5,2);default:21"`
DefaultCurrency string `json:"default_currency" gorm:"size:3;default:'CZK'"`
// Email settings
EmailFrom string `json:"email_from" gorm:"size:255"`
EmailSubject string `json:"email_subject" gorm:"size:255;default:'Faktura č. {invoice_number}'"`
EmailBody string `json:"email_body" gorm:"type:text"`
// PDF settings
PDFLogoPath string `json:"pdf_logo_path" gorm:"size:500"`
PDFFooter string `json:"pdf_footer" gorm:"type:text"`
// Legal information
RegistrationNumber string `json:"registration_number" gorm:"size:50"`
TaxRegistrationNumber string `json:"tax_registration_number" gorm:"size:50"`
// Metadata
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
UpdatedBy uint `json:"updated_by"`
}
// InvoiceSequence represents invoice number sequences
type InvoiceSequence struct {
ID uint `json:"id" gorm:"primaryKey"`
// Sequence identification
Type string `json:"type" gorm:"size:50;not null"` // "faktura", "zalohova_faktura", "proforma_faktura", "dobropis"
Year int `json:"year" gorm:"not null"`
// Sequence numbers
CurrentNumber int `json:"current_number" gorm:"default:1"`
Prefix string `json:"prefix" gorm:"size:20"`
Suffix string `json:"suffix" gorm:"size:20"`
Padding int `json:"padding" gorm:"default:6"`
// Metadata
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}