dolibarr 18.0.6
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
28abstract 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)) {
70 $object->fetch($id, $ref);
71 }
72 $this->object = $object;
73
74 return $object;
75 }
76
77 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
86 public function assign_values(&$action, $id = 0, $ref = '')
87 {
88 // phpcs:enable
89 global $conf, $langs, $db, $user, $mysoc, $canvas;
90 global $form, $formadmin, $formcompany;
91
92 if ($action == 'add' || $action == 'update') {
93 $this->assign_post($action);
94 }
95
96 if ($_GET["type"] == 'f') {
97 $this->object->fournisseur = 1;
98 }
99 if ($_GET["type"] == 'c') {
100 $this->object->client = 1;
101 }
102 if ($_GET["type"] == 'p') {
103 $this->object->client = 2;
104 }
105 if ($_GET["type"] == 'cp') {
106 $this->object->client = 3;
107 }
108 if ($_REQUEST["private"] == 1) {
109 $this->object->particulier = 1;
110 }
111
112 foreach ($this->object as $key => $value) {
113 $this->tpl[$key] = $value;
114 }
115
116 $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
117 if (is_array($GLOBALS['errors'])) {
118 $this->tpl['error'] = get_htmloutput_mesg('', $GLOBALS['errors'], 'error');
119 }
120
121 if ($action == 'create') {
122 if ($conf->use_javascript_ajax) {
123 $this->tpl['ajax_selecttype'] = "\n".'<script type="text/javascript">
124 $(document).ready(function () {
125 $("#radiocompany").click(function() {
126 document.formsoc.action.value="create";
127 document.formsoc.canvas.value="company";
128 document.formsoc.private.value=0;
129 document.formsoc.submit();
130 });
131 $("#radioprivate").click(function() {
132 document.formsoc.action.value="create";
133 document.formsoc.canvas.value="individual";
134 document.formsoc.private.value=1;
135 document.formsoc.submit();
136 });
137 });
138 </script>'."\n";
139 }
140 }
141
142 if ($action == 'create' || $action == 'edit') {
143 if ($conf->use_javascript_ajax) {
144 $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript">
145 $(document).ready(function () {
146 $("#selectcountry_id").change(function() {
147 document.formsoc.action.value="'.$action.'";
148 document.formsoc.canvas.value="'.$canvas.'";
149 document.formsoc.submit();
150 });
151 })
152 </script>'."\n";
153 }
154
155 // Load object modCodeClient
156 $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
157 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
158 $module = substr($module, 0, dol_strlen($module) - 4);
159 }
160 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
161 foreach ($dirsociete as $dirroot) {
162 $res = dol_include_once($dirroot.$module.'.php');
163 if ($res) {
164 break;
165 }
166 }
167 $modCodeClient = new $module($db);
168 $this->tpl['auto_customercode'] = $modCodeClient->code_auto;
169 // We verified if the tag prefix is used
170 if ($modCodeClient->code_auto) {
171 $this->tpl['prefix_customercode'] = $modCodeClient->verif_prefixIsUsed();
172 }
173
174 // TODO create a function
175 $this->tpl['select_customertype'] = Form::selectarray('client', array(
176 0 => $langs->trans('NorProspectNorCustomer'),
177 1 => $langs->trans('Customer'),
178 2 => $langs->trans('Prospect'),
179 3 => $langs->trans('ProspectCustomer')
180 ), $this->object->client);
181
182 // Customer
183 $this->tpl['customercode'] = $this->object->code_client;
184 if ((!$this->object->code_client || $this->object->code_client == -1) && $modCodeClient->code_auto) {
185 $this->tpl['customercode'] = $modCodeClient->getNextValue($this->object, 0);
186 }
187 $this->tpl['ismodifiable_customercode'] = $this->object->codeclient_modifiable();
188 $s = $modCodeClient->getToolTip($langs, $this->object, 0);
189 $this->tpl['help_customercode'] = $form->textwithpicto('', $s, 1);
190
191 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
192 $this->tpl['supplier_enabled'] = 1;
193
194 // Load object modCodeFournisseur
195 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
196 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
197 $module = substr($module, 0, dol_strlen($module) - 4);
198 }
199 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
200 foreach ($dirsociete as $dirroot) {
201 $res = dol_include_once($dirroot.$module.'.php');
202 if ($res) {
203 break;
204 }
205 }
206 $modCodeFournisseur = new $module;
207 $this->tpl['auto_suppliercode'] = $modCodeFournisseur->code_auto;
208 // We verified if the tag prefix is used
209 if ($modCodeFournisseur->code_auto) {
210 $this->tpl['prefix_suppliercode'] = $modCodeFournisseur->verif_prefixIsUsed();
211 }
212
213 // Supplier
214 $this->tpl['yn_supplier'] = $form->selectyesno("fournisseur", $this->object->fournisseur, 1);
215 $this->tpl['suppliercode'] = $this->object->code_fournisseur;
216 if ((!$this->object->code_fournisseur || $this->object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) {
217 $this->tpl['suppliercode'] = $modCodeFournisseur->getNextValue($this->object, 1);
218 }
219 $this->tpl['ismodifiable_suppliercode'] = $this->object->codefournisseur_modifiable();
220 $s = $modCodeFournisseur->getToolTip($langs, $this->object, 1);
221 $this->tpl['help_suppliercode'] = $form->textwithpicto('', $s, 1);
222
223 $this->object->LoadSupplierCateg();
224 $this->tpl['suppliercategory'] = $this->object->SupplierCategories;
225 }
226
227 // Zip
228 $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
229
230 // Town
231 $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
232
233 // Country
234 $this->object->country_id = ($this->object->country_id ? $this->object->country_id : $mysoc->country_id);
235 $this->object->country_code = ($this->object->country_code ? $this->object->country_code : $mysoc->country_code);
236 $this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id');
237 $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
238
239 if ($user->admin) {
240 $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
241 }
242
243 // State
244 if ($this->object->country_id) {
245 $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
246 } else {
247 $this->tpl['select_state'] = $countrynotdefined;
248 }
249
250 // Language
251 if (getDolGlobalInt('MAIN_MULTILANGS')) {
252 $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);
253 }
254
255 // VAT
256 $this->tpl['yn_assujtva'] = $form->selectyesno('assujtva_value', $this->tpl['tva_assuj'], 1); // Assujeti par defaut en creation
257
258 // Select users
259 $this->tpl['select_users'] = $form->select_dolusers($this->object->commercial_id, 'commercial_id', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
260
261 // Local Tax
262 // TODO mettre dans une classe propre au pays
263 if ($mysoc->country_code == 'ES') {
264 $this->tpl['localtax'] = '';
265
266 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
267 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
268 $this->tpl['localtax'] .= $form->selectyesno('localtax1assuj_value', $this->object->localtax1_assuj, 1);
269 $this->tpl['localtax'] .= '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>';
270 $this->tpl['localtax'] .= $form->selectyesno('localtax2assuj_value', $this->object->localtax1_assuj, 1);
271 $this->tpl['localtax'] .= '</td></tr>';
272 } elseif ($mysoc->localtax1_assuj == "1") {
273 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
274 $this->tpl['localtax'] .= $form->selectyesno('localtax1assuj_value', $this->object->localtax1_assuj, 1);
275 $this->tpl['localtax'] .= '</td><tr>';
276 } elseif ($mysoc->localtax2_assuj == "1") {
277 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
278 $this->tpl['localtax'] .= $form->selectyesno('localtax2assuj_value', $this->object->localtax1_assuj, 1);
279 $this->tpl['localtax'] .= '</td><tr>';
280 }
281 }
282 } else {
283 $head = societe_prepare_head($this->object);
284
285 $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', '', 0, 'company');
286 $this->tpl['showend'] = dol_get_fiche_end();
287
288 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
289
290 $this->tpl['checkcustomercode'] = $this->object->check_codeclient();
291 $this->tpl['checksuppliercode'] = $this->object->check_codefournisseur();
292 $this->tpl['address'] = dol_nl2br($this->object->address);
293
294 $img = picto_from_langcode($this->object->country_code);
295 if ($this->object->isInEEC()) {
296 $this->tpl['country'] = $form->textwithpicto(($img ? $img.' ' : '').$this->object->country, $langs->trans("CountryIsInEEC"), 1, 0);
297 }
298 $this->tpl['country'] = ($img ? $img.' ' : '').$this->object->country;
299
300 $this->tpl['phone'] = dol_print_phone($this->object->phone, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
301 $this->tpl['fax'] = dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id, 'AC_FAX');
302 $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 'AC_EMAIL');
303 $this->tpl['url'] = dol_print_url($this->object->url);
304
305 $this->tpl['tva_assuj'] = yn($this->object->tva_assuj);
306
307 // Third party type
308 $arr = $formcompany->typent_array(1);
309 $this->tpl['typent'] = $arr[$this->object->typent_code];
310
311 if (getDolGlobalInt('MAIN_MULTILANGS')) {
312 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
313 //$s=picto_from_langcode($this->default_lang);
314 //print ($s?$s.' ':'');
315 $langs->load("languages");
316 $this->tpl['default_lang'] = (empty($this->object->default_lang) ? '' : $langs->trans('Language_'.$this->object->default_lang));
317 }
318
319 $this->tpl['image_edit'] = img_edit();
320
321 $this->tpl['display_rib'] = $this->object->display_rib();
322
323 // Sales representatives
324 $this->tpl['sales_representatives'] = '';
325 $listsalesrepresentatives = $this->object->getSalesRepresentatives($user);
326 $nbofsalesrepresentative = count($listsalesrepresentatives);
327 if ($nbofsalesrepresentative > 3) { // We print only number
328 $this->tpl['sales_representatives'] .= $nbofsalesrepresentative;
329 } elseif ($nbofsalesrepresentative > 0) {
330 $userstatic = new User($this->db);
331 $i = 0;
332 foreach ($listsalesrepresentatives as $val) {
333 $userstatic->id = $val['id'];
334 $userstatic->lastname = $val['name'];
335 $userstatic->firstname = $val['firstname'];
336 $this->tpl['sales_representatives'] .= $userstatic->getNomUrl(1);
337 $i++;
338 if ($i < $nbofsalesrepresentative) {
339 $this->tpl['sales_representatives'] .= ', ';
340 }
341 }
342 } else {
343 $this->tpl['sales_representatives'] .= $langs->trans("NoSalesRepresentativeAffected");
344 }
345
346 // Linked member
347 if (isModEnabled('adherent')) {
348 $langs->load("members");
349 $adh = new Adherent($this->db);
350 $result = $adh->fetch('', '', $this->object->id);
351 if ($result > 0) {
352 $adh->ref = $adh->getFullName($langs);
353 $this->tpl['linked_member'] = $adh->getNomUrl(1);
354 } else {
355 $this->tpl['linked_member'] = $langs->trans("ThirdpartyNotLinkedToMember");
356 }
357 }
358
359 // Local Tax
360 // TODO mettre dans une classe propre au pays
361 if ($mysoc->country_code == 'ES') {
362 $this->tpl['localtax'] = '';
363
364 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
365 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
366 $this->tpl['localtax'] .= '<td>'.yn($this->object->localtax1_assuj).'</td>';
367 $this->tpl['localtax'] .= '<td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
368 $this->tpl['localtax'] .= '<td>'.yn($this->object->localtax2_assuj).'</td></tr>';
369 } elseif ($mysoc->localtax1_assuj == "1") {
370 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
371 $this->tpl['localtax'] .= '<td colspan="3">'.yn($this->object->localtax1_assuj).'</td></tr>';
372 } elseif ($mysoc->localtax2_assuj == "1") {
373 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
374 $this->tpl['localtax'] .= '<td colspan="3">'.yn($this->object->localtax2_assuj).'</td></tr>';
375 }
376 }
377 }
378 }
379
380 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
387 private function assign_post($action)
388 {
389 // phpcs:enable
390 global $langs, $mysoc;
391
392 $this->object->id = GETPOST("socid");
393 $this->object->name = GETPOST("nom");
394 $this->object->prefix_comm = GETPOST("prefix_comm");
395 $this->object->client = GETPOST("client");
396 $this->object->code_client = GETPOST("code_client");
397 $this->object->fournisseur = GETPOST("fournisseur");
398 $this->object->code_fournisseur = GETPOST("code_fournisseur");
399 $this->object->address = GETPOST("adresse");
400 $this->object->zip = GETPOST("zipcode");
401 $this->object->town = GETPOST("town");
402 $this->object->country_id = GETPOST("country_id") ? GETPOST("country_id") : $mysoc->country_id;
403 $this->object->state_id = GETPOST("state_id");
404 $this->object->phone = GETPOST("tel");
405 $this->object->fax = GETPOST("fax");
406 $this->object->email = GETPOST("email", 'alphawithlgt');
407 $this->object->url = GETPOST("url");
408 $this->object->capital = GETPOST("capital");
409 $this->object->idprof1 = GETPOST("idprof1");
410 $this->object->idprof2 = GETPOST("idprof2");
411 $this->object->idprof3 = GETPOST("idprof3");
412 $this->object->idprof4 = GETPOST("idprof4");
413 $this->object->typent_id = GETPOST("typent_id");
414 $this->object->effectif_id = GETPOST("effectif_id");
415 $this->object->barcode = GETPOST("barcode");
416 $this->object->forme_juridique_code = GETPOST("forme_juridique_code");
417 $this->object->default_lang = GETPOST("default_lang");
418 $this->object->commercial_id = GETPOST("commercial_id");
419
420 $this->object->tva_assuj = GETPOST("assujtva_value") ? GETPOST("assujtva_value") : 1;
421 $this->object->tva_intra = GETPOST("tva_intra");
422
423 //Local Taxes
424 $this->object->localtax1_assuj = GETPOST("localtax1assuj_value");
425 $this->object->localtax2_assuj = GETPOST("localtax2assuj_value");
426
427 // We set country_id, and country_code label of the chosen country
428 if ($this->object->country_id) {
429 $tmparray = getCountry($this->object->country_id, 'all', $this->db, $langs, 0);
430 $this->object->country_code = $tmparray['code'];
431 $this->object->country_label = $tmparray['label'];
432 }
433 }
434}
Classe permettant la gestion des tiers par defaut.
getObject($id, $ref='')
Get object from id or ref and save it into this->object.
assign_values(&$action, $id=0, $ref='')
Assign custom values for canvas (for example into this->tpl to be used by templates)
assign_post($action)
Assign POST values into object.
Class to manage members of a foundation.
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='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
get_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Get formated error messages to output (Used to show messages on html output).
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
get_htmloutput_mesg($mesgstring='', $mesgarray='', $style='ok', $keepembedded=0)
Get formated 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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='float')
Show Url link.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.