dolibarr  16.0.5
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 require '../../main.inc.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 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38 if (!empty($conf->project->enabled)) {
39  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
40 }
41 
42 $langs->loadLangs(array('bills', 'other', 'companies'));
43 
44 $id = GETPOST('facid', 'int') ?GETPOST('facid', 'int') : GETPOST('id', 'int');
45 $action = GETPOST('action', 'aZ09');
46 $confirm = GETPOST('confirm', 'alpha');
47 $ref = GETPOST('ref', 'alpha');
48 
49 // Security check
50 if ($user->socid) {
51  $socid = $user->socid;
52 }
53 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
54 $hookmanager->initHooks(array('invoicesuppliercarddocument'));
55 
56 // Get parameters
57 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
58 $sortfield = GETPOST('sortfield', 'aZ09comma');
59 $sortorder = GETPOST('sortorder', 'aZ09comma');
60 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
61 if (empty($page) || $page == -1) {
62  $page = 0;
63 } // If $page is not defined, or '' or -1
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
67 if (!$sortorder) {
68  $sortorder = "ASC";
69 }
70 if (!$sortfield) {
71  $sortfield = "name";
72 }
73 
74 $object = new FactureFournisseur($db);
75 if ($object->fetch($id, $ref)) {
76  $object->fetch_thirdparty();
77  $ref = dol_sanitizeFileName($object->ref);
78  $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$ref;
79 }
80 
81 $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer); // Used by the include of actions_setnotes.inc.php
82 
83 
84 /*
85  * Actions
86  */
87 
88 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
89 
90 
91 /*
92  * View
93  */
94 
95 $form = new Form($db);
96 
97 $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Documents');
98 $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
99 llxHeader('', $title, $helpurl);
100 
101 if ($object->id > 0) {
102  $head = facturefourn_prepare_head($object);
103  print dol_get_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
104 
105  $totalpaid = $object->getSommePaiement();
106 
107  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
108 
109  $morehtmlref = '<div class="refidno">';
110  // Ref supplier
111  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
112  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
113  // Thirdparty
114  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
115  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
116  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
117  }
118  // Project
119  if (!empty($conf->project->enabled)) {
120  $langs->load("projects");
121  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
122  if ($user->rights->facture->creer) {
123  if ($action != 'classify') {
124  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
125  $morehtmlref .= ' : ';
126  }
127  if ($action == 'classify') {
128  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
129  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
130  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
131  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
132  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
133  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
134  $morehtmlref .= '</form>';
135  } else {
136  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
137  }
138  } else {
139  if (!empty($object->fk_project)) {
140  $proj = new Project($db);
141  $proj->fetch($object->fk_project);
142  $morehtmlref .= ' : '.$proj->getNomUrl(1);
143  if ($proj->title) {
144  $morehtmlref .= ' - '.$proj->title;
145  }
146  } else {
147  $morehtmlref .= '';
148  }
149  }
150  }
151  $morehtmlref .= '</div>';
152 
153  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
154 
155  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
156 
157  print '<div class="fichecenter">';
158  print '<div class="underbanner clearboth"></div>';
159 
160  // Build file list
161  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
162  $totalsize = 0;
163  foreach ($filearray as $key => $file) {
164  $totalsize += $file['size'];
165  }
166 
167  /*
168  * Confirm delete file
169  */
170  if ($action == 'delete') {
171  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
172  }
173 
174  print '<table class="border tableforfield centpercent">';
175 
176  // Type
177  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
178  print '<span class="badgeneutral">';
179  print $object->getLibType();
180  print '</span>';
181  if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
182  $facreplaced = new FactureFournisseur($db);
183  $facreplaced->fetch($object->fk_facture_source);
184  print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
185  }
186  if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
187  $facusing = new FactureFournisseur($db);
188  $facusing->fetch($object->fk_facture_source);
189  print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
190  }
191 
192  $facidavoir = $object->getListIdAvoirFromInvoice();
193  if (count($facidavoir) > 0) {
194  $invoicecredits = array();
195  foreach ($facidavoir as $facid) {
196  $facavoir = new FactureFournisseur($db);
197  $facavoir->fetch($facid);
198  $invoicecredits[] = $facavoir->getNomUrl(1);
199  }
200  print ' ('.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits) . ')';
201  }
202  /*
203  if ($facidnext > 0) {
204  $facthatreplace = new FactureFournisseur($db);
205  $facthatreplace->fetch($facidnext);
206  print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
207  }
208  */
209  print '</td></tr>';
210 
211  // Label
212  print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
213  print $form->editfieldval("Label", 'label', $object->label, $object, 0);
214  print '</td>';
215 
216  // Amount
217  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
218  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
219 
220  // Amount Local Taxes
221  //TODO: Place into a function to control showing by country or study better option
222  if ($mysoc->localtax1_assuj == "1") { //Localtax1
223  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
224  print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
225  print '</tr>';
226  }
227  if ($mysoc->localtax2_assuj == "1") { //Localtax2
228  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
229  print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
230  print '</tr>';
231  }
232  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
233 
234  print '</table><br>';
235 
236  print '<div class="underbanner clearboth"></div>';
237 
238  print '<table class="border tableforfield centpercent">';
239 
240  // Nb of files
241  print '<tr><td class="titlefield nowrap">'.$langs->trans('NbOfAttachedFiles').'</td><td>'.count($filearray).'</td></tr>';
242 
243  print '<tr><td>'.$langs->trans('TotalSizeOfAttachedFiles').'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
244 
245  print '</table>';
246  print '</div>';
247 
248  print '<div class="clearboth"></div>';
249 
250  print dol_get_fiche_end();
251 
252 
253  $modulepart = 'facture_fournisseur';
254  $permission = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
255  $permtoedit = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
256  $param = '&facid='.$object->id;
257 
258  $defaulttpldir = '/core/tpl';
259  $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
260  foreach ($dirtpls as $module => $reldir) {
261  if (!empty($module)) {
262  $tpl = dol_buildpath($reldir.'/document_actions_post_headers.tpl.php');
263  } else {
264  $tpl = DOL_DOCUMENT_ROOT.$reldir.'/document_actions_post_headers.tpl.php';
265  }
266 
267  if (empty($conf->file->strict_mode)) {
268  $res = @include $tpl;
269  } else {
270  $res = include $tpl; // for debug
271  }
272  if ($res) {
273  break;
274  }
275  }
276 } else {
277  print $langs->trans('ErrorUnknown');
278 }
279 
280 // End of page
281 llxFooter();
282 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
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
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_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
llxFooter
llxFooter()
Footer empty.
Definition: document.php:89
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
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
llxHeader
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
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6549
dol_print_size
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
Definition: functions.lib.php:2884
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
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
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
FactureFournisseur\TYPE_REPLACEMENT
const TYPE_REPLACEMENT
Replacement invoice.
Definition: fournisseur.facture.class.php:333