dolibarr  16.0.5
html.formsocialcontrib.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
29 {
33  public $db;
34 
38  public $error = '';
39 
40 
46  public function __construct($db)
47  {
48  $this->db = $db;
49  }
50 
51  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
65  public function select_type_socialcontrib($selected = '', $htmlname = 'actioncode', $useempty = 0, $maxlen = 40, $help = 1, $morecss = 'minwidth300', $noerrorifempty = 0)
66  {
67  // phpcs:enable
68  global $conf, $db, $langs, $user, $mysoc;
69 
70  if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
71  print $langs->trans("ErrorSetupOfCountryMustBeDone");
72  return;
73  }
74 
75  if (!empty($mysoc->country_id)) {
76  $sql = "SELECT c.id, c.libelle as type";
77  $sql .= " FROM ".$this->db->prefix()."c_chargesociales as c";
78  $sql .= " WHERE c.active = 1";
79  $sql .= " AND c.fk_pays = ".((int) $mysoc->country_id);
80  $sql .= " ORDER BY c.libelle ASC";
81  } else {
82  $sql = "SELECT c.id, c.libelle as type";
83  $sql .= " FROM ".$this->db->prefix()."c_chargesociales as c, ".$this->db->prefix()."c_country as co";
84  $sql .= " WHERE c.active = 1 AND c.fk_pays = co.rowid";
85  $sql .= " AND co.code = '".$this->db->escape($mysoc->country_code)."'";
86  $sql .= " ORDER BY c.libelle ASC";
87  }
88 
89  dol_syslog("Form::select_type_socialcontrib", LOG_DEBUG);
90  $resql = $this->db->query($sql);
91  if ($resql) {
92  $num = $this->db->num_rows($resql);
93  if ($num) {
94  print '<select class="'.($morecss ? $morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
95  $i = 0;
96 
97  if ($useempty) {
98  print '<option value="0">&nbsp;</option>';
99  }
100  while ($i < $num) {
101  $obj = $this->db->fetch_object($resql);
102  print '<option value="'.$obj->id.'"';
103  if ($obj->id == $selected) {
104  print ' selected';
105  }
106  print '>'.dol_trunc($obj->type, $maxlen);
107  $i++;
108  }
109  print '</select>';
110  if ($user->admin && $help) {
111  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
112  }
113  if (!empty($conf->use_javascript_ajax)) {
114  print ajax_combobox($htmlname);
115  }
116  } else {
117  if (empty($noerrorifempty)) {
118  print $langs->trans("ErrorNoSocialContributionForSellerCountry", $mysoc->country_code);
119  }
120  }
121  } else {
122  dol_print_error($this->db);
123  }
124  }
125 }
FormSocialContrib\__construct
__construct($db)
Constructor.
Definition: html.formsocialcontrib.class.php:46
ajax_combobox
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:438
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
FormSocialContrib
Class to manage generation of HTML components for social contributions management.
Definition: html.formsocialcontrib.class.php:28
FormSocialContrib\select_type_socialcontrib
select_type_socialcontrib($selected='', $htmlname='actioncode', $useempty=0, $maxlen=40, $help=1, $morecss='minwidth300', $noerrorifempty=0)
Return list of social contributions.
Definition: html.formsocialcontrib.class.php:65
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25