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