71 'margin_on_products' => 0,
72 'margin_rate_products' =>
'',
73 'mark_rate_products' =>
'',
76 'margin_on_services' => 0,
77 'margin_rate_services' =>
'',
78 'mark_rate_services' =>
'',
82 'total_margin_rate' =>
'',
83 'total_mark_rate' =>
''
86 foreach (
$object->lines as $line) {
87 if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) {
88 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
90 if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) {
91 $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
97 if ((!isset($line->pa_ht)) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) &&
getDolGlobalInt(
'ForceBuyingPriceIfNull') > 0)) {
98 $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100));
101 $pv = $line->total_ht;
104 $pa_ht = (($pv < 0 || ($pv == 0 && in_array(
$object->element, array(
'facture',
'facture_fourn')) &&
$object->type == $object::TYPE_CREDIT_NOTE)) ? -$line->pa_ht : $line->pa_ht);
107 if ((
$object->element ==
'facture' &&
$object->type == $object::TYPE_SITUATION)
111 $pa = $line->qty * $pa_ht * ($line->situation_percent / 100);
113 $pa = $line->qty * $pa_ht;
116 $pa = $line->qty * $pa_ht;
120 if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) {
122 $marginInfos[
'pa_products'] += $pa;
123 $marginInfos[
'pv_products'] += $pv;
124 $marginInfos[
'pa_total'] += $pa;
125 $marginInfos[
'pv_total'] += $pv;
132 $marginInfos[
'margin_on_products'] += $pv - $pa;
134 $marginInfos[
'pa_services'] += $pa;
135 $marginInfos[
'pv_services'] += $pv;
136 $marginInfos[
'pa_total'] += $pa;
137 $marginInfos[
'pv_total'] += $pv;
142 $marginInfos[
'margin_on_services'] += $pv - $pa;
144 $marginInfos[
'pa_total'] += $pa;
145 $marginInfos[
'pv_total'] += $pv;
148 $type = $line->product_type ? $line->product_type : $line->fk_product_type;
150 $marginInfos[
'pa_products'] += $pa;
151 $marginInfos[
'pv_products'] += $pv;
152 $marginInfos[
'pa_total'] += $pa;
153 $marginInfos[
'pv_total'] += $pv;
161 $marginInfos[
'margin_on_products'] += $pv - $pa;
163 } elseif ($type == 1) {
164 $marginInfos[
'pa_services'] += $pa;
165 $marginInfos[
'pv_services'] += $pv;
166 $marginInfos[
'pa_total'] += $pa;
167 $marginInfos[
'pv_total'] += $pv;
172 $marginInfos[
'margin_on_services'] += $pv - $pa;
176 if ($marginInfos[
'pa_products'] > 0) {
177 $marginInfos[
'margin_rate_products'] = 100 * $marginInfos[
'margin_on_products'] / $marginInfos[
'pa_products'];
179 if ($marginInfos[
'pv_products'] > 0) {
180 $marginInfos[
'mark_rate_products'] = 100 * $marginInfos[
'margin_on_products'] / $marginInfos[
'pv_products'];
183 if ($marginInfos[
'pa_services'] > 0) {
184 $marginInfos[
'margin_rate_services'] = 100 * $marginInfos[
'margin_on_services'] / $marginInfos[
'pa_services'];
186 if ($marginInfos[
'pv_services'] > 0) {
187 $marginInfos[
'mark_rate_services'] = 100 * $marginInfos[
'margin_on_services'] / $marginInfos[
'pv_services'];
194 $marginInfos[
'total_margin'] = $marginInfos[
'pv_total'] - $marginInfos[
'pa_total'];
195 if ($marginInfos[
'pa_total'] > 0) {
196 $marginInfos[
'total_margin_rate'] = 100 * $marginInfos[
'total_margin'] / $marginInfos[
'pa_total'];
198 if ($marginInfos[
'pv_total'] > 0) {
199 $marginInfos[
'total_mark_rate'] = 100 * $marginInfos[
'total_margin'] / $marginInfos[
'pv_total'];
214 global $langs, $conf, $user, $hookmanager;
217 if (!empty($user->socid)) {
221 if (!$user->hasRight(
'margins',
'liretous')) {
227 $parameters = array(
'marginInfo' => &$marginInfo);
228 $reshook = $hookmanager->executeHooks(
'displayMarginInfos', $parameters,
$object, $action);
231 } elseif (empty($reshook)) {
233 print $langs->trans(
'ShowMarginInfos') .
' ';
234 $hidemargininfos = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $_COOKIE[
'DOLUSER_MARGININFO_HIDE_SHOW']) ??
'';
235 print
'<span id="showMarginInfos" class="linkobject valignmiddle ' . (!empty($hidemargininfos) ?
'' :
'hideobject') .
'">' .
img_picto($langs->trans(
"Disabled"),
'switch_off') .
'</span>';
236 print
'<span id="hideMarginInfos" class="linkobject valignmiddle ' . (!empty($hidemargininfos) ?
'hideobject' :
'') .
'">' .
img_picto($langs->trans(
"Enabled"),
'switch_on') .
'</span>';
238 print
'<script nonce="'.getNonce().
'">$(document).ready(function() {';
239 print
'$("span#showMarginInfos").click(function() { console.log("click on showMargininfos"); date = new Date(); date.setTime(date.getTime()+(30*86400000)); document.cookie = "DOLUSER_MARGININFO_HIDE_SHOW=0; expires=" + date.toGMTString() + "; path=/ "; $(".margintable").show(); $("span#showMarginInfos").addClass("hideobject"); $("span#hideMarginInfos").removeClass("hideobject"); });';
240 print
'$("span#hideMarginInfos").click(function() { console.log("click on hideMarginInfos"); date = new Date(); date.setTime(date.getTime()+(30*86400000)); document.cookie = "DOLUSER_MARGININFO_HIDE_SHOW=1; expires=" + date.toGMTString() + "; path=/ "; $(".margintable").hide(); $("span#hideMarginInfos").addClass("hideobject"); $("span#showMarginInfos").removeClass("hideobject"); });';
241 if (!empty($hidemargininfos)) {
242 print
'console.log("hide the margin info"); $("#margintable").hide();';
244 print
'});</script>';
247 print
'<!-- displayMarginInfos() - Show margin table -->' .
"\n";
248 print
'<div class="div-table-responsive-no-min">';
250 print
'<table class="noborder margintable centpercent" id="margintable">';
251 print
'<tr class="liste_titre">';
252 print
'<td class="liste_titre">' . $langs->trans(
'Margins') .
'</td>';
253 print
'<td class="liste_titre right">' . $langs->trans(
'SellingPrice') .
'</td>';
255 print
'<td class="liste_titre right">' . $langs->trans(
'BuyingPrice') .
'</td>';
257 print
'<td class="liste_titre right">' . $langs->trans(
'CostPrice') .
'</td>';
259 print
'<td class="liste_titre right">' . $langs->trans(
'Margin') .
'</td>';
261 print
'<td class="liste_titre right">' . $langs->trans(
'MarginRate') .
'</td>';
264 print
'<td class="liste_titre right">' . $langs->trans(
'MarkRate') .
'</td>';
268 if (isModEnabled(
"product")) {
270 print
'<tr class="oddeven">';
271 print
'<td>' . $langs->trans(
'MarginOnProducts') .
'</td>';
272 print
'<td class="right">' .
price($marginInfo[
'pv_products']) .
'</td>';
273 print
'<td class="right">' .
price($marginInfo[
'pa_products']) .
'</td>';
274 print
'<td class="right">' .
price($marginInfo[
'margin_on_products']) .
'</td>';
276 print
'<td class="right">' . (($marginInfo[
'margin_rate_products'] ==
'') ?
'' :
price($marginInfo[
'margin_rate_products'], 0,
'', 0, 0, 2) .
'%') .
'</td>';
279 print
'<td class="right">' . (($marginInfo[
'mark_rate_products'] ==
'') ?
'' :
price($marginInfo[
'mark_rate_products'], 0,
'', 0, 0, 2) .
'%') .
'</td>';
284 if (isModEnabled(
"service")) {
285 print
'<tr class="oddeven">';
286 print
'<td>' . $langs->trans(
'MarginOnServices') .
'</td>';
287 print
'<td class="right">' .
price($marginInfo[
'pv_services']) .
'</td>';
288 print
'<td class="right">' .
price($marginInfo[
'pa_services']) .
'</td>';
289 print
'<td class="right">' .
price($marginInfo[
'margin_on_services']) .
'</td>';
291 print
'<td class="right">' . (($marginInfo[
'margin_rate_services'] ==
'') ?
'' :
price($marginInfo[
'margin_rate_services'], 0,
'', 0, 0, 2) .
'%') .
'</td>';
294 print
'<td class="right">' . (($marginInfo[
'mark_rate_services'] ==
'') ?
'' :
price($marginInfo[
'mark_rate_services'], 0,
'', 0, 0, 2) .
'%') .
'</td>';
299 if (isModEnabled(
"product") && isModEnabled(
"service")) {
300 print
'<tr class="liste_total">';
301 print
'<td>' . $langs->trans(
'TotalMargin') .
'</td>';
302 print
'<td class="right">' .
price($marginInfo[
'pv_total']) .
'</td>';
303 print
'<td class="right">' .
price($marginInfo[
'pa_total']) .
'</td>';
304 print
'<td class="right">' .
price($marginInfo[
'total_margin']) .
'</td>';
306 print
'<td class="right">' . (($marginInfo[
'total_margin_rate'] ==
'') ?
'' :
price($marginInfo[
'total_margin_rate'], 0,
'', 0, 0, 2) .
'%') .
'</td>';
309 print
'<td class="right">' . (($marginInfo[
'total_mark_rate'] ==
'') ?
'' :
price($marginInfo[
'total_mark_rate'], 0,
'', 0, 0, 2) .
'%') .
'</td>';
313 print $hookmanager->resPrint;
316 } elseif ($reshook > 0) {
317 print $hookmanager->resPrint;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage predefined suppliers products.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.