dolibarr 21.0.0-alpha
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-2023 Frédéric France <frederic.france@netlogic.fr>
7 * Copyright (C) 2023 Nick Fragoulis
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
38{
39 global $db, $langs, $conf, $user;
40
41 $h = 0;
42 $head = array();
43
44 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$object->id;
45 $head[$h][1] = $langs->trans('SupplierInvoice');
46 $head[$h][2] = 'card';
47 $h++;
48
49 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
50 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
51 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/contact.php?facid='.$object->id;
52 $head[$h][1] = $langs->trans('ContactsAddresses');
53 if ($nbContact > 0) {
54 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
55 }
56 $head[$h][2] = 'contact';
57 $h++;
58 }
59
60 //if ($fac->mode_reglement_code == 'PRE')
61 if (isModEnabled('paymentbybanktransfer')) {
62 $nbStandingOrders = 0;
63 $sql = "SELECT COUNT(pfd.rowid) as nb";
64 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
65 $sql .= " WHERE pfd.fk_facture_fourn = ".((int) $object->id);
66 $sql .= " AND type = 'ban'";
67 $resql = $db->query($sql);
68 if ($resql) {
69 $obj = $db->fetch_object($resql);
70 if ($obj) {
71 $nbStandingOrders = $obj->nb;
72 }
73 } else {
74 dol_print_error($db);
75 }
76 $langs->load("banks");
77 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id.'&type=bank-transfer';
78 $head[$h][1] = $langs->trans('BankTransfer');
79 if ($nbStandingOrders > 0) {
80 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
81 }
82 $head[$h][2] = 'standingorders';
83 $h++;
84 }
85
86 // Show more tabs from modules
87 // Entries must be declared in modules descriptor with line
88 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
89 // $this->tabs = array('entity:-tabname); to remove a tab
90 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'core');
91
92 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
93 $nbNote = 0;
94 if (!empty($object->note_private)) {
95 $nbNote++;
96 }
97 if (!empty($object->note_public)) {
98 $nbNote++;
99 }
100 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/note.php?facid='.$object->id;
101 $head[$h][1] = $langs->trans('Notes');
102 if ($nbNote > 0) {
103 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
104 }
105 $head[$h][2] = 'note';
106 $h++;
107 }
108
109 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
110 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
111 $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object->ref;
112 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
113 $nbLinks = Link::count($db, $object->element, $object->id);
114 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id;
115 $head[$h][1] = $langs->trans('Documents');
116 if (($nbFiles + $nbLinks) > 0) {
117 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
118 }
119 $head[$h][2] = 'documents';
120 $h++;
121
122 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/info.php?facid='.$object->id;
123 $head[$h][1] = $langs->trans('Info');
124 $head[$h][2] = 'info';
125 $h++;
126
127 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/agenda.php?id='.$object->id;
128 $head[$h][1] = $langs->trans("Events");
129 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
130 $nbEvent = 0;
131 // Enable caching of thirdparty count actioncomm
132 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
133 $cachekey = 'count_events_facture_'.$object->id;
134 $dataretrieved = dol_getcache($cachekey);
135 if (!is_null($dataretrieved)) {
136 $nbEvent = $dataretrieved;
137 } else {
138 $sql = "SELECT COUNT(id) as nb";
139 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
140 $sql .= " WHERE fk_element = ".((int) $object->id);
141 $sql .= " AND elementtype = 'invoice_supplier'";
142 $resql = $db->query($sql);
143 if ($resql) {
144 $obj = $db->fetch_object($resql);
145 $nbEvent = $obj->nb;
146 } else {
147 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
148 }
149 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
150 }
151
152 $head[$h][1] .= '/';
153 $head[$h][1] .= $langs->trans("Agenda");
154 if ($nbEvent > 0) {
155 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
156 }
157 }
158 $head[$h][2] = 'agenda';
159 $h++;
160
161 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'external');
162
163 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'remove');
164
165 return $head;
166}
167
168
176{
177 global $db, $langs, $conf, $user;
178
179 $h = 0;
180 $head = array();
181
182 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id;
183 $head[$h][1] = $langs->trans("SupplierOrder");
184 $head[$h][2] = 'card';
185 $h++;
186
187 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
188 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
189 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/contact.php?id='.$object->id;
190 $head[$h][1] = $langs->trans('ContactsAddresses');
191 if ($nbContact > 0) {
192 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
193 }
194 $head[$h][2] = 'contact';
195 $h++;
196 }
197
198 if (isModEnabled('stock') && (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE'))) {
199 $langs->load("stocks");
200 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id;
201 $head[$h][1] = $langs->trans("OrderDispatch");
202
203 //If dispatch process running we add the number of item to dispatch into the head
204 if (in_array($object->statut, array($object::STATUS_ORDERSENT, $object::STATUS_RECEIVED_PARTIALLY, $object::STATUS_RECEIVED_COMPLETELY))) {
205 $sumQtyAllreadyDispatched = 0;
206 $sumQtyOrdered = 0;
207
208 if (empty($object->lines)) {
209 $object->fetch_lines();
210 }
211 $nbLinesOrdered = count($object->lines);
212 $dispachedLines = $object->getDispachedLines(1);
213 $nbDispachedLines = count($dispachedLines);
214
215 for ($line = 0 ; $line < $nbDispachedLines; $line++) {
216 $sumQtyAllreadyDispatched += $dispachedLines[$line]['qty'];
217 }
218 for ($line = 0 ; $line < $nbLinesOrdered; $line++) {
219 //If line is a product of conf to manage stocks for services
220 if ($object->lines[$line]->product_type == 0 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
221 $sumQtyOrdered += $object->lines[$line]->qty;
222 }
223 }
224 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.price2num($sumQtyAllreadyDispatched, 'MS').' / '.price2num($sumQtyOrdered, 'MS').'</span>';
225 }
226
227 $head[$h][2] = 'dispatch';
228 $h++;
229 }
230
231 // Show more tabs from modules
232 // Entries must be declared in modules descriptor with line
233 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
234 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
235 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'core');
236
237 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
238 $nbNote = 0;
239 if (!empty($object->note_private)) {
240 $nbNote++;
241 }
242 if (!empty($object->note_public)) {
243 $nbNote++;
244 }
245 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$object->id;
246 $head[$h][1] = $langs->trans("Notes");
247 if ($nbNote > 0) {
248 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
249 }
250 $head[$h][2] = 'note';
251 $h++;
252 }
253
254 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
255 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
256 $upload_dir = $conf->fournisseur->dir_output."/commande/".dol_sanitizeFileName($object->ref);
257 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
258 $nbLinks = Link::count($db, $object->element, $object->id);
259 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id;
260 $head[$h][1] = $langs->trans('Documents');
261 if (($nbFiles + $nbLinks) > 0) {
262 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
263 }
264 $head[$h][2] = 'documents';
265 $h++;
266
267 $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/info.php?id='.$object->id;
268 $head[$h][1] = $langs->trans("Events");
269 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
270 $head[$h][1] .= '/';
271 $head[$h][1] .= $langs->trans("Agenda");
272 }
273 $head[$h][2] = 'info';
274 $h++;
275
276 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'external');
277
278 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'remove');
279
280 return $head;
281}
282
289{
290 global $langs, $conf, $user, $db;
291
292 $extrafields = new ExtraFields($db);
293 $extrafields->fetch_name_optionals_label('commande_fournisseur');
294 $extrafields->fetch_name_optionals_label('commande_fournisseurdet');
295 $extrafields->fetch_name_optionals_label('facture_fourn');
296 $extrafields->fetch_name_optionals_label('facture_fourn_det');
297 $extrafields->fetch_name_optionals_label('facture_fourn_rec');
298 $extrafields->fetch_name_optionals_label('facture_fourn_det_rec');
299
300 $h = 0;
301 $head = array();
302
303 $head[$h][0] = DOL_URL_ROOT."/admin/supplier_order.php";
304 $head[$h][1] = $langs->trans("SupplierOrder");
305 $head[$h][2] = 'order';
306 $h++;
307
308 $head[$h][0] = DOL_URL_ROOT."/admin/supplier_invoice.php";
309 $head[$h][1] = $langs->trans("SuppliersInvoice");
310 $head[$h][2] = 'invoice';
311 $h++;
312
313 $head[$h][0] = DOL_URL_ROOT."/admin/supplier_payment.php";
314 $head[$h][1] = $langs->trans("SuppliersPayment");
315 $head[$h][2] = 'supplierpayment';
316 $h++;
317
318 complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin');
319
320 $head[$h][0] = DOL_URL_ROOT.'/admin/supplierorder_extrafields.php';
321 $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrders");
322 $nbExtrafields = $extrafields->attributes['commande_fournisseur']['count'];
323 if ($nbExtrafields > 0) {
324 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
325 }
326 $head[$h][2] = 'supplierorder';
327 $h++;
328
329 $head[$h][0] = DOL_URL_ROOT.'/admin/supplierorderdet_extrafields.php';
330 $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrdersLines");
331 $nbExtrafields = $extrafields->attributes['commande_fournisseurdet']['count'];
332 if ($nbExtrafields > 0) {
333 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
334 }
335 $head[$h][2] = 'supplierorderdet';
336 $h++;
337
338 $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoice_extrafields.php';
339 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoices");
340 $nbExtrafields = $extrafields->attributes['facture_fourn']['count'];
341 if ($nbExtrafields > 0) {
342 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
343 }
344 $head[$h][2] = 'supplierinvoice';
345 $h++;
346
347 $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoicedet_extrafields.php';
348 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLines");
349 $nbExtrafields = $extrafields->attributes['facture_fourn_det']['count'];
350 if ($nbExtrafields > 0) {
351 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
352 }
353 $head[$h][2] = 'supplierinvoicedet';
354 $h++;
355
356 $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoice_rec_extrafields.php';
357 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesRec");
358 $nbExtrafields = $extrafields->attributes['facture_fourn_rec']['count'];
359 if ($nbExtrafields > 0) {
360 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
361 }
362 $head[$h][2] = 'attributesrec';
363 $h++;
364
365 $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoicedet_rec_extrafields.php';
366 $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLinesRec");
367 $nbExtrafields = $extrafields->attributes['facture_fourn_det_rec']['count'];
368 if ($nbExtrafields > 0) {
369 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
370 }
371 $head[$h][2] = 'attributeslinesrec';
372 $h++;
373
374 complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin', 'remove');
375
376 return $head;
377}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage predefined suppliers products.
Class to manage standard extra fields.
Class to manage suppliers invoices.
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:63
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:37
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
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.
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)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.