70 'margin_on_products' => 0,
71 'margin_rate_products' =>
'',
72 'mark_rate_products' =>
'',
75 'margin_on_services' => 0,
76 'margin_rate_services' =>
'',
77 'mark_rate_services' =>
'',
81 'total_margin_rate' =>
'',
82 'total_mark_rate' =>
''
85 foreach ($object->lines as $line)
87 if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price)
89 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
91 if ($product->fetch_product_fournisseur_price($line->fk_fournprice))
92 $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
95 if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
96 $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100));
99 $pv = $line->total_ht;
100 $pa_ht = ($pv < 0 ? -$line->pa_ht : $line->pa_ht);
101 if ($object->element ==
'facture' && $object->type == $object::TYPE_SITUATION) {
102 $pa = $line->qty * $pa_ht * ($line->situation_percent / 100);
104 $pa = $line->qty * $pa_ht;
108 if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) {
109 if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT ==
'1') {
110 $marginInfos[
'pa_products'] += $pa;
111 $marginInfos[
'pv_products'] += $pv;
112 $marginInfos[
'pa_total'] += $pa;
113 $marginInfos[
'pv_total'] += $pv;
120 $marginInfos[
'margin_on_products'] += $pv - $pa;
121 } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT ==
'2') {
122 $marginInfos[
'pa_services'] += $pa;
123 $marginInfos[
'pv_services'] += $pv;
124 $marginInfos[
'pa_total'] += $pa;
125 $marginInfos[
'pv_total'] += $pv;
130 $marginInfos[
'margin_on_services'] += $pv - $pa;
131 } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT ==
'3') {
132 $marginInfos[
'pa_total'] += $pa;
133 $marginInfos[
'pv_total'] += $pv;
136 $type = $line->product_type ? $line->product_type : $line->fk_product_type;
138 $marginInfos[
'pa_products'] += $pa;
139 $marginInfos[
'pv_products'] += $pv;
140 $marginInfos[
'pa_total'] += $pa;
141 $marginInfos[
'pv_total'] += $pv;
149 $marginInfos[
'margin_on_products'] += $pv - $pa;
151 } elseif ($type == 1) {
152 $marginInfos[
'pa_services'] += $pa;
153 $marginInfos[
'pv_services'] += $pv;
154 $marginInfos[
'pa_total'] += $pa;
155 $marginInfos[
'pv_total'] += $pv;
160 $marginInfos[
'margin_on_services'] += $pv - $pa;
164 if ($marginInfos[
'pa_products'] > 0)
165 $marginInfos[
'margin_rate_products'] = 100 * $marginInfos[
'margin_on_products'] / $marginInfos[
'pa_products'];
166 if ($marginInfos[
'pv_products'] > 0)
167 $marginInfos[
'mark_rate_products'] = 100 * $marginInfos[
'margin_on_products'] / $marginInfos[
'pv_products'];
169 if ($marginInfos[
'pa_services'] > 0)
170 $marginInfos[
'margin_rate_services'] = 100 * $marginInfos[
'margin_on_services'] / $marginInfos[
'pa_services'];
171 if ($marginInfos[
'pv_services'] > 0)
172 $marginInfos[
'mark_rate_services'] = 100 * $marginInfos[
'margin_on_services'] / $marginInfos[
'pv_services'];
178 $marginInfos[
'total_margin'] = $marginInfos[
'pv_total'] - $marginInfos[
'pa_total'];
179 if ($marginInfos[
'pa_total'] > 0)
180 $marginInfos[
'total_margin_rate'] = 100 * $marginInfos[
'total_margin'] / $marginInfos[
'pa_total'];
181 if ($marginInfos[
'pv_total'] > 0)
182 $marginInfos[
'total_mark_rate'] = 100 * $marginInfos[
'total_margin'] / $marginInfos[
'pv_total'];
196 global $langs, $conf, $user;
198 if (!empty($user->socid))
return;
200 if (!$user->rights->margins->liretous)
return;
204 if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON))
206 print $langs->trans(
'ShowMarginInfos').
' : ';
207 $hidemargininfos = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $_COOKIE[
'DOLUSER_MARGININFO_HIDE_SHOW']);
208 print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos) ?
'' :
'hideobject').
'">'.
img_picto($langs->trans(
"Disabled"),
'switch_off').
'</span>';
209 print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos) ?
'hideobject' :
'').
'">'.
img_picto($langs->trans(
"Enabled"),
'switch_on').
'</span>';
211 print '<script>$(document).ready(function() {
212 $("span#showMarginInfos").click(function() { $.getScript( "'.dol_buildpath(
'/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).
'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 0); $(".margininfos").show(); $("span#showMarginInfos").addClass("hideobject"); $("span#hideMarginInfos").removeClass("hideobject");})});
213 $("span#hideMarginInfos").click(function() { $.getScript( "'.
dol_buildpath(
'/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).
'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 1); $(".margininfos").hide(); $("span#hideMarginInfos").addClass("hideobject"); $("span#showMarginInfos").removeClass("hideobject");})});
215 if (!empty($hidemargininfos))
print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>';
218 print '<div class="div-table-responsive-no-min">';
219 print '<!-- Margin table -->'.
"\n";
221 print '<table class="noborder margintable centpercent">';
222 print '<tr class="liste_titre">';
223 print '<td class="liste_titre">'.$langs->trans(
'Margins').
'</td>';
224 print '<td class="liste_titre right">'.$langs->trans(
'SellingPrice').
'</td>';
225 if ($conf->global->MARGIN_TYPE ==
"1")
226 print '<td class="liste_titre right">'.$langs->trans(
'BuyingPrice').
'</td>';
227 else print '<td class="liste_titre right">'.$langs->trans(
'CostPrice').
'</td>';
228 print '<td class="liste_titre right">'.$langs->trans(
'Margin').
'</td>';
229 if (!empty($conf->global->DISPLAY_MARGIN_RATES))
230 print '<td class="liste_titre right">'.$langs->trans(
'MarginRate').
'</td>';
231 if (!empty($conf->global->DISPLAY_MARK_RATES))
232 print '<td class="liste_titre right">'.$langs->trans(
'MarkRate').
'</td>';
235 if (!empty($conf->product->enabled))
238 print '<tr class="oddeven">';
239 print '<td>'.$langs->trans(
'MarginOnProducts').
'</td>';
240 print '<td class="right">'.price($marginInfo[
'pv_products']).
'</td>';
241 print '<td class="right">'.price($marginInfo[
'pa_products']).
'</td>';
242 print '<td class="right">'.price($marginInfo[
'margin_on_products']).
'</td>';
243 if (!empty($conf->global->DISPLAY_MARGIN_RATES))
244 print '<td class="right">'.(($marginInfo[
'margin_rate_products'] ==
'') ?
'' :
price($marginInfo[
'margin_rate_products'], null, null, null, null, 2).
'%').
'</td>';
245 if (!empty($conf->global->DISPLAY_MARK_RATES))
246 print '<td class="right">'.(($marginInfo[
'mark_rate_products'] ==
'') ?
'' :
price($marginInfo[
'mark_rate_products'], null, null, null, null, 2).
'%').
'</td>';
250 if (!empty($conf->service->enabled))
252 print '<tr class="oddeven">';
253 print '<td>'.$langs->trans(
'MarginOnServices').
'</td>';
254 print '<td class="right">'.price($marginInfo[
'pv_services']).
'</td>';
255 print '<td class="right">'.price($marginInfo[
'pa_services']).
'</td>';
256 print '<td class="right">'.price($marginInfo[
'margin_on_services']).
'</td>';
257 if (!empty($conf->global->DISPLAY_MARGIN_RATES))
258 print '<td class="right">'.(($marginInfo[
'margin_rate_services'] ==
'') ?
'' :
price($marginInfo[
'margin_rate_services'], null, null, null, null, 2).
'%').
'</td>';
259 if (!empty($conf->global->DISPLAY_MARK_RATES))
260 print '<td class="right">'.(($marginInfo[
'mark_rate_services'] ==
'') ?
'' :
price($marginInfo[
'mark_rate_services'], null, null, null, null, 2).
'%').
'</td>';
264 if (!empty($conf->product->enabled) && !empty($conf->service->enabled))
266 print '<tr class="liste_total">';
267 print '<td>'.$langs->trans(
'TotalMargin').
'</td>';
268 print '<td class="right">'.price($marginInfo[
'pv_total']).
'</td>';
269 print '<td class="right">'.price($marginInfo[
'pa_total']).
'</td>';
270 print '<td class="right">'.price($marginInfo[
'total_margin']).
'</td>';
271 if (!empty($conf->global->DISPLAY_MARGIN_RATES))
272 print '<td class="right">'.(($marginInfo[
'total_margin_rate'] ==
'') ?
'' :
price($marginInfo[
'total_margin_rate'], null, null, null, null, 2).
'%').
'</td>';
273 if (!empty($conf->global->DISPLAY_MARK_RATES))
274 print '<td class="right">'.(($marginInfo[
'total_mark_rate'] ==
'') ?
'' :
price($marginInfo[
'total_mark_rate'], null, null, null, null, 2).
'%').
'</td>';
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
print
Draft customers invoices.
Class to manage predefined suppliers products.