dolibarr/htdocs/core/lib/product.lib.php

362 lines
12 KiB
PHP
Raw Normal View History

<?php
2008-09-04 17:56:55 +00:00
/* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2012-12-30 14:13:49 +00:00
* Copyright (C) 2009-2010 Regis Houssin <regis.houssin@capnetworks.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2011-07-31 23:24:38 +00:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
2011-10-24 10:59:44 +00:00
* \file htdocs/core/lib/product.lib.php
2008-09-04 17:56:55 +00:00
* \brief Ensemble de fonctions de base pour le module produit et service
* \ingroup product
2008-08-28 00:31:27 +00:00
*/
2012-02-04 09:48:47 +00:00
/**
* Prepare array with list of tabs
*
* @param Object $object Object related to tabs
* @param User $user Object user
* @return array Array of tabs to shoc
*/
function product_prepare_head($object, $user)
{
2008-08-28 00:31:27 +00:00
global $langs, $conf;
$langs->load("products");
2008-08-28 00:31:27 +00:00
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$object->id;
2008-08-28 00:31:27 +00:00
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'card';
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/price.php?id=".$object->id;
$head[$h][1] = $langs->trans("CustomerPrices");
2008-08-28 00:31:27 +00:00
$head[$h][2] = 'price';
$h++;
2012-09-15 09:21:22 +00:00
if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire)
{
$head[$h][0] = DOL_URL_ROOT."/product/fournisseurs.php?id=".$object->id;
$head[$h][1] = $langs->trans("SuppliersPrices");
$head[$h][2] = 'suppliers';
$h++;
}
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$object->id;
2008-08-28 00:31:27 +00:00
$head[$h][1] = $langs->trans("Photos");
$head[$h][2] = 'photos';
$h++;
2008-09-04 17:56:55 +00:00
// Show category tab
2012-09-15 09:21:22 +00:00
if (! empty($conf->categorie->enabled) && $user->rights->categorie->lire)
2008-08-28 00:31:27 +00:00
{
$head[$h][0] = DOL_URL_ROOT."/categories/categorie.php?id=".$object->id.'&type=0';
2008-08-28 00:31:27 +00:00
$head[$h][1] = $langs->trans('Categories');
$head[$h][2] = 'category';
$h++;
2006-12-12 22:31:27 +00:00
}
2008-08-28 00:31:27 +00:00
// Multilangs
2012-09-15 08:01:35 +00:00
if (! empty($conf->global->MAIN_MULTILANGS))
{
$head[$h][0] = DOL_URL_ROOT."/product/traduction.php?id=".$object->id;
2008-08-28 00:31:27 +00:00
$head[$h][1] = $langs->trans("Translation");
$head[$h][2] = 'translation';
$h++;
}
2008-09-04 17:56:55 +00:00
// Sub products
2012-09-15 08:01:35 +00:00
if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
2008-08-28 00:31:27 +00:00
{
$head[$h][0] = DOL_URL_ROOT."/product/composition/fiche.php?id=".$object->id;
2008-08-28 00:31:27 +00:00
$head[$h][1] = $langs->trans('AssociatedProducts');
$head[$h][2] = 'subproduct';
$h++;
}
$head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$object->id;
2008-08-28 00:31:27 +00:00
$head[$h][1] = $langs->trans('Statistics');
$head[$h][2] = 'stats';
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$object->id;
2008-08-28 00:31:27 +00:00
$head[$h][1] = $langs->trans('Referers');
$head[$h][2] = 'referers';
$h++;
2011-01-24 23:35:21 +00:00
if($object->isproduct()) // Si produit stockable
{
2012-09-15 09:21:22 +00:00
if (! empty($conf->stock->enabled) && $user->rights->stock->lire)
2011-01-24 23:35:21 +00:00
{
$head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$object->id;
$head[$h][1] = $langs->trans("Stock");
$head[$h][2] = 'stock';
$h++;
}
}
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
2011-01-24 23:35:21 +00:00
complete_head_from_modules($conf,$langs,$object,$head,$h,'product');
2013-07-15 23:28:24 +00:00
// Attachments
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
2014-01-26 18:27:42 +00:00
$nbFiles = count(dol_dir_list($upload_dir,'files'));
2011-01-24 23:35:21 +00:00
$head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$object->id;
2008-08-28 00:31:27 +00:00
$head[$h][1] = $langs->trans('Documents');
2013-07-15 23:28:24 +00:00
if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')';
2008-08-28 00:31:27 +00:00
$head[$h][2] = 'documents';
$h++;
2008-12-07 19:19:32 +00:00
// More tabs from canvas
// TODO Is this still used ?
if (isset($object->onglets) && is_array($object->onglets))
{
foreach ($object->onglets as $onglet)
2008-08-28 00:31:27 +00:00
{
2008-12-07 19:19:32 +00:00
$head[$h] = $onglet;
$h++;
2008-08-28 00:31:27 +00:00
}
}
complete_head_from_modules($conf,$langs,$object,$head,$h,'product', 'remove');
2008-08-28 00:31:27 +00:00
return $head;
}
/**
* Return array head with list of tabs to view object informations.
*
* @param Object $object Product
* @return array head array with tabs
*/
function product_admin_prepare_head($object=null)
{
global $langs, $conf, $user;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT."/product/admin/product.php";
$head[$h][1] = $langs->trans('Parameters');
$head[$h][2] = 'general';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin');
$head[$h][0] = DOL_URL_ROOT.'/product/admin/product_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFields");
$head[$h][2] = 'attributes';
$h++;
complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin','remove');
return $head;
}
/**
2012-03-18 18:23:01 +00:00
* Show stats for company
*
2012-03-18 18:23:01 +00:00
* @param Product $product Product object
* @param int $socid Thirdparty id
* @return void
*/
function show_stats_for_company($product,$socid)
{
2008-08-28 00:31:27 +00:00
global $conf,$langs,$user,$db;
print '<tr>';
print '<td align="left" width="25%" valign="top">'.$langs->trans("Referers").'</td>';
print '<td align="right" width="25%">'.$langs->trans("NbOfThirdParties").'</td>';
print '<td align="right" width="25%">'.$langs->trans("NbOfReferers").'</td>';
print '<td align="right" width="25%">'.$langs->trans("TotalQuantity").'</td>';
print '</tr>';
// Propals
2012-09-15 09:21:22 +00:00
if (! empty($conf->propal->enabled) && $user->rights->propale->lire)
2008-08-28 00:31:27 +00:00
{
$ret=$product->load_stats_propale($socid);
if ($ret < 0) dol_print_error($db);
2008-08-28 00:31:27 +00:00
$langs->load("propal");
print '<tr><td>';
print '<a href="propal.php?id='.$product->id.'">'.img_object('','propal').' '.$langs->trans("Proposals").'</a>';
print '</td><td align="right">';
print $product->stats_propale['customers'];
print '</td><td align="right">';
print $product->stats_propale['nb'];
print '</td><td align="right">';
print $product->stats_propale['qty'];
print '</td>';
print '</tr>';
}
// Commandes clients
2012-09-15 09:21:22 +00:00
if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
2008-08-28 00:31:27 +00:00
{
$ret=$product->load_stats_commande($socid);
if ($ret < 0) dol_print_error($db);
2008-08-28 00:31:27 +00:00
$langs->load("orders");
print '<tr><td>';
print '<a href="commande.php?id='.$product->id.'">'.img_object('','order').' '.$langs->trans("CustomersOrders").'</a>';
print '</td><td align="right">';
print $product->stats_commande['customers'];
print '</td><td align="right">';
print $product->stats_commande['nb'];
print '</td><td align="right">';
print $product->stats_commande['qty'];
print '</td>';
print '</tr>';
}
// Commandes fournisseurs
2012-09-15 09:21:22 +00:00
if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->lire)
2008-08-28 00:31:27 +00:00
{
$ret=$product->load_stats_commande_fournisseur($socid);
if ($ret < 0) dol_print_error($db);
2008-08-28 00:31:27 +00:00
$langs->load("orders");
print '<tr><td>';
print '<a href="commande_fournisseur.php?id='.$product->id.'">'.img_object('','order').' '.$langs->trans("SuppliersOrders").'</a>';
print '</td><td align="right">';
print $product->stats_commande_fournisseur['suppliers'];
print '</td><td align="right">';
print $product->stats_commande_fournisseur['nb'];
print '</td><td align="right">';
print $product->stats_commande_fournisseur['qty'];
print '</td>';
print '</tr>';
}
// Contrats
2012-09-15 09:21:22 +00:00
if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
2008-08-28 00:31:27 +00:00
{
$ret=$product->load_stats_contrat($socid);
if ($ret < 0) dol_print_error($db);
2008-08-28 00:31:27 +00:00
$langs->load("contracts");
print '<tr><td>';
print '<a href="contrat.php?id='.$product->id.'">'.img_object('','contract').' '.$langs->trans("Contracts").'</a>';
print '</td><td align="right">';
print $product->stats_contrat['customers'];
print '</td><td align="right">';
print $product->stats_contrat['nb'];
print '</td><td align="right">';
print $product->stats_contrat['qty'];
print '</td>';
print '</tr>';
}
// Factures clients
2012-09-15 09:21:22 +00:00
if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
2008-08-28 00:31:27 +00:00
{
$ret=$product->load_stats_facture($socid);
if ($ret < 0) dol_print_error($db);
2008-08-28 00:31:27 +00:00
$langs->load("bills");
print '<tr><td>';
2012-07-06 08:22:37 +00:00
print '<a href="facture.php?id='.$product->id.'">'.img_object('','bill').' '.$langs->trans("CustomersInvoices").'</a>';
2008-08-28 00:31:27 +00:00
print '</td><td align="right">';
print $product->stats_facture['customers'];
print '</td><td align="right">';
print $product->stats_facture['nb'];
print '</td><td align="right">';
print $product->stats_facture['qty'];
print '</td>';
print '</tr>';
}
// Factures fournisseurs
2012-09-15 09:21:22 +00:00
if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire)
2008-08-28 00:31:27 +00:00
{
$ret=$product->load_stats_facture_fournisseur($socid);
if ($ret < 0) dol_print_error($db);
2008-08-28 00:31:27 +00:00
$langs->load("bills");
print '<tr><td>';
print '<a href="facture_fournisseur.php?id='.$product->id.'">'.img_object('','bill').' '.$langs->trans("SuppliersInvoices").'</a>';
print '</td><td align="right">';
print $product->stats_facture_fournisseur['suppliers'];
print '</td><td align="right">';
print $product->stats_facture_fournisseur['nb'];
print '</td><td align="right">';
print $product->stats_facture_fournisseur['qty'];
print '</td>';
print '</tr>';
}
return 0;
}
2008-11-16 01:09:04 +00:00
/**
2010-08-24 18:40:17 +00:00
* Return translation label of a unit key
2012-02-04 13:39:47 +00:00
*
* @param int $unit Unit key (-3,0,3,98,99...)
* @param string $measuring_style Style of unit: weight, volume,...
* @return string Unit string
2010-08-26 11:59:41 +00:00
* @see load_measuring_units
2008-11-16 01:09:04 +00:00
*/
function measuring_units_string($unit,$measuring_style='')
{
global $langs;
if ($measuring_style == 'weight')
{
$measuring_units[3] = $langs->trans("WeightUnitton");
$measuring_units[0] = $langs->trans("WeightUnitkg");
$measuring_units[-3] = $langs->trans("WeightUnitg");
$measuring_units[-6] = $langs->trans("WeightUnitmg");
2010-08-24 18:40:17 +00:00
$measuring_units[99] = $langs->trans("WeightUnitpound");
2008-11-16 01:09:04 +00:00
}
else if ($measuring_style == 'size')
{
$measuring_units[0] = $langs->trans("SizeUnitm");
$measuring_units[-1] = $langs->trans("SizeUnitdm");
$measuring_units[-2] = $langs->trans("SizeUnitcm");
$measuring_units[-3] = $langs->trans("SizeUnitmm");
2010-08-24 18:40:17 +00:00
$measuring_units[98] = $langs->trans("SizeUnitfoot");
$measuring_units[99] = $langs->trans("SizeUnitinch");
2008-11-16 01:09:04 +00:00
}
else if ($measuring_style == 'surface')
{
$measuring_units[0] = $langs->trans("SurfaceUnitm2");
$measuring_units[-2] = $langs->trans("SurfaceUnitdm2");
$measuring_units[-4] = $langs->trans("SurfaceUnitcm2");
$measuring_units[-6] = $langs->trans("SurfaceUnitmm2");
$measuring_units[98] = $langs->trans("SurfaceUnitfoot2");
$measuring_units[99] = $langs->trans("SurfaceUnitinch2");
}
else if ($measuring_style == 'volume')
{
$measuring_units[0] = $langs->trans("VolumeUnitm3");
$measuring_units[-3] = $langs->trans("VolumeUnitdm3");
$measuring_units[-6] = $langs->trans("VolumeUnitcm3");
$measuring_units[-9] = $langs->trans("VolumeUnitmm3");
$measuring_units[88] = $langs->trans("VolumeUnitfoot3");
$measuring_units[89] = $langs->trans("VolumeUnitinch3");
$measuring_units[97] = $langs->trans("VolumeUnitounce");
2010-08-26 11:59:41 +00:00
$measuring_units[98] = $langs->trans("VolumeUnitlitre");
2010-08-24 18:40:17 +00:00
$measuring_units[99] = $langs->trans("VolumeUnitgallon");
}
2008-11-16 01:09:04 +00:00
return $measuring_units[$unit];
}
?>