Documentation
¶
Overview ¶
Package store persists invoices in a SQLite database.
Index ¶
- Variables
- type Invoice
- type Store
- func (s *Store) Close() error
- func (s *Store) Get(id string) (*invoice.Invoice, error)
- func (s *Store) GetByMonth(year int, month time.Month) (*invoice.Invoice, error)
- func (s *Store) List() ([]*invoice.Invoice, error)
- func (s *Store) Remove(id string) (*invoice.Invoice, error)
- func (s *Store) Save(inv *invoice.Invoice) (string, bool, error)
- func (s *Store) SetEmailSent(year int, month time.Month, sentAt time.Time) error
- func (s *Store) SetPaid(year int, month time.Month, paid bool) error
- func (s *Store) SetProject(year int, month time.Month, project string) error
- type Week
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("invoice not found")
ErrNotFound reports that the store holds no invoice matching a lookup.
var ErrPaid = errors.New("invoice is paid")
ErrPaid reports that the store refused a write to a paid invoice.
Functions ¶
This section is empty.
Types ¶
type Invoice ¶
type Invoice struct {
ID string `gorm:"primaryKey"`
Month int
Year int
Vendor string
Customer string
ContactEmail string `gorm:"not null;default:''"`
Project string
Rate float64
Paid bool `gorm:"not null;default:false"`
EmailSentAt *time.Time
Weeks []Week `gorm:"foreignKey:InvoiceID;constraint:OnDelete:CASCADE"`
}
Invoice is the stored form of an invoice.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes invoices in a SQLite database.
func Open ¶
Open opens the database at path, creating its parent directory and running schema migrations when needed.
func (*Store) GetByMonth ¶
GetByMonth returns the invoice for the given year and month. It reports ErrNotFound when that month holds no invoice.
func (*Store) List ¶
List returns every stored invoice, newest first by year and month, with its weekly line items.
func (*Store) Remove ¶ added in v0.2.1
Remove deletes the invoice with the given identifier and its weekly line items. It returns the removed invoice and reports ErrNotFound when no invoice has that identifier.
func (*Store) Save ¶
Save stores an invoice and its weekly line items and returns the invoice identifier and whether the invoice was newly created. Saving an invoice for an existing year and month replaces the stored invoice, including its customer and project, and keeps its identifier.
func (*Store) SetEmailSent ¶ added in v0.2.4
SetEmailSent records when the invoice email was sent for the given year and month. It changes only the send time and reports ErrNotFound when that month holds no invoice.
func (*Store) SetPaid ¶
SetPaid sets the paid status on the invoice for the given year and month. It changes only the paid status and reports ErrNotFound when that month holds no invoice.
func (*Store) SetProject ¶
SetProject sets the project on the invoice for the given year and month. It changes only the project and reports ErrNotFound when that month holds no invoice. It reports ErrPaid when the invoice is paid.