dolibarr 24.0.0-beta
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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
30abstract class ActionsCardCommon
31{
35 public $db;
36
40 public $dirmodule;
44 public $targetmodule;
48 public $canvas;
52 public $card;
53
57 public $tpl = array();
58
60
63 public $object;
64
68 public $error = '';
69
73 public $errors = array();
74
75
83 protected function getObject($id, $ref = '')
84 {
85 //$ret = $this->getInstanceDao();
86
87 $object = new Societe($this->db);
88 if (!empty($id) || !empty($ref)) {
89 $object->fetch($id, $ref);
90 }
91 $this->object = $object;
92
93 return $object;
94 }
95
96 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
105 public function assign_values(&$action, $id = 0, $ref = '')
106 {
107 // phpcs:enable
108 global $conf, $langs, $db, $user, $mysoc, $canvas;
109 global $form, $formadmin, $formcompany;
110 '
111 @phan-var-force Form $form
112 @phan-var-force FormAdmin $formadmin
113 @phan-var-force FormCompany $formcompany
114 ';
115
116 if ($action == 'add' || $action == 'update') {
117 $this->assign_post($action);
118 }
119
120 if (GETPOST("type") == 'f') {
121 $this->object->fournisseur = 1;
122 }
123 if (GETPOST("type") == 'c') {
124 $this->object->client = 1;
125 }
126 if (GETPOST("type") == 'p') {
127 $this->object->client = 2;
128 }
129 if (GETPOST("type") == 'cp') {
130 $this->object->client = 3;
131 }
132 if (GETPOST("private") == 1) {
133 $this->object->particulier = 1;
134 }
135
136 foreach ($this->object as $key => $value) {
137 $this->tpl[$key] = $value;
138 }
139
140 $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
141 if (is_array($GLOBALS['errors'])) {
142 $this->tpl['error'] = get_htmloutput_mesg('', $GLOBALS['errors'], 'error');
143 }
144
145 if ($action == 'create') {
146 if ($conf->use_javascript_ajax) {
147 $this->tpl['ajax_selecttype'] = "\n".'<script type="text/javascript">
148 $(document).ready(function () {
149 $("#radiocompany").click(function() {
150 document.formsoc.action.value="create";
151 document.formsoc.canvas.value="company";
152 document.formsoc.private.value=0;
153 document.formsoc.submit();
154 });
155 $("#radioprivate").click(function() {
156 document.formsoc.action.value="create";
157 document.formsoc.canvas.value="individual";
158 document.formsoc.private.value=1;
159 document.formsoc.submit();
160 });
161 });
162 </script>'."\n";
163 }
164 }
165
166 if ($action == 'create' || $action == 'edit') {
167 if ($conf->use_javascript_ajax) {
168 $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript">
169 $(document).ready(function () {
170 $("#selectcountry_id").change(function() {
171 document.formsoc.action.value="'.$action.'";
172 document.formsoc.canvas.value="'.$canvas.'";
173 document.formsoc.submit();
174 });
175 })
176 </script>'."\n";
177 }
178
179 // Load object modCodeClient
180 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
181 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
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 $res = dol_include_once($dirroot.$module.'.php');
187 if ($res) {
188 break;
189 }
190 }
191 $modCodeClient = new $module($db);
192 '@phan-var-force ModeleThirdPartyCode $modCodeClient';
193 $this->tpl['auto_customercode'] = $modCodeClient->code_auto;
194 // We verified if the tag prefix is used
195 if ($modCodeClient->code_auto) {
196 $this->tpl['prefix_customercode'] = $modCodeClient->verif_prefixIsUsed();
197 }
198
199 // TODO create a function
200 $this->tpl['select_customertype'] = Form::selectarray('client', array(
201 0 => $langs->trans('NorProspectNorCustomer'),
202 1 => $langs->trans('Customer'),
203 2 => $langs->trans('Prospect'),
204 3 => $langs->trans('ProspectCustomer')
205 ), $this->object->client);
206
207 // Customer
208 $this->tpl['customercode'] = $this->object->code_client;
209 if ((!$this->object->code_client || $this->object->code_client == -1) && $modCodeClient->code_auto) {
210 $this->tpl['customercode'] = $modCodeClient->getNextValue($this->object, 0);
211 }
212 $this->tpl['ismodifiable_customercode'] = $this->object->codeclient_modifiable();
213 $s = $modCodeClient->getToolTip($langs, $this->object, 0);
214 $this->tpl['help_customercode'] = $form->textwithpicto('', $s, 1);
215
216 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
217 $this->tpl['supplier_enabled'] = 1;
218
219 // Load object modCodeFournisseur
220 $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON');
221 if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
222 $module = substr($module, 0, dol_strlen($module) - 4);
223 }
224 $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
225 foreach ($dirsociete as $dirroot) {
226 $res = dol_include_once($dirroot.$module.'.php');
227 if ($res) {
228 break;
229 }
230 }
231 $modCodeFournisseur = new $module();
232 '@phan-var-force ModeleThirdPartyCode $modCodeFournisseur';
233 $this->tpl['auto_suppliercode'] = $modCodeFournisseur->code_auto;
234 // We verified if the tag prefix is used
235 if ($modCodeFournisseur->code_auto) {
236 $this->tpl['prefix_suppliercode'] = $modCodeFournisseur->verif_prefixIsUsed();
237 }
238
239 // Supplier
240 $this->tpl['yn_supplier'] = $form->selectyesno("fournisseur", $this->object->fournisseur, 1);
241 $this->tpl['suppliercode'] = $this->object->code_fournisseur;
242 if ((!$this->object->code_fournisseur || $this->object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) {
243 $this->tpl['suppliercode'] = $modCodeFournisseur->getNextValue($this->object, 1);
244 }
245 $this->tpl['ismodifiable_suppliercode'] = $this->object->codefournisseur_modifiable();
246 $s = $modCodeFournisseur->getToolTip($langs, $this->object, 1);
247 $this->tpl['help_suppliercode'] = $form->textwithpicto('', $s, 1);
248
249 $this->object->LoadSupplierCateg();
250 $this->tpl['suppliercategory'] = $this->object->SupplierCategories;
251 }
252
253 // Zip
254 $this->tpl['select_zip'] = $formcompany->select_ziptown((string) $this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
255
256 // Town
257 $this->tpl['select_town'] = $formcompany->select_ziptown((string) $this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
258
259 // Country
260 $this->object->country_id = ($this->object->country_id ? $this->object->country_id : $mysoc->country_id);
261 $this->object->country_code = ($this->object->country_code ? $this->object->country_code : $mysoc->country_code);
262 $this->tpl['select_country'] = $form->select_country((string) $this->object->country_id, 'country_id');
263 $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
264
265 if ($user->admin) {
266 $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
267 }
268
269 // State
270 if ($this->object->country_id) {
271 $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
272 } else {
273 $this->tpl['select_state'] = $countrynotdefined;
274 }
275
276 // Language
277 if (getDolGlobalInt('MAIN_MULTILANGS')) {
278 $this->tpl['select_lang'] = $formadmin->select_language((empty($this->object->default_lang) ? getDolGlobalString('MAIN_LANG_DEFAULT') : $this->object->default_lang), 'default_lang', 0, array(), 1);
279 }
280
281 // VAT
282 $this->tpl['yn_assujtva'] = $form->selectyesno('assujtva_value', $this->tpl['tva_assuj'], 1); // Subject to VAT by default at creation
283
284 // Select users
285 $this->tpl['select_users'] = $form->select_dolusers($this->object->commercial_id, 'commercial_id', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'maxwidth300');
286
287 // Local Tax
288 // TODO Implement country specific action in country specific class
289 if ($mysoc->country_code == 'ES') {
290 $this->tpl['localtax'] = '';
291
292 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
293 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
294 $this->tpl['localtax'] .= $form->selectyesno('localtax1assuj_value', $this->object->localtax1_assuj, 1);
295 $this->tpl['localtax'] .= '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>';
296 $this->tpl['localtax'] .= $form->selectyesno('localtax2assuj_value', $this->object->localtax1_assuj, 1);
297 $this->tpl['localtax'] .= '</td></tr>';
298 } elseif ($mysoc->localtax1_assuj == "1") {
299 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
300 $this->tpl['localtax'] .= $form->selectyesno('localtax1assuj_value', $this->object->localtax1_assuj, 1);
301 $this->tpl['localtax'] .= '</td><tr>';
302 } elseif ($mysoc->localtax2_assuj == "1") {
303 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
304 $this->tpl['localtax'] .= $form->selectyesno('localtax2assuj_value', $this->object->localtax1_assuj, 1);
305 $this->tpl['localtax'] .= '</td><tr>';
306 }
307 }
308 } else {
309 $head = societe_prepare_head($this->object);
310
311 $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', '', 0, 'company');
312 $this->tpl['showend'] = dol_get_fiche_end();
313
314 $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'name');
315
316 $this->tpl['checkcustomercode'] = $this->object->check_codeclient();
317 $this->tpl['checksuppliercode'] = $this->object->check_codefournisseur();
318 $this->tpl['address'] = dol_nl2br((string) $this->object->address);
319
320 $img = picto_from_langcode($this->object->country_code);
321 if ($this->object->isInEEC()) {
322 $this->tpl['country'] = $form->textwithpicto(($img ? $img.' ' : '').$this->object->country, $langs->trans("CountryIsInEEC"), 1, 'info');
323 }
324 $this->tpl['country'] = ($img ? $img.' ' : '').$this->object->country;
325
326 $this->tpl['phone'] = dol_print_phone((string) $this->object->phone, $this->object->country_code, 0, $this->object->id, 'AC_TEL');
327 $this->tpl['phone_mobile'] = dol_print_phone((string) $this->object->phone_mobile, $this->object->country_code, 0, $this->object->id, 'AC_MOB');
328 $this->tpl['fax'] = dol_print_phone((string) $this->object->fax, $this->object->country_code, 0, $this->object->id, 'AC_FAX');
329 $this->tpl['email'] = dol_print_email((string) $this->object->email, 0, $this->object->id, 1);
330 $this->tpl['url'] = dol_print_url((string) $this->object->url);
331
332 $this->tpl['tva_assuj'] = yn($this->object->tva_assuj);
333
334 // Third party type
335 $arr = $formcompany->typent_array(1);
336 $this->tpl['typent'] = $arr[$this->object->typent_code];
337
338 if (getDolGlobalInt('MAIN_MULTILANGS')) {
339 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
340 //$s=picto_from_langcode($this->default_lang);
341 //print ($s?$s.' ':'');
342 $langs->load("languages");
343 $this->tpl['default_lang'] = (empty($this->object->default_lang) ? '' : $langs->trans('Language_'.$this->object->default_lang));
344 }
345
346 $this->tpl['image_edit'] = img_edit();
347
348 $this->tpl['display_rib'] = $this->object->display_rib();
349
350 // Sales representatives
351 $this->tpl['sales_representatives'] = '';
352 $listsalesrepresentatives = $this->object->getSalesRepresentatives($user);
353 $nbofsalesrepresentative = count($listsalesrepresentatives);
354 if ($nbofsalesrepresentative > 3) { // We print only number
355 $this->tpl['sales_representatives'] .= $nbofsalesrepresentative;
356 } elseif ($nbofsalesrepresentative > 0) {
357 $userstatic = new User($this->db);
358 $i = 0;
359 foreach ($listsalesrepresentatives as $val) {
360 $userstatic->id = $val['id'];
361 $userstatic->lastname = $val['lastname'];
362 $userstatic->firstname = $val['firstname'];
363 $this->tpl['sales_representatives'] .= $userstatic->getNomUrl(1);
364 $i++;
365 if ($i < $nbofsalesrepresentative) {
366 $this->tpl['sales_representatives'] .= ', ';
367 }
368 }
369 } else {
370 $this->tpl['sales_representatives'] .= $langs->trans("NoSalesRepresentativeAffected");
371 }
372
373 // Linked member
374 if (isModEnabled('member')) {
375 $langs->load("members");
376 $adh = new Adherent($this->db);
377 $result = $adh->fetch(0, '', $this->object->id);
378 if ($result > 0) {
379 $adh->ref = $adh->getFullName($langs);
380 $this->tpl['linked_member'] = $adh->getNomUrl(1);
381 } else {
382 $this->tpl['linked_member'] = $langs->trans("ThirdpartyNotLinkedToMember");
383 }
384 }
385
386 // Local Tax
387 // TODO Implement country specific action in country specific class
388 if ($mysoc->country_code == 'ES') {
389 $this->tpl['localtax'] = '';
390
391 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
392 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
393 $this->tpl['localtax'] .= '<td>'.yn($this->object->localtax1_assuj).'</td>';
394 $this->tpl['localtax'] .= '<td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
395 $this->tpl['localtax'] .= '<td>'.yn($this->object->localtax2_assuj).'</td></tr>';
396 } elseif ($mysoc->localtax1_assuj == "1") {
397 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
398 $this->tpl['localtax'] .= '<td colspan="3">'.yn($this->object->localtax1_assuj).'</td></tr>';
399 } elseif ($mysoc->localtax2_assuj == "1") {
400 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
401 $this->tpl['localtax'] .= '<td colspan="3">'.yn($this->object->localtax2_assuj).'</td></tr>';
402 }
403 }
404 }
405 }
406
407 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
414 private function assign_post($action)
415 {
416 // phpcs:enable
417 global $langs, $mysoc;
418
419 $this->object->id = GETPOSTINT("socid");
420 $this->object->name = GETPOST("name") ? GETPOST("name") : GETPOST("nom");
421 $this->object->prefix_comm = GETPOST("prefix_comm");
422 $this->object->client = GETPOSTINT("client");
423 $this->object->code_client = GETPOST("code_client");
424 $this->object->fournisseur = GETPOSTINT("fournisseur");
425 $this->object->code_fournisseur = GETPOST("code_fournisseur");
426 $this->object->address = GETPOST("address");
427 $this->object->zip = GETPOST("zipcode");
428 $this->object->town = GETPOST("town");
429 $this->object->country_id = GETPOST("country_id") ? GETPOST("country_id") : $mysoc->country_id;
430 $this->object->state_id = GETPOSTINT("state_id");
431 $this->object->phone = GETPOST("phone");
432 $this->object->phone_mobile = GETPOST("phone_mobile");
433 $this->object->fax = GETPOST("fax");
434 $this->object->email = GETPOST("email", 'alphawithlgt');
435 $this->object->url = GETPOST("url");
436 $this->object->capital = (float) GETPOST("capital");
437 $this->object->idprof1 = GETPOST("idprof1");
438 $this->object->idprof2 = GETPOST("idprof2");
439 $this->object->idprof3 = GETPOST("idprof3");
440 $this->object->idprof4 = GETPOST("idprof4");
441 $this->object->typent_id = GETPOSTINT("typent_id");
442 $this->object->effectif_id = GETPOSTINT("effectif_id");
443 $this->object->barcode = GETPOST("barcode");
444 $this->object->forme_juridique_code = GETPOSTINT("forme_juridique_code");
445 $this->object->default_lang = GETPOST("default_lang");
446 $this->object->commercial_id = GETPOSTINT("commercial_id");
447
448 $this->object->tva_assuj = GETPOST("assujtva_value") ? GETPOST("assujtva_value") : 1;
449 $this->object->tva_intra = GETPOST("tva_intra");
450
451 //Local Taxes
452 $this->object->localtax1_assuj = GETPOSTINT("localtax1assuj_value");
453 $this->object->localtax2_assuj = GETPOSTINT("localtax2assuj_value");
454
455 // We set country_id, and country_code label of the chosen country
456 if ($this->object->country_id) {
457 $tmparray = getCountry($this->object->country_id, 'all', $this->db, $langs, 0);
458 $this->object->country_code = $tmparray['code'];
459 $this->object->country_label = $tmparray['label'];
460 }
461 }
462}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
Abstract class to manage third parties.
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=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
get_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Get formatted 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_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a 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.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
get_htmloutput_mesg($mesgstring='', $mesgarray=[], $style='ok', $keepembedded=0)
Get formatted messages to output (Used to show messages on html output).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.