Patch Doli 5.0.4 to use PERCENTAGE REVENUESTAMP

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 ' &rarr; <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

Selecci_564.png

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’ :wink:

== 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:

Peek2017-11-1412-56.gif

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! :happy:

== Step 5: PDF fine ! :happy:

Finally, i checked that if you open the PDF generated by Doli for the facture, it contains the correctly percentage calculated by my patch

Selecci_562.png

Note: in this example i choosed a 3% (over 1,379.38)

4 Likes

Hi !

The file facture.php is no more in /compta/ and the structure has changed.

Any idea on how to set that up in 6.0.x ?

:wink:

Monsignore, i’ve not tested it, but it seems that in 6.0.x these are the files to be edited:

  • /htdocs/compta/facture/card.php #3592
  • /htdocs/compta/facture/prelevement.php #489

:sunglasses:

Thanks.
I introduced and enhanced this patch into v7 beta.

2 Likes

I don’t think I need this but can anyone kindly explain why and where a ‘revenue stamp’ would be needed?

Is it just an overall discount on the invoice?

Hi !

Many countries apply a supplementary tax on bills, generally when paid in cash.

For ex here we have 0.25% fees on cash bills :happy:
Some add a “X bucks” fix amount :happy:

@monsinore

Thanks. Good job we don’t use that in the UK haha

So technically, the revenue stamp can be quick hack also for a ‘delivery charge’.

aljawaid what about PayPal fees or international bank transfer fees using IBAN? I think it can be used for that as well but I haven’t had time to test it yet. Anyway caos30 thanks a lot for another implementation :sunglasses: btw. your currency path works very well :sunglasses: I’ll try now to finally reply to your last email :evil:

Well, normal bank fees… Not yet different from normal bills at the moment in dolibarr unfortunately :happy:

Works perfectly fine on D 7.0 (a great one indeed !)

Now a question. Any way to FORCE the stamp IF “cash” payement is selected ?

thanks for all this great work !

But more important : the stamp is calculated over the no VAT bill amount, how to apply it on the total bill amount ? (WITH VAT)