dolibarr 21.0.4
contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3 * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
6 * Copyright (C) 2021-2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2023 Christian Foellmann <christian@foellmann.de>
8 * Copyright (C) 2026 Serhii Bondarenko <serhiilabs@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
37if (isModEnabled('project')) {
38 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
39}
40
49$langs->loadLangs(array("bills", "other", "companies"));
50
51$id = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('facid'));
52$ref = GETPOST('ref', 'alpha');
53$action = GETPOST('action', 'aZ09');
54$socid = GETPOSTINT('socid');
55
56// Security check
57if ($user->socid) {
58 $socid = $user->socid;
59}
60$hookmanager->initHooks(array('invoicesuppliercardcontact','invoicesuppliercontactcard', 'globalcard'));
61$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
62
64
65$usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
66$permissiontoadd = $usercancreate;
67
68/*
69 * Actions
70 */
71
72$parameters = array('id'=>$id);
73$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
74if ($reshook < 0) {
75 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
76}
77
78/*
79 * Add a new contact
80 */
81
82if (empty($reshook)) {
83 if ($action == 'addcontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
84 $result = $object->fetch($id, $ref);
85
86 if ($result > 0 && $id > 0) {
87 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
88 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
89 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
90 }
91
92 if ($result >= 0) {
93 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
94 exit;
95 } else {
96 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
97 $langs->load("errors");
98 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
99 } else {
100 setEventMessages($object->error, $object->errors, 'errors');
101 }
102 }
103 } elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
104 // bascule du statut d'un contact
105 if ($object->fetch($id)) {
106 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
107 } else {
108 dol_print_error($db);
109 }
110 } elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
111 // Efface un contact
112 $object->fetch($id);
113 $result = $object->delete_contact(GETPOSTINT("lineid"));
114
115 if ($result >= 0) {
116 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
117 exit;
118 } else {
119 dol_print_error($db);
120 }
121 }
122}
123
124
125/*
126 * View
127 */
128$form = new Form($db);
129$formcompany = new FormCompany($db);
130$contactstatic = new Contact($db);
131$userstatic = new User($db);
132
133
134/* *************************************************************************** */
135/* */
136/* Card view and edit mode */
137/* */
138/* *************************************************************************** */
139
140if ($id > 0 || !empty($ref)) {
141 if ($object->fetch($id, $ref) > 0) {
142 $object->fetch_thirdparty();
143
144 $alreadypaid = $object->getSommePaiement();
145
146 $title = $object->ref." - ".$langs->trans('ContactsAddresses');
147 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
148 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-fourn-facture page-card_contact');
149
150 $head = facturefourn_prepare_head($object);
151
152 print dol_get_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
153
154 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
155
156 $morehtmlref = '<div class="refidno">';
157 // Ref supplier
158 $morehtmlref .= $form->editfieldkey("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
159 $morehtmlref .= $form->editfieldval("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
160 // Thirdparty
161 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
162 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
163 $morehtmlref .= ' <div class="inline-block valignmiddle">(<a class="valignmiddle" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)</div>';
164 }
165 // Project
166 if (isModEnabled('project')) {
167 $langs->load("projects");
168 $morehtmlref .= '<br>';
169 if (0) {
170 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
171 if ($action != 'classify') {
172 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
173 }
174 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
175 } else {
176 if (!empty($object->fk_project)) {
177 $proj = new Project($db);
178 $proj->fetch($object->fk_project);
179 $morehtmlref .= $proj->getNomUrl(1);
180 if ($proj->title) {
181 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
182 }
183 }
184 }
185 }
186 $morehtmlref .= '</div>';
187
188 $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
189
190 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
191
192 /*
193 print '<div class="fichecenter">';
194 print '<div class="fichehalfleft">';
195 print '<div class="underbanner clearboth"></div>';
196
197 print '<table class="border centpercent tableforfield">';
198
199 // Type
200 print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="4">';
201 print '<span class="badgeneutral">';
202 print $object->getLibType();
203 print '</span>';
204 if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
205 $facreplaced = new FactureFournisseur($db);
206 $facreplaced->fetch($object->fk_facture_source);
207 print ' '.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1));
208 }
209 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
210 $facusing = new FactureFournisseur($db);
211 $facusing->fetch($object->fk_facture_source);
212 print ' '.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1));
213 }
214
215 $facidavoir = $object->getListIdAvoirFromInvoice();
216 if (count($facidavoir) > 0) {
217 $invoicecredits = array();
218 foreach ($facidavoir as $facid) {
219 $facavoir = new FactureFournisseur($db);
220 $facavoir->fetch($facid);
221 $invoicecredits[] = $facavoir->getNomUrl(1);
222 }
223 print ' '.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits);
224 }
225 //if ($facidnext > 0) {
226 // $facthatreplace = new FactureFournisseur($db);
227 // $facthatreplace->fetch($facidnext);
228 // print ' '.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1));
229 //}
230 print '</td></tr>';
231
232 // Label
233 print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
234 print $form->editfieldval("Label", 'label', $object->label, $object, 0);
235 print '</td></tr>';
236
237 print '</table>';
238
239 print '</div><div class="fichehalfright">';
240 print '<div class="underbanner clearboth"></div>';
241
242 print '<table class="border centpercent tableforfield">';
243
244 // Amount
245 print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
246 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
247
248 // Amount Local Taxes
249 //TODO: Place into a function to control showing by country or study better option
250 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { //Localtax1
251 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
252 print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
253 print '</tr>';
254 }
255 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { //Localtax2
256 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
257 print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
258 print '</tr>';
259 }
260 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
261
262 print "</table>";
263 print '</div>';
264
265 print '</div>';
266 */
267
268 print dol_get_fiche_end();
269
270 //print '<div class="clearboth"></div>';
271 //print '<br>';
272
273 // Contacts lines (modules that overwrite templates must declare this into descriptor)
274 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
275 foreach ($dirtpls as $reldir) {
276 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
277 if ($res) {
278 break;
279 }
280 }
281 } else {
282 print "ErrorRecordNotFound";
283 }
284}
285
286// End of page
287llxFooter();
288$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage contact/addresses.
Class to manage suppliers invoices.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage Dolibarr users.
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
Definition fourn.lib.php:37
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.