dolibarr 25.0.0-alpha
ToolInvoices Class Reference

Class ToolInvoices. More...

Inheritance diagram for ToolInvoices:
Collaboration diagram for ToolInvoices:

Public Member Functions

 __construct (DoliDB $db, $user=null, $conf=null)
 Constructor.
 
 getDefinitions ()
 Returns an array of tool definitions, including name, description, and input schema.
 
 getRequiredRights (string $toolName)
 Customer and supplier invoice reads and lifecycle actions.
 
 writeConfirmationPreview (string $toolName, array $args)
 Preview of the invoice action this call would perform.
 
 getCategories ()
 Return categories this tool belongs to.
 
 execute (string $name, array $args)
 Executes the requested tool function based on its name.
 
- Public Member Functions inherited from McpTool
 __construct ($db, $user, $conf)
 Constructor.
 
 isSystem ()
 Return true if this is a system/infrastructure tool that must always remain visible and executable regardless of the admin allow-list.
 

Private Member Functions

 getUser ()
 Return the authenticated user, preferring DI ($this->user) and falling back to global $user.
 
 searchInvoices ($args)
 Search invoices based on filters.
 
 getInvoice ($args)
 Get full invoice details.
 
 validateInvoice ($args)
 Validate a draft invoice.
 
 payInvoice ($args)
 Register a payment on an invoice.
 
 searchSupplierInvoices ($args)
 Search supplier invoices.
 
 getSupplierInvoice ($args)
 Get one supplier invoice with lines.
 
 findCustomer ($identifier)
 Find a customer by identifier.
 
 findInvoice ($identifier)
 Find an invoice by identifier.
 
 findBankAccount ($identifier)
 Find a bank account.
 

Additional Inherited Members

- Public Attributes inherited from McpTool
const RIGHTS_UNDECLARED = 'undeclared'
 Default of getRequiredRights(): the class never declared anything, deny.
 
const NO_WRITE = ''
 Returned by writeConfirmationPreview() when the tool writes nothing.
 

Detailed Description

Class ToolInvoices.

Provides various tools related to Dolibarr invoices.

Definition at line 38 of file invoices.class.php.

Constructor & Destructor Documentation

◆ __construct()

ToolInvoices::__construct ( DoliDB $db,
$user = null,
$conf = null )

Constructor.

Aligned with McpHandler's instantiation contract: new $className($db, $user, $conf).

Parameters
DoliDB$dbDatabase handler
User | null$userService user provided by McpHandler (from AI_MCP_USER_ID)
Conf | null$confDolibarr config (optional)

Definition at line 50 of file invoices.class.php.

References conf(), and user.

Member Function Documentation

◆ execute()

ToolInvoices::execute ( string $name,
array $args )

Executes the requested tool function based on its name.

Parameters
string$nameThe name of the tool to execute.
array<string,mixed>$args The arguments for the tool (key-value pairs).
Returns
mixed The result of the tool execution (usually an array) or an error array.

Reimplemented from McpTool.

Definition at line 249 of file invoices.class.php.

References getInvoice(), getSupplierInvoice(), payInvoice(), searchInvoices(), searchSupplierInvoices(), and validateInvoice().

◆ findBankAccount()

ToolInvoices::findBankAccount ( $identifier)
private

Find a bank account.

Parameters
string | int$identifierBank account id, ref or label
Returns
object|null

Definition at line 830 of file invoices.class.php.

References getEntity().

Referenced by payInvoice().

◆ findCustomer()

ToolInvoices::findCustomer ( $identifier)
private

Find a customer by identifier.

Parameters
string$identifierID, ref, code or name
Returns
Societe|array<string, mixed>

Definition at line 733 of file invoices.class.php.

References getEntity().

Referenced by searchInvoices().

◆ findInvoice()

ToolInvoices::findInvoice ( $identifier)
private

Find an invoice by identifier.

Parameters
string | int$identifierInvoice ID or ref
Returns
Facture|array<string, string>

Definition at line 802 of file invoices.class.php.

Referenced by getInvoice(), payInvoice(), and validateInvoice().

◆ getCategories()

ToolInvoices::getCategories ( )

Return categories this tool belongs to.

Used by the intent parser to filter available tools.

Returns
array<string> List of categories (e.g., ['billing', 'commercial'])

Reimplemented from McpTool.

Definition at line 237 of file invoices.class.php.

◆ getDefinitions()

ToolInvoices::getDefinitions ( )

Returns an array of tool definitions, including name, description, and input schema.

Returns
list<array<string, mixed>> Array of tool definitions.

Reimplemented from McpTool.

Definition at line 81 of file invoices.class.php.

◆ getInvoice()

ToolInvoices::getInvoice ( $args)
private

Get full invoice details.

Parameters
array<string,mixed>$args Input parameters (ref or id)
Returns
array<string, mixed>

Definition at line 413 of file invoices.class.php.

References $id, dol_html_entity_decode(), dol_print_date(), findInvoice(), and price().

Referenced by execute().

◆ getRequiredRights()

ToolInvoices::getRequiredRights ( string $toolName)

Customer and supplier invoice reads and lifecycle actions.

Parameters
string$toolNameTool being executed.
Returns
array<int,array<int,string>>|string Rights required, or a RIGHTS_* constant.

Reimplemented from McpTool.

Definition at line 193 of file invoices.class.php.

References McpTool\RIGHTS_UNDECLARED.

◆ getSupplierInvoice()

ToolInvoices::getSupplierInvoice ( $args)
private

Get one supplier invoice with lines.

Parameters
array<string,mixed>$args ref or id
Returns
array<string, mixed>

Definition at line 676 of file invoices.class.php.

References dol_html_entity_decode(), dol_print_date(), getEntity(), price(), and user.

Referenced by execute().

◆ getUser()

ToolInvoices::getUser ( )
private

Return the authenticated user, preferring DI ($this->user) and falling back to global $user.

In HTTP MCP context there is no PHP web session — only the service user injected via DI.

Returns
User|null

Definition at line 65 of file invoices.class.php.

References user.

Referenced by payInvoice(), and validateInvoice().

◆ payInvoice()

ToolInvoices::payInvoice ( $args)
private

Register a payment on an invoice.

Parameters
array<string,mixed>$args Input parameters (invoice, amount, payment_mode, bank_account)
Returns
array<string, mixed>

Definition at line 507 of file invoices.class.php.

References dol_getIdFromCode(), dol_now(), findBankAccount(), findInvoice(), getUser(), and price().

Referenced by execute().

◆ searchInvoices()

ToolInvoices::searchInvoices ( $args)
private

Search invoices based on filters.

Parameters
array<string,mixed>$args Input filters (limit, status, customer)
Returns
array<int|string, mixed>

Definition at line 281 of file invoices.class.php.

References dol_print_date(), dol_syslog(), findCustomer(), getEntity(), and price().

Referenced by execute().

◆ searchSupplierInvoices()

ToolInvoices::searchSupplierInvoices ( $args)
private

Search supplier invoices.

Parameters
array<string,mixed>$args query, status, limit
Returns
array<int|string, mixed>

Definition at line 581 of file invoices.class.php.

References dol_print_date(), dol_syslog(), price(), and user.

Referenced by execute().

◆ validateInvoice()

ToolInvoices::validateInvoice ( $args)
private

Validate a draft invoice.

Parameters
array<string,mixed>$args Input parameters (invoice ref or id)
Returns
array<string, mixed>

Definition at line 459 of file invoices.class.php.

References findInvoice(), and getUser().

Referenced by execute().

◆ writeConfirmationPreview()

ToolInvoices::writeConfirmationPreview ( string $toolName,
array $args )

Preview of the invoice action this call would perform.

Parameters
string$toolNameTool that would run.
array<string,mixed>$args Arguments it would run with.
Returns
string Preview text, or McpTool\NO_WRITE for a read.

Reimplemented from McpTool.

Definition at line 215 of file invoices.class.php.

References McpTool\NO_WRITE, and price().


The documentation for this class was generated from the following file: