27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
35 private $options_cache = array();
72 public function select_journal($selectid, $htmlname =
'journal', $nature = 0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss =
'maxwidth300 maxwidthonsmartphone', $usecache =
'', $disabledajaxcombo = 0)
80 if ($usecache && !empty($this->options_cache[$usecache])) {
81 $options = $this->options_cache[$usecache];
82 $selected = $selectid;
84 $sql =
"SELECT rowid, code, label, nature, entity, active";
85 $sql .=
" FROM ".$this->db->prefix().
"accounting_journal";
86 $sql .=
" WHERE active = 1";
87 $sql .=
" AND entity = ".$conf->entity;
88 if ($nature && is_numeric($nature)) {
89 $sql .=
" AND nature = ".((int) $nature);
91 $sql .=
" ORDER BY code";
93 dol_syslog(get_class($this).
"::select_journal", LOG_DEBUG);
97 $this->error =
"Error ".$this->db->lasterror();
98 dol_syslog(get_class($this).
"::select_journal ".$this->error, LOG_ERR);
103 $langs->load(
'accountancy');
104 while ($obj = $this->
db->fetch_object(
$resql)) {
105 $label = $obj->code.
' - '.$langs->trans($obj->label);
107 $select_value_in = $obj->rowid;
108 $select_value_out = $obj->rowid;
111 if ($select_in == 1) {
112 $select_value_in = $obj->code;
114 if ($select_out == 1) {
115 $select_value_out = $obj->code;
118 if ($selectid !=
'' && $selectid == $select_value_in) {
120 $selected = $select_value_out;
123 $options[$select_value_out] = $label;
128 $this->options_cache[$usecache] = $options;
132 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'', $morecss, ($disabledajaxcombo ? 0 : 1));
152 public function multi_select_journal($selectedIds = array(), $htmlname =
'journal', $nature = 0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss =
'', $usecache =
'', $disabledajaxcombo = 0)
155 global $conf, $langs;
160 if ($usecache && !empty($this->options_cache[$usecache])) {
161 $options = $this->options_cache[$usecache];
162 $selected = $selectedIds;
164 $sql =
"SELECT rowid, code, label, nature, entity, active";
165 $sql .=
" FROM ".$this->db->prefix().
"accounting_journal";
166 $sql .=
" WHERE active = 1";
167 $sql .=
" AND entity = ".$conf->entity;
168 if ($nature && is_numeric($nature)) {
169 $sql .=
" AND nature = ".((int) $nature);
171 $sql .=
" ORDER BY code";
173 dol_syslog(get_class($this).
"::multi_select_journal", LOG_DEBUG);
177 $this->error =
"Error ".$this->db->lasterror();
178 dol_syslog(get_class($this).
"::multi_select_journal ".$this->error, LOG_ERR);
183 $langs->load(
'accountancy');
184 while ($obj = $this->
db->fetch_object(
$resql)) {
185 $label = $langs->trans($obj->label);
187 $select_value_in = $obj->rowid;
188 $select_value_out = $obj->rowid;
191 if ($select_in == 1) {
192 $select_value_in = $obj->code;
194 if ($select_out == 1) {
195 $select_value_out = $obj->code;
198 if (!empty($selectedIds) && in_array($select_value_in, $selectedIds)) {
200 $selected[] = $select_value_out;
202 $options[$select_value_out] = $label;
207 $this->options_cache[$usecache] = $options;
211 $out .=
Form::multiselectarray($htmlname, $options, $selected, $showempty, 0, $morecss, 0, 0, 0,
'code_journal',
'', ($disabledajaxcombo ? 0 : 1));
229 public function select_accounting_category($selected =
'', $htmlname =
'account_category', $useempty = 0, $maxlen = 0, $help = 1, $allcountries = 0)
232 global $db, $langs, $user, $mysoc;
234 if (empty($mysoc->country_id) && empty($mysoc->country_code) && empty($allcountries)) {
235 dol_print_error(
'',
'Call to select_accounting_account with mysoc country not yet defined');
239 if (!empty($mysoc->country_id)) {
240 $sql =
"SELECT c.rowid, c.label as type, c.range_account";
241 $sql .=
" FROM ".$this->db->prefix().
"c_accounting_category as c";
242 $sql .=
" WHERE c.active = 1";
243 $sql .=
" AND c.category_type = 0";
244 if (empty($allcountries)) {
245 $sql .=
" AND c.fk_country = ".((int) $mysoc->country_id);
247 $sql .=
" ORDER BY c.label ASC";
249 $sql =
"SELECT c.rowid, c.label as type, c.range_account";
250 $sql .=
" FROM ".$this->db->prefix().
"c_accounting_category as c, ".$this->
db->prefix().
"c_country as co";
251 $sql .=
" WHERE c.active = 1";
252 $sql .=
" AND c.category_type = 0";
253 $sql .=
" AND c.fk_country = co.rowid";
254 if (empty($allcountries)) {
255 $sql .=
" AND co.code = '".$this->db->escape($mysoc->country_code).
"'";
257 $sql .=
" ORDER BY c.label ASC";
260 dol_syslog(get_class($this).
'::'.__METHOD__, LOG_DEBUG);
265 $out =
'<select class="flat minwidth200" id="'.$htmlname.
'" name="'.$htmlname.
'">';
269 $out .=
'<option value="0"> </option>';
272 $obj = $this->
db->fetch_object(
$resql);
274 $titletoshowhtml = ($maxlen ?
dol_trunc($obj->type, $maxlen) : $obj->type).($obj->range_account ?
' <span class="opacitymedium">('.$obj->range_account.
')</span>' :
'');
275 $titletoshow = ($maxlen ?
dol_trunc($obj->type, $maxlen) : $obj->type).($obj->range_account ?
' ('.$obj->range_account.
')' :
'');
277 $out .=
'<option value="'.$obj->rowid.
'"';
278 if ($obj->rowid == $selected) {
290 $out = $langs->trans(
"ErrorNoAccountingCategoryForThisCountry", $mysoc->country_code);
314 $sql =
"SELECT DISTINCT import_key FROM ".$this->db->prefix().
"accounting_bookkeeping";
315 $sql .=
" WHERE entity IN (".getEntity(
'accountancy').
")";
316 $sql .=
' ORDER BY import_key DESC';
318 dol_syslog(get_class($this).
"::select_bookkeeping_importkey", LOG_DEBUG);
322 $this->error =
"Error ".$this->db->lasterror();
323 dol_syslog(get_class($this).
"::select_bookkeeping_importkey ".$this->error, LOG_ERR);
327 while ($obj = $this->
db->fetch_object(
$resql)) {
328 $options[$obj->import_key] = $obj->import_key;
349 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss =
'minwidth100 maxwidth300 maxwidthonsmartphone', $usecache =
'', $active =
'1')
352 global $conf, $langs;
354 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
360 if ($showempty == 2) {
361 $options[
'0'] =
'--- '.$langs->trans(
"None").
' ---';
364 if ($usecache && !empty($this->options_cache[$usecache])) {
365 $options = $options + $this->options_cache[$usecache];
366 $selected = $selectid;
368 $trunclength =
getDolGlobalInt(
'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT', 50);
370 $sql =
"SELECT DISTINCT aa.account_number, aa.label, aa.labelshort, aa.rowid, aa.fk_pcg_version";
371 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa";
372 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
373 $sql .=
" AND asy.rowid = ".((int) $conf->global->CHARTOFACCOUNTS);
374 if ($active ===
'1') {
375 $sql .=
" AND aa.active = 1";
376 } elseif ($active ===
'0') {
377 $sql .=
" AND aa.active = 0";
379 $sql .=
" AND aa.entity=".((int) $conf->entity);
380 $sql .=
" ORDER BY aa.account_number";
382 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
386 $this->error =
"Error ".$this->db->lasterror();
387 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
391 $num_rows = $this->
db->num_rows(
$resql);
393 if ($num_rows == 0 && (empty($conf->global->CHARTOFACCOUNTS) || $conf->global->CHARTOFACCOUNTS < 0)) {
394 $langs->load(
"errors");
395 $showempty = $langs->trans(
"ErrorYouMustFirstSetupYourChartOfAccount");
397 $selected = $selectid;
398 while ($obj = $this->
db->fetch_object(
$resql)) {
399 if (empty($obj->labelshort)) {
400 $labeltoshow = $obj->label;
402 $labeltoshow = $obj->labelshort;
406 $label =
dol_trunc($label, $trunclength);
408 $select_value_in = $obj->rowid;
409 $select_value_out = $obj->rowid;
412 if ($select_in == 1) {
413 $select_value_in = $obj->account_number;
415 if ($select_out == 1) {
416 $select_value_out = $obj->account_number;
420 if ($selectid !=
'' && $selectid == $select_value_in) {
422 $selected = $select_value_out;
425 $options[$select_value_out] = $label;
432 $this->options_cache[$usecache] = $options;
433 unset($this->options_cache[$usecache][
'0']);
437 $out .=
Form::selectarray($htmlname, $options, $selected, ($showempty ? (is_numeric($showempty) ? 1 : $showempty): 0), 0, 0,
'', 0, 0, 0,
'', $morecss, 1);
454 public function select_auxaccount($selectid, $htmlname =
'account_num_aux', $showempty = 0, $morecss =
'maxwidth250', $usecache =
'', $labelhtmlname =
'')
458 $aux_account = array();
460 if ($usecache && !empty($this->options_cache[$usecache])) {
461 $aux_account = $aux_account + $this->options_cache[$usecache];
463 dol_syslog(get_class($this).
"::select_auxaccount", LOG_DEBUG);
466 $sql =
"SELECT code_compta, code_compta_fournisseur, nom as name";
467 $sql .=
" FROM ".$this->db->prefix().
"societe";
468 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
469 $sql .=
" AND (client IN (1,3) OR fournisseur = 1)";
473 while ($obj = $this->
db->fetch_object(
$resql)) {
474 if (!empty($obj->code_compta)) {
475 $aux_account[$obj->code_compta] = $obj->code_compta.
' <span class="opacitymedium">('.$obj->name.
')</span>';
477 if (!empty($obj->code_compta_fournisseur)) {
478 $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.
' <span class="opacitymedium">('.$obj->name.
')</span>';
482 $this->error =
"Error ".$this->db->lasterror();
483 dol_syslog(get_class($this).
"::select_auxaccount ".$this->error, LOG_ERR);
492 $sql =
"SELECT DISTINCT accountancy_code, lastname, firstname ";
493 $sql .=
" FROM ".$this->db->prefix().
"user";
494 $sql .=
" WHERE entity IN (".getEntity(
'user').
")";
495 $sql .=
" ORDER BY accountancy_code";
499 while ($obj = $this->
db->fetch_object(
$resql)) {
500 if (!empty($obj->accountancy_code)) {
501 $aux_account[$obj->accountancy_code] = $obj->accountancy_code.
' <span class="opacitymedium">('.
dolGetFirstLastname($obj->firstname, $obj->lastname).
')</span>';
505 $this->error =
"Error ".$this->db->lasterror();
506 dol_syslog(get_class($this).
"::select_auxaccount ".$this->error, LOG_ERR);
512 $this->options_cache[$usecache] = $aux_account;
518 $out .=
Form::selectarray($htmlname, $aux_account, $selectid, ($showempty ? (is_numeric($showempty) ? 1 : $showempty): 0), 0, 0,
'', 0, 0, 0,
'', $morecss, 1);
520 if (!empty($conf->use_javascript_ajax) && !empty($labelhtmlname)) {
522 jQuery(document).ready(() => {
523 $("#'.$htmlname.
'").on("select2:select", function(e) {
524 var regExp = /\(([^)]+)\)/;
525 const match = regExp.exec(e.params.data.text);
526 $(\'input[name="'.
dol_escape_js($labelhtmlname).
'"]\').val(match[1]);
551 $out_array = array();
553 $sql =
"SELECT DISTINCT date_format(doc_date, '%Y') as dtyear";
554 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
555 $sql .=
" WHERE entity IN (".getEntity(
'accountancy').
")";
556 $sql .=
" ORDER BY date_format(doc_date, '%Y')";
561 $this->error =
"Error ".$this->db->lasterror();
565 while ($obj = $this->
db->fetch_object(
$resql)) {
566 $out_array[$obj->dtyear] = $obj->dtyear;
570 if ($output_format ==
'html') {
571 return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0,
'placeholder="aa"');
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array())
Clean a string to keep only desirable HTML tags.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.