Question about templates for PDF output

SimpleInvoices Group Forum Forums Fearless359 SimpleInvoices Discussion Group Question about templates for PDF output

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #2187
    marcnyc
    Participant

    Hello, I have recently updated my SI installation to the latest version 2023.0.7 and I have a question about how templates are now handled and about the PDF output.

    In my previous 2020 install I had a file in:
    custom/default_template/invoices/manage.tpl
    but in the new 2023 version I don’t see a manage.tpl file any longer. What file does now do what the manage.tpl file used to do?

    Also if I wanted to make all the fonts smaller in the PDF output, which file would I have to act on to change the styling of the PDF?

    Thank you so much

    #2189
    RRowley
    Participant

    The files in the custom directory are not part of the library. They are ones you develop. Try copying the invoices/manager.tpl from your backed up, previous version to the custom/default_template directory. See if that doesn’t resolve your issue.

    For pdf characteristics such as font size, use the exportPdf… values in the config/custom.config.ini file.

    #2193
    marcnyc
    Participant

    Moving the manage.tpl file from the old install to custom/default_template didn’t work…
    Basically, what I am trying to do is change what values are shown inside the table that is shown in the main MONEY>INVOICES screen (at the URL: /index.php?module=invoices&view=manage)
    What part of the template file generates this table so I can change what is show in that table? Or is there another way to change what is shown?

    As for the PDF, thanks for telling me where the font settings are.

    I have one last PDF question: my name is misspelled in the PDF invoice at the top right corner and I can’t find where the settings are for that… I’ve looked in all the PEOPLE menus and SETTINGS menus but I can’t see where the misspelled name is, where would that be saved?

    Thanks

    #2197
    marcnyc
    Participant

    just bumping this up to make sure it is seen…

    #2198
    RRowley
    Participant

    Check out the Extensions menu option. What you want to do is set up an extension for the templates/invoices/manage.tpl file. If the data you want to display is not in the data.json file that feeds the DataTables, then you will need to add the module/invoices/manage.php file to the extension and include the field/fields that you want to display. Try and keep your changes to these files as it can get more complicated if you have to add other classes and such to the change. If you need data that is not provided by an existing class method, try making the PdoDb request withing the manage.php file and adding it to the $invoices array prior to submitting it to the json encode function.

    Hope this helps get you going. If you need more help, try explaining what it is you want to see versus what is there now.

    • This reply was modified 2 months, 4 weeks ago by RRowley.
    #2227
    marcnyc
    Participant

    Sorry to be dumb, but I am a bit confused.
    I found the Settings > Customize > Extensions menu and I see the “Core part and the “eway payment gateway” and nothing else. I don’t see a way to add an extension here.
    How would I add an extension? And what would the extension be/entail?

    What I am trying to achieve are two separete things:

    1. add some of the CUSTOM FIELDS that I have set in Settings>Custom Fields to the main view that I see when I load the main page in Money>Invoices.

    Right now that page shows a table with: Actions / Invoice / Biller / Customer / Preference etc etc
    What I want to do is add two custom fields to that table.

    2. somehow I misspelled my name in the PDF invoice at the top right corner and I can’t find where the settings are for that… I’ve looked in all the PEOPLE menus and SETTINGS menus but I can’t see where the misspelled name is, where would that be saved?

    #2229
    RRowley
    Participant

    The first step is to create an extension. Go to the SETTINGS, Customize option and add your extension. The extension is not enabled when created. You can enable it via this same screen when you are ready to test it. Next, you would would create the extensions/<extensionname>/modules/invoices/manage.php and the extensions/<extensionname>/templates/default/invoices/manage.tpl files. This might be all you need. The manage.php file gathers the data and puts it in the data.json file and the manage.tpl builds the display screen that shows the data. It is likely that the custom fields you want to display are in the $invoices record returned by the getAllWithHavings function. This will take a bit of coding on your part. Hope it works out. BTW, when new versions of SI are loaded, you manually copy your extentions directory from old to new version and it should keep working.

    • This reply was modified 1 month ago by RRowley.
    #2234
    marcnyc
    Participant

    I think this is the post you were referring to in the other thread…
    I followed these instructions and I copied /modules/invoices/manage.php to extensions/MYextension/modules/invoices/manage.php and then I copied /templates/default/invoices/manage.tpl to extensions/MYextension/templates/default/invoices/manage.tpl and then I enabled MYextension in SETTINGS > Customize > Extensions (it now has a lit light bulb and a green puzzle piece on the right).

    You mentioned the getAllWithHavings but in the manage.php file I only see this code:

        $invoices = Invoice::getAllWithHavings($having, '', '', true, false,
                                               $invoiceDisplayDays);

    and no other way to add any fields there…

    Next I opened in the editor the manage.tpl file and where the table is built and this line is:
    <th>{$LANG.billerUc}</th>
    I’ve added (just to make sure I’m in the right place) of the code:
    <th>xxxx{$LANG.billerUc}</th>
    but I don’t see those “xxxx” being displayed anywhere in my table, even after re-loading, logging out and using an incognito browser window. What am I doing wrong?

    Also later in that file I see:

        <script>
            {literal}
            $(document).ready(function () {
                $('#si-data-table').DataTable({
                    "ajax": "./public/data.json",
                    "orderClasses": false,
                    "deferRender": true,
                    "responsive": true,
                    "columns": [
                        {"data": "action"},
                        {"data": "index_id"},
                        {"data": "biller"},
                        {"data": "customer"},
                        {"data": "preference"},
                        {"data": "date"},

    but what are the other “data” fields I can add here? How do I add the custom fields here?

    #2237
    RRowley
    Participant

    I ran a test that works correctly. I only tested the template since that was what you put the “xxxx” in. I’ve attached a pic of the directory structure. One trouble I had was that I clicked on the register/unregister icon on the left (green thing). But didn’t click on the enable icon that appeared once the extension was registered. Of course, the light bulb on the right was not lit. When I did finally enable the extension (light bulb lit), the extension template was picked up and its changes displayed. So since you have your light bulb lit (extension enabled), I’m not quite sure why you are having a problem.

    Attachments:
    #2239
    marcnyc
    Participant

    Yes I had figured out the switch thing on my own by clicking around, but I don’t see those XXXX appear anywhere…
    here’s screenshots of my structure and backend

    #2245
    fearless359
    Keymaster

    You appear to have a spelling error: templates vs tamplates.

    #2246
    marcnyc
    Participant

    Oh damn, I feel stupid now… it’s always the small stuff…

    Ok so now that I see what I’m modifying, would you please tell me what the names of the Custom Fields are in the database?

    Speicfically, if I have:
    invoice :: Custom field 1 set to Artist

    How can I access/refer to/call the name of the invoice :: Custom field 1 and the contents to put inside the json file?

    #2247
    fearless359
    Keymaster

    Hopefully you have phpMyAdmin installed so you can look up database information like this. If you look at the si_invoices table you will see that you have custom_field1, 2, 3 & 4. This should be how they are named in the array of invoices returned from the get method.

    #2248
    marcnyc
    Participant

    I see in the si_invoices table in phpMyAdmin that they are called custom_field1, custom_field2 etc but if I edit my manage.tpl file code from this:

                    "columns": [
                        {"data": "action"},
                        {"data": "index_id"},
                        {"data": "biller"},

    to this:

                    "columns": [
                        {"data": "action"},
                        {"data": "index_id"},
                        {"data": "custom_field1"},

    What I get when I reloead the web page is this error alert box:

    DataTables warning: table id=si-data-table – Requested unknown parameter ‘custom_field1’ for row 0, column 2. For more information about this error, please see http://datatables.net/tn/4

    I don’t see the biller being one of the si_invoices table columns so I have a feeling I’m changing the wrong part of the code, but that is the only place I see the word “biller” appear in the manage.tpl file and I don’t see it appear anywhere else in that file or in the manage.php file.

    What am I missing?

    #2249
    fearless359
    Keymaster

    The issue is that the Invoice::manageTableInfo method does not preserve the custom fields for the invoice. Hence, they are undefined by the time it gets to the screen. The easiest way to resolve this is to modify said method to include these fields which would be referenced as $row['custom_field1'], etc. Copy the Inc/Claz/Invoice.php file into the extension directory preserving the “Inc/Claz/” path the same as you did for the template and module files. Then modify the method to add the custom field assignments to the table.

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.