dolibarr 24.0.0-beta
fourn.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
39{
40 global $db, $langs, $conf, $user;
41
42 $h = 0;
43 $head = array();
44
45 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$object->id;
46 $head[$h][1] = $langs->trans('SupplierInvoice');
47 $head[$h][2] = 'card';
48 $h++;
49
50 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
51 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
52 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/contact.php?facid='.$object->id;
53 $head[$h][1] = $langs->trans('ContactsAddresses');
54 if ($nbContact > 0) {
55 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
56 }
57 $head[$h][2] = 'contact';
58 $h++;
59 }
60
61 //if ($fac->mode_reglement_code == 'PRE')
62 if (isModEnabled('paymentbybanktransfer')) {
63 $nbStandingOrders = 0;
64 $sql = "SELECT COUNT(pfd.rowid) as nb";
65 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
66 $sql .= " WHERE pfd.fk_facture_fourn = ".((int) $object->id);
67 $sql .= " AND type = 'ban'";
68 $resql = $db->query($sql);
69 if ($resql) {
70 $obj = $db->fetch_object($resql);
71 if ($obj) {
72 $nbStandingOrders = $obj->nb;
73 }
74 } else {
76 }
77 $langs->load("banks");
78 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id.'&type=bank-transfer';
79 $head[$h][1] = $langs->trans('BankTransfer');
80 if ($nbStandingOrders > 0) {
81 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
82 }
83 $head[$h][2] = 'standingorders';
84 $h++;
85 }
86
87 // Show more tabs from modules
88 // Entries must be declared in modules descriptor with line
89 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
90 // $this->tabs = array('entity:-tabname); to remove a tab
91 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'core');
92
93 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
94 $nbNote = 0;
95 if (!empty($object->note_private)) {
96 $nbNote++;
97 }
98 if (!empty($object->note_public)) {
99 $nbNote++;
100 }
101 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/note.php?facid='.$object->id;
102 $head[$h][1] = $langs->trans('Notes');
103 if ($nbNote > 0) {
104 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
105 }
106 $head[$h][2] = 'note';
107 $h++;
108 }
109
110 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
111 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
112 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object->ref;
113 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
114 $nbLinks = Link::count($db, $object->element, $object->id);
115 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id;
116 $head[$h][1] = $langs->trans('Documents');
117 if (($nbFiles + $nbLinks) > 0) {
118 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
119 }
120 $head[$h][2] = 'documents';
121 $h++;
122
123 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/info.php?facid='.$object->id;
124 $head[$h][1] = $langs->trans('Info');
125 $head[$h][2] = 'info';
126 $h++;
127
128 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/agenda.php?id='.$object->id;
129 $head[$h][1] = $langs->trans("Events");
130 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
131 $nbEvent = 0;
132 // Enable caching of thirdparty count actioncomm
133 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
134 $cachekey = 'count_events_facture_'.$object->id;
135 $dataretrieved = dol_getcache($cachekey);
136 if (!is_null($dataretrieved)) {
137 $nbEvent = $dataretrieved;
138 } else {
139 $sql = "SELECT COUNT(id) as nb";
140 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
141 $sql .= " WHERE fk_element = ".((int) $object->id);
142 $sql .= " AND elementtype = 'invoice_supplier'";
143 $resql = $db->query($sql);
144 if ($resql) {
145 $obj = $db->fetch_object($resql);
146 $nbEvent = $obj->nb;
147 } else {
148 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
149 }
150 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
151 }
152
153 $head[$h][1] .= '/';
154 $head[$h][1] .= $langs->trans("Agenda");
155 if ($nbEvent > 0) {
156 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
157 }
158 }
159 $head[$h][2] = 'agenda';
160 $h++;
161
162 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'external');
163
164 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'remove');
165
166 return $head;
167}
168
169
177{
178 global $db, $langs, $conf, $user;
179
180 $h = 0;
181 $head = array();
182
183 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id;
184 $head[$h][1] = $langs->trans("SupplierOrder");
185 $head[$h][2] = 'card';
186 $h++;
187
188 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
189 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
190 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/contact.php?id='.$object->id;
191 $head[$h][1] = $langs->trans('ContactsAddresses');
192 if ($nbContact > 0) {
193 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
194 }
195 $head[$h][2] = 'contact';
196 $h++;
197 }
198
199 if (isModEnabled('stock') && (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE'))) {
200 $langs->load("stocks");
201 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id;
202 $head[$h][1] = $langs->trans("OrderDispatch");
203
204 //If dispatch process running we add the number of item to dispatch into the head
205 if (in_array($object->status, array($object::STATUS_ORDERSENT, $object::STATUS_RECEIVED_PARTIALLY, $object::STATUS_RECEIVED_COMPLETELY))) {
206 $sumQtyAllreadyDispatched = 0;
207 $sumQtyOrdered = 0;
208
209 if (empty($object->lines)) {
210 $object->fetch_lines();
211 }
212 $nbLinesOrdered = count($object->lines);
213 $dispachedLines = $object->getDispachedLines(1);
214 $nbDispachedLines = count($dispachedLines);
215
216 for ($line = 0 ; $line < $nbDispachedLines; $line++) {
217 $sumQtyAllreadyDispatched += $dispachedLines[$line]['qty'];
218 }
219 for ($line = 0 ; $line < $nbLinesOrdered; $line++) {
220 //If line is a product of conf to manage stocks for services
221 if ($object->lines[$line]->product_type == 0 || ($object->lines[$line]->product_type == 1 && getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
222 $sumQtyOrdered += $object->lines[$line]->qty;
223 }
224 }
225 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.price2num($sumQtyAllreadyDispatched, 'MS').' / '.price2num($sumQtyOrdered, 'MS').'</span>';
226 }
227
228 $head[$h][2] = 'dispatch';
229 $h++;
230 }
231
232 // Show more tabs from modules
233 // Entries must be declared in modules descriptor with line
234 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
235 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
236 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'core');
237
238 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
239 $nbNote = 0;
240 if (!empty($object->note_private)) {
241 $nbNote++;
242 }
243 if (!empty($object->note_public)) {
244 $nbNote++;
245 }
246 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$object->id;
247 $head[$h][1] = $langs->trans("Notes");
248 if ($nbNote > 0) {
249 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
250 }
251 $head[$h][2] = 'note';
252 $h++;
253 }
254
255 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
256 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
257 $upload_dir = $conf->fournisseur->dir_output."/commande/".dol_sanitizeFileName($object->ref);
258 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
259 $nbLinks = Link::count($db, $object->element, $object->id);
260 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id;
261 $head[$h][1] = $langs->trans('Documents');
262 if (($nbFiles + $nbLinks) > 0) {
263 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
264 }
265 $head[$h][2] = 'documents';
266 $h++;
267
268 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/info.php?id='.$object->id;
269 $head[$h][1] = $langs->trans("Events");
270 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
271 $nbEvent = 0;
272 // Enable caching of order supplier count actioncomm
273 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
274 $cachekey = 'count_events_order_'.$object->id;
275 $dataretrieved = dol_getcache($cachekey);
276 if (!is_null($dataretrieved)) {
277 $nbEvent = $dataretrieved;
278 } else {
279 $sql = "SELECT COUNT(id) as nb";
280 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
281 $sql .= " WHERE fk_element = ".((int) $object->id);
282 $sql .= " AND elementtype = 'order_supplier'";
283 $resql = $db->query($sql);
284 if ($resql) {
285 $obj = $db->fetch_object($resql);
286 $nbEvent = $obj->nb;
287 } else {
288 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
289 }
290 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
291 }
292
293 $head[$h][1] .= '/';
294 $head[$h][1] .= $langs->trans("Agenda");
295 if ($nbEvent > 0) {
296 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
297 }
298 }
299 $head[$h][2] = 'info';
300 $h++;
301
302 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'external');
303
304 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'remove');
305
306 return $head;
307}
308
315{
316 global $langs, $conf, $user, $extrafields;
317
318 $extrafields->fetch_name_optionals_label('commande_fournisseur');
319 $extrafields->fetch_name_optionals_label('commande_fournisseurdet');
320 $extrafields->fetch_name_optionals_label('facture_fourn');
321 $extrafields->fetch_name_optionals_label('facture_fourn_det');
322 $extrafields->fetch_name_optionals_label('facture_fourn_rec');
323 $extrafields->fetch_name_optionals_label('facture_fourn_det_rec');
324
325 $h = 0;
326 $head = array();
327
328 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/supplier_order/admin/supplier_order.php");
329 $head[$h][1] = $langs->trans("SupplierOrder");
330 $head[$h][2] = 'order';
331 $h++;
332
333 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/supplier_invoice/admin/supplier_invoice.php");
334 $head[$h][1] = $langs->trans("SuppliersInvoice");
335 $head[$h][2] = 'invoice';
336 $h++;
337
338 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/supplier_invoice/admin/supplier_payment.php");
339 $head[$h][1] = $langs->trans("SuppliersPayment");
340 $head[$h][2] = 'supplierpayment';
341 $h++;
342
343 complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin');
344
345 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_order/admin/supplierorder_extrafields.php');
346 $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrders");
347 $nbExtrafields = $extrafields->attributes['commande_fournisseur']['count'];
348 if ($nbExtrafields > 0) {
349 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
350 }
351 $head[$h][2] = 'supplierorder';
352 $h++;
353
354 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_order/admin/supplierorderdet_extrafields.php');
355 $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrdersLines");
356 $nbExtrafields = $extrafields->attributes['commande_fournisseurdet']['count'];
357 if ($nbExtrafields > 0) {
358 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
359 }
360 $head[$h][2] = 'supplierorderdet';
361 $h++;
362
363 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_invoice/admin/supplierinvoice_extrafields.php');
364 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoices");
365 $nbExtrafields = $extrafields->attributes['facture_fourn']['count'];
366 if ($nbExtrafields > 0) {
367 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
368 }
369 $head[$h][2] = 'supplierinvoice';
370 $h++;
371
372 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_invoice/admin/supplierinvoicedet_extrafields.php');
373 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLines");
374 $nbExtrafields = $extrafields->attributes['facture_fourn_det']['count'];
375 if ($nbExtrafields > 0) {
376 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
377 }
378 $head[$h][2] = 'supplierinvoicedet';
379 $h++;
380
381 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_invoice/admin/supplierinvoice_rec_extrafields.php');
382 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesRec");
383 $nbExtrafields = $extrafields->attributes['facture_fourn_rec']['count'];
384 if ($nbExtrafields > 0) {
385 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
386 }
387 $head[$h][2] = 'attributesrec';
388 $h++;
389
390 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_invoice/admin/supplierinvoicedet_rec_extrafields.php');
391 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLinesRec");
392 $nbExtrafields = $extrafields->attributes['facture_fourn_det_rec']['count'];
393 if ($nbExtrafields > 0) {
394 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
395 }
396 $head[$h][2] = 'attributeslinesrec';
397 $h++;
398
399 complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin', 'remove');
400
401 return $head;
402}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage predefined suppliers products.
Class to manage suppliers invoices.
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
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
supplierorder_admin_prepare_head()
Return array head with list of tabs to view object information.
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
Definition fourn.lib.php:38
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_setcache($memoryid, $data, $expire=0, $filecache=0, $replace=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid, $filecache=0)
Read a memory area shared by all users, all sessions on server.