Financial Management (Invoicing & Expenses)
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- apps/gauzy-e2e/src/integration/ExpensesTest.ts
- apps/gauzy-e2e/src/integration/InvoicesTest.ts
- apps/gauzy-e2e/src/integration/SalesInvoicesTest.ts
- packages/core/src/lib/expense/expense.entity.ts
- packages/core/src/lib/income/income.entity.ts
- packages/core/src/lib/invoice/generate-invoice-pdf.ts
- packages/core/src/lib/invoice/invoice.entity.ts
- packages/core/src/lib/payment/payment.entity.ts
- packages/mcp-server/src/lib/tools/invoices.ts
- packages/ui-core/i18n/assets/i18n/en.json
The Financial Management module is a core component of the Ever Gauzy platform, providing functionalities for accounting, invoicing, and cost management. It enables organizations to track financial transactions, including income, expenses, and payments, and to generate and manage invoices and estimates. This system is integral to the platform's ERP capabilities, supporting sales, project management, and human resources by linking financial data to employees, projects, and clients.
The module is designed to be flexible, supporting multiple currencies, configurable tax and discount rules, and various methods for generating invoice items based on work performed or products sold. It also includes features for generating PDF documents for invoices and receipts, and programmatic access via the Model Context Protocol (MCP) server for automation and integration.
Sources: README.md, packages/ui-core/i18n/assets/i18n/en.json
Core Data Models
The financial management system is built upon a set of interconnected data entities that model key financial concepts. The primary entities are Invoice, Expense, Income, and Payment.
The following diagram illustrates the high-level relationships between these core financial entities.
This diagram shows the main financial entities and their relationships, such as an Invoice having multiple Payments.
Sources: packages/core/src/lib/invoice/invoice.entity.ts, packages/core/src/lib/payment/payment.entity.ts, packages/core/src/lib/expense/expense.entity.ts, packages/core/src/lib/income/income.entity.ts
Invoice Entity
The Invoice entity is the central object for billing. It can also function as an estimate (isEstimate flag). It contains details about the billing transaction, including due dates, taxes, discounts, and associated items.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the invoice. |
invoiceNumber | string | A unique number for the invoice. |
invoiceDate | Date | The date the invoice was issued. |
dueDate | Date | The date the invoice payment is due. |
currency | string | The currency for the invoice amounts (e.g., 'USD'). |
discountValue | number | The value of the discount. |
discountType | DiscountTaxTypeEnum | The type of discount ('FLAT' or 'PERCENT'). |
tax | number | The value of the primary tax. |
taxType | DiscountTaxTypeEnum | The type of the primary tax ('FLAT' or 'PERCENT'). |
tax2 | number | The value of the secondary tax. |
tax2Type | DiscountTaxTypeEnum | The type of the secondary tax ('FLAT' or 'PERCENT'). |
terms | string | Payment terms and conditions. |
totalValue | number | The total amount of the invoice. |
paid | boolean | A flag indicating if the invoice has been fully paid. |
status | InvoiceStatusEnum | The current status of the invoice (e.g., 'DRAFT', 'SENT', 'PAID'). |
invoiceType | InvoiceTypeEnum | The method used to generate invoice items. |
isEstimate | boolean | If true, this record is an estimate, not a formal invoice. |
invoiceItems | InvoiceItem[] | A list of line items on the invoice. |
payments | Payment[] | A list of payments made against the invoice. |
Sources: packages/core/src/lib/invoice/invoice.entity.ts:21-209
Expense Entity
The Expense entity tracks money spent by the organization or its employees. Expenses can be billable to a contact and can be split among all employees.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the expense. |
amount | number | The monetary value of the expense. |
currency | string | The currency of the expense amount. |
valueDate | Date | The date the expense was incurred. |
purpose | string | A description of the reason for the expense. |
split | boolean | If true, the expense is divided equally among all employees. |
billable | boolean | If true, the expense can be billed to a client. |
organizationContactId | string | The ID of the contact to whom the expense is billable. |
vendorId | string | The ID of the vendor associated with the expense. |
Sources: packages/core/src/lib/expense/expense.entity.ts:20-112
Income Entity
The Income entity tracks money received by the organization.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the income record. |
amount | number | The monetary value of the income. |
currency | string | The currency of the income amount. |
valueDate | Date | The date the income was received. |
isBonus | boolean | If true, this income is considered a direct bonus. |
employeeId | string | The ID of the employee who generated the income. |
organizationContactId | string | The ID of the contact from whom the income was received. |
Sources: packages/core/src/lib/income/income.entity.ts:19-86
Payment Entity
The Payment entity records a payment made against an invoice. An invoice can have multiple partial payments.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the payment. |
amount | number | The amount of money paid. |
paymentDate | Date | The date the payment was made. |
paymentMethod | string | The method of payment (e.g., 'CASH', 'CREDIT_CARD'). |
invoiceId | string | The ID of the invoice this payment is for. |
recordedBy | string | The ID of the user who recorded the payment. |
note | string | An optional note about the payment. |
Sources: packages/core/src/lib/payment/payment.entity.ts:19-74
Invoicing System
The invoicing system manages the entire lifecycle of an invoice, from creation and drafting to sending, payment, and archival.
Invoice Lifecycle
The typical flow of an invoice is creation as a draft, sending it to the client, and then recording payments until it is fully paid.
This diagram shows the lifecycle of an invoice from creation to payment and other actions.
Sources: apps/gauzy-e2e/src/integration/InvoicesTest.ts, apps/gauzy-e2e/src/integration/SalesInvoicesTest.ts
Invoice and Estimate Types
Invoices and estimates can be generated based on different sources of billable work or items. The InvoiceTypeEnum defines these sources.
| Type | Description |
|---|---|
BY_EMPLOYEE_HOURS | Items are generated based on tracked hours for specific employees. |
BY_PROJECT_HOURS | Items are generated based on tracked hours for specific projects. |
BY_TASK_HOURS | Items are generated based on tracked hours for specific tasks. |
BY_PRODUCTS | Items are generated from a list of products. |
BY_EXPENSES | Items are generated from uninvoiced, billable expenses. |
DETAILED_ITEMS | Items are added manually with detailed descriptions. |
Sources: packages/core/src/lib/invoice/invoice.entity.ts:11-18, packages/core/src/lib/invoice/generate-invoice-pdf.ts:19-42
Invoice Status
An invoice progresses through several statuses during its lifecycle, defined by InvoiceStatusEnum.
| Status | Description |
|---|---|
DRAFT | The invoice has been created but not yet sent to the client. |
SENT | The invoice has been sent to the client. |
VIEWED | The client has viewed the invoice (if a public link is used). |
PARTIALLY_PAID | A partial payment has been recorded against the invoice. |
FULLY_PAID | The invoice has been paid in full. |
OVERPAID | The total payments recorded exceed the invoice total. |
ACCEPTED | An estimate has been accepted by the client. |
REJECTED | An estimate has been rejected by the client. |
VOID | The invoice has been voided and is no longer valid. |
Sources: packages/core/src/lib/invoice/invoice.entity.ts:20-30
PDF Generation
The system can generate a PDF document for any invoice or estimate. The generateInvoicePdfDefinition function constructs the document structure for the pdfmake library.
Key features of PDF generation include:
- Dynamic Columns: The table of invoice items dynamically adds a leading column (e.g., 'Employee', 'Project', 'Task') depending on the
invoiceType. - Watermark: A large, semi-transparent "PAID" watermark is added to the background of invoices that have been fully paid.
- Localization: The function accepts translated text to generate the PDF in the user's selected language.
- Detailed Totals: The PDF includes breakdowns for taxes, discounts, subtotal, and total value.
Sources: packages/core/src/lib/invoice/generate-invoice-pdf.ts
Expense Management
The expense management system allows for tracking organizational and employee-specific costs.
The flow for adding a new expense is as follows:
This diagram shows the process of adding a new expense.
Sources: apps/gauzy-e2e/src/integration/ExpensesTest.ts
Key features include:
- Categorization: Expenses are assigned to categories, which can be managed by the organization.
- Splitting: An expense can be marked with the
splitflag, which divides its cost equally among all employees for accounting purposes. - Billable Expenses: Expenses can be marked as
billableand associated with a client contact, allowing them to be included in future invoices.
Sources: packages/core/src/lib/expense/expense.entity.ts:47-66, packages/ui-core/i18n/assets/i18n/en.json
MCP Server Tools for Financials
The MCP (Model Context Protocol) server exposes a suite of tools for programmatic interaction with financial data. The invoices.ts toolset provides comprehensive control over invoices.
| Tool Name | Description | Parameters |
|---|---|---|
get_invoices | Retrieves a paginated list of invoices. | page, limit, search, relations, status, invoiceType, paid, startDate, endDate |
get_invoice_count | Gets the total count of invoices based on filters. | status, paid, startDate, endDate |
get_invoice | Fetches a single invoice by its ID. | id, relations |
create_invoice | Creates a new invoice. | invoice_data (object with invoice details) |
update_invoice | Updates an existing invoice. | id, invoice_data |
delete_invoice | Deletes an invoice. | id |
send_invoice_email | Sends an invoice to a specified email address. | email, params (including invoiceId) |
download_invoice_pdf | Downloads the PDF for an invoice as binary data. | id |
generate_invoice_link | Generates a public, shareable link for an invoice. | id |
Sources: packages/mcp-server/src/lib/tools/invoices.ts
This tooling enables automation of financial workflows, such as automatically generating invoices at the end of a billing cycle or integrating Gauzy's financial data with external accounting systems.
Sources: packages/mcp-server/README.md