dolibarr  17.0.3
product.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2009-2010 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6  * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
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 product_prepare_head($object)
36 {
37  global $db, $langs, $conf, $user;
38  $langs->load("products");
39 
40  $label = $langs->trans('Product');
41  $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS')?$user->hasRight('product', 'product_advance', 'read_prices'):$user->hasRight('product', 'read');
42 
43  if ($object->isService()) {
44  $label = $langs->trans('Service');
45  $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS')?$user->hasRight('service', 'service_advance', 'read_prices'):$user->hasRight('service', 'read');
46  }
47 
48  $h = 0;
49  $head = array();
50 
51  $head[$h][0] = DOL_URL_ROOT."/product/card.php?id=".$object->id;
52  $head[$h][1] = $label;
53  $head[$h][2] = 'card';
54  $h++;
55 
56  if (!empty($object->status)) {
57  if ($usercancreadprice) {
58  $head[$h][0] = DOL_URL_ROOT."/product/price.php?id=".$object->id;
59  $head[$h][1] = $langs->trans("SellingPrices");
60  $head[$h][2] = 'price';
61  $h++;
62  } else {
63  $head[$h][0] = '#';
64  $head[$h][1] = $langs->trans("SellingPrices");
65  $head[$h][2] = 'price';
66  $head[$h][5] = 'disabled';
67  $h++;
68  }
69  }
70 
71  if (!empty($object->status_buy) || (isModEnabled('margin') && !empty($object->status))) { // If margin is on and product on sell, we may need the cost price even if product os not on purchase
72  if ((((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $user->rights->fournisseur->lire)
73  || (isModEnabled('margin') && $user->hasRight("margin", "liretous"))
74  ) {
75  if ($usercancreadprice) {
76  $head[$h][0] = DOL_URL_ROOT."/product/fournisseurs.php?id=".$object->id;
77  $head[$h][1] = $langs->trans("BuyingPrices");
78  $head[$h][2] = 'suppliers';
79  $h++;
80  } else {
81  $head[$h][0] = '#';
82  $head[$h][1] = $langs->trans("BuyingPrices");
83  $head[$h][2] = 'suppliers';
84  $head[$h][5] = 'disabled';
85  $h++;
86  }
87  }
88  }
89 
90  // Multilangs
91  if (getDolGlobalInt('MAIN_MULTILANGS')) {
92  $head[$h][0] = DOL_URL_ROOT."/product/traduction.php?id=".$object->id;
93  $head[$h][1] = $langs->trans("Translations");
94  $head[$h][2] = 'translation';
95  $h++;
96  }
97 
98  // Sub products
99  if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) {
100  $head[$h][0] = DOL_URL_ROOT."/product/composition/card.php?id=".$object->id;
101  $head[$h][1] = $langs->trans('AssociatedProducts');
102 
103  $nbFatherAndChild = $object->hasFatherOrChild();
104  if ($nbFatherAndChild > 0) {
105  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFatherAndChild.'</span>';
106  }
107  $head[$h][2] = 'subproduct';
108  $h++;
109  }
110 
111  if (isModEnabled('variants') && ($object->isProduct() || $object->isService())) {
112  global $db;
113 
114  require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
115 
116  $prodcomb = new ProductCombination($db);
117 
118  if ($prodcomb->fetchByFkProductChild($object->id) <= 0) {
119  $head[$h][0] = DOL_URL_ROOT."/variants/combinations.php?id=".$object->id;
120  $head[$h][1] = $langs->trans('ProductCombinations');
121  $head[$h][2] = 'combinations';
122  $nbVariant = $prodcomb->countNbOfCombinationForFkProductParent($object->id);
123  if ($nbVariant > 0) {
124  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbVariant.'</span>';
125  }
126  }
127 
128  $h++;
129  }
130 
131  if ($object->isProduct() || ($object->isService() && !empty($conf->global->STOCK_SUPPORTS_SERVICES))) { // If physical product we can stock (or service with option)
132  if (isModEnabled('stock') && $user->rights->stock->lire) {
133  $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$object->id;
134  $head[$h][1] = $langs->trans("Stock");
135  $head[$h][2] = 'stock';
136  $h++;
137  }
138  }
139 
140  // Tab to link resources
141  if (isModEnabled('resource')) {
142  if ($object->isProduct() && !empty($conf->global->RESOURCE_ON_PRODUCTS)) {
143  $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=product&ref='.$object->ref;
144  $head[$h][1] = $langs->trans("Resources");
145  $head[$h][2] = 'resources';
146  $h++;
147  }
148  if ($object->isService() && !empty($conf->global->RESOURCE_ON_SERVICES)) {
149  $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=service&ref='.$object->ref;
150  $head[$h][1] = $langs->trans("Resources");
151  $head[$h][2] = 'resources';
152  $h++;
153  }
154  }
155 
156  $head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?showmessage=1&id=".$object->id;
157  $head[$h][1] = $langs->trans('Referers');
158  $head[$h][2] = 'referers';
159  $h++;
160 
161  $head[$h][0] = DOL_URL_ROOT."/product/stats/card.php?id=".$object->id;
162  $head[$h][1] = $langs->trans('Statistics');
163  $head[$h][2] = 'stats';
164  $h++;
165 
166  // Show more tabs from modules
167  // Entries must be declared in modules descriptor with line
168  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
169  // $this->tabs = array('entity:-tabname); to remove a tab
170  complete_head_from_modules($conf, $langs, $object, $head, $h, 'product', 'add', 'core');
171 
172  // Notes
173  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
174  $nbNote = 0;
175  if (!empty($object->note_private)) {
176  $nbNote++;
177  }
178  if (!empty($object->note_public)) {
179  $nbNote++;
180  }
181  $head[$h][0] = DOL_URL_ROOT.'/product/note.php?id='.$object->id;
182  $head[$h][1] = $langs->trans('Notes');
183  if ($nbNote > 0) {
184  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
185  }
186  $head[$h][2] = 'note';
187  $h++;
188  }
189 
190  // Attachments
191  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
192  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
193  if (isModEnabled("product") && ($object->type == Product::TYPE_PRODUCT)) {
194  $upload_dir = $conf->product->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
195  }
196  if (isModEnabled("service") && ($object->type == Product::TYPE_SERVICE)) {
197  $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
198  }
199  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
200  if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
201  if (isModEnabled("product") && ($object->type == Product::TYPE_PRODUCT)) {
202  $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id.'/photos';
203  }
204  if (isModEnabled("service") && ($object->type == Product::TYPE_SERVICE)) {
205  $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id.'/photos';
206  }
207  $nbFiles += count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
208  }
209  $nbLinks = Link::count($db, $object->element, $object->id);
210  $head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$object->id;
211  $head[$h][1] = $langs->trans('Documents');
212  if (($nbFiles + $nbLinks) > 0) {
213  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
214  }
215  $head[$h][2] = 'documents';
216  $h++;
217 
218  // Log
219  $head[$h][0] = DOL_URL_ROOT.'/product/agenda.php?id='.$object->id;
220  $head[$h][1] = $langs->trans("Events");
221  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
222  $head[$h][1] .= '/';
223  $head[$h][1] .= $langs->trans("Agenda");
224  }
225  $head[$h][2] = 'agenda';
226  $h++;
227 
228  complete_head_from_modules($conf, $langs, $object, $head, $h, 'product', 'add', 'external');
229 
230  complete_head_from_modules($conf, $langs, $object, $head, $h, 'product', 'remove');
231 
232  return $head;
233 }
234 
241 function productlot_prepare_head($object)
242 {
243  global $db, $langs, $conf, $user;
244 
245  // Load translation files required by the page
246  $langs->loadLangs(array("products", "productbatch"));
247 
248  $h = 0;
249  $head = array();
250 
251  $head[$h][0] = DOL_URL_ROOT."/product/stock/productlot_card.php?id=".$object->id;
252  $head[$h][1] = $langs->trans("Lot");
253  $head[$h][2] = 'card';
254  $h++;
255 
256  // Attachments
257  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
258  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
259  $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
260  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
261  $nbLinks = Link::count($db, $object->element, $object->id);
262  $head[$h][0] = DOL_URL_ROOT."/product/stock/productlot_document.php?id=".$object->id;
263  $head[$h][1] = $langs->trans("Documents");
264  if (($nbFiles + $nbLinks) > 0) {
265  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
266  }
267  $head[$h][2] = 'documents';
268  $h++;
269 
270  // Notes
271  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
272  $nbNote = 0;
273  if (!empty($object->note_private)) {
274  $nbNote++;
275  }
276  if (!empty($object->note_public)) {
277  $nbNote++;
278  }
279  $head[$h][0] = DOL_URL_ROOT .'/product/stock/productlot_note.php?id=' . $object->id;
280  $head[$h][1] = $langs->trans('Notes');
281  if ($nbNote > 0) {
282  $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>';
283  }
284  $head[$h][2] = 'note';
285  $h++;
286  }
287 
288  // Show more tabs from modules
289  // Entries must be declared in modules descriptor with line
290  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
291  // $this->tabs = array('entity:-tabname); to remove a tab
292  complete_head_from_modules($conf, $langs, $object, $head, $h, 'productlot');
293 
294  complete_head_from_modules($conf, $langs, $object, $head, $h, 'productlot', 'remove');
295 
296  // Log
297  /*
298  $head[$h][0] = DOL_URL_ROOT.'/product/info.php?id='.$object->id;
299  $head[$h][1] = $langs->trans("Info");
300  $head[$h][2] = 'info';
301  $h++;
302  */
303 
304  return $head;
305 }
306 
307 
308 
315 {
316  global $langs, $conf, $user, $db;
317 
318  $extrafields = new ExtraFields($db);
319  $extrafields->fetch_name_optionals_label('product');
320  $extrafields->fetch_name_optionals_label('product_fournisseur_price');
321 
322  $h = 0;
323  $head = array();
324 
325  $head[$h][0] = DOL_URL_ROOT."/product/admin/product.php";
326  $head[$h][1] = $langs->trans('Parameters');
327  $head[$h][2] = 'general';
328  $h++;
329 
330  if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($conf->global->PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL)) {
331  $head[$h] = array(
332  0 => DOL_URL_ROOT."/product/admin/price_rules.php",
333  1 => $langs->trans('MultipriceRules'),
334  2 => 'generator'
335  );
336  $h++;
337  }
338 
339  // Show more tabs from modules
340  // Entries must be declared in modules descriptor with line
341  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
342  // $this->tabs = array('entity:-tabname); to remove a tab
343  complete_head_from_modules($conf, $langs, null, $head, $h, 'product_admin');
344 
345  $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_extrafields.php';
346  $head[$h][1] = $langs->trans("ExtraFields");
347  $nbExtrafields = $extrafields->attributes['product']['count'];
348  if ($nbExtrafields > 0) {
349  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
350  }
351  $head[$h][2] = 'attributes';
352  $h++;
353 
354  $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_supplier_extrafields.php';
355  $head[$h][1] = $langs->trans("ProductSupplierExtraFields");
356  $nbExtrafields = $extrafields->attributes['product_fournisseur_price']['count'];
357  if ($nbExtrafields > 0) {
358  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
359  }
360  $head[$h][2] = 'supplierAttributes';
361  $h++;
362 
363  complete_head_from_modules($conf, $langs, null, $head, $h, 'product_admin', 'remove');
364 
365  return $head;
366 }
367 
368 
369 
376 {
377  global $langs, $conf, $user, $db;
378 
379  $extrafields = new ExtraFields($db);
380  $extrafields->fetch_name_optionals_label('product_lot');
381 
382  $h = 0;
383  $head = array();
384 
385  $head[$h][0] = DOL_URL_ROOT."/product/admin/product_lot.php";
386  $head[$h][1] = $langs->trans('Parameters');
387  $head[$h][2] = 'settings';
388  $h++;
389 
390  // Show more tabs from modules
391  // Entries must be declared in modules descriptor with line
392  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
393  // $this->tabs = array('entity:-tabname); to remove a tab
394  complete_head_from_modules($conf, $langs, null, $head, $h, 'product_lot_admin');
395 
396  $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_lot_extrafields.php';
397  $head[$h][1] = $langs->trans("ExtraFields");
398  $nbExtrafields = $extrafields->attributes['product_lot']['count'];
399  if ($nbExtrafields > 0) {
400  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
401  }
402  $head[$h][2] = 'attributes';
403  $h++;
404 
405  complete_head_from_modules($conf, $langs, null, $head, $h, 'product_lot_admin', 'remove');
406 
407  return $head;
408 }
409 
410 
411 
419 function show_stats_for_company($product, $socid)
420 {
421  global $conf, $langs, $user, $db, $hookmanager;
422 
423  $form = new Form($db);
424 
425  $nblines = 0;
426 
427  print '<tr class="liste_titre">';
428  print '<td class="left" width="25%">'.$langs->trans("Referers").'</td>';
429  print '<td class="right" width="25%">'.$langs->trans("NbOfThirdParties").'</td>';
430  print '<td class="right" width="25%">'.$langs->trans("NbOfObjectReferers").'</td>';
431  print '<td class="right" width="25%">'.$langs->trans("TotalQuantity").'</td>';
432  print '</tr>';
433 
434  // Customer proposals
435  if (isModEnabled("propal") && $user->rights->propal->lire) {
436  $nblines++;
437  $ret = $product->load_stats_propale($socid);
438  if ($ret < 0) {
439  dol_print_error($db);
440  }
441  $langs->load("propal");
442  print '<tr><td>';
443  print '<a href="propal.php?id='.$product->id.'">'.img_object('', 'propal', 'class="pictofixedwidth"').$langs->trans("Proposals").'</a>';
444  print '</td><td class="right">';
445  print $product->stats_propale['customers'];
446  print '</td><td class="right">';
447  print $product->stats_propale['nb'];
448  print '</td><td class="right">';
449  print $product->stats_propale['qty'];
450  print '</td>';
451  print '</tr>';
452  }
453  // Supplier proposals
454  if (isModEnabled('supplier_proposal') && $user->rights->supplier_proposal->lire) {
455  $nblines++;
456  $ret = $product->load_stats_proposal_supplier($socid);
457  if ($ret < 0) {
458  dol_print_error($db);
459  }
460  $langs->load("supplier_proposal");
461  print '<tr><td>';
462  print '<a href="supplier_proposal.php?id='.$product->id.'">'.img_object('', 'supplier_proposal', 'class="pictofixedwidth"').$langs->trans("SupplierProposals").'</a>';
463  print '</td><td class="right">';
464  print $product->stats_proposal_supplier['suppliers'];
465  print '</td><td class="right">';
466  print $product->stats_proposal_supplier['nb'];
467  print '</td><td class="right">';
468  print $product->stats_proposal_supplier['qty'];
469  print '</td>';
470  print '</tr>';
471  }
472  // Sales orders
473  if (isModEnabled('commande') && $user->rights->commande->lire) {
474  $nblines++;
475  $ret = $product->load_stats_commande($socid);
476  if ($ret < 0) {
477  dol_print_error($db);
478  }
479  $langs->load("orders");
480  print '<tr><td>';
481  print '<a href="commande.php?id='.$product->id.'">'.img_object('', 'order', 'class="pictofixedwidth"').$langs->trans("CustomersOrders").'</a>';
482  print '</td><td class="right">';
483  print $product->stats_commande['customers'];
484  print '</td><td class="right">';
485  print $product->stats_commande['nb'];
486  print '</td><td class="right">';
487  print $product->stats_commande['qty'];
488  print '</td>';
489  print '</tr>';
490  }
491  // Supplier orders
492  if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->commande->lire) || (isModEnabled("supplier_order") && $user->rights->supplier_order->lire)) {
493  $nblines++;
494  $ret = $product->load_stats_commande_fournisseur($socid);
495  if ($ret < 0) {
496  dol_print_error($db);
497  }
498  $langs->load("orders");
499  print '<tr><td>';
500  print '<a href="commande_fournisseur.php?id='.$product->id.'">'.img_object('', 'supplier_order', 'class="pictofixedwidth"').$langs->trans("SuppliersOrders").'</a>';
501  print '</td><td class="right">';
502  print $product->stats_commande_fournisseur['suppliers'];
503  print '</td><td class="right">';
504  print $product->stats_commande_fournisseur['nb'];
505  print '</td><td class="right">';
506  print $product->stats_commande_fournisseur['qty'];
507  print '</td>';
508  print '</tr>';
509  }
510  // Customer invoices
511  if (isModEnabled('facture') && $user->rights->facture->lire) {
512  $nblines++;
513  $ret = $product->load_stats_facture($socid);
514  if ($ret < 0) {
515  dol_print_error($db);
516  }
517  $langs->load("bills");
518  print '<tr><td>';
519  print '<a href="facture.php?id='.$product->id.'">'.img_object('', 'bill', 'class="pictofixedwidth"').$langs->trans("CustomersInvoices").'</a>';
520  print '</td><td class="right">';
521  print $product->stats_facture['customers'];
522  print '</td><td class="right">';
523  print $product->stats_facture['nb'];
524  print '</td><td class="right">';
525  print $product->stats_facture['qty'];
526  print '</td>';
527  print '</tr>';
528  }
529  // Customer template invoices
530  if (isModEnabled("facture") && $user->rights->facture->lire) {
531  $nblines++;
532  $ret = $product->load_stats_facturerec($socid);
533  if ($ret < 0) {
534  dol_print_error($db);
535  }
536  $langs->load("bills");
537  print '<tr><td>';
538  print '<a href="facturerec.php?id='.$product->id.'">'.img_object('', 'bill', 'class="pictofixedwidth"').$langs->trans("RecurringInvoiceTemplate").'</a>';
539  print '</td><td class="right">';
540  print $product->stats_facture['customers'];
541  print '</td><td class="right">';
542  print $product->stats_facturerec['nb'];
543  print '</td><td class="right">';
544  print $product->stats_facturerec['qty'];
545  print '</td>';
546  print '</tr>';
547  }
548  // Supplier invoices
549  if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire) || (isModEnabled("supplier_invoice") && $user->rights->supplier_invoice->lire)) {
550  $nblines++;
551  $ret = $product->load_stats_facture_fournisseur($socid);
552  if ($ret < 0) {
553  dol_print_error($db);
554  }
555  $langs->load("bills");
556  print '<tr><td>';
557  print '<a href="facture_fournisseur.php?id='.$product->id.'">'.img_object('', 'supplier_invoice', 'class="pictofixedwidth"').$langs->trans("SuppliersInvoices").'</a>';
558  print '</td><td class="right">';
559  print $product->stats_facture_fournisseur['suppliers'];
560  print '</td><td class="right">';
561  print $product->stats_facture_fournisseur['nb'];
562  print '</td><td class="right">';
563  print $product->stats_facture_fournisseur['qty'];
564  print '</td>';
565  print '</tr>';
566  }
567 
568  // Contracts
569  if (isModEnabled('contrat') && $user->rights->contrat->lire) {
570  $nblines++;
571  $ret = $product->load_stats_contrat($socid);
572  if ($ret < 0) {
573  dol_print_error($db);
574  }
575  $langs->load("contracts");
576  print '<tr><td>';
577  print '<a href="contrat.php?id='.$product->id.'">'.img_object('', 'contract', 'class="pictofixedwidth"').$langs->trans("Contracts").'</a>';
578  print '</td><td class="right">';
579  print $product->stats_contrat['customers'];
580  print '</td><td class="right">';
581  print $product->stats_contrat['nb'];
582  print '</td><td class="right">';
583  print $product->stats_contrat['qty'];
584  print '</td>';
585  print '</tr>';
586  }
587 
588  // BOM
589  if (isModEnabled('bom') && $user->rights->bom->read) {
590  $nblines++;
591  $ret = $product->load_stats_bom($socid);
592  if ($ret < 0) {
593  setEventMessage($product->error, 'errors');
594  }
595  $langs->load("mrp");
596 
597  print '<tr><td>';
598  print '<a href="bom.php?id='.$product->id.'">'.img_object('', 'bom', 'class="pictofixedwidth"').$langs->trans("BOM").'</a>';
599  print '</td><td class="right">';
600 
601  print '</td><td class="right">';
602  print $form->textwithpicto($product->stats_bom['nb_toconsume'], $langs->trans("RowMaterial"));
603  print $form->textwithpicto($product->stats_bom['nb_toproduce'], $langs->trans("Finished"));
604  print '</td><td class="right">';
605  print $form->textwithpicto($product->stats_bom['qty_toconsume'], $langs->trans("RowMaterial"));
606  print $form->textwithpicto($product->stats_bom['qty_toproduce'], $langs->trans("Finished"));
607  print '</td>';
608  print '</tr>';
609  }
610 
611  // MO
612  if (isModEnabled('mrp') && !empty($user->rights->mrp->read)) {
613  $nblines++;
614  $ret = $product->load_stats_mo($socid);
615  if ($ret < 0) {
616  setEventMessages($product->error, $product->errors, 'errors');
617  }
618  $langs->load("mrp");
619  print '<tr><td>';
620  print '<a href="mo.php?id='.$product->id.'">'.img_object('', 'mrp', 'class="pictofixedwidth"').$langs->trans("MO").'</a>';
621  print '</td><td class="right">';
622  print $form->textwithpicto($product->stats_mo['customers_toconsume'], $langs->trans("ToConsume"));
623  print $form->textwithpicto($product->stats_mo['customers_consumed'], $langs->trans("QtyAlreadyConsumed"));
624  print $form->textwithpicto($product->stats_mo['customers_toproduce'], $langs->trans("QtyToProduce"));
625  print $form->textwithpicto($product->stats_mo['customers_produced'], $langs->trans("QtyAlreadyProduced"));
626  print '</td><td class="right">';
627  print $form->textwithpicto($product->stats_mo['nb_toconsume'], $langs->trans("ToConsume"));
628  print $form->textwithpicto($product->stats_mo['nb_consumed'], $langs->trans("QtyAlreadyConsumed"));
629  print $form->textwithpicto($product->stats_mo['nb_toproduce'], $langs->trans("QtyToProduce"));
630  print $form->textwithpicto($product->stats_mo['nb_produced'], $langs->trans("QtyAlreadyProduced"));
631  print '</td><td class="right">';
632  print $form->textwithpicto($product->stats_mo['qty_toconsume'], $langs->trans("ToConsume"));
633  print $form->textwithpicto($product->stats_mo['qty_consumed'], $langs->trans("QtyAlreadyConsumed"));
634  print $form->textwithpicto($product->stats_mo['qty_toproduce'], $langs->trans("QtyToProduce"));
635  print $form->textwithpicto($product->stats_mo['qty_produced'], $langs->trans("QtyAlreadyProduced"));
636  print '</td>';
637  print '</tr>';
638  }
639  $parameters = array('socid'=>$socid);
640  $reshook = $hookmanager->executeHooks('addMoreProductStat', $parameters, $product, $nblines); // Note that $action and $object may have been modified by some hooks
641  if ($reshook < 0) {
642  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
643  }
644 
645  print $hookmanager->resPrint;
646 
647 
648  return $nblines++;
649 }
650 
663 function measuring_units_string($scale = '', $measuring_style = '', $unit = 0, $use_short_label = 0, $outputlangs = null)
664 {
665  return measuringUnitString($unit, $measuring_style, $scale, $use_short_label, $outputlangs);
666 }
667 
679 function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_short_label = 0, $outputlangs = null)
680 {
681  global $langs, $db;
682  global $measuring_unit_cache;
683 
684  if (empty($outputlangs)) {
685  $outputlangs = $langs;
686  }
687 
688  if (empty($measuring_unit_cache[$unit.'_'.$measuring_style.'_'.$scale.'_'.$use_short_label])) {
689  require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
690  $measuringUnits = new CUnits($db);
691 
692  if ($measuring_style == '' && $scale == '') {
693  $arrayforfilter = array(
694  't.rowid' => $unit,
695  't.active' => 1
696  );
697  } elseif ($scale !== '') {
698  $arrayforfilter = array(
699  't.scale' => $scale,
700  't.unit_type' => $measuring_style,
701  't.active' => 1
702  );
703  } else {
704  $arrayforfilter = array(
705  't.rowid' => $unit,
706  't.unit_type' => $measuring_style,
707  't.active' => 1
708  );
709  }
710  $result = $measuringUnits->fetchAll('', '', 0, 0, $arrayforfilter);
711 
712  if ($result < 0) {
713  return -1;
714  } else {
715  if (is_array($measuringUnits->records) && count($measuringUnits->records) > 0) {
716  if ($use_short_label) {
717  $labeltoreturn = $measuringUnits->records[key($measuringUnits->records)]->short_label;
718  } else {
719  $labeltoreturn = $outputlangs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label);
720  }
721  } else {
722  $labeltoreturn = '';
723  }
724  $measuring_unit_cache[$unit.'_'.$measuring_style.'_'.$scale.'_'.$use_short_label] = $labeltoreturn;
725  return $labeltoreturn;
726  }
727  } else {
728  return $measuring_unit_cache[$unit.'_'.$measuring_style.'_'.$scale.'_'.$use_short_label];
729  }
730 }
731 
739 function measuring_units_squared($unit)
740 {
741  $measuring_units = array();
742  $measuring_units[0] = 0; // m -> m3
743  $measuring_units[-1] = -2; // dm-> dm2
744  $measuring_units[-2] = -4; // cm -> cm2
745  $measuring_units[-3] = -6; // mm -> mm2
746  $measuring_units[98] = 98; // foot -> foot2
747  $measuring_units[99] = 99; // inch -> inch2
748  return $measuring_units[$unit];
749 }
750 
751 
759 function measuring_units_cubed($unit)
760 {
761  $measuring_units = array();
762  $measuring_units[0] = 0; // m -> m2
763  $measuring_units[-1] = -3; // dm-> dm3
764  $measuring_units[-2] = -6; // cm -> cm3
765  $measuring_units[-3] = -9; // mm -> mm3
766  $measuring_units[98] = 88; // foot -> foot3
767  $measuring_units[99] = 89; // inch -> inch3
768  return $measuring_units[$unit];
769 }
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
ProductCombination
Class ProductCombination Used to represent a product combination.
Definition: ProductCombination.class.php:24
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:4993
measuring_units_squared
measuring_units_squared($unit)
Transform a given unit scale into the square of that unit, if known.
Definition: product.lib.php:739
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, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
product_prepare_head
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
productlot_prepare_head
productlot_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:241
measuringUnitString
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
Definition: product.lib.php:679
measuring_units_string
measuring_units_string($scale='', $measuring_style='', $unit=0, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
Definition: product.lib.php:663
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:6735
complete_head_from_modules
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).
Definition: functions.lib.php:9395
product_lot_admin_prepare_head
product_lot_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: product.lib.php:375
CUnits
Class of dictionary type of thirdparty (used by imports)
Definition: cunits.class.php:28
setEventMessage
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Definition: functions.lib.php:8437
product_admin_prepare_head
product_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: product.lib.php:314
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
measuring_units_cubed
measuring_units_cubed($unit)
Transform a given unit scale into the cube of that unit, if known.
Definition: product.lib.php:759
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4360
show_stats_for_company
show_stats_for_company($product, $socid)
Show stats for company.
Definition: product.lib.php:419
Product\TYPE_SERVICE
const TYPE_SERVICE
Service.
Definition: product.class.php:546
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8466
Product\TYPE_PRODUCT
const TYPE_PRODUCT
Regular product.
Definition: product.class.php:542
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96