Secondary line in another currency below the invoice total

Hi all,

Due recent changes in our local laws (Country: Bulgaria) we’re required to add a second line on each price in EUR side-to-side with the price for BGN. I’ve tried the odt template with very poor success, I’ve tried the marketplace but found nothing that would help me, looked around but found nothing useful.

I have the multi-currency module installed, but it doesn’t do what I need to have.

Considering this law will be applied until 01.01.2026 then we all switch to EUR as primary currency doing major coding / changes is plain stupid, can someone help me do a quick & dirty change in pdf_sponge.modules.php (or any other file) that just adds another line to the PDF with a hard-coded text (i.e. total in EUR) and for value - the total value of the invoice multipled by 0.51 ?

I’m fully aware that’s not the way to do things, and I’m fully aware that it can cause any sort of problems, but that will be on me. I’m also wiling to pay any reasonable amount of money to any app that can do basically that. I like the sponge template, but I don’t have the skills / knowledge to do it myself.

Greetings :wink:

Hi @tzerber

You will have to modify htdocs/core/modules/facture/doc/pdf_sponge.modules.php
Find function drawTotalTable
There under section // Total TTC and before section // Retained warranty add following code

                //Total in Euro
				$index++;
				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
				$pdf->SetTextColor(0, 0, 60);
				$pdf->SetFillColor(224, 224, 224);
				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total in Euro").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Total in Euro") : ''), $useborder, 'L', true);
				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
				$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc * 0.51, 0, $outputlangs), $useborder, 'R', true);

Every time you upgrade you have to manually add the code till your country’s transition to euro is complete.

1 Like

Thanks a lot, will try it now and post back results.

EDIT: My math rounding goes wrong, and it can lead to weird results. So I modified it a bit, to be more accurate:

price(round(ceil( $total_ttc * 51.1291) / 100, 2), 0, $outputlangs)
(on large sums rounding the euro to 0.51 is bad idea, the current actual price is 0.511291)

Since I’m no expert in PHP I am unsure if this is the correct approach, but math works.

Also, changed $outputlangs->transnoentities(“TotalEuro”) and manually added a translation in the menu, and now it shows the correct text in Bulgarian language in the invoice.