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