dolibarr 24.0.2
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-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
9 * Copyright (C) 2021-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../../main.inc.php';
34
44require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
45require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
50if (isModEnabled('project')) {
51 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
52}
53
54$langs->loadLangs(array('bills', 'other', 'companies'));
55
56$id = GETPOSTINT('facid') ? GETPOSTINT('facid') : GETPOSTINT('id');
57$action = GETPOST('action', 'aZ09');
58$confirm = GETPOST('confirm', 'alpha');
59$ref = GETPOST('ref', 'alpha');
60
62$object->fetch($id, $ref);
63if ($object->id > 0) {
64 $id = $object->id; // The page may be called with the ref only: the security check must be done on the object found
65}
66
67// Security check
68if ($user->socid) {
69 $socid = $user->socid;
70}
71$hookmanager->initHooks(array('invoicesuppliercarddocument'));
72$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
73
74// Get parameters
75$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
76$sortfield = GETPOST('sortfield', 'aZ09comma');
77$sortorder = GETPOST('sortorder', 'aZ09comma');
78$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
79if (empty($page) || $page == -1) {
80 $page = 0;
81} // If $page is not defined, or '' or -1
82$offset = $limit * $page;
83$pageprev = $page - 1;
84$pagenext = $page + 1;
85if (!$sortorder) {
86 $sortorder = "ASC";
87}
88if (!$sortfield) {
89 $sortfield = "name";
90}
91
93$upload_dir = null;
94if ($object->fetch($id, $ref)) {
95 $object->fetch_thirdparty();
96 $ref = dol_sanitizeFileName($object->ref);
97 $upload_dir = getMultidirOutput($object).'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$ref;
98}
99
100$permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); // Used by the include of actions_setnotes.inc.php
101
102
103/*
104 * Actions
105 */
106
107include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
108
109
110/*
111 * View
112 */
113
114$form = new Form($db);
115
116$title = $object->ref." - ".$langs->trans('Documents');
117$helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
118llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-fourn-facture page-card_document');
119
120if ($object->id > 0 && $upload_dir !== null) {
121 $head = facturefourn_prepare_head($object);
122 print dol_get_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, $object->picto, 0, '', '', 0, '', 1);
123
124 $totalpaid = $object->getSommePaiement();
125
126 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
127
128 $morehtmlref = '<div class="refidno">';
129 // Ref supplier
130 $morehtmlref .= $form->editfieldkey("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
131 $morehtmlref .= $form->editfieldval("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
132 // Thirdparty
133 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
134 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
135 $morehtmlref .= ' <div class="inline-block valignmiddle">(<a class="valignmiddle" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherBills").'</a>)</div>';
136 }
137 // Project
138 if (isModEnabled('project')) {
139 $langs->load("projects");
140 $morehtmlref .= '<br>';
141 if (0) { // @phpstan-ignore-line
142 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
143 if ($action != 'classify') {
144 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
145 }
146 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
147 } else {
148 if (!empty($object->fk_project)) {
149 $proj = new Project($db);
150 $proj->fetch($object->fk_project);
151 $morehtmlref .= $proj->getNomUrl(1);
152 if ($proj->title) {
153 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
154 }
155 }
156 }
157 }
158 $morehtmlref .= '</div>';
159
160 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
161
162 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
163
164 print '<div class="fichecenter">';
165 print '<div class="underbanner clearboth"></div>';
166
167 // Build file list
168 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
169 $totalsize = 0;
170 foreach ($filearray as $key => $file) {
171 $totalsize += $file['size'];
172 }
173
174 /*
175 * Confirm delete file
176 */
177 if ($action == 'delete') {
178 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
179 }
180
181 print '<table class="border tableforfield centpercent">';
182
183 // Type
184 print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
185 print '<span class="badgeneutral">';
186 print $object->getLibType();
187 print '</span>';
189 $facreplaced = new FactureFournisseur($db);
190 $facreplaced->fetch($object->fk_facture_source);
191 print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
192 }
194 $facusing = new FactureFournisseur($db);
195 $facusing->fetch($object->fk_facture_source);
196 print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
197 }
198
199 // Retrieve credit note ids
200 $object->getListIdAvoirFromInvoice();
201
202 if (!empty($object->creditnote_ids)) {
203 $invoicecredits = array();
204 foreach ($object->creditnote_ids as $invoiceid) {
205 $creditnote = new FactureFournisseur($db);
206 $creditnote->fetch($invoiceid);
207 $invoicecredits[] = $creditnote->getNomUrl(1);
208 }
209 print ' ('.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits) . ')';
210 }
211 /*
212 if ($facidnext > 0) {
213 $facthatreplace = new FactureFournisseur($db);
214 $facthatreplace->fetch($facidnext);
215 print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
216 }
217 */
218 print '</td></tr>';
219
220 // Label
221 print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
222 print $form->editfieldval("Label", 'label', $object->label, $object, 0);
223 print '</td>';
224
225 // Amount
226 print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
227 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
228
229 // Amount Local Taxes
230 //TODO: Place into a function to control showing by country or study better option
231 if ($mysoc->localtax1_assuj == "1") { //Localtax1
232 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
233 print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
234 print '</tr>';
235 }
236 if ($mysoc->localtax2_assuj == "1") { //Localtax2
237 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
238 print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
239 print '</tr>';
240 }
241 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
242
243 print '</table><br>';
244
245 print '<div class="underbanner clearboth"></div>';
246
247 print '<table class="border tableforfield centpercent">';
248
249 // Nb of files
250 print '<tr><td class="titlefield nowrap">'.$langs->trans('NbOfAttachedFiles').'</td><td>'.count($filearray).'</td></tr>';
251
252 print '<tr><td>'.$langs->trans('TotalSizeOfAttachedFiles').'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
253
254 print '</table>';
255 print '</div>';
256
257 print '<div class="clearboth"></div>';
258
259 print dol_get_fiche_end();
260
261
262 $modulepart = 'facture_fournisseur';
263 $permission = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
264 $permtoedit = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
265 $param = '&facid='.$object->id;
266
267 $defaulttpldir = '/core/tpl';
268 $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
269 foreach ($dirtpls as $module => $reldir) {
270 if (!empty($module)) {
271 $tpl = dol_buildpath($reldir.'/document_actions_post_headers.tpl.php');
272 } else {
273 $tpl = DOL_DOCUMENT_ROOT.$reldir.'/document_actions_post_headers.tpl.php';
274 }
275
276 if (empty($conf->file->strict_mode)) {
277 $res = @include $tpl;
278 } else {
279 $res = include $tpl; // for debug
280 }
281 if ($res) {
282 break;
283 }
284 }
285} else {
286 print $langs->trans('ErrorUnknown');
287}
288
289// End of page
290llxFooter();
291$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_dir_list($utf8_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:64
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
Definition fourn.lib.php:38
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.