empty field in database not handled as expected

SimpleInvoices Group Forum Forums Fearless359 SimpleInvoices Discussion Group empty field in database not handled as expected

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1543
    ppmt
    Participant

    For my template I basically used the default one and have adapted it to my requirement.

    I can see that through the templates it either use isset or print_if_not_null to decide if a field should be printed or not.

    In my case the logic doesn’t work. I have a some fields that are not populated for some of my customers and yet the label for that field is still printed in the pdf generated.

    I have tried to edit the database and set the field to null and it seems to fix the problem but as soon as I go and edit the customers and save it then the fields reappear.

    My database is coming from previous update so I am wondering if something in the format of the database is wrong.

    Any idea or pointer as what could be wrong?

    #1544
    ppmt
    Participant

    Here are some printout. I could not put them in the main post as it was telling me it looks like spam!

    describe si_customers;
    +--------------------------+------------------+------+-----+---------+----------------+
    | Field                    | Type             | Null | Key | Default | Extra          |
    +--------------------------+------------------+------+-----+---------+----------------+
    | id                       | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
    | domain_id                | int(11) unsigned | NO   | PRI | NULL    |                |
    | attention                | varchar(255)     | YES  |     | NULL    |                |
    | name                     | varchar(255)     | YES  |     | NULL    |                |
    | department               | varchar(255)     | YES  |     | NULL    |                |
    | street_address           | varchar(255)     | YES  |     | NULL    |                |
    | street_address2          | varchar(255)     | YES  |     | NULL    |                |
    | city                     | varchar(255)     | YES  |     | NULL    |                |
    | state                    | varchar(255)     | YES  |     | NULL    |                |
    | zip_code                 | varchar(20)      | YES  |     | NULL    |                |
    | country                  | varchar(255)     | YES  |     | NULL    |                |
    | phone                    | varchar(255)     | YES  |     | NULL    |                |
    | mobile_phone             | varchar(255)     | YES  |     | NULL    |                |
    | fax                      | varchar(255)     | YES  |     | NULL    |                |
    | email                    | varchar(255)     | YES  |     | NULL    |                |
    | credit_card_holder_name  | varchar(255)     | YES  |     | NULL    |                |
    | credit_card_number       | varchar(20)      | YES  |     | NULL    |                |
    | credit_card_expiry_month | varchar(2)       | YES  |     | NULL    |                |
    | credit_card_expiry_year  | varchar(4)       | YES  |     | NULL    |                |
    | notes                    | text             | YES  |     | NULL    |                |
    | parent_customer_id       | int(11)          | YES  |     | NULL    |                |
    | default_invoice          | int(10) unsigned | NO   |     | 0       |                |
    | custom_field1            | varchar(255)     | YES  |     | NULL    |                |
    | custom_field2            | varchar(255)     | YES  |     | NULL    |                |
    | custom_field3            | varchar(255)     | YES  |     | NULL    |                |
    | custom_field4            | varchar(255)     | YES  |     | NULL    |                |
    | enabled                  | tinyint(1)       | NO   |     | 1       |                |
    +--------------------------+------------------+------+-----+---------+----------------+
    27 rows in set (0.002 sec)
    • This reply was modified 2 weeks, 2 days ago by ppmt.
    #1545
    ppmt
    Participant

    and some empty field from that table

    select attention, phone, street_address from si_customers where name= “Andy”;
    +———–+——-+—————-+
    | attention | phone | street_address |
    +———–+——-+—————-+
    | | | |
    +———–+——-+—————-+

    #1549
    RRowley
    Participant

    The isset() test for a field is to see if there is valid content to print. You can use the empty() test on a field to determine if both the label and the field should be printed. For instance here is a test to determine if custom field 1 should be printed:

    <!-- Show the Invoice Custom Fields if valid -->
     {if !empty($customFieldLabels.invoice_cf1) && isset($invoice.custom_field1)}
     <tr>
       <td nowrap class="">{$customFieldLabels.invoice_cf1|htmlSafe}:</td>
       <td class="si_right" colspan="3">{$invoice.custom_field1|htmlSafe}</td>
     </tr>
     {/if}
    #1550
    ppmt
    Participant

    Ok so !empty does fix the problem I have with isset. Thanks

    How about the print_if_not_null function? I found that there is print_if_not_empty but looking at the code it is actually the same as print_if_not_null.
    I guess I will copy that function, put it in my theme plugins and replace isset by !empty

    Is there any reason why the “empty” field are not set to NULL when not populated? The talbe definition seems to indicate that the defaul should be NULL

    #1552
    RRowley
    Participant

    I’ve gone through and removed all duplicate occurrences of the various smarty function so that the standard version in the library is used. There is no need to include a function in a invoice templates plugin directory unless you want to modify it for some reason.

    I’ve updated internal comments in the not null and not empty functions to explain the difference. Basically and item can be not null but empty (blank, 0, etc. are empty values). It appears there is no use of the not empty function but I’ll keep it around for now anyway.

    #1553
    ppmt
    Participant

    Ok so may be I am missing something but it doesn’t seem to work for me. Here is an extract of an invoice. As you can see the field phone, fax, mobile and email are empty but the field is still displayed.

    Here is the code I am using in my template:

          {print_if_not_empty label=$LANG.phoneShort field=$customer.phone class1='' class2='' colspan="3"}
          {print_if_not_empty label=$LANG.fax field=$customer.fax class1='' class2='' colspan="3"}
          {print_if_not_empty label=$LANG.mobileShort field=$customer.mobile_phone class1='' class2='' colspan="3"}
          {print_if_not_empty label=$LANG.email field=$customer.email class1='' class2='' colspan="3"}

    I have tried with print_if_not_null as well and the result is the same.

    #1555
    RRowley
    Participant

    It works in all my testing. Make sure you don’t have a local copy of the function in your invoice plugins directory. I removed them all from the standard version and have worked with this in testing the logic in the various templates and it works fine. I’m in the middle of making some significant changes to SI which includes enhancements to these functions to using multiple labels values and such. So it will be a little while before I get those delivered.

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