dolibarr  17.0.4
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 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 
35 function facturefourn_prepare_head($object)
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 (!empty($conf->paymentbybanktransfer->enabled)) {
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 pfd.ext_payment_id IS NULL";
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  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id.'&type=bank-transfer';
75  $head[$h][1] = $langs->trans('BankTransfer');
76  if ($nbStandingOrders > 0) {
77  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
78  }
79  $head[$h][2] = 'standingorders';
80  $h++;
81  }
82 
83  // Show more tabs from modules
84  // Entries must be declared in modules descriptor with line
85  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
86  // $this->tabs = array('entity:-tabname); to remove a tab
87  complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'core');
88 
89  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
90  $nbNote = 0;
91  if (!empty($object->note_private)) {
92  $nbNote++;
93  }
94  if (!empty($object->note_public)) {
95  $nbNote++;
96  }
97  $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/note.php?facid='.$object->id;
98  $head[$h][1] = $langs->trans('Notes');
99  if ($nbNote > 0) {
100  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
101  }
102  $head[$h][2] = 'note';
103  $h++;
104  }
105 
106  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
107  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
108  $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object->ref;
109  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
110  $nbLinks = Link::count($db, $object->element, $object->id);
111  $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id;
112  $head[$h][1] = $langs->trans('Documents');
113  if (($nbFiles + $nbLinks) > 0) {
114  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
115  }
116  $head[$h][2] = 'documents';
117  $h++;
118 
119  $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/info.php?facid='.$object->id;
120  $head[$h][1] = $langs->trans('Info');
121  $head[$h][2] = 'info';
122  $h++;
123 
124  complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'external');
125 
126  complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'remove');
127 
128  return $head;
129 }
130 
131 
139 {
140  global $db, $langs, $conf, $user;
141 
142  $h = 0;
143  $head = array();
144 
145  $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id;
146  $head[$h][1] = $langs->trans("SupplierOrder");
147  $head[$h][2] = 'card';
148  $h++;
149 
150  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
151  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
152  $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/contact.php?id='.$object->id;
153  $head[$h][1] = $langs->trans('ContactsAddresses');
154  if ($nbContact > 0) {
155  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
156  }
157  $head[$h][2] = 'contact';
158  $h++;
159  }
160 
161  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))) {
162  $langs->load("stocks");
163  $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id;
164  $head[$h][1] = $langs->trans("OrderDispatch");
165 
166  //If dispach process running we add the number of item to dispatch into the head
167  if (in_array($object->statut, array($object::STATUS_ORDERSENT, $object::STATUS_RECEIVED_PARTIALLY, $object::STATUS_RECEIVED_COMPLETELY))) {
168  $sumQtyAllreadyDispatched = 0;
169  $sumQtyOrdered = 0;
170 
171  if (empty($object->lines)) {
172  $object->fetch_lines();
173  }
174  $nbLinesOrdered = count($object->lines);
175  $dispachedLines = $object->getDispachedLines(1);
176  $nbDispachedLines = count($dispachedLines);
177 
178  for ($line = 0 ; $line < $nbDispachedLines; $line++) {
179  $sumQtyAllreadyDispatched = $sumQtyAllreadyDispatched + $dispachedLines[$line]['qty'];
180  }
181  for ($line = 0 ; $line < $nbLinesOrdered; $line++) {
182  //If line is a product of conf to manage stocks for services
183  if ($object->lines[$line]->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
184  $sumQtyOrdered = $sumQtyOrdered + $object->lines[$line]->qty;
185  }
186  }
187  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.price2num($sumQtyAllreadyDispatched, 'MS').' / '.price2num($sumQtyOrdered, 'MS').'</span>';
188  }
189 
190  $head[$h][2] = 'dispatch';
191  $h++;
192  }
193 
194  // Show more tabs from modules
195  // Entries must be declared in modules descriptor with line
196  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
197  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
198  complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'core');
199 
200  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
201  $nbNote = 0;
202  if (!empty($object->note_private)) {
203  $nbNote++;
204  }
205  if (!empty($object->note_public)) {
206  $nbNote++;
207  }
208  $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$object->id;
209  $head[$h][1] = $langs->trans("Notes");
210  if ($nbNote > 0) {
211  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
212  }
213  $head[$h][2] = 'note';
214  $h++;
215  }
216 
217  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
218  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
219  $upload_dir = $conf->fournisseur->dir_output."/commande/".dol_sanitizeFileName($object->ref);
220  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
221  $nbLinks = Link::count($db, $object->element, $object->id);
222  $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id;
223  $head[$h][1] = $langs->trans('Documents');
224  if (($nbFiles + $nbLinks) > 0) {
225  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
226  }
227  $head[$h][2] = 'documents';
228  $h++;
229 
230  $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/info.php?id='.$object->id;
231  $head[$h][1] = $langs->trans("Events");
232  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
233  $head[$h][1] .= '/';
234  $head[$h][1] .= $langs->trans("Agenda");
235  }
236  $head[$h][2] = 'info';
237  $h++;
238 
239  complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'external');
240 
241  complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'remove');
242 
243  return $head;
244 }
245 
252 {
253  global $langs, $conf, $user, $db;
254 
255  $extrafields = new ExtraFields($db);
256  $extrafields->fetch_name_optionals_label('commande_fournisseur');
257  $extrafields->fetch_name_optionals_label('commande_fournisseurdet');
258  $extrafields->fetch_name_optionals_label('facture_fourn');
259  $extrafields->fetch_name_optionals_label('facture_fourn_det');
260 
261  $h = 0;
262  $head = array();
263 
264  $head[$h][0] = DOL_URL_ROOT."/admin/supplier_order.php";
265  $head[$h][1] = $langs->trans("SupplierOrder");
266  $head[$h][2] = 'order';
267  $h++;
268 
269  $head[$h][0] = DOL_URL_ROOT."/admin/supplier_invoice.php";
270  $head[$h][1] = $langs->trans("SuppliersInvoice");
271  $head[$h][2] = 'invoice';
272  $h++;
273 
274  $head[$h][0] = DOL_URL_ROOT."/admin/supplier_payment.php";
275  $head[$h][1] = $langs->trans("SuppliersPayment");
276  $head[$h][2] = 'supplierpayment';
277  $h++;
278 
279  complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin');
280 
281  $head[$h][0] = DOL_URL_ROOT.'/admin/supplierorder_extrafields.php';
282  $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrders");
283  $nbExtrafields = $extrafields->attributes['commande_fournisseur']['count'];
284  if ($nbExtrafields > 0) {
285  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
286  }
287  $head[$h][2] = 'supplierorder';
288  $h++;
289 
290  $head[$h][0] = DOL_URL_ROOT.'/admin/supplierorderdet_extrafields.php';
291  $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrdersLines");
292  $nbExtrafields = $extrafields->attributes['commande_fournisseurdet']['count'];
293  if ($nbExtrafields > 0) {
294  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
295  }
296  $head[$h][2] = 'supplierorderdet';
297  $h++;
298 
299  $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoice_extrafields.php';
300  $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoices");
301  $nbExtrafields = $extrafields->attributes['facture_fourn']['count'];
302  if ($nbExtrafields > 0) {
303  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
304  }
305  $head[$h][2] = 'supplierinvoice';
306  $h++;
307 
308  $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoicedet_extrafields.php';
309  $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLines");
310  $nbExtrafields = $extrafields->attributes['facture_fourn_det']['count'];
311  if ($nbExtrafields > 0) {
312  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
313  }
314  $head[$h][2] = 'supplierinvoicedet';
315  $h++;
316 
317  complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin', 'remove');
318 
319  return $head;
320 }
Class to manage predefined suppliers products.
Class to manage standard extra fields.
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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:61
facturefourn_prepare_head($object)
Prepare array with list of tabs.
Definition: fourn.lib.php:35
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
Definition: fourn.lib.php:138
supplierorder_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: fourn.lib.php:251
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.