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