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