27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
36 private $options_cache = array();
73 public function select_journal($selectid, $htmlname =
'journal', $nature = 0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss =
'maxwidth300 maxwidthonsmartphone', $usecache =
'', $disabledajaxcombo = 0)
81 if ($usecache && !empty($this->options_cache[$usecache]))
83 $options = $this->options_cache[$usecache];
84 $selected = $selectid;
86 $sql =
"SELECT rowid, code, label, nature, entity, active";
87 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_journal";
88 $sql .=
" WHERE active = 1";
89 $sql .=
" AND entity = ".$conf->entity;
90 if ($nature && is_numeric($nature)) $sql .=
" AND nature = ".$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))
106 $label = $obj->code.
' - '.$langs->trans($obj->label);
108 $select_value_in = $obj->rowid;
109 $select_value_out = $obj->rowid;
112 if ($select_in == 1) {
113 $select_value_in = $obj->code;
115 if ($select_out == 1) {
116 $select_value_out = $obj->code;
119 if ($selectid !=
'' && $selectid == $select_value_in) {
121 $selected = $select_value_out;
124 $options[$select_value_out] = $label;
130 $this->options_cache[$usecache] = $options;
134 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'', $morecss, ($disabledajaxcombo ? 0 : 1));
152 public function select_accounting_category($selected =
'', $htmlname =
'account_category', $useempty = 0, $maxlen = 0, $help = 1, $allcountries = 0)
155 global $db, $langs, $user, $mysoc;
157 if (empty($mysoc->country_id) && empty($mysoc->country_code) && empty($allcountries))
159 dol_print_error(
'',
'Call to select_accounting_account with mysoc country not yet defined');
163 if (!empty($mysoc->country_id))
165 $sql =
"SELECT c.rowid, c.label as type, c.range_account";
166 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_accounting_category as c";
167 $sql .=
" WHERE c.active = 1";
168 $sql .=
" AND c.category_type = 0";
169 if (empty($allcountries)) $sql .=
" AND c.fk_country = ".$mysoc->country_id;
170 $sql .=
" ORDER BY c.label ASC";
172 $sql =
"SELECT c.rowid, c.label as type, c.range_account";
173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_accounting_category as c, ".MAIN_DB_PREFIX.
"c_country as co";
174 $sql .=
" WHERE c.active = 1";
175 $sql .=
" AND c.category_type = 0";
176 $sql .=
" AND c.fk_country = co.rowid";
177 if (empty($allcountries)) $sql .=
" AND co.code = '".$this->db->escape($mysoc->country_code).
"'";
178 $sql .=
" ORDER BY c.label ASC";
181 dol_syslog(get_class($this).
'::'.__METHOD__, LOG_DEBUG);
188 $out =
'<select class="flat minwidth200" id="'.$htmlname.
'" name="'.$htmlname.
'">';
191 if ($useempty) $out .=
'<option value="0"> </option>';
194 $obj = $this->
db->fetch_object(
$resql);
195 $out .=
'<option value="'.$obj->rowid.
'"';
196 if ($obj->rowid == $selected) $out .=
' selected';
197 $out .=
'>'.($maxlen ?
dol_trunc($obj->type, $maxlen) : $obj->type);
198 $out .=
' ('.$obj->range_account.
')';
204 $out .= $langs->trans(
"ErrorNoAccountingCategoryForThisCountry", $mysoc->country_code);
228 $sql =
'SELECT DISTINCT import_key from '.MAIN_DB_PREFIX.
'accounting_bookkeeping';
229 $sql .=
" WHERE entity IN (".getEntity(
'accountancy').
")";
230 $sql .=
' ORDER BY import_key DESC';
232 dol_syslog(get_class($this).
"::select_bookkeeping_importkey", LOG_DEBUG);
236 $this->error =
"Error ".$this->db->lasterror();
237 dol_syslog(get_class($this).
"::select_bookkeeping_importkey ".$this->error, LOG_ERR);
241 while ($obj = $this->
db->fetch_object(
$resql)) {
242 $options[$obj->import_key] = $obj->import_key;
262 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss =
'minwidth100 maxwidth300 maxwidthonsmartphone', $usecache =
'')
265 global $conf, $langs;
267 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
275 $options[
'0'] =
'--- '.$langs->trans(
"None").
' ---';
278 if ($usecache && !empty($this->options_cache[$usecache]))
280 $options = $options + $this->options_cache[$usecache];
281 $selected = $selectid;
283 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT) ? 50 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT;
285 $sql =
"SELECT DISTINCT aa.account_number, aa.label, aa.labelshort, aa.rowid, aa.fk_pcg_version";
286 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa";
287 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
288 $sql .=
" AND asy.rowid = ".$conf->global->CHARTOFACCOUNTS;
289 $sql .=
" AND aa.active = 1";
290 $sql .=
" AND aa.entity=".$conf->entity;
291 $sql .=
" ORDER BY aa.account_number";
293 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
297 $this->error =
"Error ".$this->db->lasterror();
298 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
302 $num_rows = $this->
db->num_rows(
$resql);
304 if ($num_rows == 0) {
305 $langs->load(
"errors");
306 $showempty = $langs->trans(
"ErrorYouMustFirstSetupYourChartOfAccount");
308 $selected = $selectid;
309 while ($obj = $this->
db->fetch_object(
$resql)) {
310 if (empty($obj->labelshort))
312 $labeltoshow = $obj->label;
314 $labeltoshow = $obj->labelshort;
318 $label =
dol_trunc($label, $trunclength);
320 $select_value_in = $obj->rowid;
321 $select_value_out = $obj->rowid;
324 if ($select_in == 1) {
325 $select_value_in = $obj->account_number;
327 if ($select_out == 1) {
328 $select_value_out = $obj->account_number;
332 if ($selectid !=
'' && $selectid == $select_value_in) {
334 $selected = $select_value_out;
337 $options[$select_value_out] = $label;
345 $this->options_cache[$usecache] = $options;
346 unset($this->options_cache[$usecache][
'0']);
350 $out .=
Form::selectarray($htmlname, $options, $selected, ($showempty ? (is_numeric($showempty) ? 1 : $showempty): 0), 0, 0,
'', 0, 0, 0,
'', $morecss, 1);
365 public function select_auxaccount($selectid, $htmlname =
'account_num_aux', $showempty = 0, $morecss =
'maxwidth200')
369 $aux_account = array();
372 $sql =
"SELECT DISTINCT code_compta, nom ";
373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
374 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
375 $sql .=
" AND client IN (1 ,3)";
376 $sql .=
" ORDER BY code_compta";
378 dol_syslog(get_class($this).
"::select_auxaccount", LOG_DEBUG);
381 while ($obj = $this->
db->fetch_object(
$resql)) {
382 if (!empty($obj->code_compta)) {
383 $aux_account[$obj->code_compta] = $obj->code_compta.
' <span class="opacitymedium">('.$obj->nom.
')</span>';
387 $this->error =
"Error ".$this->db->lasterror();
388 dol_syslog(get_class($this).
"::select_auxaccount ".$this->error, LOG_ERR);
394 $sql =
"SELECT DISTINCT code_compta_fournisseur, nom ";
395 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
396 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
397 $sql .=
" AND fournisseur = 1";
398 $sql .=
" ORDER BY code_compta_fournisseur";
399 dol_syslog(get_class($this).
"::select_auxaccount", LOG_DEBUG);
402 while ($obj = $this->
db->fetch_object(
$resql)) {
403 if ($obj->code_compta_fournisseur !=
"") {
404 $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.
' <span class="opacitymedium">('.$obj->nom.
')</span>';
408 $this->error =
"Error ".$this->db->lasterror();
409 dol_syslog(get_class($this).
"::select_auxaccount ".$this->error, LOG_ERR);
415 $sql =
"SELECT DISTINCT accountancy_code, lastname, firstname ";
416 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user";
417 $sql .=
" WHERE entity IN (".getEntity(
'user').
")";
418 $sql .=
" ORDER BY accountancy_code";
419 dol_syslog(get_class($this).
"::select_auxaccount", LOG_DEBUG);
422 while ($obj = $this->
db->fetch_object(
$resql)) {
423 if (!empty($obj->accountancy_code)) {
424 $aux_account[$obj->accountancy_code] = $obj->accountancy_code.
' <span class="opacitymedium">('.
dolGetFirstLastname($obj->firstname, $obj->lastname).
')</span>';
428 $this->error =
"Error ".$this->db->lasterror();
429 dol_syslog(get_class($this).
"::select_auxaccount ".$this->error, LOG_ERR);
435 $out .=
Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0,
'', 0, 0, 0,
'', $morecss, 1);
455 $out_array = array();
457 $sql =
"SELECT DISTINCT date_format(doc_date, '%Y') as dtyear";
458 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping";
459 $sql .=
" WHERE entity IN (".getEntity(
'accountancy').
")";
460 $sql .=
" ORDER BY date_format(doc_date, '%Y')";
465 $this->error =
"Error ".$this->db->lasterror();
469 while ($obj = $this->
db->fetch_object(
$resql)) {
470 $out_array[$obj->dtyear] = $obj->dtyear;
474 if ($output_format ==
'html') {
475 return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0,
'placeholder="aa"');
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
$conf db
API class for accounts.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $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.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.