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