class FormProduct (View source)

Class with static methods for building HTML components related to products Only components common to products and services must be here.

Properties

DoliDB $db
string $error
array<int, array{id: int, label: string, parent_id: int, description: string, stock: string, full_label: string}> $cache_warehouses
array<int, array<int, array{id: int, batch: string, entrepot_id: int, entrepot_label: string, qty: float, eatbydate: int|string, sellbydate: int|string}>> $cache_lot
array<int, array{id: int, ref: string, label: string, type: string, nb_operators_required: int, thm_operator_estimated: float, thm_machine_estimated: float}> $cache_workstations

Methods

__construct($db)

Constructor

int
loadWarehouses(int $fk_product = 0, string $batch = '', string $status = '', bool $sumStock = true, int[] $exclude = array(), bool|int $stockMin = false, string $orderBy = 'e.ref')

Load in cache array list of warehouses If fk_product is not 0, we do not use cache

int
loadWorkstations(int $fk_product = 0, int[] $exclude = array(), string $orderBy = 'w.ref')

Load in cache array list of workstations If fk_product is not 0, we do not use cache

selectWarehouses($selected = '', string $htmlname = 'idwarehouse', $filterstatus = '', $empty = 0, $disabled = 0, $fk_product = 0, $empty_label = '', $showstock = 0, $forcecombo = 0, array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events = array(), $morecss = 'minwidth200', $exclude = array(), $showfullpath = 1, $stockMin = false, $orderBy = 'e.ref', $multiselect = 0)

Return list of warehouses

selectWorkstations($selected = '', string $htmlname = 'idworkstations', $empty = 0, $disabled = 0, $fk_product = 0, $empty_label = '', $forcecombo = 0, array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events = array(), $morecss = 'minwidth200', $exclude = array(), $showfullpath = 1, $orderBy = 'e.ref')

Return list of workstations

formSelectWarehouses($page, string|int $selected = '', $htmlname = 'warehouse_id', $addempty = 0)

Display form to select warehouse

select_measuring_units($name = 'measuring_units', string $measuring_style = '', $selected = '0', $adddefault = 0, $mode = 0)

Output a combo box with list of units Currently the units are not define in the DB

selectMeasuringUnits($name = 'measuring_units', string $measuring_style = '', $selected = '0', $adddefault = 0, $mode = 0, $morecss = 'minwidth75 maxwidth125')

Return a combo box with list of units Units labels are defined in llx_c_units

selectProductNature($name = 'finished', string $selected = '', $mode = 0, $showempty = 1)

Return a combo box with list of units NAture of product labels are defined in llx_c_product_nature

selectLotStock($selected = '', string $htmlname = 'batch_id', $filterstatus = '', $empty = 0, $disabled = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array(), $empty_label = '', $forcecombo = 0, array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events = array(), $morecss = 'minwidth200')

Return list of lot numbers (stock from product_batch) with stock location and stock qty

selectLotDataList($htmlname = 'batch_id', int $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array())

Return list of lot numbers (stock from product_batch) for product and warehouse.

Details

__construct($db)

Constructor

@param DoliDB $db Database handler

Parameters

$db

int loadWarehouses(int $fk_product = 0, string $batch = '', string $status = '', bool $sumStock = true, int[] $exclude = array(), bool|int $stockMin = false, string $orderBy = 'e.ref')

Load in cache array list of warehouses If fk_product is not 0, we do not use cache

Parameters

int $fk_product

Add quantity of stock in label for product with id fk_product. Nothing if 0.

string $batch

Add quantity of batch stock in label for product with batch name batch, batch name precedes batch_id. Nothing if ''.

string $status

warehouse status filter, following comma separated filter options can be used 'warehouseopen' = select products from open warehouses, 'warehouseclosed' = select products from closed warehouses, 'warehouseinternal' = select products from warehouses for internal correct/transfer only

bool $sumStock

sum total stock of a warehouse, default true

int[] $exclude

warehouses ids to exclude

bool|int $stockMin

[=false] Value of minimum stock to filter (only warehouse with stock > stockMin are loaded) or false not not filter by minimum stock

string $orderBy

[='e.ref'] Order by

Return Value

int

Nb of loaded lines, 0 if already loaded, <0 if KO

Exceptions

Exception

int loadWorkstations(int $fk_product = 0, int[] $exclude = array(), string $orderBy = 'w.ref')

Load in cache array list of workstations If fk_product is not 0, we do not use cache

Parameters

int $fk_product

Add quantity of stock in label for product with id fk_product. Nothing if 0.

int[] $exclude

warehouses ids to exclude

string $orderBy

[='e.ref'] Order by

Return Value

int

Nb of loaded lines, 0 if already loaded, <0 if KO

Exceptions

Exception

selectWarehouses($selected = '', string $htmlname = 'idwarehouse', $filterstatus = '', $empty = 0, $disabled = 0, $fk_product = 0, $empty_label = '', $showstock = 0, $forcecombo = 0, array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events = array(), $morecss = 'minwidth200', $exclude = array(), $showfullpath = 1, $stockMin = false, $orderBy = 'e.ref', $multiselect = 0)

Return list of warehouses

@param ''|'-1'|'ifone'|'ifonenodefault'|'-2'|string|int|int[] $selected Id of preselected warehouse ('' or '-1' for no value, 'ifone' and 'ifonenodefault' = select value if one value otherwise no value, '-2' to use the default value from setup)

Parameters

$selected
string $htmlname

Name of html select html @param string $filterstatus warehouse status filter, following comma separated filter options can be used 'warehouseopen' = select products from open warehouses, 'warehouseclosed' = select products from closed warehouses, 'warehouseinternal' = select products from warehouses for internal correct/transfer only @param int<0,1>|string $empty Use 1 or 'label'=Can be empty, 0 if not @param int<0,1> $disabled 1=Select is disabled @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0. @param string $empty_label Empty label if needed (deprecated, set the label into the field $empty) @param int<0,1> $showstock 1=Show stock count @param int<0,1> $forcecombo 1=Force combo iso ajax select2

$filterstatus
$empty
$disabled
$fk_product
$empty_label
$showstock
$forcecombo
array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events

Events to add to select2 @param string $morecss Add more css classes to HTML select @param int[] $exclude Warehouses ids to exclude @param int<0,1> $showfullpath 1=Show full path of name (parent ref into label), 0=Show only ref of current warehouse @param bool|int $stockMin [=false] Value of minimum stock to filter (only warehouse with stock > stockMin are loaded) or false not not filter by minimum stock @param string $orderBy [='e.ref'] Order by @param int<0,1> $multiselect 1=Allow multiselect @return string HTML select

@throws Exception

$morecss
$exclude
$showfullpath
$stockMin
$orderBy
$multiselect

selectWorkstations($selected = '', string $htmlname = 'idworkstations', $empty = 0, $disabled = 0, $fk_product = 0, $empty_label = '', $forcecombo = 0, array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events = array(), $morecss = 'minwidth200', $exclude = array(), $showfullpath = 1, $orderBy = 'e.ref')

Return list of workstations

@param string|int $selected Id of preselected warehouse ('' or '-1' for no value, 'ifone' and 'ifonenodefault' = select value if one value otherwise no value, '-2' to use the default value from setup)

Parameters

$selected
string $htmlname

Name of html select html @param int<0,1> $empty 1=Can be empty, 0 if not @param int<0,1> $disabled 1=Select is disabled @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0. @param string $empty_label Empty label if needed (only if $empty=1) @param int<0,1> $forcecombo 1=Force combo iso ajax select2

$empty
$disabled
$fk_product
$empty_label
$forcecombo
array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events

Events to add to select2 @param string $morecss Add more css classes to HTML select @param int[] $exclude Warehouses ids to exclude @param int<0,1> $showfullpath 1=Show full path of name (parent ref into label), 0=Show only ref of current warehouse @param string $orderBy [='e.ref'] Order by @return string HTML select

@throws Exception

$morecss
$exclude
$showfullpath
$orderBy

formSelectWarehouses($page, string|int $selected = '', $htmlname = 'warehouse_id', $addempty = 0)

Display form to select warehouse

@param string $page Page

Parameters

$page
string|int $selected

Id of warehouse @param string $htmlname Name of select html field @param int<0,2> $addempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. @return void

$htmlname
$addempty

select_measuring_units($name = 'measuring_units', string $measuring_style = '', $selected = '0', $adddefault = 0, $mode = 0)

Output a combo box with list of units Currently the units are not define in the DB

@param string $name Name of HTML field

Parameters

$name
string $measuring_style

Unit to show: weight, size, surface, volume, time @param string $selected Preselected value @param int $adddefault Add empty unit called "Default" @param int $mode 1=Use short label as value, 0=Use rowid @return void @deprecated

$selected
$adddefault
$mode

selectMeasuringUnits($name = 'measuring_units', string $measuring_style = '', $selected = '0', $adddefault = 0, $mode = 0, $morecss = 'minwidth75 maxwidth125')

Return a combo box with list of units Units labels are defined in llx_c_units

@param string $name Name of HTML field

Parameters

$name
string $measuring_style

Unit to show: weight, size, surface, volume, time @param int|string $selected Preselected value. Can be a numeric -3, 0, 3, ... 60, 3600, ... for time or a short label like 'm', 'm2', ... @param int|string $adddefault 1=Add empty unit called "Default", ''=Add empty value @param int<0,2> $mode 1=Use short label as value, 0=Use rowid, 2=Use scale (power) @param string $morecss More CSS @return string|int<-1,-1>

$selected
$adddefault
$mode
$morecss

selectProductNature($name = 'finished', string $selected = '', $mode = 0, $showempty = 1)

Return a combo box with list of units NAture of product labels are defined in llx_c_product_nature

@param string $name Name of HTML field

Parameters

$name
string $selected

Preselected value @param int $mode 1=Use label as value, 0=Use code @param int $showempty 1=show empty value, 0= no @return string|int

$mode
$showempty

selectLotStock($selected = '', string $htmlname = 'batch_id', $filterstatus = '', $empty = 0, $disabled = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array(), $empty_label = '', $forcecombo = 0, array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events = array(), $morecss = 'minwidth200')

Return list of lot numbers (stock from product_batch) with stock location and stock qty

@param string|int $selected Id of preselected lot stock id ('' for no value, 'ifone'=select value if one value otherwise no value)

Parameters

$selected
string $htmlname

Name of html select html @param string $filterstatus lot status filter, following comma separated filter options can be used @param int $empty 1=Can be empty, 0 if not @param int $disabled 1=Select is disabled @param int $fk_product show lot numbers of product with id fk_product. All from objectLines if 0. @param int $fk_entrepot filter lot numbers for warehouse with id fk_entrepot. All if 0. @param CommonObjectLine[] $objectLines Only cache lot numbers for products in lines of object. If no lines only for fk_product. If no fk_product, all. @param string $empty_label Empty label if needed (only if $empty=1) @param int $forcecombo 1=Force combo iso ajax select2

$filterstatus
$empty
$disabled
$fk_product
$fk_entrepot
$objectLines
$empty_label
$forcecombo
array<array{method: string, url: string, htmlname: string, params: array<string, string>}> $events

Events to add to select2 @param string $morecss Add more css classes to HTML select

@return string HTML select

$morecss

selectLotDataList($htmlname = 'batch_id', int $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array())

Return list of lot numbers (stock from product_batch) for product and warehouse.

@param string $htmlname Name of key that is inside attribute "list" of an input text field.

Parameters

$htmlname
int $empty

1=Can be empty, 0 if not @param int $fk_product show lot numbers of product with id fk_product. All from objectLines if 0. @param int $fk_entrepot filter lot numbers for warehouse with id fk_entrepot. All if 0. @param CommonObjectLine[] $objectLines Only cache lot numbers for products in lines of object. If no lines only for fk_product. If no fk_product, all. @return string HTML datalist

$fk_product
$fk_entrepot
$objectLines