Jump to content

[Solved] Customizing PDF Invoice to Include Total Amount in Words


Eutanasio

Recommended Posts

Hi,

I'm trying to customize the PDF invoices generated by my Prestashop 1.7 store to include the total amount to be paid in words (in French), which is a legal requirement in my country. I've attempted to modify the following files but have not succeeded in getting the desired result. Here are the details of my approach:

1. Helper.php: Added a function to convert numbers to French words.

class Helper extends HelperCore
{
    public static function convert_number_to_words($num = false)
    {
        if (!is_numeric($num)) {
            return false;
        }

        $num = number_format($num, 2, '.', '');
        list($integerPart, $fractionPart) = explode('.', $num);

        $words = self::convert_integer_to_words_fr($integerPart);
        $currency = 'dirhams';
        $subunit = 'centimes';

        $words .= ' ' . $currency;

        if ($fractionPart > 0) {
            $words .= ' et ' . self::convert_integer_to_words_fr($fractionPart) . ' ' . $subunit;
        }

        return ucfirst(trim($words)) . '.';
    }

    private static function convert_integer_to_words_fr($num)
    {
        // Function implementation...
    }
}

2. invoice.note-tab.tpl: Modified the template to include the total amount in words.

{if isset($order_invoice->note) && $order_invoice->note}
    <tr>
        <td colspan="12" height="10">&nbsp;</td>
    </tr>

    <tr>
        <td colspan="6" class="left">
            <table id="note-tab" style="width: 100%">
                <tr>
                    <td class="grey">{l s='Note' d='Shop.Pdf' pdf='true'}</td>
                </tr>
                <tr>
                    <td class="note">{$order_invoice->note|nl2br} {$total_paid_in_words} Dirhams</td>
                </tr>
            </table>
        </td>
        <td colspan="1">&nbsp;</td>
    </tr>
{/if}

3. HTMLTemplateInvoice.php: Overridden the `getContent` method to assign the total amount in words to the template.

class HTMLTemplateInvoice extends HTMLTemplateInvoiceCore
{
    public function getContent()
    {
        $order = new Order((int)$this->order->id);
        $total_paid = $order->total_paid;

        // Convert total paid to words in French
        $total_paid_in_words = Helper::convert_number_to_words($total_paid);

        // Assign the total paid in words to the template
        $this->smarty->assign(array(
            'total_paid_in_words' => $total_paid_in_words,
        ));

        // Call the parent method to retain existing functionality
        return parent::getContent();
    }
}

Despite these modifications, the total amount in words does not appear on the PDF invoices. Could anyone guide me on what might be going wrong or provide a solution to achieve this customization?

Thank you in advance for your help!

Link to comment
Share on other sites

  • Eutanasio changed the title to [Solved] Customizing PDF Invoice to Include Total Amount in Words

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...