29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
40 private $options_cache = array();
59 public $nbaccounts_category;
87 public function select_journal($selectid, $htmlname =
'journal', $nature = 0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss =
'maxwidth300 maxwidthonsmartphone', $usecache =
'', $disabledajaxcombo = 0)
95 if ($usecache && !empty($this->options_cache[$usecache])) {
96 $options = $this->options_cache[$usecache];
97 $selected = $selectid;
99 $sql =
"SELECT rowid, code, label, nature, entity, active";
100 $sql .=
" FROM ".$this->db->prefix().
"accounting_journal";
101 $sql .=
" WHERE active = 1";
102 $sql .=
" AND entity = ".((int)
$conf->entity);
103 if ($nature && is_numeric($nature)) {
104 $sql .=
" AND nature = ".((int) $nature);
106 $sql .=
" ORDER BY code";
108 dol_syslog(get_class($this).
"::select_journal", LOG_DEBUG);
109 $resql = $this->db->query($sql);
112 $this->error =
"Error ".$this->db->lasterror();
113 dol_syslog(get_class($this).
"::select_journal ".$this->error, LOG_ERR);
118 $langs->load(
'accountancy');
119 while ($obj = $this->db->fetch_object($resql)) {
120 $label = $obj->code.
' - '.$langs->trans($obj->label);
122 $select_value_in = $obj->rowid;
123 $select_value_out = $obj->rowid;
126 if ($select_in == 1) {
127 $select_value_in = $obj->code;
129 if ($select_out == 1) {
130 $select_value_out = $obj->code;
133 if ($selectid !=
'' && $selectid == $select_value_in) {
135 $selected = $select_value_out;
138 $options[$select_value_out] = $label;
140 $this->db->free($resql);
143 $this->options_cache[$usecache] = $options;
147 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'', $morecss, ($disabledajaxcombo ? 0 : 1));
167 public function multi_select_journal($selectedIds = array(), $htmlname =
'journal', $nature = 0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss =
'', $usecache =
'', $disabledajaxcombo = 0)
170 global
$conf, $langs;
175 if ($usecache && !empty($this->options_cache[$usecache])) {
176 $options = $this->options_cache[$usecache];
177 $selected = $selectedIds;
179 $sql =
"SELECT rowid, code, label, nature, entity, active";
180 $sql .=
" FROM ".$this->db->prefix().
"accounting_journal";
181 $sql .=
" WHERE active = 1";
182 $sql .=
" AND entity = ".$conf->entity;
183 if ($nature && is_numeric($nature)) {
184 $sql .=
" AND nature = ".((int) $nature);
186 $sql .=
" ORDER BY code";
188 dol_syslog(get_class($this).
"::multi_select_journal", LOG_DEBUG);
189 $resql = $this->db->query($sql);
192 $this->error =
"Error ".$this->db->lasterror();
193 dol_syslog(get_class($this).
"::multi_select_journal ".$this->error, LOG_ERR);
198 $langs->load(
'accountancy');
199 while ($obj = $this->db->fetch_object($resql)) {
201 $translatedLabel = $langs->trans($obj->label);
202 if (empty($translatedLabel) || $translatedLabel === $obj->label) {
203 $translatedLabel = $obj->label;
205 $label = $obj->code .
' - ' . $translatedLabel;
207 $select_value_in = ($select_in == 1 ? $obj->code : $obj->rowid);
208 $select_value_out = ($select_out == 1 ? $obj->code : $obj->rowid);
211 if (!empty($selectedIds) && in_array($select_value_in, $selectedIds)) {
212 $selected[] = $select_value_out;
214 $options[$select_value_out] = $label;
216 $this->db->free($resql);
219 $this->options_cache[$usecache] = $options;
223 $out .=
Form::multiselectarray($htmlname, $options, $selected, 0, 0, $morecss, 0, 0,
'',
'code_journal',
'', ($disabledajaxcombo ? 0 : 1));
241 public function select_accounting_category($selected = 0, $htmlname =
'account_category', $useempty = 0, $maxlen = 0, $help = 1, $allcountries = 0)
246 if (empty(
$mysoc->country_id) && empty(
$mysoc->country_code) && empty($allcountries)) {
247 dol_print_error(
null,
'Call to select_accounting_account with mysoc country not yet defined');
253 if (!empty(
$mysoc->country_id)) {
254 $sql =
"SELECT c.rowid, c.label as type, c.range_account";
255 $sql .=
" FROM ".$this->db->prefix().
"c_accounting_category as c";
256 $sql .=
" WHERE c.active = 1";
257 $sql .=
" AND c.category_type = 0";
258 if (empty($allcountries)) {
259 $sql .=
" AND c.fk_country = ".((int)
$mysoc->country_id);
261 $sql .=
" ORDER BY c.label ASC";
263 $sql =
"SELECT c.rowid, c.label as type, c.range_account";
264 $sql .=
" FROM ".$this->db->prefix().
"c_accounting_category as c, ".$this->db->prefix().
"c_country as co";
265 $sql .=
" WHERE c.active = 1";
266 $sql .=
" AND c.category_type = 0";
267 $sql .=
" AND c.fk_country = co.rowid";
268 if (empty($allcountries)) {
269 $sql .=
" AND co.code = '".$this->db->escape(
$mysoc->country_code).
"'";
271 $sql .=
" ORDER BY c.label ASC";
274 $this->nbaccounts_category = 0;
276 dol_syslog(get_class($this).
'::'.__METHOD__, LOG_DEBUG);
277 $resql = $this->db->query($sql);
279 $num = $this->db->num_rows($resql);
281 $this->nbaccounts_category = $num;
283 $out .=
'<select class="flat minwidth200" id="'.$htmlname.
'" name="'.$htmlname.
'">';
287 $out .=
'<option value="0"> </option>';
290 $obj = $this->db->fetch_object($resql);
292 $titletoshowhtml = ($maxlen ?
dol_trunc($obj->type, $maxlen) : $obj->type).($obj->range_account ?
' <span class="opacitymedium">('.$obj->range_account.
')</span>' :
'');
293 $titletoshow = ($maxlen ?
dol_trunc($obj->type, $maxlen) : $obj->type).($obj->range_account ?
' ('.$obj->range_account.
')' :
'');
295 $out .=
'<option value="'.$obj->rowid.
'"';
296 if ($obj->rowid == $selected) {
300 $out .=
' data-html="'.dolPrintHTMLForAttribute($titletoshowhtml).
'"';
311 $out .=
'<span class="opacitymedium">'.$langs->trans(
"ErrorNoAccountingCategoryForThisCountry",
$mysoc->country_code, $langs->transnoentitiesnoconv(
"Accounting"), $langs->transnoentitiesnoconv(
"Setup"), $langs->transnoentitiesnoconv(
"AccountingCategories")).
'</span>';
333 $sql =
"SELECT DISTINCT import_key FROM ".$this->db->prefix().
"accounting_bookkeeping";
334 $sql .=
" WHERE entity IN (".getEntity(
'accountancy').
")";
335 $sql .=
' ORDER BY import_key DESC';
337 dol_syslog(get_class($this).
"::select_bookkeeping_importkey", LOG_DEBUG);
338 $resql = $this->db->query($sql);
341 $this->error =
"Error ".$this->db->lasterror();
342 dol_syslog(get_class($this).
"::select_bookkeeping_importkey ".$this->error, LOG_ERR);
346 while ($obj = $this->db->fetch_object($resql)) {
347 $options[$obj->import_key] = $obj->import_key;
369 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss =
'minwidth100 maxwidth300 maxwidthonsmartphone', $usecache =
'', $active =
'1', $centralized = 0)
371 global
$conf, $langs;
372 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
378 $selectid = (
string) $selectid;
380 if ($showempty == 2) {
381 $options[
'0'] =
'--- '.$langs->trans(
"None").
' ---';
384 if ($usecache && !empty($this->options_cache[$usecache])) {
385 $options += $this->options_cache[$usecache];
386 $selected = (
string) $selectid;
388 $trunclength =
getDolGlobalInt(
'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT', 50);
391 $sql =
"SELECT DISTINCT aa.account_number, aa.label, aa.labelshort, aa.rowid, aa.fk_pcg_version, aa.centralized";
392 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa";
393 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
394 $sql .=
" AND asy.rowid = ".((int)
getDolGlobalInt(
'CHARTOFACCOUNTS'));
396 if ($active ===
'1') {
397 $sql .=
" AND aa.active = 1";
398 } elseif ($active ===
'0') {
399 $sql .=
" AND aa.active = 0";
402 if ($centralized == 1) {
403 $sql .=
" AND aa.centralized = 1";
406 $sql .=
" AND aa.entity=".((int)
$conf->entity);
409 if ($centralized == 2) {
410 $sql .=
" ORDER BY aa.centralized DESC, aa.account_number";
412 $sql .=
" ORDER BY aa.account_number";
415 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
416 $resql = $this->db->query($sql);
419 $this->error =
"Error ".$this->db->lasterror();
420 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
424 $num_rows = $this->db->num_rows($resql);
427 $langs->load(
"errors");
428 $showempty = $langs->trans(
"ErrorYouMustFirstSetupYourChartOfAccount");
429 } elseif ($num_rows == 0) {
430 $langs->load(
"errors");
431 $showempty = $langs->trans(
"ErrorYouMustFirstSetupYourChartOfAccount");
433 $selected = $selectid;
434 $lastCentralized =
null;
436 while ($obj = $this->db->fetch_object($resql)) {
438 if ($centralized == 2 && $lastCentralized !==
null && $lastCentralized != $obj->centralized) {
439 $options[
'0'] =
'-------------';
442 $lastCentralized = $obj->centralized;
444 $labeltoshow = !empty($obj->labelshort) ? $obj->labelshort : $obj->label;
446 $label =
dol_trunc($label, $trunclength);
448 $select_value_in = $obj->rowid;
449 $select_value_out = $obj->rowid;
451 if ($select_in == 1) {
452 $select_value_in = $obj->account_number;
454 if ($select_out == 1) {
455 $select_value_out = $obj->account_number;
458 if ($selectid !=
'' && $selectid == (
string) $select_value_in) {
459 $selected = (
string) $select_value_out;
462 $options[$select_value_out] = array(
464 'data-centralized' => $obj->centralized ? 1 : 0
469 $this->db->free($resql);
472 $this->options_cache[$usecache] = $options;
473 unset($this->options_cache[$usecache][
'0']);
477 $out .=
Form::selectarray($htmlname, $options, $selected, ($showempty ? (is_numeric($showempty) ? 1 : $showempty) : 0), 0, 0,
'', 0, 0, 0,
'', $morecss, 1);
478 $this->nbaccounts = count($options) - ($showempty == 2 ? 1 : 0);
502 public function select_auxaccount($selectid, $htmlname =
'account_num_aux', $showempty = 0, $morecss =
'minwidth100 maxwidth300 maxwidthonsmartphone', $usecache =
'', $labelhtmlname =
'', $selected_input_value =
'')
505 global
$conf, $langs;
508 $auxaccount_mode =
getDolGlobalInt(
'ACCOUNTANCY_AUXACCOUNT_USE_SEARCH_TO_SELECT', 0);
509 $placeholder = (!empty($showempty) && !is_numeric($showempty)) ? $showempty : $langs->trans(
"SubledgerAccount");
512 if ($auxaccount_mode == 0) {
513 $out .=
'<input type="text" class="'.$morecss.
'" name="'.$htmlname.
'" id="'.$htmlname.
'" value="'.
dol_escape_htmltag($selectid).
'" placeholder="'.
dol_escape_htmltag($placeholder).
'" />';
519 if (!empty(
$conf->use_javascript_ajax) && $auxaccount_mode >= 2) {
520 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
522 $minLength = $auxaccount_mode - 1;
523 $urloption =
'htmlname='.urlencode($htmlname).
'&outjson=1';
526 if ($selectid && empty($selected_input_value)) {
528 $sql =
"SELECT nom AS name FROM ".$this->db->prefix().
"societe";
529 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
530 $sql .=
" AND (code_compta = '".$this->db->escape($selectid).
"'";
531 $sql .=
" OR code_compta_fournisseur = '".$this->db->escape($selectid).
"')";
532 $sql .= $this->db->plimit(1, 0);
533 $resql = $this->db->query($sql);
534 if ($resql && ($obj = $this->db->fetch_object($resql))) {
535 $selected_input_value = $selectid.
' ('.$obj->name.
')';
536 $this->db->free($resql);
539 $sql2 =
"SELECT lastname, firstname FROM ".$this->db->prefix().
"user";
540 $sql2 .=
" WHERE entity IN (".getEntity(
'user').
")";
541 $sql2 .=
" AND accountancy_code = '".$this->db->escape($selectid).
"'";
542 $sql2 .= $this->db->plimit(1, 0);
543 $resql2 = $this->db->query($sql2);
544 if ($resql2 && ($obj2 = $this->db->fetch_object($resql2))) {
545 $selected_input_value = $selectid.
' ('.
dolGetFirstLastname($obj2->firstname, $obj2->lastname).
')';
546 $this->db->free($resql2);
548 $selected_input_value = $selectid;
554 $out .=
'<input type="text" class="'.$morecss.
'" name="search_'.$htmlname.
'" id="search_'.$htmlname.
'" value="'.
dol_escape_htmltag($selected_input_value).
'" placeholder="'.
dol_escape_htmltag($placeholder).
'" />';
558 $ajaxoptions = array();
559 if (!empty($labelhtmlname)) {
560 $ajaxoptions[
'update'] = array($labelhtmlname =>
'label_name');
564 $out .=
ajax_autocompleter($selectid, $htmlname, DOL_URL_ROOT.
'/core/ajax/auxaccount.php', $urloption, $minLength, 0, $ajaxoptions);
570 $aux_account = array();
572 if ($usecache && !empty($this->options_cache[$usecache])) {
573 $aux_account += $this->options_cache[$usecache];
575 dol_syslog(get_class($this).
"::select_auxaccount", LOG_DEBUG);
578 $sql =
"SELECT code_compta as code_compta_client, code_compta_fournisseur, nom as name";
579 $sql .=
" FROM ".$this->db->prefix().
"societe";
580 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
581 $sql .=
" AND (client IN (1,3) OR fournisseur = 1)";
583 $resql = $this->db->query($sql);
585 while ($obj = $this->db->fetch_object($resql)) {
586 if (!empty($obj->code_compta_client)) {
587 $aux_account[$obj->code_compta_client] = $obj->code_compta_client.
' <span class="opacitymedium">('.$obj->name.
')</span>';
589 if (!empty($obj->code_compta_fournisseur)) {
590 $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.
' <span class="opacitymedium">('.$obj->name.
')</span>';
594 $this->error =
"Error ".$this->db->lasterror();
595 dol_syslog(get_class($this).
"::select_auxaccount ".$this->error, LOG_ERR);
598 $this->db->free($resql);
601 $sql =
"SELECT DISTINCT accountancy_code, lastname, firstname";
602 $sql .=
" FROM ".$this->db->prefix().
"user";
603 $sql .=
" WHERE entity IN (".getEntity(
'user').
")";
604 $sql .=
" ORDER BY accountancy_code";
606 $resql = $this->db->query($sql);
608 while ($obj = $this->db->fetch_object($resql)) {
609 if (!empty($obj->accountancy_code)) {
610 $aux_account[$obj->accountancy_code] = $obj->accountancy_code.
' <span class="opacitymedium">('.
dolGetFirstLastname($obj->firstname, $obj->lastname).
')</span>';
614 $this->error =
"Error ".$this->db->lasterror();
615 dol_syslog(get_class($this).
"::select_auxaccount ".$this->error, LOG_ERR);
618 $this->db->free($resql);
623 $this->options_cache[$usecache] = $aux_account;
628 $out .=
Form::selectarray($htmlname, $aux_account, $selectid, $placeholder, 0, 0,
'', 0, 0, 0,
'', $morecss, 1);
631 if (!empty(
$conf->use_javascript_ajax) && !empty($labelhtmlname)) {
632 $out .=
'<script nonce="'.getNonce().
'">
633 jQuery(document).ready(() => {
634 $("#'.
dol_escape_js($htmlname).
'").on("select2:select", function(e) {
635 var match = /\(([^)]+)\)/.exec(e.params.data.text);
636 if (match) { $("input[name=\"'.
dol_escape_js($labelhtmlname).
'\"]").val(match[1]); }
660 $out_array = array();
662 $sql =
"SELECT DISTINCT date_format(doc_date, '%Y') as dtyear";
663 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
664 $sql .=
" WHERE entity IN (".getEntity(
'accountancy').
")";
665 $sql .=
" ORDER BY date_format(doc_date, '%Y')";
667 $resql = $this->db->query($sql);
670 $this->error =
"Error ".$this->db->lasterror();
674 while ($obj = $this->db->fetch_object($resql)) {
675 $out_array[$obj->dtyear] = $obj->dtyear;
677 $this->db->free($resql);
679 if ($output_format ==
'html') {
680 return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0,
'placeholder="aa"');
698 public function formAccountingAccount($page, $selected =
'', $htmlname =
'none', $option = 0, $useempty = 1, $filter =
'', $nooutput = 0)
703 if ($htmlname !=
"none") {
704 $out .=
'<form method="post" action="' . $page .
'">';
705 $out .=
'<input type="hidden" name="action" value="set'.$htmlname.
'">';
706 $out .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
708 $out .= $this->
select_account($selected, $htmlname, $useempty, array(), 1, 1,
'minwidth100 maxwidth300 maxwidthonsmartphone',
'accounts', $filter);
710 $out .= $this->
select_auxaccount($selected, $htmlname, $useempty,
'minwidth100 maxwidth300 maxwidthonsmartphone',
'subaccounts');
712 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" name="modify" value="' . $langs->trans(
"Modify") .
'">';
738 public static function printJournalLine($langs, $date, $ref, $accountAccounting, $labelOperation, $paymentMode, $amount)
740 $out =
'<tr class="oddeven">';
741 $out .=
'<td>'.$date.
'</td>';
742 $out .=
'<td>'.$ref.
'</td>';
746 if (empty($accounttoshow) || $accounttoshow ==
'NotDefined') {
748 $out .=
'<span class="error">'.$langs->trans(
'AccountNotDefined').
'</span>';
750 $out .= $accounttoshow;
753 $out .=
'<td>'.$labelOperation.
'</td>';
754 $out .=
'<td class="center">'.$paymentMode.
'</td>';
755 $out .=
'<td class="nowraponall right amount">'.($amount >= 0 ?
price($amount) :
'').
'</td>';
756 $out .=
'<td class="nowraponall right amount">'.($amount < 0 ?
price(-$amount) :
'').
'</td>';
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to transform a common input text or select field into ...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php