diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 9f8a2aabf7d..6d8dfff5934 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2946,11 +2946,11 @@ abstract class CommonObject
global $conf,$langs,$bc;
//var_dump($line);
- if (!empty($line->date_start))
- {
+ if (!empty($line->date_start))
+ {
$date_start=$line->date_start;
}
- else
+ else
{
$date_start=$line->date_debut_prevue;
if ($line->date_debut_reel) $date_start=$line->date_debut_reel;
@@ -2959,7 +2959,7 @@ abstract class CommonObject
{
$date_end=$line->date_end;
}
- else
+ else
{
$date_end=$line->date_fin_prevue;
if ($line->date_fin_reel) $date_end=$line->date_fin_reel;
@@ -2995,7 +2995,7 @@ abstract class CommonObject
$this->tpl['label'].=$line->desc;
}else {
$this->tpl['label'].= ($line->label ? ' '.$line->label : '');
- }
+ }
// Dates
if ($line->product_type == 1 && ($date_start || $date_end))
{
@@ -3048,149 +3048,160 @@ abstract class CommonObject
}
+ /**
+ *
+ * @param string $force_price
+ * @return multitype:number string NULL
+ */
+ function getMarginInfos($force_price=false) {
+ global $conf;
+ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
- function getMarginInfos($force_price=false) {
- global $conf;
- require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
- $marginInfos = array(
- 'pa_products' => 0,
- 'pv_products' => 0,
- 'margin_on_products' => 0,
- 'margin_rate_products' => '',
- 'mark_rate_products' => '',
- 'pa_services' => 0,
- 'pv_services' => 0,
- 'margin_on_services' => 0,
- 'margin_rate_services' => '',
- 'mark_rate_services' => '',
- 'pa_total' => 0,
- 'pv_total' => 0,
- 'total_margin' => 0,
- 'total_margin_rate' => '',
- 'total_mark_rate' => ''
- );
- foreach($this->lines as $line) {
- if (isset($line->fk_fournprice) && !$force_price) {
- $product = new ProductFournisseur($this->db);
- if ($product->fetch_product_fournisseur_price($line->fk_fournprice))
- $line->pa_ht = $product->fourn_unitprice;
- if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0)
- $line->pa_ht += $product->fourn_unitcharges;
- }
- // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente
- if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
- $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100));
- }
+ $marginInfos = array(
+ 'pa_products' => 0,
+ 'pv_products' => 0,
+ 'margin_on_products' => 0,
+ 'margin_rate_products' => '',
+ 'mark_rate_products' => '',
+ 'pa_services' => 0,
+ 'pv_services' => 0,
+ 'margin_on_services' => 0,
+ 'margin_rate_services' => '',
+ 'mark_rate_services' => '',
+ 'pa_total' => 0,
+ 'pv_total' => 0,
+ 'total_margin' => 0,
+ 'total_margin_rate' => '',
+ 'total_mark_rate' => ''
+ );
- // calcul des marges
- if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) { // remise
- if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit
- $marginInfos['pa_products'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
- $marginInfos['pv_products'] += $line->subprice * (1 - $line->remise_percent / 100);
- $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
- $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100);
+ foreach($this->lines as $line) {
+ if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) {
+ $product = new ProductFournisseur($this->db);
+ if ($product->fetch_product_fournisseur_price($line->fk_fournprice))
+ $line->pa_ht = $product->fourn_unitprice;
+ if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0)
+ $line->pa_ht += $product->fourn_unitcharges;
+ }
+ // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente
+ if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
+ $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100));
+ }
+
+ // calcul des marges
+ if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) { // remise
+ if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit
+ $marginInfos['pa_products'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
+ $marginInfos['pv_products'] += $line->subprice * (1 - $line->remise_percent / 100);
+ $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
+ $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100);
}
- elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service
- $marginInfos['pa_services'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
- $marginInfos['pv_services'] += $line->subprice * (1 - ($line->remise_percent / 100));
- $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
- $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100);
+ elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service
+ $marginInfos['pa_services'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
+ $marginInfos['pv_services'] += $line->subprice * (1 - ($line->remise_percent / 100));
+ $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
+ $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100);
}
- elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total
- $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
- $marginInfos['pv_total'] += $line->subprice * (1 - ($line->remise_percent / 100));
+ elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total
+ $marginInfos['pa_total'] += $line->pa_ht;// ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
+ $marginInfos['pv_total'] += $line->subprice * (1 - ($line->remise_percent / 100));
}
}
- else {
- $type=$line->product_type?$line->product_type:$line->fk_product_type;
- if ($type == 0) { // product
- $marginInfos['pa_products'] += $line->qty * $line->pa_ht;
- $marginInfos['pv_products'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
- $marginInfos['pa_total'] += $line->qty * $line->pa_ht;
- $marginInfos['pv_total'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
- }
- elseif ($type == 1) { // service
- $marginInfos['pa_services'] += $line->qty * $line->pa_ht;
- $marginInfos['pv_services'] += $line->qty * $line->subprice * (1 - ($line->remise_percent / 100));
- $marginInfos['pa_total'] += $line->qty * $line->pa_ht;
- $marginInfos['pv_total'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
- }
- }
- }
+ else {
+ $type=$line->product_type?$line->product_type:$line->fk_product_type;
+ if ($type == 0) { // product
+ $marginInfos['pa_products'] += $line->qty * $line->pa_ht;
+ $marginInfos['pv_products'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
+ $marginInfos['pa_total'] += $line->qty * $line->pa_ht;
+ $marginInfos['pv_total'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
+ }
+ elseif ($type == 1) { // service
+ $marginInfos['pa_services'] += $line->qty * $line->pa_ht;
+ $marginInfos['pv_services'] += $line->qty * $line->subprice * (1 - ($line->remise_percent / 100));
+ $marginInfos['pa_total'] += $line->qty * $line->pa_ht;
+ $marginInfos['pv_total'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
+ }
+ }
+ }
- $marginInfos['margin_on_products'] = $marginInfos['pv_products'] - $marginInfos['pa_products'];
- if ($marginInfos['pa_products'] > 0)
- $marginInfos['margin_rate_products'] = 100 * round($marginInfos['margin_on_products'] / $marginInfos['pa_products'],5);
- if ($marginInfos['pv_products'] > 0)
- $marginInfos['mark_rate_products'] = 100 * round($marginInfos['margin_on_products'] / $marginInfos['pv_products'],5);
+ $marginInfos['margin_on_products'] = $marginInfos['pv_products'] - $marginInfos['pa_products'];
+ if ($marginInfos['pa_products'] > 0)
+ $marginInfos['margin_rate_products'] = 100 * round($marginInfos['margin_on_products'] / $marginInfos['pa_products'],5);
+ if ($marginInfos['pv_products'] > 0)
+ $marginInfos['mark_rate_products'] = 100 * round($marginInfos['margin_on_products'] / $marginInfos['pv_products'],5);
- $marginInfos['margin_on_services'] = $marginInfos['pv_services'] - $marginInfos['pa_services'];
- if ($marginInfos['pa_services'] > 0)
- $marginInfos['margin_rate_services'] = 100 * round($marginInfos['margin_on_services'] / $marginInfos['pa_services'],5);
- if ($marginInfos['pv_services'] > 0)
- $marginInfos['mark_rate_services'] = 100 * round($marginInfos['margin_on_services'] / $marginInfos['pv_services'],5);
+ $marginInfos['margin_on_services'] = $marginInfos['pv_services'] - $marginInfos['pa_services'];
+ if ($marginInfos['pa_services'] > 0)
+ $marginInfos['margin_rate_services'] = 100 * round($marginInfos['margin_on_services'] / $marginInfos['pa_services'],5);
+ if ($marginInfos['pv_services'] > 0)
+ $marginInfos['mark_rate_services'] = 100 * round($marginInfos['margin_on_services'] / $marginInfos['pv_services'],5);
+ $marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total'];
+ if ($marginInfos['pa_total'] > 0)
+ $marginInfos['total_margin_rate'] = 100 * round($marginInfos['total_margin'] / $marginInfos['pa_total'],5);
+ if ($marginInfos['pv_total'] > 0)
+ $marginInfos['total_mark_rate'] = 100 * round($marginInfos['total_margin'] / $marginInfos['pv_total'],5);
- $marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total'];
- if ($marginInfos['pa_total'] > 0)
- $marginInfos['total_margin_rate'] = 100 * round($marginInfos['total_margin'] / $marginInfos['pa_total'],5);
- if ($marginInfos['pv_total'] > 0)
- $marginInfos['total_mark_rate'] = 100 * round($marginInfos['total_margin'] / $marginInfos['pv_total'],5);
+ return $marginInfos;
+ }
- return $marginInfos;
- }
+ /**
+ *
+ * @param string $force_price
+ */
+ function displayMarginInfos($force_price=false) {
+ global $langs, $conf;
+
+ $marginInfo = $this->getMarginInfos($force_price);
+
+ print '
';
+ print '';
+ print '| '.$langs->trans('Margins').' | ';
+ print ''.$langs->trans('SellingPrice').' | ';
+ if ($conf->global->MARGIN_TYPE == "1")
+ print ''.$langs->trans('BuyingPrice').' | ';
+ else
+ print ''.$langs->trans('CostPrice').' | ';
+ print ''.$langs->trans('Margin').' | ';
+ if (! empty($conf->global->DISPLAY_MARGIN_RATES))
+ print ''.$langs->trans('MarginRate').' | ';
+ if (! empty($conf->global->DISPLAY_MARK_RATES))
+ print ''.$langs->trans('MarkRate').' | ';
+ print '
';
+ //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) {
+ print '';
+ print '| '.$langs->trans('MarginOnProducts').' | ';
+ print ''.price($marginInfo['pv_products']).' | ';
+ print ''.price($marginInfo['pa_products']).' | ';
+ print ''.price($marginInfo['margin_on_products']).' | ';
+ if (! empty($conf->global->DISPLAY_MARGIN_RATES))
+ print ''.(($marginInfo['margin_rate_products'] == '')?'n/a':price($marginInfo['margin_rate_products']).'%').' | ';
+ if (! empty($conf->global->DISPLAY_MARK_RATES))
+ print ''.(($marginInfo['mark_rate_products'] == '')?'n/a':price($marginInfo['mark_rate_products']).'%').' | ';
+ print '
';
+ print '';
+ print '| '.$langs->trans('MarginOnServices').' | ';
+ print ''.price($marginInfo['pv_services']).' | ';
+ print ''.price($marginInfo['pa_services']).' | ';
+ print ''.price($marginInfo['margin_on_services']).' | ';
+ if (! empty($conf->global->DISPLAY_MARGIN_RATES))
+ print ''.(($marginInfo['margin_rate_services'] == '')?'n/a':price($marginInfo['margin_rate_services']).'%').' | ';
+ if (! empty($conf->global->DISPLAY_MARK_RATES))
+ print ''.(($marginInfo['mark_rate_services'] == '')?'n/a':price($marginInfo['mark_rate_services']).'%').' | ';
+ print '
';
+ //}
+ print '';
+ print '| '.$langs->trans('TotalMargin').' | ';
+ print ''.price($marginInfo['pv_total']).' | ';
+ print ''.price($marginInfo['pa_total']).' | ';
+ print ''.price($marginInfo['total_margin']).' | ';
+ if (! empty($conf->global->DISPLAY_MARGIN_RATES))
+ print ''.(($marginInfo['total_margin_rate'] == '')?'n/a':price($marginInfo['total_margin_rate']).'%').' | ';
+ if (! empty($conf->global->DISPLAY_MARK_RATES))
+ print ''.(($marginInfo['total_mark_rate'] == '')?'n/a':price($marginInfo['total_mark_rate']).'%').' | ';
+ print '
';
+ print '
';
+ }
- function displayMarginInfos($force_price=false) {
- global $langs, $conf;
- $marginInfo = $this->getMarginInfos($force_price);
- print '';
- print '';
- print '| '.$langs->trans('Margins').' | ';
- print ''.$langs->trans('SellingPrice').' | ';
- if ($conf->global->MARGIN_TYPE == "1")
- print ''.$langs->trans('BuyingPrice').' | ';
- else
- print ''.$langs->trans('CostPrice').' | ';
- print ''.$langs->trans('Margin').' | ';
- if (! empty($conf->global->DISPLAY_MARGIN_RATES))
- print ''.$langs->trans('MarginRate').' | ';
- if (! empty($conf->global->DISPLAY_MARK_RATES))
- print ''.$langs->trans('MarkRate').' | ';
- print '
';
- //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) {
- print '';
- print '| '.$langs->trans('MarginOnProducts').' | ';
- print ''.price($marginInfo['pv_products']).' | ';
- print ''.price($marginInfo['pa_products']).' | ';
- print ''.price($marginInfo['margin_on_products']).' | ';
- if (! empty($conf->global->DISPLAY_MARGIN_RATES))
- print ''.(($marginInfo['margin_rate_products'] == '')?'n/a':price($marginInfo['margin_rate_products']).'%').' | ';
- if (! empty($conf->global->DISPLAY_MARK_RATES))
- print ''.(($marginInfo['mark_rate_products'] == '')?'n/a':price($marginInfo['mark_rate_products']).'%').' | ';
- print '
';
- print '';
- print '| '.$langs->trans('MarginOnServices').' | ';
- print ''.price($marginInfo['pv_services']).' | ';
- print ''.price($marginInfo['pa_services']).' | ';
- print ''.price($marginInfo['margin_on_services']).' | ';
- if (! empty($conf->global->DISPLAY_MARGIN_RATES))
- print ''.(($marginInfo['margin_rate_services'] == '')?'n/a':price($marginInfo['margin_rate_services']).'%').' | ';
- if (! empty($conf->global->DISPLAY_MARK_RATES))
- print ''.(($marginInfo['mark_rate_services'] == '')?'n/a':price($marginInfo['mark_rate_services']).'%').' | ';
- print '
';
- //}
- print '';
- print '| '.$langs->trans('TotalMargin').' | ';
- print ''.price($marginInfo['pv_total']).' | ';
- print ''.price($marginInfo['pa_total']).' | ';
- print ''.price($marginInfo['total_margin']).' | ';
- if (! empty($conf->global->DISPLAY_MARGIN_RATES))
- print ''.(($marginInfo['total_margin_rate'] == '')?'n/a':price($marginInfo['total_margin_rate']).'%').' | ';
- if (! empty($conf->global->DISPLAY_MARK_RATES))
- print ''.(($marginInfo['total_mark_rate'] == '')?'n/a':price($marginInfo['total_mark_rate']).'%').' | ';
- print '
';
- print '
';
- }
}
-
?>