dolibarr 25.0.0-alpha
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.
 
 getRequiredRights (string $toolName)
 Catalog reads, supplier prices and stock forecast.
 
 writeConfirmationPreview (string $toolName, array $args)
 Preview of the catalog record this call would write.
 
 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

 create (array $args)
 Create a new product or service in the catalog.
 
 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.
 

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 ToolProducts.

Provides various tools related to Dolibarr products and services.

Definition at line 42 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 50 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 877 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().

◆ create()

ToolProducts::create ( array $args)
private

Create a new product or service in the catalog.

Parameters
array{label?:string,ref?:string,type?:string,price?:float|int|string,price_base_type?:string,vat_rate?:float|int|string,cost_price?:float|int|string,barcode?:string,description?:string}$args Tool arguments.
Returns
array{success:bool, id?:int, ref?:string, type?:string, url?:string, error?:string, errors?:string[]}

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

References Product\TYPE_PRODUCT, Product\TYPE_SERVICE, 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 250 of file products.class.php.

References analyze(), create(), 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 461 of file products.class.php.

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 339 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.
float$dailyBurnRateEstimated daily consumption rate.
Returns
array{action: string, urgency: string, suggested_qty: int, reason: string}

Definition at line 795 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 238 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 61 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 618 of file products.class.php.

References $prod, aiStripPersonalExtrafields(), dol_buildpath(), dol_include_once(), extractIdentifier(), findProduct(), getProductCategories(), 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 709 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 750 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 581 of file products.class.php.

References $conf, and dol_include_once().

Referenced by getDetails().

◆ getRequiredRights()

ToolProducts::getRequiredRights ( string $toolName)

Catalog reads, supplier prices and stock forecast.

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

Reimplemented from McpTool.

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

References McpTool\RIGHTS_UNDECLARED.

◆ 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 1002 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 490 of file products.class.php.

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

Referenced by execute().

◆ writeConfirmationPreview()

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

Preview of the catalog record this call would write.

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 219 of file products.class.php.

References McpTool\NO_WRITE.


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