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) {
86 if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) {
87 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
89 if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) {
90 $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
96 if ((!isset($line->pa_ht)) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull > 0)) {
97 $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100));
100 $pv = $line->total_ht;
101 $pa_ht = ($pv < 0 ? -$line->pa_ht : $line->pa_ht);
102 if (($object->element ==
'facture' && $object->type == $object::TYPE_SITUATION)
103 || ($object->element ==
'facture' && $object->type == $object::TYPE_CREDIT_NOTE &&
getDolGlobalInt(
'INVOICE_USE_SITUATION_CREDIT_NOTE') && $object->situation_counter > 0)) {
104 $pa = $line->qty * $pa_ht * ($line->situation_percent / 100);
106 $pa = $line->qty * $pa_ht;
110 if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) {
112 $marginInfos[
'pa_products'] += $pa;
113 $marginInfos[
'pv_products'] += $pv;
114 $marginInfos[
'pa_total'] += $pa;
115 $marginInfos[
'pv_total'] += $pv;
122 $marginInfos[
'margin_on_products'] += $pv - $pa;
124 $marginInfos[
'pa_services'] += $pa;
125 $marginInfos[
'pv_services'] += $pv;
126 $marginInfos[
'pa_total'] += $pa;
127 $marginInfos[
'pv_total'] += $pv;
132 $marginInfos[
'margin_on_services'] += $pv - $pa;
134 $marginInfos[
'pa_total'] += $pa;
135 $marginInfos[
'pv_total'] += $pv;
138 $type = $line->product_type ? $line->product_type : $line->fk_product_type;
140 $marginInfos[
'pa_products'] += $pa;
141 $marginInfos[
'pv_products'] += $pv;
142 $marginInfos[
'pa_total'] += $pa;
143 $marginInfos[
'pv_total'] += $pv;
151 $marginInfos[
'margin_on_products'] += $pv - $pa;
153 } elseif ($type == 1) {
154 $marginInfos[
'pa_services'] += $pa;
155 $marginInfos[
'pv_services'] += $pv;
156 $marginInfos[
'pa_total'] += $pa;
157 $marginInfos[
'pv_total'] += $pv;
162 $marginInfos[
'margin_on_services'] += $pv - $pa;
166 if ($marginInfos[
'pa_products'] > 0) {
167 $marginInfos[
'margin_rate_products'] = 100 * $marginInfos[
'margin_on_products'] / $marginInfos[
'pa_products'];
169 if ($marginInfos[
'pv_products'] > 0) {
170 $marginInfos[
'mark_rate_products'] = 100 * $marginInfos[
'margin_on_products'] / $marginInfos[
'pv_products'];
173 if ($marginInfos[
'pa_services'] > 0) {
174 $marginInfos[
'margin_rate_services'] = 100 * $marginInfos[
'margin_on_services'] / $marginInfos[
'pa_services'];
176 if ($marginInfos[
'pv_services'] > 0) {
177 $marginInfos[
'mark_rate_services'] = 100 * $marginInfos[
'margin_on_services'] / $marginInfos[
'pv_services'];
184 $marginInfos[
'total_margin'] = $marginInfos[
'pv_total'] - $marginInfos[
'pa_total'];
185 if ($marginInfos[
'pa_total'] > 0) {
186 $marginInfos[
'total_margin_rate'] = 100 * $marginInfos[
'total_margin'] / $marginInfos[
'pa_total'];
188 if ($marginInfos[
'pv_total'] > 0) {
189 $marginInfos[
'total_mark_rate'] = 100 * $marginInfos[
'total_margin'] / $marginInfos[
'pv_total'];
204 global $langs, $conf, $user, $hookmanager;
206 if (!empty($user->socid)) {
210 if (empty($user->rights->margins->liretous)) {
216 $parameters=array(
'marginInfo'=>&$marginInfo);
217 $reshook = $hookmanager->executeHooks(
'displayMarginInfos', $parameters, $object, $action);
220 } elseif (empty($reshook)) {
221 if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) {
222 print $langs->trans(
'ShowMarginInfos') .
' ';
223 $hidemargininfos = preg_replace(
'/[^a-zA-Z0-9_\-]/',
'', $_COOKIE[
'DOLUSER_MARGININFO_HIDE_SHOW']);
224 print
'<span id="showMarginInfos" class="linkobject valignmiddle ' . (!empty($hidemargininfos) ?
'' :
'hideobject') .
'">' .
img_picto($langs->trans(
"Disabled"),
'switch_off') .
'</span>';
225 print
'<span id="hideMarginInfos" class="linkobject valignmiddle ' . (!empty($hidemargininfos) ?
'hideobject' :
'') .
'">' .
img_picto($langs->trans(
"Enabled"),
'switch_on') .
'</span>';
227 print
'<script>$(document).ready(function() {
228 $("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"); });
229 $("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"); });
231 if (!empty($hidemargininfos)) {
232 print
'<script>$(document).ready(function() { console.log("hide the margin info"); $("#margintable").hide(); });</script>';
236 print
'<div class="div-table-responsive-no-min">';
237 print
'<!-- Margin table -->' .
"\n";
239 print
'<table class="noborder margintable centpercent" id="margintable">';
240 print
'<tr class="liste_titre">';
241 print
'<td class="liste_titre">' . $langs->trans(
'Margins') .
'</td>';
242 print
'<td class="liste_titre right">' . $langs->trans(
'SellingPrice') .
'</td>';
243 if ($conf->global->MARGIN_TYPE ==
"1") {
244 print
'<td class="liste_titre right">' . $langs->trans(
'BuyingPrice') .
'</td>';
246 print
'<td class="liste_titre right">' . $langs->trans(
'CostPrice') .
'</td>';
248 print
'<td class="liste_titre right">' . $langs->trans(
'Margin') .
'</td>';
249 if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
250 print
'<td class="liste_titre right">' . $langs->trans(
'MarginRate') .
'</td>';
252 if (!empty($conf->global->DISPLAY_MARK_RATES)) {
253 print
'<td class="liste_titre right">' . $langs->trans(
'MarkRate') .
'</td>';
259 print
'<tr class="oddeven">';
260 print
'<td>' . $langs->trans(
'MarginOnProducts') .
'</td>';
261 print
'<td class="right">' .
price($marginInfo[
'pv_products']) .
'</td>';
262 print
'<td class="right">' .
price($marginInfo[
'pa_products']) .
'</td>';
263 print
'<td class="right">' .
price($marginInfo[
'margin_on_products']) .
'</td>';
264 if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
265 print
'<td class="right">' . (($marginInfo[
'margin_rate_products'] ==
'') ?
'' :
price($marginInfo[
'margin_rate_products'],
null,
null,
null,
null, 2) .
'%') .
'</td>';
267 if (!empty($conf->global->DISPLAY_MARK_RATES)) {
268 print
'<td class="right">' . (($marginInfo[
'mark_rate_products'] ==
'') ?
'' :
price($marginInfo[
'mark_rate_products'],
null,
null,
null,
null, 2) .
'%') .
'</td>';
274 print
'<tr class="oddeven">';
275 print
'<td>' . $langs->trans(
'MarginOnServices') .
'</td>';
276 print
'<td class="right">' .
price($marginInfo[
'pv_services']) .
'</td>';
277 print
'<td class="right">' .
price($marginInfo[
'pa_services']) .
'</td>';
278 print
'<td class="right">' .
price($marginInfo[
'margin_on_services']) .
'</td>';
279 if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
280 print
'<td class="right">' . (($marginInfo[
'margin_rate_services'] ==
'') ?
'' :
price($marginInfo[
'margin_rate_services'],
null,
null,
null,
null, 2) .
'%') .
'</td>';
282 if (!empty($conf->global->DISPLAY_MARK_RATES)) {
283 print
'<td class="right">' . (($marginInfo[
'mark_rate_services'] ==
'') ?
'' :
price($marginInfo[
'mark_rate_services'],
null,
null,
null,
null, 2) .
'%') .
'</td>';
289 print
'<tr class="liste_total">';
290 print
'<td>' . $langs->trans(
'TotalMargin') .
'</td>';
291 print
'<td class="right">' .
price($marginInfo[
'pv_total']) .
'</td>';
292 print
'<td class="right">' .
price($marginInfo[
'pa_total']) .
'</td>';
293 print
'<td class="right">' .
price($marginInfo[
'total_margin']) .
'</td>';
294 if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
295 print
'<td class="right">' . (($marginInfo[
'total_margin_rate'] ==
'') ?
'' :
price($marginInfo[
'total_margin_rate'],
null,
null,
null,
null, 2) .
'%') .
'</td>';
297 if (!empty($conf->global->DISPLAY_MARK_RATES)) {
298 print
'<td class="right">' . (($marginInfo[
'total_mark_rate'] ==
'') ?
'' :
price($marginInfo[
'total_mark_rate'],
null,
null,
null,
null, 2) .
'%') .
'</td>';
302 print $hookmanager->resPrint;
305 } elseif ($reshook > 0) {
306 print $hookmanager->resPrint;
Class to manage predefined suppliers products.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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 dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
$conf db
API class for accounts.