Due date

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
clowther
Posts: 1
Joined: 2016-04-25 14:56

Due date

Post by clowther » 2016-04-25 14:59

Help!..... Please.


Ok I have a quick and hopefully simple problem.
I need to have a way to show if an inspection is expired.
I have a date field in my app and if its been over a year since it was done according to todays date I need it to return a value of EXPIRED to another field.

How can I do this?? Directions very helpful.

Example
Date Inspected 1-1-2015 Should return a value from todays date of Expired.

Thanks
Clayton

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Due date

Post by AhmedBR » 2016-04-26 23:54

Create a field called ALERT in the same table (or any other name you choose) and use this code in the init hook of your table:

Code: Select all

sql("update `YOUR_TABLE` set `Alert`= if(Date_Add(Date(`Inspection`), interval 365 day)<CurDate(),'Expired',null)",$eo);
This should do the trick.

I use this code a lot to expire discounts, special prices for clients etc. etc. ;)
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

facos79
Veteran Member
Posts: 115
Joined: 2014-10-29 12:31

Re: Due date

Post by facos79 » 2017-06-26 19:59

Hello,
does not work. Probably something wrong.
How can I do ?

My table is called: 'Gestione_Ordini'
The names of the fields are these: 'Data_Consegna' e 'Alert'

Code: Select all

 sql("update `Gestione_Ordini` set `Alert`= if(Date_Add(Date(`Data_Consegna`), interval 365 day)<CurDate(),'Alert',null)",$eo); 


I insert the code into the hook file '' Gestione_Ordini '' but exactly where to put it?
Thanks in advance for the help

Greetings

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Due date

Post by AhmedBR » 2017-06-26 22:54

You should the code right after this line:

Code: Select all

function Gestione_Ordini_init(&$options, $memberInfo, &$args){
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

facos79
Veteran Member
Posts: 115
Joined: 2014-10-29 12:31

Re: Due date

Post by facos79 » 2017-06-27 11:19

I have entered the code in your specified space but it does not work.
What should look like in the ALERT cell?
According to you, the code shown above has been modified by me correctly?

I attached the hook file

Thank you very much for your help.
Attachments
Gestione_Ordini.zip
(2.56 KiB) Downloaded 226 times

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Due date

Post by AhmedBR » 2017-06-27 12:11

The Code looks fine to me, check the following: Data Type your are using for Data_Consegna has to be DATE.
Check if you have expired dates, maybe all the dates are less than one year (use like 30 days to check if this is not the problem).
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

facos79
Veteran Member
Posts: 115
Joined: 2014-10-29 12:31

Re: Due date

Post by facos79 » 2017-06-27 13:53

Hi, it was just a field size problem. It was not DATE.
Now works.
Thanks so much for help.
Good day :)

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Due date

Post by AhmedBR » 2017-06-27 15:24

Glad it works ;)
Have a nice day
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

facos79
Veteran Member
Posts: 115
Joined: 2014-10-29 12:31

Re: Due date

Post by facos79 » 2017-06-27 20:04

Sorry if it disturbs you again. The code works but I would need to put a warning on the lines that expire in the next 30 days (even previous ones compared to the date of the day of the display).
Example: today is 27.06.2017
I should mark the rows with date 20.06.2017 but also those with date 25.07.2017.
It is not necessary to indicate those with date 30.07.2017 because they are over 30 days.

How can I do ?

Code: Select all

sql("update `Gestione_Ordini` set `Alert`= if(Date_Add(Date(`Data_Consegna`), interval 30 day) >CurDate(),'ATTENZIONE!',null)",$eo);

facos79
Veteran Member
Posts: 115
Joined: 2014-10-29 12:31

Re: Due date

Post by facos79 » 2017-06-27 20:42

Maybe I've solved this way:

Code: Select all

sql("update `Gestione_Ordini` set `Alert`= if((`Data_Consegna`) < (CurDate() + interval 30 day),'ATTENZIONE!',null)",$eo);
It seems to work.

Thanks again for everything.

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Due date

Post by AhmedBR » 2017-06-27 21:03

Just a warning you could NULL other alerts this way.
You should COMBINE BOTH lines in one IF sql update.

In other words you should check for status of 30 days and 365 in same IF formula.
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

facos79
Veteran Member
Posts: 115
Joined: 2014-10-29 12:31

Re: Due date

Post by facos79 » 2017-06-29 19:29

Grazie :)

Post Reply