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