dolibarr  19.0.0-dev
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 // Load Dolibarr environment
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
34 if (isModEnabled('project')) {
35  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
36 }
37 
38 $langs->loadLangs(array("bills", "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 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
49 $hookmanager->initHooks(array('invoicesuppliernote'));
50 
51 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
52 
53 $object = new FactureFournisseur($db);
54 $object->fetch($id, $ref);
55 
56 $usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
57 $permissiontoadd = $usercancreate;
58 $permissionnote = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); // Used by the include of actions_setnotes.inc.php
59 
60 
61 /*
62  * Actions
63  */
64 
65 $reshook = $hookmanager->executeHooks('doActions', array(), $object, $action); // Note that $action and $object may have been modified by some hooks
66 if ($reshook < 0) {
67  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
68 }
69 if (empty($reshook)) {
70  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
71 }
72 
73 // Set label
74 if ($action == 'setlabel' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
75  $object->label = GETPOST('label');
76  $result = $object->update($user);
77  if ($result < 0) {
78  dol_print_error($db);
79  }
80 }
81 
82 
83 /*
84  * View
85  */
86 
87 $form = new Form($db);
88 
89 $title = $object->ref." - ".$langs->trans('Notes');
90 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
91 llxHeader('', $title, $helpurl);
92 
93 if ($object->id > 0) {
94  $object->fetch_thirdparty();
95 
96  $alreadypaid = $object->getSommePaiement();
97 
98  $head = facturefourn_prepare_head($object);
99  $titre = $langs->trans('SupplierInvoice');
100  print dol_get_fiche_head($head, 'note', $titre, -1, 'supplier_invoice');
101 
102 
103  // Supplier invoice card
104  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
105 
106  $morehtmlref = '<div class="refidno">';
107  // Ref supplier
108  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
109  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
110  // Thirdparty
111  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
112  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
113  $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>';
114  }
115  // Project
116  if (isModEnabled('project')) {
117  $langs->load("projects");
118  $morehtmlref .= '<br>';
119  if (0) {
120  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
121  if ($action != 'classify') {
122  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
123  }
124  $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');
125  } else {
126  if (!empty($object->fk_project)) {
127  $proj = new Project($db);
128  $proj->fetch($object->fk_project);
129  $morehtmlref .= $proj->getNomUrl(1);
130  if ($proj->title) {
131  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
132  }
133  }
134  }
135  }
136  $morehtmlref .= '</div>';
137 
138  $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
139 
140  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
141 
142  print '<div class="fichecenter">';
143  print '<div class="underbanner clearboth"></div>';
144 
145  print '<table class="border centpercent tableforfield">';
146 
147  // Type
148  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
149  print '<span class="badgeneutral">';
150  print $object->getLibType();
151  print '</span>';
152  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
153  $facreplaced = new FactureFournisseur($db);
154  $facreplaced->fetch($object->fk_facture_source);
155  print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
156  }
157  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
158  $facusing = new FactureFournisseur($db);
159  $facusing->fetch($object->fk_facture_source);
160  print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
161  }
162 
163  $facidavoir = $object->getListIdAvoirFromInvoice();
164  if (count($facidavoir) > 0) {
165  $invoicecredits = array();
166  foreach ($facidavoir as $facid) {
167  $facavoir = new FactureFournisseur($db);
168  $facavoir->fetch($facid);
169  $invoicecredits[] = $facavoir->getNomUrl(1);
170  }
171  print ' ('.$langs->transnoentities("InvoiceHasAvoir") . implode(',', $invoicecredits) . ')';
172  }
173  /*
174  if ($facidnext > 0) {
175  $facthatreplace = new FactureFournisseur($db);
176  $facthatreplace->fetch($facidnext);
177  print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')';
178  }
179  */
180  print '</td></tr>';
181 
182  // Label
183  print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
184  print $form->editfieldval("Label", 'label', $object->label, $object, 0);
185  print '</td></tr>';
186 
187  // Amount
188  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
189  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
190 
191  // Amount Local Taxes
192  //TODO: Place into a function to control showing by country or study better option
193  if ($mysoc->localtax1_assuj == "1") { //Localtax1
194  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
195  print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
196  print '</tr>';
197  }
198  if ($mysoc->localtax2_assuj == "1") { //Localtax2
199  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
200  print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
201  print '</tr>';
202  }
203  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
204 
205  print "</table>";
206 
207  print '<br>';
208 
209  print '<div class="underbanner clearboth"></div>';
210  $cssclass = "titlefield";
211  include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
212 
213  print dol_get_fiche_end();
214 }
215 
216 // End of page
217 llxFooter();
218 $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 suppliers invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
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.
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.
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.