Hi all, a friend of mine ask me about the possibility to use PERCENTAGE revenue stamps (over the net amount of a facture/bill). And i get to develop an easy trick to accomplish that. The default behaviour of Dolibarr (at least on Doli 5.X) is to consider the revenuestamp as a FIX amount.
=== Steps
== Step 0: modify the file /htdocs/compta/facture.php #3447
Where it puts:
if ($action == 'editrevenuestamp') {
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="action" value="setrevenuestamp">';
print $formother->select_revenue_stamp(GETPOST('revenuestamp'), 'revenuestamp', $mysoc->country_code);
// print '<input type="text" class="flat" size="4" name="revenuestamp" value="'.price2num($object->revenuestamp).'">';
print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
} else {
print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
}
You must put this:
if ($action == 'editrevenuestamp' && PERCENTAGE_REVENUESTAMP != '1') {
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="action" value="setrevenuestamp">';
print $formother->select_revenue_stamp(GETPOST('revenuestamp'), 'revenuestamp', $mysoc->country_code);
// print '<input type="text" class="flat" size="4" name="revenuestamp" value="'.price2num($object->revenuestamp).'">';
print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
}else if ($action == 'editrevenuestamp' && PERCENTAGE_REVENUESTAMP == '1') {
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="action" value="setrevenuestamp">';
print '<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).'">';
print $formother->select_revenue_stamp('', 'revenuestamp_type', $mysoc->country_code).'% ';
print ' → <span id="revenuestamp_span"></span>';
print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
print " <script>
$(document).ready(function(){
js_recalculate_revenuestamp();
$('select[name=revenuestamp_type]').on('change',function(){
js_recalculate_revenuestamp();
});
});
function js_recalculate_revenuestamp(){
var revenue_type = parseFloat($('select[name=revenuestamp_type]').val());
var amount_net = ".round($object->total_ht , 2).";
var revenue = revenue_type * amount_net / 100;
revenue = revenue.toFixed(2);
$('#revenuestamp_val').val(revenue);
$('#revenuestamp_span').html('$'+revenue);
}
</script>";
} else {
print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
}
== Step 1: Add a new entry in Setup -> Other Setup
== Step 2: add this CONSTANT: PERCENTAGE_REVENUESTAMP with value 1
Note: This option WILL ACTIVATE MY PATCH when editing a facture, using the revenuestamp values (in their respective dictionary of your Doli) as PERCENTAGE instead of as a FIX AMOUNT !! So if you need to set a fix revenuestamp for an specific facture, you can go here and set a ‘0’ instead of a ‘1’
== Step 3: Go to dictionary llx_c_revenuestamp and add so many “types” as you need for YOUR COUNTRY:
== Step 4: Editing a facture (bill)
Now, when you edit a facture you will be able to choose a type WHICH WILL BE UNDERSTOOD AS A PERCENTAGE and it will save for you the corresponding value calculated over the “net amount” of that facture:
Note: this above is AN ANIMATED GIF !!! so, ir foy are not seing the animation (here inside the email body), you should open the attached file: Peek 2017-11-14 12-56.gif because it show how it runs!
== Step 5: PDF fine !
Finally, i checked that if you open the PDF generated by Doli for the facture, it contains the correctly percentage calculated by my patch
Note: in this example i choosed a 3% (over 1,379.38)