dolibarr 24.0.0-beta
ToolProducts Class Reference

Class ToolProducts. More...

Inheritance diagram for ToolProducts:
Collaboration diagram for ToolProducts:

Public Member Functions

 __construct ($db, $user)
 Constructor.
 
 getDefinitions ()
 Returns an array of tool definitions, including name, description, and input schema.
 
 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

 findProduct ($identifier, ?string $type=null)
 Find a product by various identifiers (ID, Ref, Barcode, Label).
 
 extractIdentifier (array $args)
 Extracts the product identifier from arguments.
 
 search (array $args)
 Searches for products or services based on a query, type, and pagination.
 
 getProductCategories (int $product_id)
 Fetch product categories.
 
 getDetails (array $args)
 Retrieves comprehensive details for a specific product or service.
 
 getPendingCustomerOrdersQty (int $product_id)
 Get pending customer orders quantity for a product.
 
 getPendingSupplierOrdersQty (int $product_id)
 Get pending supplier orders quantity for a product.
 
 generateReplenishmentRecommendation (float $virtual_stock, float $min_stock_alert, float $desired_stock, float $dailyBurnRate)
 Generate replenishment recommendation.
 
 analyze (array $args)
 Performs an inventory analysis for a specific product.
 
 getSupplierPrices (array $args)
 Retrieves a list of all defined supplier prices for a given product or service.
 

Detailed Description

Class ToolProducts.

Provides various tools related to Dolibarr products and services.

Definition at line 39 of file products.class.php.

Constructor & Destructor Documentation

◆ __construct()

ToolProducts::__construct ( $db,
$user )

Constructor.

Parameters
DoliDB$dbDatabase handler
User$userUser object for permission checks

Definition at line 47 of file products.class.php.

References user.

Member Function Documentation

◆ analyze()

ToolProducts::analyze ( array $args)
private

Performs an inventory analysis for a specific product.

Calculates burn rate based on last 90 days of sales (Invoices) and predicts stockout dates.

Parameters
array{product_id?int|string, product_name?: string, type?: string} $args Arguments array.
Returns
array<string, mixed> Analysis results or an error array. Returns ['error' => string] on failure. Success shape: { id: int, ref: string, label: string, type: string, physical_stock: float, virtual_stock: float, min_stock_alert: float, desired_stock: float, pending_customer_orders_qty: float, pending_supplier_orders_qty: float, analysis: array{sales_last_90_days: float, daily_burn_rate: float, estimated_days_until_stockout: ?int, predicted_stockout_date: ?string, note?: string}, recommendation: array }

Definition at line 749 of file products.class.php.

References $conf, $prod, dol_buildpath(), dol_include_once(), dol_now(), dol_print_date(), dol_syslog(), dol_time_plus_duree(), extractIdentifier(), findProduct(), generateReplenishmentRecommendation(), getEntity(), getPendingCustomerOrdersQty(), getPendingSupplierOrdersQty(), and user.

Referenced by execute().

◆ execute()

ToolProducts::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 189 of file products.class.php.

References analyze(), getDetails(), getSupplierPrices(), and search().

◆ extractIdentifier()

ToolProducts::extractIdentifier ( array $args)
private

Extracts the product identifier from arguments.

Returns the identifier string/int or null if missing.

Parameters
array{product_id?int|string, product_name?: string, type?: string} $args Arguments array
Returns
array{identifier: string|int|null, type: string|null} The identifier and optional type.

Definition at line 335 of file products.class.php.

References string.

Referenced by analyze(), getDetails(), and getSupplierPrices().

◆ findProduct()

ToolProducts::findProduct ( $identifier,
?string $type = null )
private

Find a product by various identifiers (ID, Ref, Barcode, Label).

Parameters
string | int$identifierThe search term (ID, ref, barcode, etc.).
string | null$typeOptional filter: 'product' or 'service'.
Returns
Product|array{error: string, matches?: list<string>} Returns the Product object on success, or an error array.

Definition at line 213 of file products.class.php.

References getEntity().

Referenced by analyze(), getDetails(), and getSupplierPrices().

◆ generateReplenishmentRecommendation()

ToolProducts::generateReplenishmentRecommendation ( float $virtual_stock,
float $min_stock_alert,
float $desired_stock,
float $dailyBurnRate )
private

Generate replenishment recommendation.

Logic prioritizes Critical (Negative) -> High (Below Alert) -> Low (Below Desired).

Parameters
float$virtual_stockCurrent virtual stock (Physical + Incoming - Outgoing).
float$min_stock_alertMinimum stock alert level (Seuil alerte).
float$desired_stockDesired stock level (Stock désiré).
float$dailyBurnRateEstimated daily consumption rate.
Returns
array{action: string, urgency: string, suggested_qty: int, reason: string}

Definition at line 667 of file products.class.php.

Referenced by analyze().

◆ getCategories()

ToolProducts::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 177 of file products.class.php.

◆ getDefinitions()

ToolProducts::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 58 of file products.class.php.

◆ getDetails()

ToolProducts::getDetails ( array $args)
private

Retrieves comprehensive details for a specific product or service.

Parameters
array{product_id?int|string, product_name?: string, type?: string} $args Arguments array.
Returns
array<string, mixed> Product details or an error array. Returns ['error' => string] on failure.

Definition at line 492 of file products.class.php.

References $prod, dol_buildpath(), dol_include_once(), extractIdentifier(), findProduct(), getProductCategories(), string, and user.

Referenced by execute().

◆ getPendingCustomerOrdersQty()

ToolProducts::getPendingCustomerOrdersQty ( int $product_id)
private

Get pending customer orders quantity for a product.

Calculates the total quantity found in Sales Orders with status Validated (1) or In Process (2).

Parameters
int$product_idProduct ID
Returns
float Pending quantity

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

References $conf, dol_syslog(), and getEntity().

Referenced by analyze().

◆ getPendingSupplierOrdersQty()

ToolProducts::getPendingSupplierOrdersQty ( int $product_id)
private

Get pending supplier orders quantity for a product.

Sums quantity from Supplier Orders with status Validated(1), Approved(2), Ordered(3), or Partially Received(4).

Parameters
int$product_idProduct ID
Returns
float Pending quantity

Definition at line 622 of file products.class.php.

References $conf, dol_syslog(), and getEntity().

Referenced by analyze().

◆ getProductCategories()

ToolProducts::getProductCategories ( int $product_id)
private

Fetch product categories.

Parameters
int$product_idProduct ID
Returns
array<int, array{id: int, label: string, fk_parent: int}> List of categories

Definition at line 455 of file products.class.php.

References $conf, and dol_include_once().

Referenced by getDetails().

◆ getSupplierPrices()

ToolProducts::getSupplierPrices ( array $args)
private

Retrieves a list of all defined supplier prices for a given product or service.

Parameters
array<string,mixed>$args Input parameters (product_id, product_name, type)
Returns
array<string, mixed>|array<string, string>

Definition at line 874 of file products.class.php.

References $prod, dol_buildpath(), dol_print_date(), dol_syslog(), extractIdentifier(), findProduct(), getEntity(), and user.

Referenced by execute().

◆ search()

ToolProducts::search ( array $args)
private

Searches for products or services based on a query, type, and pagination.

Parameters
array{query?string, type?: string, limit?: int, offset?: int} $args Arguments array.
Returns
array<string, mixed> Result array containing 'count', 'offset', 'limit', and 'results'. Results is a list of array<string, mixed>. Returns ['error' => string] on failure.

Definition at line 364 of file products.class.php.

References dol_buildpath(), dol_syslog(), getEntity(), price(), string, and user.

Referenced by execute().


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