Page 1 of 1

More auto updating fields [Solved]

PostPosted: Tue May 18, 2010 2:07 pm
by cantlep
Hiya,

Can you help with another auto update field requirement?!

In my "ContractData" table I have various columns. One of them it titled "Contract Status" and another is "Contract Active"

What I'd like to have is the Contract Active column say "YES" or "NO" depending on the following:

If "Contract Status = ACCEPTED" and today's date is greater than or equal to "Contract Start Date" and is less then "Contract End Date" then Contract Active = YES, else Contract Active = No.

Is something like that possible..perhaps with a rendercell call in ContractData.php ?

Thanks once again

Paul

Re: More auto updating fields

PostPosted: Tue May 18, 2010 2:15 pm
by shannah
Yes. The best way is probably to do a grafted field.
e.g.

Code: Select all
__sql__ = "select t.*, if(t.Contract_Status='Approved' and t.Contract_Start_Date<=NOW() and t.Contract_End_Date<=NOW(),'YES','NO') as Contract_Active from mytable t"

Re: More auto updating fields

PostPosted: Wed May 19, 2010 1:55 am
by cantlep
Thanks Steve,

I have this in ContractData/fields.ini

Code: Select all
[ContractActive]
widget:label = "Active Contract?"
__sql__ = "select t.*, if(t.ContractStatus='Accepted' and t.ContractStartDate<=NOW() and t.ContractEndDate>=NOW(),'YES','NO' as ContractActive from ContractData t"


I know I've missed something (probably obvious). I'm also struggling to work out when __sql__ code needs to be in fields.ini or a table class in table.php I seem to have a combination of the two.

e.g. The contract length one you did for me
Code: Select all
function __sql__(){
        return "select t.*, datediff(t.ContractEndDate,t.ContractStartDate) as ContractLength from ContractData t";
}

resides in ContractData.php

Is that where I should be putting that first bit of code to auto update with YES or NO? I know when a table class is used, that column name doesn't need to be in the DB as it's created on the fly. What about when in fields.ini

Confused - :?

Can you help?

Cheers

Paul

Re: More auto updating fields

PostPosted: Wed May 19, 2010 6:38 am
by cantlep
OK, read more documentation and now get the differences. I've moved all my grafted fields from fields.ini into table delegate class and removed those columns from the DB. Life is good.

Still need some assistance with the ContractActive thing though.

Cheers

Re: More auto updating fields

PostPosted: Thu May 20, 2010 3:21 am
by cantlep
All sorted. I'd missed a bracket from your code (after the NO) :oops

I've now got this in ContractData.php

Code: Select all
function __sql__(){
        return "select t.*, datediff(t.ContractEndDate,t.ContractStartDate) as ContractLength, if(t.ContractStatus='Accepted' and t.ContractStartDate<=NOW() and t.ContractEndDate>=NOW(),'YES','NO') as ContractActive from ContractData t";
}


Works like a charm. Thanks for all your help, Steve

Paul