24require_once DOL_DOCUMENT_ROOT .
'/core/class/fields/commonfield.class.php';
35 public $emptyValues = array(
'');
50 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
52 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
53 $htmlName = $keyPrefix . $key . $keySuffix;
55 $value = $tmp[
'price'];
56 $currency = $tmp[
'currency'];
59 $aliasPrice = $tmp[
'aliasPrice'];
60 $fieldPrice = $tmp[
'fieldPrice'];
61 $aliasCurrency = $tmp[
'aliasCurrency'];
62 $fieldCurrency = $tmp[
'fieldCurrency'];
64 $out = self::$form->inputType(
'text', $htmlName, (
string) $value, $htmlName, $moreCss, $moreAttrib);
65 if (!empty($fieldCurrency)) {
66 $out .= self::$form->selectCurrency($currency, $htmlName .
'currency_id');
84 public function printInputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
86 $moreCss = $this->
getInputCss($fieldInfos, $moreCss);
87 $autoFocus = $fieldInfos->inputAutofocus ?
' autofocus' :
'';
88 $htmlName = $keyPrefix . $key . $keySuffix;
90 $value = $tmp[
'price'];
91 $currency = $tmp[
'currency'];
94 $out = self::$form->inputType(
'text', $htmlName, (
string) $value, $htmlName, $moreCss, $moreAttrib . $autoFocus);
95 $out .= self::$form->selectCurrency($currency, $htmlName .
'currency_id');
97 return '<span class="form-select-price-currency-container">'.$out.
'</span>';
112 public function printOutputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
116 $value = $tmp[
'price'];
117 $currency = $tmp[
'currency'];
131 public function getInputCss($fieldInfos, $moreCss =
'', $defaultCss =
'')
133 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss :
'maxwidth75');
147 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
148 if ($result && !$this->
isEmptyValue($fieldInfos, $value)) {
150 $value = $tmp[
'price'];
151 $currency = $tmp[
'currency'];
152 if (!self::$validator->isNumeric($value)) {
174 $htmlName = $keyPrefix . $key . $keySuffix;
175 $value =
GETPOST($htmlName,
'restricthtml') .
':' .
GETPOST($htmlName .
"currency_id",
'restricthtml');
176 $value = str_replace(
',',
'.', $value);
192 public function getPostFieldValue($fieldInfos, $key, $defaultValue =
null, $keyPrefix =
'', $keySuffix =
'')
194 $htmlName = $keyPrefix . $key . $keySuffix;
196 if (GETPOSTISSET($htmlName)) {
199 $value = $defaultValue;
218 $htmlName = $keyPrefix . $key . $keySuffix;
220 if (GETPOSTISSET($htmlName)) {
222 'value' =>
GETPOST($htmlName,
'alphanohtml'),
223 'currency' =>
GETPOST($htmlName .
"currency_id",
'alpha'),
226 $value = $defaultValue;
243 $filterValue = $value[
'value'] ??
'';
244 $filterCurrency = $value[
'currency'] ??
'';
245 if ($filterCurrency ==
'-1') $filterCurrency =
'';
248 $aliasPrice = $tmp[
'aliasPrice'];
249 $fieldPrice = $tmp[
'fieldPrice'];
250 $aliasCurrency = $tmp[
'aliasCurrency'];
251 $fieldCurrency = $tmp[
'fieldCurrency'];
253 if (!empty($filterValue)) {
254 return natural_search($aliasPrice . $fieldPrice, $filterValue, 1);
256 if (!empty($filterCurrency) && !empty($fieldCurrency)) {
257 return natural_search($aliasCurrency . $fieldCurrency, $filterCurrency, 0);
276 $currency =
$conf->currency;
279 $tmp = explode(
':', $value);
280 $price = $this->
isEmptyValue($fieldInfos, $tmp[0] ??
'') ?
'' : $tmp[0];
281 $currency = !empty($tmp[1]) ? $tmp[1] :
$conf->currency;
285 'price' => (
float) $price,
286 'currency' => $currency
299 $alias = $fieldInfos->sqlAlias ??
't.';
300 $tmp = explode(
':', $alias);
301 $aliasPrice = $tmp[0] ??
'';
302 $aliasCurrency = $tmp[1] ??
'';
304 $field = $fieldInfos->nameInTable ?? $key;
305 $tmp = explode(
':', $field);
306 $fieldPrice = $tmp[0] ??
'';
307 $fieldCurrency = $tmp[1] ??
'';
310 'aliasPrice' => trim($aliasPrice),
311 'aliasCurrency' => trim($aliasCurrency),
312 'fieldPrice' => trim($fieldPrice),
313 'fieldCurrency' => trim($fieldCurrency),
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to pricecy field (price with currency)
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
getPriceAndCurrencyFromValue($fieldInfos, $value)
Get price and currency from value.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
getPriceAndCurrencyAliasAndField($fieldInfos, $key)
Get alias and field name in table for price and currency.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.