dolibarr  13.0.2
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 <https://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', 'aZ09');
42 
43 // Security check
44 if ($user->socid) $socid = $user->socid;
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  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
62  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
63  }
64 
65  if ($result >= 0)
66  {
67  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
68  exit;
69  } else {
70  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
71  {
72  $langs->load("errors");
73  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
74  } else {
75  setEventMessages($object->error, $object->errors, 'errors');
76  }
77  }
78 }
79 
80 // bascule du statut d'un contact
81 elseif ($action == 'swapstatut' && $user->rights->fournisseur->facture->creer)
82 {
83  if ($object->fetch($id))
84  {
85  $result = $object->swapContactStatus(GETPOST('ligne'));
86  } else {
87  dol_print_error($db);
88  }
89 }
90 
91 // Efface un contact
92 elseif ($action == 'deletecontact' && $user->rights->fournisseur->facture->creer)
93 {
94  $object->fetch($id);
95  $result = $object->delete_contact($_GET["lineid"]);
96 
97  if ($result >= 0)
98  {
99  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
100  exit;
101  } else {
102  dol_print_error($db);
103  }
104 }
105 
106 
107 /*
108  * View
109  */
110 
111 $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('ContactsAddresses');
112 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
113 llxHeader('', $title, $helpurl);
114 
115 $form = new Form($db);
116 $formcompany = new FormCompany($db);
117 $contactstatic = new Contact($db);
118 $userstatic = new User($db);
119 
120 
121 /* *************************************************************************** */
122 /* */
123 /* Mode vue et edition */
124 /* */
125 /* *************************************************************************** */
126 
127 if ($id > 0 || !empty($ref))
128 {
129  if ($object->fetch($id, $ref) > 0)
130  {
131  $object->fetch_thirdparty();
132 
133  $alreadypaid = $object->getSommePaiement();
134 
135  $head = facturefourn_prepare_head($object);
136 
137  print dol_get_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
138 
139  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
140 
141  $morehtmlref = '<div class="refidno">';
142  // Ref supplier
143  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
144  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
145  // Thirdparty
146  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
147  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>)';
148  // Project
149  if (!empty($conf->projet->enabled))
150  {
151  $langs->load("projects");
152  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
153  if ($user->rights->facture->creer)
154  {
155  if ($action != 'classify')
156  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
157  $morehtmlref .= ' : ';
158  if ($action == 'classify') {
159  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
160  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
161  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
162  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
163  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
164  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
165  $morehtmlref .= '</form>';
166  } else {
167  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
168  }
169  } else {
170  if (!empty($object->fk_project)) {
171  $proj = new Project($db);
172  $proj->fetch($object->fk_project);
173  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
174  $morehtmlref .= $proj->ref;
175  $morehtmlref .= '</a>';
176  } else {
177  $morehtmlref .= '';
178  }
179  }
180  }
181  $morehtmlref .= '</div>';
182 
183  $object->totalpaye = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
184 
185  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
186 
187  print '<div class="fichecenter">';
188  print '<div class="underbanner clearboth"></div>';
189 
190  print '<table class="border centpercent tableforfield">';
191 
192  // Type
193  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="4">';
194  print $object->getLibType();
195  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT)
196  {
197  $facreplaced = new FactureFournisseur($db);
198  $facreplaced->fetch($object->fk_facture_source);
199  print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
200  }
201  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE)
202  {
203  $facusing = new FactureFournisseur($db);
204  $facusing->fetch($object->fk_facture_source);
205  print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
206  }
207 
208  $facidavoir = $object->getListIdAvoirFromInvoice();
209  if (count($facidavoir) > 0)
210  {
211  print ' ('.$langs->transnoentities("InvoiceHasAvoir");
212  $i = 0;
213  foreach ($facidavoir as $fid)
214  {
215  if ($i == 0) print ' ';
216  else print ',';
217  $facavoir = new FactureFournisseur($db);
218  $facavoir->fetch($fid);
219  print $facavoir->getNomUrl(1);
220  }
221  print ')';
222  }
223  if ($facidnext > 0)
224  {
225  $facthatreplace = new FactureFournisseur($db);
226  $facthatreplace->fetch($facidnext);
227  print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')';
228  }
229  print '</td></tr>';
230 
231  // Label
232  print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
233  print $form->editfieldval("Label", 'label', $object->label, $object, 0);
234  print '</td></tr>';
235 
236  // Amount
237  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
238  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
239 
240  // Amount Local Taxes
241  //TODO: Place into a function to control showing by country or study better option
242  if ($societe->localtax1_assuj == "1") //Localtax1
243  {
244  print '<tr><td>'.$langs->transcountry("AmountLT1", $societe->country_code).'</td>';
245  print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
246  print '</tr>';
247  }
248  if ($societe->localtax2_assuj == "1") //Localtax2
249  {
250  print '<tr><td>'.$langs->transcountry("AmountLT2", $societe->country_code).'</td>';
251  print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
252  print '</tr>';
253  }
254  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
255 
256  print "</table>";
257 
259 
260  print '<br>';
261 
262  // Contacts lines
263  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
264  } else {
265  print "ErrorRecordNotFound";
266  }
267 }
268 
269 // End of page
270 llxFooter();
271 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage suppliers invoices.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
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.
facturefourn_prepare_head($object)
Prepare array with list of tabs.
Definition: fourn.lib.php:34
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
const TYPE_CREDIT_NOTE
Credit note invoice.
print
Draft customers invoices.
Definition: index.php:89
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.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59