SimpleInvoices Group Forum › Forums › Fearless359 SimpleInvoices Discussion Group › empty field in database not handled as expected
Tagged: empty, template, test fields
- This topic has 12 replies, 2 voices, and was last updated 3 years, 7 months ago by ppmt.
-
AuthorPosts
-
April 23, 2021 at 7:53 am #1543ppmtParticipant
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?
April 23, 2021 at 7:55 am #1544ppmtParticipantHere 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 3 years, 8 months ago by ppmt.
April 23, 2021 at 7:55 am #1545ppmtParticipantand some empty field from that table
select attention, phone, street_address from si_customers where name= “Andy”;
+———–+——-+—————-+
| attention | phone | street_address |
+———–+——-+—————-+
| | | |
+———–+——-+—————-+April 26, 2021 at 7:27 am #1549RRowleyParticipantThe
isset()
test for a field is to see if there is valid content to print. You can use theempty()
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}
April 26, 2021 at 12:20 pm #1550ppmtParticipantOk so
!empty
does fix the problem I have withisset
. ThanksHow about the
print_if_not_null
function? I found that there isprint_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 !emptyIs 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
April 28, 2021 at 12:55 pm #1552RRowleyParticipantI’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.
April 28, 2021 at 1:48 pm #1553ppmtParticipantOk 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.
Attachments:
May 7, 2021 at 7:31 am #1555RRowleyParticipantIt 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.
May 20, 2021 at 7:52 am #1556ppmtParticipantHi,
Sorry for the delay been away.I cleared my plugins directory and deleted everything in tmp and the problem remains.
I can wait for your next update and hopefully something will change.It must be something with my setting or my database then because I have the same issue when I use the other templates provided by default.
May 20, 2021 at 8:48 am #1557RRowleyParticipantI believe you need to start adding debug statements to the function. Try this. In the
include/smarty_plugins/function.print_if_not_empty.php
file add the following code after the setting of the$class2
variable:if ($params['label'] == "Ph.") { $str = "smarty_function_print_if_not_empty(): Ph is "; $str .= empty($params['field']) ? "empty. " : "not empty. "; $str .= "printIfEmpty is "; $str .= $printIfEmpty ? "true." : "false."; var_dump($str); }
When you print the template, you will get a message at the top of the print info screen that will tell you if it sees the phone field as empty and if it is setting the print if empty option for some reason. A not empty phone field or a true setting on the print if empty variable are the only ways that the logic will print something.
Hope this helps.
May 22, 2021 at 11:01 am #1558ppmtParticipantGood news!
It turns out I was not quite up to date with github. I couldn’t find the $class2 your were talking about.
So I downloaded the latest version and now it works. If I use print_if_not_empty then it now works.May 25, 2021 at 5:20 am #1559RRowleyParticipantThese are the first three lines of the function. The code would go in after them.
$printIfEmpty = !empty($params['printIfEmpty']) && $params['printIfEmpty'] == true; $class1 = empty($params['class1']) ? '' : Util::htmlSafe($params['class1']); $class2 = empty($params['class2']) ? '' : Util::htmlSafe($params['class2']);
May 25, 2021 at 7:35 am #1560ppmtParticipantHi Richards,
Thanks for your help and patience.
I didn’t have the latest version from the github which contains the new code for the function. After I downloaded it I can report that theprint_if_not_empty
function is now working as intended.I now just have a few tweaks to do in my template and I will be able to switch to the master_2020 version on my production machine.
-
AuthorPosts
- You must be logged in to reply to this topic.
Recent Comments