dolibarr  16.0.5
note.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
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 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33 if (!empty($conf->project->enabled)) {
34  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35 }
36 
37 $langs->loadLangs(array("bills", "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) {
45  $socid = $user->socid;
46 }
47 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
48 $hookmanager->initHooks(array('invoicesuppliernote'));
49 
50 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
51 
52 $object = new FactureFournisseur($db);
53 $object->fetch($id, $ref);
54 
55 $permissionnote = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer); // Used by the include of actions_setnotes.inc.php
56 
57 
58 /*
59  * Actions
60  */
61 
62 $reshook = $hookmanager->executeHooks('doActions', array(), $object, $action); // Note that $action and $object may have been modified by some hooks
63 if ($reshook < 0) {
64  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
65 }
66 if (empty($reshook)) {
67  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
68 }
69 
70 // Set label
71 if ($action == 'setlabel' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
72  $object->label = GETPOST('label');
73  $result = $object->update($user);
74  if ($result < 0) {
75  dol_print_error($db);
76  }
77 }
78 
79 
80 /*
81  * View
82  */
83 
84 $form = new Form($db);
85 
86 $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Notes');
87 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
88 llxHeader('', $title, $helpurl);
89 
90 if ($object->id > 0) {
91  $object->fetch_thirdparty();
92 
93  $alreadypaid = $object->getSommePaiement();
94 
95  $head = facturefourn_prepare_head($object);
96  $titre = $langs->trans('SupplierInvoice');
97  print dol_get_fiche_head($head, 'note', $titre, -1, 'supplier_invoice');
98 
99 
100  // Supplier invoice card
101  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
102 
103  $morehtmlref = '<div class="refidno">';
104  // Ref supplier
105  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
106  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
107  // Thirdparty
108  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
109  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
110  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
111  }
112  // Project
113  if (!empty($conf->project->enabled)) {
114  $langs->load("projects");
115  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
116  if ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer) {
117  if ($action != 'classify') {
118  // $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
119  $morehtmlref .= ' : ';
120  }
121  if ($action == 'classify') {
122  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
123  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
124  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
125  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
126  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
127  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
128  $morehtmlref .= '</form>';
129  } else {
130  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
131  }
132  } else {
133  if (!empty($object->fk_project)) {
134  $proj = new Project($db);
135  $proj->fetch($object->fk_project);
136  $morehtmlref .= ' : '.$proj->getNomUrl(1);
137  if ($proj->title) {
138  $morehtmlref .= ' - '.$proj->title;
139  }
140  } else {
141  $morehtmlref .= '';
142  }
143  }
144  }
145  $morehtmlref .= '</div>';
146 
147  $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
148 
149  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
150 
151  print '<div class="fichecenter">';
152  print '<div class="underbanner clearboth"></div>';
153 
154  print '<table class="border centpercent tableforfield">';
155 
156  // Type
157  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
158  print '<span class="badgeneutral">';
159  print $object->getLibType();
160  print '</span>';
161  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
162  $facreplaced = new FactureFournisseur($db);
163  $facreplaced->fetch($object->fk_facture_source);
164  print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
165  }
166  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
167  $facusing = new FactureFournisseur($db);
168  $facusing->fetch($object->fk_facture_source);
169  print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
170  }
171 
172  $facidavoir = $object->getListIdAvoirFromInvoice();
173  if (count($facidavoir) > 0) {
174  $invoicecredits = array();
175  foreach ($facidavoir as $facid) {
176  $facavoir = new FactureFournisseur($db);
177  $facavoir->fetch($facid);
178  $invoicecredits[] = $facavoir->getNomUrl(1);
179  }
180  print ' ('.$langs->transnoentities("InvoiceHasAvoir") . implode(',', $invoicecredits) . ')';
181  }
182  /*
183  if ($facidnext > 0) {
184  $facthatreplace = new FactureFournisseur($db);
185  $facthatreplace->fetch($facidnext);
186  print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')';
187  }
188  */
189  print '</td></tr>';
190 
191  // Label
192  print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
193  print $form->editfieldval("Label", 'label', $object->label, $object, 0);
194  print '</td></tr>';
195 
196  // Amount
197  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
198  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
199 
200  // Amount Local Taxes
201  //TODO: Place into a function to control showing by country or study better option
202  if ($mysoc->localtax1_assuj == "1") { //Localtax1
203  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
204  print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
205  print '</tr>';
206  }
207  if ($mysoc->localtax2_assuj == "1") { //Localtax2
208  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
209  print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
210  print '</tr>';
211  }
212  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
213 
214  print "</table>";
215 
216  print '<br>';
217 
218  print '<div class="underbanner clearboth"></div>';
219  $cssclass = "titlefield";
220  include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
221 
222  print dol_get_fiche_end();
223 }
224 
225 // End of page
226 llxFooter();
227 $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
FactureFournisseur\TYPE_CREDIT_NOTE
const TYPE_CREDIT_NOTE
Credit note invoice.
Definition: fournisseur.facture.class.php:338
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
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
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
price
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.
Definition: functions.lib.php:5541
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
FactureFournisseur\TYPE_REPLACEMENT
const TYPE_REPLACEMENT
Replacement invoice.
Definition: fournisseur.facture.class.php:333