Merge pull request #15852 from aspangaro/14a8
NEW: Add total in agent margin & uniformize code
This commit is contained in:
commit
243a3f9680
@ -291,17 +291,40 @@ if ($result)
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print "<td>".$group_array['htmlname']."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($pv, 'MT'))."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($pa, 'MT'))."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($marge, 'MT'))."</td>\n";
|
||||
print '<td class="nowrap right">'.price(price2num($pv, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($pa, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($marge, 'MT')).'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print "<td class=\"right\">".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
print "<td class=\"right\">".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$i++;
|
||||
$cumul_achat += $pa;
|
||||
$cumul_vente += $pv;
|
||||
}
|
||||
}
|
||||
print "</table>";
|
||||
|
||||
// Show total margin
|
||||
$totalMargin = $cumul_vente - $cumul_achat;
|
||||
|
||||
$marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : '';
|
||||
$markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : '';
|
||||
|
||||
print '<tr class="liste_total">';
|
||||
print '<td>';
|
||||
print $langs->trans('TotalMargin')."</td>";
|
||||
print '<td class="nowrap right">'.price(price2num($cumul_vente, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($cumul_achat, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($totalMargin, 'MT')).'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print '<td class="nowrap right">'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
print '<td class="nowrap right">'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
@ -310,9 +333,13 @@ $db->free($result);
|
||||
|
||||
print "\n".'<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#agentid").change(function() {
|
||||
$("div.fiche form").submit();
|
||||
});
|
||||
$("#agentid").change(function() {
|
||||
$("div.fiche form").submit();
|
||||
});
|
||||
|
||||
$("#totalMargin").html("'.price(price2num($totalMargin, 'MT')).'");
|
||||
$("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'");
|
||||
$("#markRate").html("'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'");
|
||||
});
|
||||
</script>'."\n";
|
||||
|
||||
|
||||
@ -303,23 +303,23 @@ if ($result)
|
||||
$invoicestatic->id = $objp->facid;
|
||||
$invoicestatic->ref = $objp->ref;
|
||||
print $invoicestatic->getNomUrl(1);
|
||||
print "</td>\n";
|
||||
print "<td class=\"center\">";
|
||||
print dol_print_date($db->jdate($objp->datef), 'day')."</td>";
|
||||
print '</td>';
|
||||
print '<td class="center">';
|
||||
print dol_print_date($db->jdate($objp->datef), 'day').'</td>';
|
||||
} else {
|
||||
$companystatic->id = $objp->socid;
|
||||
$companystatic->name = $objp->name;
|
||||
$companystatic->client = $objp->client;
|
||||
print "<td>".$companystatic->getNomUrl(1, 'margin')."</td>\n";
|
||||
print '<td>'.$companystatic->getNomUrl(1, 'margin').'</td>';
|
||||
}
|
||||
|
||||
print "<td class=\"right\">".price(price2num($pv, 'MT'))."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($pa, 'MT'))."</td>\n";
|
||||
print "<td class=\"right\">".price(price2num($marge, 'MT'))."</td>\n";
|
||||
print '<td class="nowrap right">'.price(price2num($pv, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($pa, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($marge, 'MT')).'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print "<td class=\"right\">".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
print "<td class=\"right\">".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$i++;
|
||||
@ -347,16 +347,16 @@ if ($result)
|
||||
print '<td colspan=2>';
|
||||
else print '<td>';
|
||||
print $langs->trans('TotalMargin')."</td>";
|
||||
print "<td class=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
|
||||
print "<td class=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
|
||||
print "<td class=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
|
||||
print '<td class="nowrap right">'.price(price2num($cumul_vente, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($cumul_achat, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($totalMargin, 'MT')).'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print "<td class=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
print "<td class=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
|
||||
print "</tr>\n";
|
||||
print '<td class="nowrap right">'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
print "</table>";
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
@ -370,9 +370,9 @@ $(document).ready(function() {
|
||||
$("div.fiche form").submit();
|
||||
});*/
|
||||
|
||||
$("#totalMargin").html("'.price($totalMargin, null, null, null, null, $rounding).'");
|
||||
$("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%").'");
|
||||
$("#markRate").html("'.(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%").'");
|
||||
$("#totalMargin").html("'.price(price2num($totalMargin, 'MT')).'");
|
||||
$("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'");
|
||||
$("#markRate").html("'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'");
|
||||
});
|
||||
</script>
|
||||
';
|
||||
|
||||
@ -300,14 +300,14 @@ if ($result)
|
||||
print "</td>\n";
|
||||
//print "<td>".$product_static->getNomUrl(1)."</td>\n";
|
||||
}
|
||||
print "<td class=\"center\">".$qty."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($pv, 'MT'))."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($pa, 'MT'))."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($marge, 'MT'))."</td>\n";
|
||||
print '<td class="center">'.$qty.'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($pv, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($pa, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($marge, 'MT')).'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print "<td class=\"right\">".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
print "<td class=\"right\">".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$i++;
|
||||
@ -328,15 +328,15 @@ if ($result)
|
||||
if ($id > 0)
|
||||
print '<td colspan=2>';
|
||||
else print '<td>';
|
||||
print $langs->trans('TotalMargin')."</td>";
|
||||
print "<td class=\"center\">".$cumul_qty."</td>";
|
||||
print "<td class=\"nowrap right\">".price(price2num($cumul_vente, 'MT'))."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($cumul_achat, 'MT'))."</td>\n";
|
||||
print "<td class=\"nowrap right\">".price(price2num($totalMargin, 'MT'))."</td>\n";
|
||||
print $langs->trans('TotalMargin').'</td>';
|
||||
print '<td class="center">'.$cumul_qty.'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($cumul_vente, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($cumul_achat, 'MT')).'</td>';
|
||||
print '<td class="nowrap right">'.price(price2num($totalMargin, 'MT')).'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||
print "<td class=\"right\">".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'</td>';
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES))
|
||||
print "<td class=\"right\">".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."</td>\n";
|
||||
print '<td class="nowrap right">'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
print "</table>";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user