dolibarr  17.0.4
document.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
7  * Copyright (C) 2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
8  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
9  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 // Load Dolibarr environment
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39 if (isModEnabled('project')) {
40  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
41 }
42 
43 $langs->loadLangs(array('bills', 'other', 'companies'));
44 
45 $id = GETPOST('facid', 'int') ?GETPOST('facid', 'int') : GETPOST('id', 'int');
46 $action = GETPOST('action', 'aZ09');
47 $confirm = GETPOST('confirm', 'alpha');
48 $ref = GETPOST('ref', 'alpha');
49 
50 // Security check
51 if ($user->socid) {
52  $socid = $user->socid;
53 }
54 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
55 $hookmanager->initHooks(array('invoicesuppliercarddocument'));
56 
57 // Get parameters
58 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
59 $sortfield = GETPOST('sortfield', 'aZ09comma');
60 $sortorder = GETPOST('sortorder', 'aZ09comma');
61 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
62 if (empty($page) || $page == -1) {
63  $page = 0;
64 } // If $page is not defined, or '' or -1
65 $offset = $limit * $page;
66 $pageprev = $page - 1;
67 $pagenext = $page + 1;
68 if (!$sortorder) {
69  $sortorder = "ASC";
70 }
71 if (!$sortfield) {
72  $sortfield = "name";
73 }
74 
75 $object = new FactureFournisseur($db);
76 if ($object->fetch($id, $ref)) {
77  $object->fetch_thirdparty();
78  $ref = dol_sanitizeFileName($object->ref);
79  $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$ref;
80 }
81 
82 $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer); // Used by the include of actions_setnotes.inc.php
83 
84 
85 /*
86  * Actions
87  */
88 
89 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
90 
91 
92 /*
93  * View
94  */
95 
96 $form = new Form($db);
97 
98 $title = $object->ref." - ".$langs->trans('Documents');
99 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
100 llxHeader('', $title, $helpurl);
101 
102 if ($object->id > 0) {
103  $head = facturefourn_prepare_head($object);
104  print dol_get_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
105 
106  $totalpaid = $object->getSommePaiement();
107 
108  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
109 
110  $morehtmlref = '<div class="refidno">';
111  // Ref supplier
112  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
113  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
114  // Thirdparty
115  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
116  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
117  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
118  }
119  // Project
120  if (isModEnabled('project')) {
121  $langs->load("projects");
122  $morehtmlref .= '<br>';
123  if (0) {
124  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
125  if ($action != 'classify') {
126  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
127  }
128  $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');
129  } else {
130  if (!empty($object->fk_project)) {
131  $proj = new Project($db);
132  $proj->fetch($object->fk_project);
133  $morehtmlref .= $proj->getNomUrl(1);
134  if ($proj->title) {
135  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
136  }
137  }
138  }
139  }
140  $morehtmlref .= '</div>';
141 
142  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
143 
144  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
145 
146  print '<div class="fichecenter">';
147  print '<div class="underbanner clearboth"></div>';
148 
149  // Build file list
150  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
151  $totalsize = 0;
152  foreach ($filearray as $key => $file) {
153  $totalsize += $file['size'];
154  }
155 
156  /*
157  * Confirm delete file
158  */
159  if ($action == 'delete') {
160  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
161  }
162 
163  print '<table class="border tableforfield centpercent">';
164 
165  // Type
166  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
167  print '<span class="badgeneutral">';
168  print $object->getLibType();
169  print '</span>';
170  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
171  $facreplaced = new FactureFournisseur($db);
172  $facreplaced->fetch($object->fk_facture_source);
173  print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
174  }
175  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
176  $facusing = new FactureFournisseur($db);
177  $facusing->fetch($object->fk_facture_source);
178  print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
179  }
180 
181  $facidavoir = $object->getListIdAvoirFromInvoice();
182  if (count($facidavoir) > 0) {
183  $invoicecredits = array();
184  foreach ($facidavoir as $facid) {
185  $facavoir = new FactureFournisseur($db);
186  $facavoir->fetch($facid);
187  $invoicecredits[] = $facavoir->getNomUrl(1);
188  }
189  print ' ('.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits) . ')';
190  }
191  /*
192  if ($facidnext > 0) {
193  $facthatreplace = new FactureFournisseur($db);
194  $facthatreplace->fetch($facidnext);
195  print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
196  }
197  */
198  print '</td></tr>';
199 
200  // Label
201  print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
202  print $form->editfieldval("Label", 'label', $object->label, $object, 0);
203  print '</td>';
204 
205  // Amount
206  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
207  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
208 
209  // Amount Local Taxes
210  //TODO: Place into a function to control showing by country or study better option
211  if ($mysoc->localtax1_assuj == "1") { //Localtax1
212  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
213  print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
214  print '</tr>';
215  }
216  if ($mysoc->localtax2_assuj == "1") { //Localtax2
217  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
218  print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
219  print '</tr>';
220  }
221  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
222 
223  print '</table><br>';
224 
225  print '<div class="underbanner clearboth"></div>';
226 
227  print '<table class="border tableforfield centpercent">';
228 
229  // Nb of files
230  print '<tr><td class="titlefield nowrap">'.$langs->trans('NbOfAttachedFiles').'</td><td>'.count($filearray).'</td></tr>';
231 
232  print '<tr><td>'.$langs->trans('TotalSizeOfAttachedFiles').'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
233 
234  print '</table>';
235  print '</div>';
236 
237  print '<div class="clearboth"></div>';
238 
239  print dol_get_fiche_end();
240 
241 
242  $modulepart = 'facture_fournisseur';
243  $permission = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
244  $permtoedit = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
245  $param = '&facid='.$object->id;
246 
247  $defaulttpldir = '/core/tpl';
248  $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
249  foreach ($dirtpls as $module => $reldir) {
250  if (!empty($module)) {
251  $tpl = dol_buildpath($reldir.'/document_actions_post_headers.tpl.php');
252  } else {
253  $tpl = DOL_DOCUMENT_ROOT.$reldir.'/document_actions_post_headers.tpl.php';
254  }
255 
256  if (empty($conf->file->strict_mode)) {
257  $res = @include $tpl;
258  } else {
259  $res = include $tpl; // for debug
260  }
261  if ($res) {
262  break;
263  }
264  }
265 } else {
266  print $langs->trans('ErrorUnknown');
267 }
268 
269 // End of page
270 llxFooter();
271 $db->close();
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
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
llxFooter()
Footer empty.
Definition: document.php:89
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
facturefourn_prepare_head($object)
Prepare array with list of tabs.
Definition: fourn.lib.php:35
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
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='')
Show tabs of a record.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
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.