dolibarr  19.0.0-dev
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 // Load Dolibarr environment
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35 if (isModEnabled('project')) {
36  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37 }
38 
39 $langs->loadLangs(array("bills", "other", "companies"));
40 
41 $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int'));
42 $ref = GETPOST('ref', 'alpha');
43 $action = GETPOST('action', 'aZ09');
44 
45 // Security check
46 if ($user->socid) {
47  $socid = $user->socid;
48 }
49 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
50 $hookmanager->initHooks(array('invoicesuppliercardcontact'));
51 
52 $object = new FactureFournisseur($db);
53 
54 $usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
55 $permissiontoadd = $usercancreate;
56 
57 
58 /*
59  * Ajout d'un nouveau contact
60  */
61 
62 if ($action == 'addcontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
63  $result = $object->fetch($id, $ref);
64 
65  if ($result > 0 && $id > 0) {
66  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
67  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
68  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
69  }
70 
71  if ($result >= 0) {
72  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
73  exit;
74  } else {
75  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
76  $langs->load("errors");
77  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
78  } else {
79  setEventMessages($object->error, $object->errors, 'errors');
80  }
81  }
82 } elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
83  // bascule du statut d'un contact
84  if ($object->fetch($id)) {
85  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
86  } else {
87  dol_print_error($db);
88  }
89 } elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
90  // Efface un contact
91  $object->fetch($id);
92  $result = $object->delete_contact(GETPOST("lineid", 'int'));
93 
94  if ($result >= 0) {
95  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
96  exit;
97  } else {
98  dol_print_error($db);
99  }
100 }
101 
102 
103 /*
104  * View
105  */
106 $form = new Form($db);
107 $formcompany = new FormCompany($db);
108 $contactstatic = new Contact($db);
109 $userstatic = new User($db);
110 
111 
112 /* *************************************************************************** */
113 /* */
114 /* Mode vue et edition */
115 /* */
116 /* *************************************************************************** */
117 
118 if ($id > 0 || !empty($ref)) {
119  if ($object->fetch($id, $ref) > 0) {
120  $object->fetch_thirdparty();
121 
122  $alreadypaid = $object->getSommePaiement();
123 
124  $title = $object->ref." - ".$langs->trans('ContactsAddresses');
125  $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
126  llxHeader('', $title, $helpurl);
127 
128  $head = facturefourn_prepare_head($object);
129 
130  print dol_get_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
131 
132  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
133 
134  $morehtmlref = '<div class="refidno">';
135  // Ref supplier
136  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
137  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
138  // Thirdparty
139  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
140  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
141  $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>';
142  }
143  // Project
144  if (isModEnabled('project')) {
145  $langs->load("projects");
146  $morehtmlref .= '<br>';
147  if (0) {
148  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
149  if ($action != 'classify') {
150  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
151  }
152  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
153  } else {
154  if (!empty($object->fk_project)) {
155  $proj = new Project($db);
156  $proj->fetch($object->fk_project);
157  $morehtmlref .= $proj->getNomUrl(1);
158  if ($proj->title) {
159  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
160  }
161  }
162  }
163  }
164  $morehtmlref .= '</div>';
165 
166  $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
167 
168  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
169 
170  /*
171  print '<div class="fichecenter">';
172  print '<div class="fichehalfleft">';
173  print '<div class="underbanner clearboth"></div>';
174 
175  print '<table class="border centpercent tableforfield">';
176 
177  // Type
178  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="4">';
179  print '<span class="badgeneutral">';
180  print $object->getLibType();
181  print '</span>';
182  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
183  $facreplaced = new FactureFournisseur($db);
184  $facreplaced->fetch($object->fk_facture_source);
185  print ' '.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1));
186  }
187  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
188  $facusing = new FactureFournisseur($db);
189  $facusing->fetch($object->fk_facture_source);
190  print ' '.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1));
191  }
192 
193  $facidavoir = $object->getListIdAvoirFromInvoice();
194  if (count($facidavoir) > 0) {
195  $invoicecredits = array();
196  foreach ($facidavoir as $facid) {
197  $facavoir = new FactureFournisseur($db);
198  $facavoir->fetch($facid);
199  $invoicecredits[] = $facavoir->getNomUrl(1);
200  }
201  print ' '.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits);
202  }
203  //if ($facidnext > 0) {
204  // $facthatreplace = new FactureFournisseur($db);
205  // $facthatreplace->fetch($facidnext);
206  // print ' '.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1));
207  //}
208  print '</td></tr>';
209 
210  // Label
211  print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
212  print $form->editfieldval("Label", 'label', $object->label, $object, 0);
213  print '</td></tr>';
214 
215  print '</table>';
216 
217  print '</div><div class="fichehalfright">';
218  print '<div class="underbanner clearboth"></div>';
219 
220  print '<table class="border centpercent tableforfield">';
221 
222  // Amount
223  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
224  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
225 
226  // Amount Local Taxes
227  //TODO: Place into a function to control showing by country or study better option
228  if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { //Localtax1
229  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
230  print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
231  print '</tr>';
232  }
233  if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { //Localtax2
234  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
235  print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
236  print '</tr>';
237  }
238  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
239 
240  print "</table>";
241  print '</div>';
242 
243  print '</div>';
244  */
245 
246  print dol_get_fiche_end();
247 
248  //print '<div class="clearboth"></div>';
249  //print '<br>';
250 
251  // Contacts lines
252  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
253  } else {
254  print "ErrorRecordNotFound";
255  }
256 }
257 
258 // End of page
259 llxFooter();
260 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
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.
Definition: user.class.php:48
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
Definition: fourn.lib.php:35
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)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
isModEnabled($module)
Is Dolibarr module enabled.
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.