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 *
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();
42
44 public $object;
45
49 public $error = '';
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 (GETPOST("type") == 'f') {
97 $this->object->fournisseur = 1;
98 }
99 if (GETPOST("type") == 'c') {
100 $this->object->client = 1;
101 }
102 if (GETPOST("type") == 'p') {
103 $this->object->client = 2;
104 }
105 if (GETPOST("type") == 'cp') {
106 $this->object->client = 3;
107 }
108 if (GETPOST("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 = getDolGlobalString('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 = getDolGlobalString('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((empty($this->object->default_lang) ? getDolGlobalString('MAIN_LANG_DEFAULT') : $this->object->default_lang), '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 default 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 Implement country specific action in country specific class
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['phone_mobile'] = dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id, 'AC_MOB');
302 $this->tpl['fax'] = dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id, 'AC_FAX');
303 $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 1);
304 $this->tpl['url'] = dol_print_url($this->object->url);
305
306 $this->tpl['tva_assuj'] = yn($this->object->tva_assuj);
307
308 // Third party type
309 $arr = $formcompany->typent_array(1);
310 $this->tpl['typent'] = $arr[$this->object->typent_code];
311
312 if (getDolGlobalInt('MAIN_MULTILANGS')) {
313 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
314 //$s=picto_from_langcode($this->default_lang);
315 //print ($s?$s.' ':'');
316 $langs->load("languages");
317 $this->tpl['default_lang'] = (empty($this->object->default_lang) ? '' : $langs->trans('Language_'.$this->object->default_lang));
318 }
319
320 $this->tpl['image_edit'] = img_edit();
321
322 $this->tpl['display_rib'] = $this->object->display_rib();
323
324 // Sales representatives
325 $this->tpl['sales_representatives'] = '';
326 $listsalesrepresentatives = $this->object->getSalesRepresentatives($user);
327 $nbofsalesrepresentative = count($listsalesrepresentatives);
328 if ($nbofsalesrepresentative > 3) { // We print only number
329 $this->tpl['sales_representatives'] .= $nbofsalesrepresentative;
330 } elseif ($nbofsalesrepresentative > 0) {
331 $userstatic = new User($this->db);
332 $i = 0;
333 foreach ($listsalesrepresentatives as $val) {
334 $userstatic->id = $val['id'];
335 $userstatic->lastname = $val['name'];
336 $userstatic->firstname = $val['firstname'];
337 $this->tpl['sales_representatives'] .= $userstatic->getNomUrl(1);
338 $i++;
339 if ($i < $nbofsalesrepresentative) {
340 $this->tpl['sales_representatives'] .= ', ';
341 }
342 }
343 } else {
344 $this->tpl['sales_representatives'] .= $langs->trans("NoSalesRepresentativeAffected");
345 }
346
347 // Linked member
348 if (isModEnabled('member')) {
349 $langs->load("members");
350 $adh = new Adherent($this->db);
351 $result = $adh->fetch('', '', $this->object->id);
352 if ($result > 0) {
353 $adh->ref = $adh->getFullName($langs);
354 $this->tpl['linked_member'] = $adh->getNomUrl(1);
355 } else {
356 $this->tpl['linked_member'] = $langs->trans("ThirdpartyNotLinkedToMember");
357 }
358 }
359
360 // Local Tax
361 // TODO Implement country specific action in country specific class
362 if ($mysoc->country_code == 'ES') {
363 $this->tpl['localtax'] = '';
364
365 if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
366 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
367 $this->tpl['localtax'] .= '<td>'.yn($this->object->localtax1_assuj).'</td>';
368 $this->tpl['localtax'] .= '<td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
369 $this->tpl['localtax'] .= '<td>'.yn($this->object->localtax2_assuj).'</td></tr>';
370 } elseif ($mysoc->localtax1_assuj == "1") {
371 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
372 $this->tpl['localtax'] .= '<td colspan="3">'.yn($this->object->localtax1_assuj).'</td></tr>';
373 } elseif ($mysoc->localtax2_assuj == "1") {
374 $this->tpl['localtax'] .= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
375 $this->tpl['localtax'] .= '<td colspan="3">'.yn($this->object->localtax2_assuj).'</td></tr>';
376 }
377 }
378 }
379 }
380
381 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
388 private function assign_post($action)
389 {
390 // phpcs:enable
391 global $langs, $mysoc;
392
393 $this->object->id = GETPOST("socid");
394 $this->object->name = GETPOST("nom");
395 $this->object->prefix_comm = GETPOST("prefix_comm");
396 $this->object->client = GETPOST("client");
397 $this->object->code_client = GETPOST("code_client");
398 $this->object->fournisseur = GETPOST("fournisseur");
399 $this->object->code_fournisseur = GETPOST("code_fournisseur");
400 $this->object->address = GETPOST("address");
401 $this->object->zip = GETPOST("zipcode");
402 $this->object->town = GETPOST("town");
403 $this->object->country_id = GETPOST("country_id") ? GETPOST("country_id") : $mysoc->country_id;
404 $this->object->state_id = GETPOST("state_id");
405 $this->object->phone = GETPOST("phone");
406 $this->object->phone_mobile = GETPOST("phone_mobile");
407 $this->object->fax = GETPOST("fax");
408 $this->object->email = GETPOST("email", 'alphawithlgt');
409 $this->object->url = GETPOST("url");
410 $this->object->capital = GETPOST("capital");
411 $this->object->idprof1 = GETPOST("idprof1");
412 $this->object->idprof2 = GETPOST("idprof2");
413 $this->object->idprof3 = GETPOST("idprof3");
414 $this->object->idprof4 = GETPOST("idprof4");
415 $this->object->typent_id = GETPOST("typent_id");
416 $this->object->effectif_id = GETPOST("effectif_id");
417 $this->object->barcode = GETPOST("barcode");
418 $this->object->forme_juridique_code = GETPOST("forme_juridique_code");
419 $this->object->default_lang = GETPOST("default_lang");
420 $this->object->commercial_id = GETPOST("commercial_id");
421
422 $this->object->tva_assuj = GETPOST("assujtva_value") ? GETPOST("assujtva_value") : 1;
423 $this->object->tva_intra = GETPOST("tva_intra");
424
425 //Local Taxes
426 $this->object->localtax1_assuj = GETPOST("localtax1assuj_value");
427 $this->object->localtax2_assuj = GETPOST("localtax2assuj_value");
428
429 // We set country_id, and country_code label of the chosen country
430 if ($this->object->country_id) {
431 $tmparray = getCountry($this->object->country_id, 'all', $this->db, $langs, 0);
432 $this->object->country_code = $tmparray['code'];
433 $this->object->country_label = $tmparray['label'];
434 }
435 }
436}
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.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='')
Format phone numbers according to country.
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 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.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
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.
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 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.