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