dolibarr 24.0.0-beta
supplier_invoice.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2006 Marc Barilley <marc@ocebo.com>
5 * Copyright (C) 2011-2013 Philippe Grand <philippe.grand@atoo-net.com>
6 * Copyright (C) 2022-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2023 Nick Fragoulis
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
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 * or see https://www.gnu.org/
24 */
25
38/*
39function supplierinvoice_prepare_head(FactureFournisseur $object)
40{
41 global $db, $langs, $conf, $user;
42
43 $h = 0;
44 $head = array();
45
46 $head[$h][0] = DOL_URL_ROOT.'/supplier_invoice/card.php?facid='.$object->id;
47 $head[$h][1] = $langs->trans('SupplierInvoice');
48 $head[$h][2] = 'card';
49 $h++;
50
51 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
52 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
53 $head[$h][0] = DOL_URL_ROOT.'/supplier_invoice/contact.php?facid='.$object->id;
54 $head[$h][1] = $langs->trans('ContactsAddresses');
55 if ($nbContact > 0) {
56 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
57 }
58 $head[$h][2] = 'contact';
59 $h++;
60 }
61
62 //if ($fac->mode_reglement_code == 'PRE')
63 if (isModEnabled('paymentbybanktransfer')) {
64 $nbStandingOrders = 0;
65 $sql = "SELECT COUNT(pfd.rowid) as nb";
66 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
67 $sql .= " WHERE pfd.fk_facture_fourn = ".((int) $object->id);
68 $sql .= " AND type = 'ban'";
69 $resql = $db->query($sql);
70 if ($resql) {
71 $obj = $db->fetch_object($resql);
72 if ($obj) {
73 $nbStandingOrders = $obj->nb;
74 }
75 } else {
76 dol_print_error($db);
77 }
78 $langs->load("banks");
79 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id.'&type=bank-transfer';
80 $head[$h][1] = $langs->trans('BankTransfer');
81 if ($nbStandingOrders > 0) {
82 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
83 }
84 $head[$h][2] = 'standingorders';
85 $h++;
86 }
87
88 // Show more tabs from modules
89 // Entries must be declared in modules descriptor with line
90 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
91 // $this->tabs = array('entity:-tabname); to remove a tab
92 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'core');
93
94 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
95 $nbNote = 0;
96 if (!empty($object->note_private)) {
97 $nbNote++;
98 }
99 if (!empty($object->note_public)) {
100 $nbNote++;
101 }
102 $head[$h][0] = DOL_URL_ROOT.'/supplier_invoice/note.php?facid='.$object->id;
103 $head[$h][1] = $langs->trans('Notes');
104 if ($nbNote > 0) {
105 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
106 }
107 $head[$h][2] = 'note';
108 $h++;
109 }
110
111 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
112 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
113 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object->ref;
114 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
115 $nbLinks = Link::count($db, $object->element, $object->id);
116 $head[$h][0] = DOL_URL_ROOT.'/supplier_invoice/document.php?facid='.$object->id;
117 $head[$h][1] = $langs->trans('Documents');
118 if (($nbFiles + $nbLinks) > 0) {
119 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
120 }
121 $head[$h][2] = 'documents';
122 $h++;
123
124 $head[$h][0] = DOL_URL_ROOT.'/supplier_invoice/info.php?facid='.$object->id;
125 $head[$h][1] = $langs->trans('Info');
126 $head[$h][2] = 'info';
127 $h++;
128
129 $head[$h][0] = DOL_URL_ROOT.'/supplier_invoice/agenda.php?id='.$object->id;
130 $head[$h][1] = $langs->trans("Events");
131 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
132 $nbEvent = 0;
133 // Enable caching of thirdparty count actioncomm
134 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
135 $cachekey = 'count_events_facture_'.$object->id;
136 $dataretrieved = dol_getcache($cachekey);
137 if (!is_null($dataretrieved)) {
138 $nbEvent = $dataretrieved;
139 } else {
140 $sql = "SELECT COUNT(id) as nb";
141 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
142 $sql .= " WHERE fk_element = ".((int) $object->id);
143 $sql .= " AND elementtype = 'invoice_supplier'";
144 $resql = $db->query($sql);
145 if ($resql) {
146 $obj = $db->fetch_object($resql);
147 $nbEvent = $obj->nb;
148 } else {
149 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
150 }
151 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
152 }
153
154 $head[$h][1] .= '/';
155 $head[$h][1] .= $langs->trans("Agenda");
156 if ($nbEvent > 0) {
157 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
158 }
159 }
160 $head[$h][2] = 'agenda';
161 $h++;
162
163 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'external');
164
165 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'remove');
166
167 return $head;
168}
169*/
170
177{
178 global $langs, $conf, $user, $extrafields;
179
180 $extrafields->fetch_name_optionals_label('facture_fourn');
181 $extrafields->fetch_name_optionals_label('facture_fourn_det');
182 $extrafields->fetch_name_optionals_label('facture_fourn_rec');
183 $extrafields->fetch_name_optionals_label('facture_fourn_det_rec');
184
185 $h = 0;
186 $head = array();
187
188 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/supplier_invoice/admin/supplier_invoice.php");
189 $head[$h][1] = $langs->trans("SuppliersInvoice");
190 $head[$h][2] = 'invoice';
191 $h++;
192
193 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/supplier_invoice/admin/supplier_payment.php");
194 $head[$h][1] = $langs->trans("SuppliersPayment");
195 $head[$h][2] = 'supplierpayment';
196 $h++;
197
198 complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierinvoice_admin');
199
200 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_invoice/admin/supplierinvoice_extrafields.php');
201 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoices");
202 $nbExtrafields = $extrafields->attributes['facture_fourn']['count'];
203 if ($nbExtrafields > 0) {
204 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
205 }
206 $head[$h][2] = 'supplierinvoice';
207 $h++;
208
209 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_invoice/admin/supplierinvoicedet_extrafields.php');
210 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLines");
211 $nbExtrafields = $extrafields->attributes['facture_fourn_det']['count'];
212 if ($nbExtrafields > 0) {
213 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
214 }
215 $head[$h][2] = 'supplierinvoicedet';
216 $h++;
217
218 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_invoice/admin/supplierinvoice_rec_extrafields.php');
219 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesRec");
220 $nbExtrafields = $extrafields->attributes['facture_fourn_rec']['count'];
221 if ($nbExtrafields > 0) {
222 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
223 }
224 $head[$h][2] = 'attributesrec';
225 $h++;
226
227 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_invoice/admin/supplierinvoicedet_rec_extrafields.php');
228 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLinesRec");
229 $nbExtrafields = $extrafields->attributes['facture_fourn_det_rec']['count'];
230 if ($nbExtrafields > 0) {
231 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
232 }
233 $head[$h][2] = 'attributeslinesrec';
234 $h++;
235
236 complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierinvoice_admin', 'remove');
237
238 return $head;
239}
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
supplier_invoice_admin_prepare_head()
Prepare array with list of tabs.