invoice

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2017 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXT_PDF   = "pdf"
	EXT_JSON  = "json"
	EXT_TOML  = "toml"
	EXT_JSONE = "json.cfb"
	EXT_CFB   = ".cfb"
)
View Source
const (
	BOX_FULL_WIDTH     float64 = 0
	DEFAULT_LINE_BREAK float64 = -1

	TEXT_ALIGN_LEFT   = "L"
	NO_FILL           = false
	FILL              = true
	NO_BORDER         = "0"
	BORDER_BOTTOM     = "1B"
	BORDER_TOP_BOTTOM = "TB"

	FONT_STYLE_BOLD      = "B"
	FONT_STYLE_NORMAL    = ""
	TEXT_ALIGN_RIGHT_MID = "RM"
	TEXT_ALIGN_RIGHT_TOP = "RT"
	TEXT_ALIGN_RIGHT_BTM = "RB"
	TEXT_ALIGN_LEFT_MID  = "LM"

	BLACK_R, BLACK_G, BLACK_B = 0, 0, 0
	WHITE_R, WHITE_G, WHITE_B = 255, 255, 255
)
View Source
const (
	FIELD_NUMBER   = "Number"
	FIELD_CUSTOMER = "Customer"
	FIELD_AMOUNT   = "Amount"
	FIELD_DATE     = "Date"

	QUERY_DATE_FORMAT       = "2006-01-02"
	QUERY_DEFAULT_DATE_FROM = "1970-01-01"
	QUERY_DEFAULT_AMOUNT_GE = float64(0)
	QUERY_DEFAULT_AMOUNT_LE = float64(1000000000000)
	QUERY_DEFAULT_CUSTOMER  = "none"
)

Variables

View Source
var InvoiceDescriptorExists = errors.New("Invoice descriptor already exists")

Errors

Functions

func CreateSearchIndex

func CreateSearchIndex() error

CreateSearchIndex create a new empty search index in the GetSearchIndexFilePath folder

func GetConfigFilePath

func GetConfigFilePath() string

func GetConfigHome

func GetConfigHome() string

func GetI18nHome

func GetI18nHome() string

func GetI18nTranslationPath

func GetI18nTranslationPath(lang string) string

func GetSearchIndexFilePath

func GetSearchIndexFilePath() (string, bool)

func ReadUserInput

func ReadUserInput(message string) string

func ReadUserPassword

func ReadUserPassword(message string) (string, error)

func RebuildSearchIndex

func RebuildSearchIndex(c *Config, password *string) (int, time.Duration, error)

RebuildSearchIndex rebuild search index

func RenderInvoice

func RenderInvoice(c *Config, password string) (string, error)

RenderInvoice render the master descriptor to a pdf file and create the encrypted descriptor of the invoice. The pdf and the descriptor are stored in the workspace folder in the format $INVOICE_NUMBER.pdf / $INVOICE_NUMBER.json.cfb

func RenderPDF

func RenderPDF(invoice *Invoice, layout *Layout, pdfPath *string, T i18n.TranslateFunc)

func RestoreInvoice

func RestoreInvoice(c *Config, invoiceNumber, password string) error

RestoreInvoice restore the encrypted invoice descriptor into the master descriptor for editing. Overwrites the master descriptor without asking for confirmation.

func Setup

func Setup(workspace string) (string, string, error)

Setup setup the applications, create the workspace and the master invoice create the configuration with default values returns the configration file path and the master template path

Types

type BankCoordinates

type BankCoordinates struct {
	AccountHolder string `json:"account_holder"`
	Bank          string `json:"account_bank"`
	Iban          string `json:"account_iban"`
	Bic           string `json:"account_bic"`
}

type Block

type Block struct {
	Position Coords
}

Block represents an pdf block

type Config

type Config struct {
	Workspace         string `toml:"workspace"`
	SearchResultLimit int    `toml:"searchResultLimit"`
	MasterDescriptor  string `toml:"masterDescriptor"`
	DateInputFormat   string `toml:"dateInputFormat"`
	Layout            Layout `toml:"layout"`
}

============== CONFIGURATION FILE =================

func (*Config) GetInvoiceJsonPath

func (c *Config) GetInvoiceJsonPath(name string) (string, bool)

GetInvoiceJsonPath get the path of the encrypted version of an invoice in the workspace. returns the path of the invoice, and a boolean if the invoice already exists (true) or not (false)

func (*Config) GetInvoicePdfPath

func (c *Config) GetInvoicePdfPath(name string) (string, bool)

func (*Config) GetMasterPath

func (c *Config) GetMasterPath() (string, bool)

type Coords

type Coords struct {
	X float64 `toml:"x"`
	Y float64 `toml:"y"`
}

type Daily

type Daily struct {
	Enabled  bool           `json:"enabled"`
	DateFrom string         `json:"date_from,omitempty"`
	DateTo   string         `json:"date_to",omitempty`
	Projects []DailyProject `json:"projects",omitempty`
}

type DailyProject

type DailyProject struct {
	Name            string  `json:"name"`
	ItemDescription string  `json:"item_description"`
	ItemPrice       float64 `json:"item_price,omitempty"`
}

type I18NOther

type I18NOther struct {
	Other string `toml:"other"`
}

type Invoice

type Invoice struct {
	From           Recipient       `json:"from"`
	To             Recipient       `json:"to"`
	PaymentDetails BankCoordinates `json:"payment_details"`
	Invoice        InvoiceData     `json:"invoice"`
	Settings       InvoiceSettings `json:"settings"`
	Dailytime      Daily           `json:"dailytime"`
	Items          *[]Item         `json:"items"`
	Notes          []string        `json:"notes"`
}

Invoice contains all the information to generate an invoice

func ReadMasterDescriptor

func ReadMasterDescriptor(c *Config) (Invoice, error)

func (*Invoice) DisableExtensions

func (i *Invoice) DisableExtensions()

DisableExtensions disable the extensions of the invoices TODO extenesions should be treathed as a list

func (*Invoice) GetTotals

func (i *Invoice) GetTotals() (float64, float64)

GetTotals calculate and retrieve the subtotal (without tax) and the total (with tax) if the tax rate is 0 the subtotal and total are the same

func (*Invoice) PushItem

func (i *Invoice) PushItem(description string, quantity, price float64, quantitySymbol string)

PushItem push an item to the list of the items of the invoice

type InvoiceData

type InvoiceData struct {
	Number string `json:"number"`
	Date   string `json:"date"`
	Due    string `json:"due"`
}

type InvoiceEntry

type InvoiceEntry struct {
	Number   string
	Customer string
	Amount   float64
	Date     time.Time
}

InvoiceQuery is the object indexed by bleve

func SearchInvoice

func SearchInvoice(q InvoiceQuery) ([]InvoiceEntry, uint64, time.Duration, error)

SearchInvoice search for an invoice using InvoiceQuery object returns the entries found (first 50), the total number of hits, the duration of the query and error

type InvoiceQuery

type InvoiceQuery struct {
	Customer string
	AmountGE float64
	AmountLE float64
	DateFrom time.Time
	DateTo   time.Time
}

InvoiceQuery is the query object to search for invoices

func DefaultInvoiceQuery

func DefaultInvoiceQuery() InvoiceQuery

DefaultInvoiceQuery return the default invoice query object

func (*InvoiceQuery) String

func (q *InvoiceQuery) String() string

type InvoiceSettings

type InvoiceSettings struct {
	ItemsPrice          float64 `json:"items_price"`
	ItemsQuantitySymbol string  `json:"items_quantity_symbol"`
	VatRate             float64 `json:"vat_rate"`
	CurrencySymbol      string  `json:"currency_symbol"`
	Language            string  `json:"lang"`
	DateInputFormat     string  `json:"date_format",omitempty`
}

type Item

type Item struct {
	Description    string  `json:"description"`
	Quantity       float64 `json:"quantity"`
	Price          float64 `json:"price,omitempty"`
	QuantitySymbol string  `json:"quantity_symbol,omitempty"`
}

func (*Item) FormatQuantity

func (i *Item) FormatQuantity(quantitySymbol string) string

FormatQuantity with a qunatity symbol if present

func (*Item) GetCost

func (i *Item) GetCost(basePrice *float64) (float64, float64)

GetCost return the cost of an item, that is the ItemPrice multiplied the ItemQuantity. if the ItemPrice of the item is 0 then the global item price will be used

type Layout

type Layout struct {
	Style Style `toml:"style"`

	Items    Block `toml:"items"`
	From     Block `toml:"from"`
	To       Block `toml:"to"`
	Invoice  Block `toml:"invoice"`
	Payments Block `toml:"payments"`
	Notes    Block `toml:"notes"`
}

type Margins

type Margins struct {
	Bottom float64 `toml:"bottom"`
	Left   float64 `toml:"left"`
	Right  float64 `toml:"right"`
	Top    float64 `toml:"top"`
}

type Recipient

type Recipient struct {
	Name      string `json:"name"`
	Address   string `json:"address"`
	City      string `json:"city"`
	AreaCode  string `json:"area_code"`
	Country   string `json:"country"`
	TaxId     string `json:"tax_id"`
	VatNumber string `json:"vat_number"`
	Email     string `json:"email"`
}

type RowStyle

type RowStyle struct {
	ColWidths []float64
	Height    float64
	Border    string
	TextAlign string
	Fill      bool
}

type Style

type Style struct {
	Margins          Margins `toml:"margins"`
	FontFamily       string  `toml:"fontFamily"`
	FontSizeNormal   float64 `toml:"fontSizeNormal"`
	FontSizeH1       float64 `toml:"fontSizeH1"`
	FontSizeH2       float64 `toml:"fontSizeH2"`
	FontSizeSmall    float64 `toml:"fontsizeSmall"`
	LineHeightNormal float64 `toml:"lineHeightNormal"`
	LineHeightH1     float64 `toml:"lineHeightH1"`
	LineHeightH2     float64 `toml:"lineHeightH2"`
	LineHeightSmall  float64 `toml:"lineHeightSmall"`
	TableCol1W       float64 `toml:"tableCol1w"`
	TableCol2W       float64 `toml:"tableCol2w"`
	TableCol3W       float64 `toml:"tableCol3w"`
	TableCol4W       float64 `toml:"tableCol4w"`
	TableHeadHeight  float64 `toml:"tableHeadHeight"`
	TableRowHeight   float64 `toml:"tableRowHeight"`
}

type Translation

type Translation struct {
	From               I18NOther `toml:"from"`
	Sender             I18NOther `toml:"sender"`
	To                 I18NOther `toml:"to"`
	Recipient          I18NOther `toml:"recipient"`
	Invoice            I18NOther `toml:"invoice"`
	InvoiceData        I18NOther `toml:"invoice_data"`
	PaymentDetails     I18NOther `toml:"payment_details"`
	PaymentDetailsData I18NOther `toml:"payment_details_data"`
	Notes              I18NOther `toml:"notes"`
	Desc               I18NOther `toml:"desc"`
	Quantity           I18NOther `toml:"quantity"`
	Rate               I18NOther `toml:"rate"`
	Cost               I18NOther `toml:"cost"`
	Subtotal           I18NOther `toml:"subtotal"`
	Total              I18NOther `toml:"total"`
	Tax                I18NOther `toml:"tax"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL