Merge pull request #19413 from FHenry/dev_add_hook_marginDisplay
new: add hook for displayMarginInfos
This commit is contained in:
commit
8b1c45d0fe
@ -230,7 +230,8 @@ class HookManager
|
||||
'setContentSecurityPolicy',
|
||||
'setHtmlTitle',
|
||||
'completeTabsHead',
|
||||
'formDolBanner'
|
||||
'formDolBanner',
|
||||
'displayMarginInfos',
|
||||
)
|
||||
)) {
|
||||
$hooktype = 'addreplace';
|
||||
|
||||
@ -201,7 +201,7 @@ class FormMargin
|
||||
*/
|
||||
public function displayMarginInfos($object, $force_price = false)
|
||||
{
|
||||
global $langs, $conf, $user;
|
||||
global $langs, $conf, $user, $hookmanager;
|
||||
|
||||
if (!empty($user->socid)) {
|
||||
return;
|
||||
@ -213,88 +213,97 @@ class FormMargin
|
||||
|
||||
$marginInfo = $this->getMarginInfosArray($object, $force_price);
|
||||
|
||||
if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) { // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better
|
||||
print $langs->trans('ShowMarginInfos').' : ';
|
||||
$hidemargininfos = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']); // Clean cookie
|
||||
print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos) ? '' : 'hideobject').'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</span>';
|
||||
print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos) ? 'hideobject' : '').'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</span>';
|
||||
$parameters=array('marginInfo'=>$marginInfo);
|
||||
$reshook = $hookmanager->executeHooks('displayMarginInfos', $parameters, $object, $action);
|
||||
if ($reshook < 0) {
|
||||
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||
} elseif (empty($reshook)) {
|
||||
if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) { // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better
|
||||
print $langs->trans('ShowMarginInfos') . ' : ';
|
||||
$hidemargininfos = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']); // Clean cookie
|
||||
print '<span id="showMarginInfos" class="linkobject ' . (!empty($hidemargininfos) ? '' : 'hideobject') . '">' . img_picto($langs->trans("Disabled"), 'switch_off') . '</span>';
|
||||
print '<span id="hideMarginInfos" class="linkobject ' . (!empty($hidemargininfos) ? 'hideobject' : '') . '">' . img_picto($langs->trans("Enabled"), 'switch_on') . '</span>';
|
||||
|
||||
print '<script>$(document).ready(function() {
|
||||
$("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");})});
|
||||
$("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");})});
|
||||
print '<script>$(document).ready(function() {
|
||||
$("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");})});
|
||||
$("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");})});
|
||||
});</script>';
|
||||
if (!empty($hidemargininfos)) {
|
||||
print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>';
|
||||
if (!empty($hidemargininfos)) {
|
||||
print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<!-- Margin table -->'."\n";
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<!-- Margin table -->' . "\n";
|
||||
|
||||
print '<table class="noborder margintable centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td class="liste_titre">'.$langs->trans('Margins').'</td>';
|
||||
print '<td class="liste_titre right">'.$langs->trans('SellingPrice').'</td>';
|
||||
if ($conf->global->MARGIN_TYPE == "1") {
|
||||
print '<td class="liste_titre right">'.$langs->trans('BuyingPrice').'</td>';
|
||||
} else {
|
||||
print '<td class="liste_titre right">'.$langs->trans('CostPrice').'</td>';
|
||||
}
|
||||
print '<td class="liste_titre right">'.$langs->trans('Margin').'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
|
||||
print '<td class="liste_titre right">'.$langs->trans('MarginRate').'</td>';
|
||||
}
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES)) {
|
||||
print '<td class="liste_titre right">'.$langs->trans('MarkRate').'</td>';
|
||||
}
|
||||
print '</tr>';
|
||||
|
||||
if (!empty($conf->product->enabled)) {
|
||||
//if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans('MarginOnProducts').'</td>';
|
||||
print '<td class="right">'.price($marginInfo['pv_products']).'</td>';
|
||||
print '<td class="right">'.price($marginInfo['pa_products']).'</td>';
|
||||
print '<td class="right">'.price($marginInfo['margin_on_products']).'</td>';
|
||||
print '<table class="noborder margintable centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td class="liste_titre">' . $langs->trans('Margins') . '</td>';
|
||||
print '<td class="liste_titre right">' . $langs->trans('SellingPrice') . '</td>';
|
||||
if ($conf->global->MARGIN_TYPE == "1") {
|
||||
print '<td class="liste_titre right">' . $langs->trans('BuyingPrice') . '</td>';
|
||||
} else {
|
||||
print '<td class="liste_titre right">' . $langs->trans('CostPrice') . '</td>';
|
||||
}
|
||||
print '<td class="liste_titre right">' . $langs->trans('Margin') . '</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
|
||||
print '<td class="right">'.(($marginInfo['margin_rate_products'] == '') ? '' : price($marginInfo['margin_rate_products'], null, null, null, null, 2).'%').'</td>';
|
||||
print '<td class="liste_titre right">' . $langs->trans('MarginRate') . '</td>';
|
||||
}
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES)) {
|
||||
print '<td class="right">'.(($marginInfo['mark_rate_products'] == '') ? '' : price($marginInfo['mark_rate_products'], null, null, null, null, 2).'%').'</td>';
|
||||
print '<td class="liste_titre right">' . $langs->trans('MarkRate') . '</td>';
|
||||
}
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (!empty($conf->service->enabled)) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans('MarginOnServices').'</td>';
|
||||
print '<td class="right">'.price($marginInfo['pv_services']).'</td>';
|
||||
print '<td class="right">'.price($marginInfo['pa_services']).'</td>';
|
||||
print '<td class="right">'.price($marginInfo['margin_on_services']).'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
|
||||
print '<td class="right">'.(($marginInfo['margin_rate_services'] == '') ? '' : price($marginInfo['margin_rate_services'], null, null, null, null, 2).'%').'</td>';
|
||||
if (!empty($conf->product->enabled)) {
|
||||
//if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>' . $langs->trans('MarginOnProducts') . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['pv_products']) . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['pa_products']) . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['margin_on_products']) . '</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
|
||||
print '<td class="right">' . (($marginInfo['margin_rate_products'] == '') ? '' : price($marginInfo['margin_rate_products'], null, null, null, null, 2) . '%') . '</td>';
|
||||
}
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES)) {
|
||||
print '<td class="right">' . (($marginInfo['mark_rate_products'] == '') ? '' : price($marginInfo['mark_rate_products'], null, null, null, null, 2) . '%') . '</td>';
|
||||
}
|
||||
print '</tr>';
|
||||
}
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES)) {
|
||||
print '<td class="right">'.(($marginInfo['mark_rate_services'] == '') ? '' : price($marginInfo['mark_rate_services'], null, null, null, null, 2).'%').'</td>';
|
||||
}
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
|
||||
print '<tr class="liste_total">';
|
||||
print '<td>'.$langs->trans('TotalMargin').'</td>';
|
||||
print '<td class="right">'.price($marginInfo['pv_total']).'</td>';
|
||||
print '<td class="right">'.price($marginInfo['pa_total']).'</td>';
|
||||
print '<td class="right">'.price($marginInfo['total_margin']).'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
|
||||
print '<td class="right">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
|
||||
if (!empty($conf->service->enabled)) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>' . $langs->trans('MarginOnServices') . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['pv_services']) . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['pa_services']) . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['margin_on_services']) . '</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
|
||||
print '<td class="right">' . (($marginInfo['margin_rate_services'] == '') ? '' : price($marginInfo['margin_rate_services'], null, null, null, null, 2) . '%') . '</td>';
|
||||
}
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES)) {
|
||||
print '<td class="right">' . (($marginInfo['mark_rate_services'] == '') ? '' : price($marginInfo['mark_rate_services'], null, null, null, null, 2) . '%') . '</td>';
|
||||
}
|
||||
print '</tr>';
|
||||
}
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES)) {
|
||||
print '<td class="right">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
|
||||
|
||||
if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
|
||||
print '<tr class="liste_total">';
|
||||
print '<td>' . $langs->trans('TotalMargin') . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['pv_total']) . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['pa_total']) . '</td>';
|
||||
print '<td class="right">' . price($marginInfo['total_margin']) . '</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES)) {
|
||||
print '<td class="right">' . (($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2) . '%') . '</td>';
|
||||
}
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES)) {
|
||||
print '<td class="right">' . (($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2) . '%') . '</td>';
|
||||
}
|
||||
print '</tr>';
|
||||
}
|
||||
print '</tr>';
|
||||
print $hookmanager->resPrint;
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
} elseif ($reshook > 0) {
|
||||
print $hookmanager->resPrint;
|
||||
}
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user