Page 1 of 1
Conditional picture display
Posted: Wed Dec 08, 2021 10:58 pm
by treed
Hello all, I have an invoice report and If the paid date is not null I'd like to display an image that says "Paid in Full". So I have 2 questions.
1. Where is the best place to store the image so it won't get overwritten by updates?
2. How would one create and implement the conditional logic in the report?
Re: Conditional picture display
Posted: Fri Dec 10, 2021 3:53 am
by kev1n
Hi,
Use Setup -> Files to store images.
Do you want to display just one image on the report or several (for each row?)
Re: Conditional picture display
Posted: Mon Dec 13, 2021 10:31 pm
by treed
Thanks, good to know pictures can be stored that way. What I need to know is how to display that picture based on conditional logic. Kind of like MS Access had a visible property. If a field is null I want to not see the image and if there is an entry the image is visible. Any idea how to approach that?
Re: Conditional picture display
Posted: Wed Dec 15, 2021 4:55 pm
by kev1n
If there was just one picture to be displayed (or not), one could try using a hash cookie. But if you need to show pictures per row based on a condition, it might get more tricky. I have to think about how to tackle this. Maybe someone else will have a bright idea.
Re: Conditional picture display
Posted: Fri Dec 17, 2021 9:48 pm
by treed
I just want to display one image in the footer, so the hash cookie might work. However I have no idea on how to get from hash cookie to what I need within the constraints of the report writer. If you could point me in the right direction it would be much appreciated.
Re: Conditional picture display
Posted: Sun Dec 19, 2021 1:49 pm
by kev1n
1. Upload your image under Setup -> Files. (In this example I use the image code image_paid). The image has to be in jpg format.
2. Upload a 1x1 pixel jpg image with code paid_image_blank.
3. Create a Procedure under Builders -> Procedure.
Replace FR0 with your report code.
Code: Select all
// To-do:
// Run a db query and based on the result set $showImage = '1' to show the image or $showImage = '0' to "hide" it.
$js = "
if ($showImage == '1') {
nuSetProperty('paid_image', 'Image:paid_image');
} else {
nuSetProperty('paid_image', 'Image:paid_image_blank');
}
nuRunReport('FR0');
";
nuJavascriptCallback($js);
4. In your report, add an image object. In its Source field, use this Hash Cookie:
report_image.jpg
5. To run the report, add this JS in a button's onclick event:
Re: Conditional picture display
Posted: Tue Dec 21, 2021 7:22 pm
by treed
One question, how is the invoice_id passed to the PHP code for use in the query?
Re: Conditional picture display
Posted: Tue Dec 21, 2021 8:00 pm
by kev1n
invoice_id can be retrieved as Hash Cookie in PHP: #invoice_id#
E.g. assign it to a variable
Re: Conditional picture display
Posted: Tue Dec 21, 2021 11:15 pm
by treed
Thanks so much for your help with this kev1n. I used to be pretty good at PHP and now I see more clearly how things tie together.