dolibarr  13.0.2
actions_card_common.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2011-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
28 abstract class ActionsCardCommon
29 {
33  public $db;
34 
35  public $dirmodule;
36  public $targetmodule;
37  public $canvas;
38  public $card;
39 
41  public $tpl = array();
43  public $object;
44 
48  public $error = '';
49 
50 
54  public $errors = array();
55 
56 
64  protected function getObject($id, $ref = '')
65  {
66  //$ret = $this->getInstanceDao();
67 
68  $object = new Societe($this->db);
69  if (!empty($id) || !empty($ref)) $object->fetch($id, $ref);
70  $this->object = $object;
71  }
72 
73  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
82  public function assign_values(&$action, $id = 0, $ref = '')
83  {
84  // phpcs:enable
85  global $conf, $langs, $db, $user, $mysoc, $canvas;
86  global $form, $formadmin, $formcompany;
87 
88  if ($action == 'add' || $action == 'update') $this->assign_post($action);
89 
90  if ($_GET["type"] == 'f') { $this->object->fournisseur = 1; }
91  if ($_GET["type"] == 'c') { $this->object->client = 1; }
92  if ($_GET["type"] == 'p') { $this->object->client = 2; }
93  if ($_GET["type"] == 'cp') { $this->object->client = 3; }
94  if ($_REQUEST["private"] == 1) { $this->object->particulier = 1; }
95 
96  foreach ($this->object as $key => $value)
97  {
98  $this->tpl[$key] = $value;
99  }
100 
101  $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
102  if (is_array($GLOBALS['errors'])) $this->tpl['error'] = get_htmloutput_mesg('', $GLOBALS['errors'], 'error');
103 
104  if ($action == 'create')
105  {
106  if ($conf->use_javascript_ajax)
107  {
108  $this->tpl['ajax_selecttype'] = "\n".'<script type="text/javascript" language="javascript">
109  $(document).ready(function () {
110  $("#radiocompany").click(function() {
111  document.formsoc.action.value="create";
112  document.formsoc.canvas.value="company";
113  document.formsoc.private.value=0;
114  document.formsoc.submit();
115  });
116  $("#radioprivate").click(function() {
117  document.formsoc.action.value="create";
118  document.formsoc.canvas.value="individual";
119  document.formsoc.private.value=1;
120  document.formsoc.submit();
121  });
122  });
123  </script>'."\n";
124  }
125  }
126 
127  if ($action == 'create' || $action == 'edit')
128  {
129  if ($conf->use_javascript_ajax)
130  {
131  $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript" language="javascript">
132  $(document).ready(function () {
133  $("#selectcountry_id").change(function() {
134  document.formsoc.action.value="'.$action.'";
135  document.formsoc.canvas.value="'.$canvas.'";
136  document.formsoc.submit();
137  });
138  })
139  </script>'."\n";
140  }
141 
142  // Load object modCodeClient
143  $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
144  if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
145  {
146  $module = substr($module, 0, dol_strlen($module) - 4);
147  }
148  $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
149  foreach ($dirsociete as $dirroot)
150  {
151  $res = dol_include_once($dirroot.$module.'.php');
152  if ($res) break;
153  }
154  $modCodeClient = new $module($db);
155  $this->tpl['auto_customercode'] = $modCodeClient->code_auto;
156  // We verified if the tag prefix is used
157  if ($modCodeClient->code_auto) $this->tpl['prefix_customercode'] = $modCodeClient->verif_prefixIsUsed();
158 
159  // TODO create a function
160  $this->tpl['select_customertype'] = Form::selectarray('client', array(
161  0 => $langs->trans('NorProspectNorCustomer'),
162  1 => $langs->trans('Customer'),
163  2 => $langs->trans('Prospect'),
164  3 => $langs->trans('ProspectCustomer')
165  ), $this->object->client);
166 
167  // Customer
168  $this->tpl['customercode'] = $this->object->code_client;
169  if ((!$this->object->code_client || $this->object->code_client == -1) && $modCodeClient->code_auto) $this->tpl['customercode'] = $modCodeClient->getNextValue($this->object, 0);
170  $this->tpl['ismodifiable_customercode'] = $this->object->codeclient_modifiable();
171  $s = $modCodeClient->getToolTip($langs, $this->object, 0);
172  $this->tpl['help_customercode'] = $form->textwithpicto('', $s, 1);
173 
174  if (!empty($conf->fournisseur->enabled))
175  {
176  $this->tpl['supplier_enabled'] = 1;
177 
178  // Load object modCodeFournisseur
179  $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
180  if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
181  {
182  $module = substr($module, 0, dol_strlen($module) - 4);
183  }
184  $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
185  foreach ($dirsociete as $dirroot)
186  {
187  $res = dol_include_once($dirroot.$module.'.php');
188  if ($res) break;
189  }
190  $modCodeFournisseur = new $module;
191  $this->tpl['auto_suppliercode'] = $modCodeFournisseur->code_auto;
192  // We verified if the tag prefix is used
193  if ($modCodeFournisseur->code_auto) $this->tpl['prefix_suppliercode'] = $modCodeFournisseur->verif_prefixIsUsed();
194 
195  // Supplier
196  $this->tpl['yn_supplier'] = $form->selectyesno("fournisseur", $this->object->fournisseur, 1);
197  $this->tpl['suppliercode'] = $this->object->code_fournisseur;
198  if ((!$this->object->code_fournisseur || $this->object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) $this->tpl['suppliercode'] = $modCodeFournisseur->getNextValue($this->object, 1);
199  $this->tpl['ismodifiable_suppliercode'] = $this->object->codefournisseur_modifiable();
200  $s = $modCodeFournisseur->getToolTip($langs, $this->object, 1);
201  $this->tpl['help_suppliercode'] = $form->textwithpicto('', $s, 1);
202 
203  $this->object->LoadSupplierCateg();
204  $this->tpl['suppliercategory'] = $this->object->SupplierCategories;
205  }
206 
207  // Zip
208  $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
209 
210  // Town
211  $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
212 
213  // Country
214  $this->object->country_id = ($this->object->country_id ? $this->object->country_id : $mysoc->country_id);
215  $this->object->country_code = ($this->object->country_code ? $this->object->country_code : $mysoc->country_code);
216  $this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
217  $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
218 
219  if ($user->admin) $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
220 
221  // State
222  if ($this->object->country_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
223  else $this->tpl['select_state'] = $countrynotdefined;
224 
225  // Language
226  if (!empty($conf->global->MAIN_MULTILANGS)) $this->tpl['select_lang'] = $formadmin->select_language(($this->object->default_lang ? $this->object->default_lang : $conf->global->MAIN_LANG_DEFAULT), 'default_lang', 0, 0, 1);
227 
228  // VAT
229  $this->tpl['yn_assujtva'] = $form->selectyesno('assujtva_value', $this->tpl['tva_assuj'], 1); // Assujeti par defaut en creation
230 
231  // Select users
232  $this->tpl['select_users'] = $form->select_dolusers($this->object->commercial_id, 'commercial_id', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
233 
234  // Local Tax
235  // TODO mettre dans une classe propre au pays
236  if ($mysoc->country_code == 'ES')
237  {
238  $this->tpl['localtax'] = '';
239 
240  if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
241  {
242  $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
243  $this->tpl['localtax'] .= $form->selectyesno('localtax1assuj_value', $this->object->localtax1_assuj, 1);
244  $this->tpl['localtax'] .= '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>';
245  $this->tpl['localtax'] .= $form->selectyesno('localtax2assuj_value', $this->object->localtax1_assuj, 1);
246  $this->tpl['localtax'] .= '</td></tr>';
247  } elseif ($mysoc->localtax1_assuj == "1")
248  {
249  $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
250  $this->tpl['localtax'] .= $form->selectyesno('localtax1assuj_value', $this->object->localtax1_assuj, 1);
251  $this->tpl['localtax'] .= '</td><tr>';
252  } elseif ($mysoc->localtax2_assuj == "1")
253  {
254  $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
255  $this->tpl['localtax'] .= $form->selectyesno('localtax2assuj_value', $this->object->localtax1_assuj, 1);
256  $this->tpl['localtax'] .= '</td><tr>';
257  }
258  }
259  } else {
260  $head = societe_prepare_head($this->object);
261 
262  $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', '', 0, 'company');
263  $this->tpl['showend'] = dol_get_fiche_end();
264 
265  $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
266 
267  $this->tpl['checkcustomercode'] = $this->object->check_codeclient();
268  $this->tpl['checksuppliercode'] = $this->object->check_codefournisseur();
269  $this->tpl['address'] = dol_nl2br($this->object->address);
270 
271  $img = picto_from_langcode($this->object->country_code);
272  if ($this->object->isInEEC()) $this->tpl['country'] = $form->textwithpicto(($img ? $img.' ' : '').$this->object->country, $langs->trans("CountryIsInEEC"), 1, 0);
273  $this->tpl['country'] = ($img ? $img.' ' : '').$this->object->country;
274 
275  $this->tpl['phone'] = dol_print_phone($this->object->phone, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
276  $this->tpl['fax'] = dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id, 'AC_FAX');
277  $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 'AC_EMAIL');
278  $this->tpl['url'] = dol_print_url($this->object->url);
279 
280  $this->tpl['tva_assuj'] = yn($this->object->tva_assuj);
281 
282  // Third party type
283  $arr = $formcompany->typent_array(1);
284  $this->tpl['typent'] = $arr[$this->object->typent_code];
285 
286  if (!empty($conf->global->MAIN_MULTILANGS))
287  {
288  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
289  //$s=picto_from_langcode($this->default_lang);
290  //print ($s?$s.' ':'');
291  $langs->load("languages");
292  $this->tpl['default_lang'] = ($this->default_lang ? $langs->trans('Language_'.$this->object->default_lang) : '');
293  }
294 
295  $this->tpl['image_edit'] = img_edit();
296 
297  $this->tpl['display_rib'] = $this->object->display_rib();
298 
299  // Sales representatives
300  $this->tpl['sales_representatives'] = '';
301  $listsalesrepresentatives = $this->object->getSalesRepresentatives($user);
302  $nbofsalesrepresentative = count($listsalesrepresentatives);
303  if ($nbofsalesrepresentative > 3) // We print only number
304  {
305  $this->tpl['sales_representatives'] .= $nbofsalesrepresentative;
306  } elseif ($nbofsalesrepresentative > 0)
307  {
308  $userstatic = new User($this->db);
309  $i = 0;
310  foreach ($listsalesrepresentatives as $val)
311  {
312  $userstatic->id = $val['id'];
313  $userstatic->lastname = $val['name'];
314  $userstatic->firstname = $val['firstname'];
315  $this->tpl['sales_representatives'] .= $userstatic->getNomUrl(1);
316  $i++;
317  if ($i < $nbofsalesrepresentative) $this->tpl['sales_representatives'] .= ', ';
318  }
319  } else $this->tpl['sales_representatives'] .= $langs->trans("NoSalesRepresentativeAffected");
320 
321  // Linked member
322  if (!empty($conf->adherent->enabled))
323  {
324  $langs->load("members");
325  $adh = new Adherent($this->db);
326  $result = $adh->fetch('', '', $this->object->id);
327  if ($result > 0)
328  {
329  $adh->ref = $adh->getFullName($langs);
330  $this->tpl['linked_member'] = $adh->getNomUrl(1);
331  } else {
332  $this->tpl['linked_member'] = $langs->trans("ThirdpartyNotLinkedToMember");
333  }
334  }
335 
336  // Local Tax
337  // TODO mettre dans une classe propre au pays
338  if ($mysoc->country_code == 'ES')
339  {
340  $this->tpl['localtax'] = '';
341 
342  if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
343  {
344  $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
345  $this->tpl['localtax'] .= '<td>'.yn($this->object->localtax1_assuj).'</td>';
346  $this->tpl['localtax'] .= '<td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
347  $this->tpl['localtax'] .= '<td>'.yn($this->object->localtax2_assuj).'</td></tr>';
348  } elseif ($mysoc->localtax1_assuj == "1")
349  {
350  $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
351  $this->tpl['localtax'] .= '<td colspan="3">'.yn($this->object->localtax1_assuj).'</td></tr>';
352  } elseif ($mysoc->localtax2_assuj == "1")
353  {
354  $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
355  $this->tpl['localtax'] .= '<td colspan="3">'.yn($this->object->localtax2_assuj).'</td></tr>';
356  }
357  }
358  }
359  }
360 
361  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
368  private function assign_post($action)
369  {
370  // phpcs:enable
371  global $langs, $mysoc;
372 
373  $this->object->id = $_POST["socid"];
374  $this->object->name = $_POST["nom"];
375  $this->object->prefix_comm = $_POST["prefix_comm"];
376  $this->object->client = $_POST["client"];
377  $this->object->code_client = $_POST["code_client"];
378  $this->object->fournisseur = $_POST["fournisseur"];
379  $this->object->code_fournisseur = $_POST["code_fournisseur"];
380  $this->object->address = $_POST["adresse"];
381  $this->object->zip = $_POST["zipcode"];
382  $this->object->town = $_POST["town"];
383  $this->object->country_id = $_POST["country_id"] ? $_POST["country_id"] : $mysoc->country_id;
384  $this->object->state_id = $_POST["state_id"];
385  $this->object->phone = $_POST["tel"];
386  $this->object->fax = $_POST["fax"];
387  $this->object->email = $_POST["email"];
388  $this->object->url = $_POST["url"];
389  $this->object->capital = $_POST["capital"];
390  $this->object->idprof1 = $_POST["idprof1"];
391  $this->object->idprof2 = $_POST["idprof2"];
392  $this->object->idprof3 = $_POST["idprof3"];
393  $this->object->idprof4 = $_POST["idprof4"];
394  $this->object->typent_id = $_POST["typent_id"];
395  $this->object->effectif_id = $_POST["effectif_id"];
396  $this->object->barcode = $_POST["barcode"];
397  $this->object->forme_juridique_code = $_POST["forme_juridique_code"];
398  $this->object->default_lang = $_POST["default_lang"];
399  $this->object->commercial_id = $_POST["commercial_id"];
400 
401  $this->object->tva_assuj = $_POST["assujtva_value"] ? $_POST["assujtva_value"] : 1;
402  $this->object->tva_intra = $_POST["tva_intra"];
403 
404  //Local Taxes
405  $this->object->localtax1_assuj = $_POST["localtax1assuj_value"];
406  $this->object->localtax2_assuj = $_POST["localtax2assuj_value"];
407 
408  // We set country_id, and country_code label of the chosen country
409  if ($this->object->country_id)
410  {
411  $tmparray = getCountry($this->object->country_id, 'all', $this->db, $langs, 0);
412  $this->object->country_code = $tmparray['code'];
413  $this->object->country_label = $tmparray['label'];
414  }
415  }
416 }
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
static selectarray($htmlname, $array, $id= '', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam= '', $translate=0, $maxlen=0, $disabled=0, $sort= '', $morecss= '', $addjscombo=0, $moreparamonempty= '', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_print_url($url, $target= '_blank', $max=32, $withpicto=0)
Show Url link.
assign_values(&$action, $id=0, $ref= '')
Assign custom values for canvas (for example into this-&gt;tpl to be used by templates) ...
Classe permettant la gestion des tiers par defaut.
$tpl
Template container.
Class to manage Dolibarr users.
Definition: user.class.php:44
get_htmloutput_errors($mesgstring= '', $mesgarray=array(), $keepembedded=0)
Get formated error messages to output (Used to show messages on html output).
dol_print_phone($phone, $countrycode= '', $cid=0, $socid=0, $addlink= '', $separ="&nbsp;", $withpicto= '', $titlealt= '', $adddivfloat=0)
Format phone numbers according to country.
assign_post($action)
Assign POST values into object.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage third parties objects (customers, suppliers, prospects...)
get_htmloutput_mesg($mesgstring= '', $mesgarray= '', $style= 'ok', $keepembedded=0)
Get formated messages to output (Used to show messages on html output).
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
Class to manage members of a foundation.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getObject($id, $ref= '')
Get object from id or ref and save it into this-&gt;object.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
picto_from_langcode($codelang, $moreatt= '')
Return img flag of country for a language code or country code.