dolibarr 19.0.3
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 Frédéric France <frederic.france@netlogic.fr>
7 * Copyright (C) 2023 Christian Foellmann <christian@foellmann.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
32require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36if (isModEnabled('project')) {
37 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38}
39
40$langs->loadLangs(array("bills", "other", "companies"));
41
42$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int'));
43$ref = GETPOST('ref', 'alpha');
44$action = GETPOST('action', 'aZ09');
45
46// Security check
47if ($user->socid) {
48 $socid = $user->socid;
49}
50$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
51$hookmanager->initHooks(array('invoicesuppliercardcontact','invoicesuppliercontactcard', 'globalcard'));
52
53$object = new FactureFournisseur($db);
54
55$usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
56$permissiontoadd = $usercancreate;
57
58/*
59 * Actions
60 */
61
62$parameters = array('id'=>$id);
63$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
64if ($reshook < 0) {
65 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
66}
67
68/*
69 * Add a new contact
70 */
71
72if (empty($reshook)) {
73 if ($action == 'addcontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
74 $result = $object->fetch($id, $ref);
75
76 if ($result > 0 && $id > 0) {
77 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
78 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
79 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
80 }
81
82 if ($result >= 0) {
83 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
84 exit;
85 } else {
86 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
87 $langs->load("errors");
88 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
89 } else {
90 setEventMessages($object->error, $object->errors, 'errors');
91 }
92 }
93 } elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
94 // bascule du statut d'un contact
95 if ($object->fetch($id)) {
96 $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
97 } else {
98 dol_print_error($db);
99 }
100 } elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
101 // Efface un contact
102 $object->fetch($id);
103 $result = $object->delete_contact(GETPOST("lineid", 'int'));
104
105 if ($result >= 0) {
106 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
107 exit;
108 } else {
109 dol_print_error($db);
110 }
111 }
112}
113
114
115/*
116 * View
117 */
118$form = new Form($db);
119$formcompany = new FormCompany($db);
120$contactstatic = new Contact($db);
121$userstatic = new User($db);
122
123
124/* *************************************************************************** */
125/* */
126/* Mode vue et edition */
127/* */
128/* *************************************************************************** */
129
130if ($id > 0 || !empty($ref)) {
131 if ($object->fetch($id, $ref) > 0) {
132 $object->fetch_thirdparty();
133
134 $alreadypaid = $object->getSommePaiement();
135
136 $title = $object->ref." - ".$langs->trans('ContactsAddresses');
137 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
138 llxHeader('', $title, $helpurl);
139
140 $head = facturefourn_prepare_head($object);
141
142 print dol_get_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
143
144 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
145
146 $morehtmlref = '<div class="refidno">';
147 // Ref supplier
148 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
149 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
150 // Thirdparty
151 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
152 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
153 $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>';
154 }
155 // Project
156 if (isModEnabled('project')) {
157 $langs->load("projects");
158 $morehtmlref .= '<br>';
159 if (0) {
160 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
161 if ($action != 'classify') {
162 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
163 }
164 $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');
165 } else {
166 if (!empty($object->fk_project)) {
167 $proj = new Project($db);
168 $proj->fetch($object->fk_project);
169 $morehtmlref .= $proj->getNomUrl(1);
170 if ($proj->title) {
171 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
172 }
173 }
174 }
175 }
176 $morehtmlref .= '</div>';
177
178 $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
179
180 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
181
182 /*
183 print '<div class="fichecenter">';
184 print '<div class="fichehalfleft">';
185 print '<div class="underbanner clearboth"></div>';
186
187 print '<table class="border centpercent tableforfield">';
188
189 // Type
190 print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="4">';
191 print '<span class="badgeneutral">';
192 print $object->getLibType();
193 print '</span>';
194 if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
195 $facreplaced = new FactureFournisseur($db);
196 $facreplaced->fetch($object->fk_facture_source);
197 print ' '.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1));
198 }
199 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
200 $facusing = new FactureFournisseur($db);
201 $facusing->fetch($object->fk_facture_source);
202 print ' '.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1));
203 }
204
205 $facidavoir = $object->getListIdAvoirFromInvoice();
206 if (count($facidavoir) > 0) {
207 $invoicecredits = array();
208 foreach ($facidavoir as $facid) {
209 $facavoir = new FactureFournisseur($db);
210 $facavoir->fetch($facid);
211 $invoicecredits[] = $facavoir->getNomUrl(1);
212 }
213 print ' '.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits);
214 }
215 //if ($facidnext > 0) {
216 // $facthatreplace = new FactureFournisseur($db);
217 // $facthatreplace->fetch($facidnext);
218 // print ' '.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1));
219 //}
220 print '</td></tr>';
221
222 // Label
223 print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
224 print $form->editfieldval("Label", 'label', $object->label, $object, 0);
225 print '</td></tr>';
226
227 print '</table>';
228
229 print '</div><div class="fichehalfright">';
230 print '<div class="underbanner clearboth"></div>';
231
232 print '<table class="border centpercent tableforfield">';
233
234 // Amount
235 print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
236 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
237
238 // Amount Local Taxes
239 //TODO: Place into a function to control showing by country or study better option
240 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { //Localtax1
241 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
242 print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
243 print '</tr>';
244 }
245 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { //Localtax2
246 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
247 print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
248 print '</tr>';
249 }
250 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
251
252 print "</table>";
253 print '</div>';
254
255 print '</div>';
256 */
257
258 print dol_get_fiche_end();
259
260 //print '<div class="clearboth"></div>';
261 //print '<br>';
262
263 // Contacts lines
264 include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
265 } else {
266 print "ErrorRecordNotFound";
267 }
268}
269
270// End of page
271llxFooter();
272$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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:36
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
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_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
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.
Contact()
Old copy.
Definition index.php:572