Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » Date formats in PDF
Date formats in PDF [message #1603] Thu, 04 September 2008 11:19 Go to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I'm trying to print reports via the PDF output, but am having a problem getting the date format correct.

The config.inc file has
// set date format - choose one of the following
$GLOBALS['date_format'] = 'dmy';
//$GLOBALS['date_format'] = 'mdy';
//$GLOBALS['date_format'] = 'ymd';

and I am seeing the correct date format on the screens. However, in the reports dates are showing as YYYY-MM-DD. Could something be overriding the config.inc?

Also, is it possible to specify any other date formats for printing, e.g. dd/mm/yy ?

Graham

Re: Date formats in PDF [message #1604 is a reply to message #1603] Thu, 04 September 2008 13:48 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
I have just tried this using the PERSON table in the XAMPLE application (which is included in the Radicore download) and what comes out in the PDF document is exactly the same as what is shown in the screen. Both times the standard formatData() method inside 'std.table.class.inc' is called.

I have tried changing the date format in the config.inc file and it works as expected. If it doesn't work for you then I suggest that you step through with your debugger to see why the date formatting function is not being called.


Re: Date formats in PDF [message #1605 is a reply to message #1603] Thu, 04 September 2008 19:20 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I'm a bit stumped on this one Tony. The config.inc is definitely being read and used for the screen handling as changes are immediately reflected in dates on the screen.

I switched on the dateisinfinity functionality and set some dates to 9999-12-31. They are blank on the screen but show literally in the PDF output.

This suggests either the function isn't being called at all, or the fieldspec is not showing the item as a date. Interestingly, the date in the footer of the document (today's date) shows correctly.

I turned logging on and saw that the generated xml has the dates in the unconverted format.

Graham
Re: Date formats in PDF [message #1606 is a reply to message #1605] Fri, 05 September 2008 04:57 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
You need to step through with your debugger to see what happens when the formatData() method is called. This is supposed to take each field and format it for output. It works for me when I test it, so why isn't it working for you? This is where having a debugger can saves hours of fruitless guessing and searching -simply step through the code as it is being executed and you will see what happens and where it happens.

Re: Date formats in PDF [message #1607 is a reply to message #1603] Fri, 05 September 2008 12:07 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Tony, I've stepped through with a debugger and from what I can see the FormatData function is not being called for all the fields being printed.

My report is a list view containing fields from a parent table and multiple rows from a child table. A number of fields are also coming in via foreign key relationships to other tables. The date field I am having a problem with is from such a foreign key table.

It appears that fieldspecs are only being passed for field directly in the child table, and are not present for the other fields. FormatData is only called where there is a fieldspec, so it stops short of these other fields.

I think I can probably work around this for now, by calling FormatData directly from _cm_post_fetchrow()

Can you confirm whether my findings are correct?

Thanks,

Graham
Re: Date formats in PDF [message #1608 is a reply to message #1607] Fri, 05 September 2008 12:23 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
The formatData() method can only format dates for those fields in $this->fieldspec which are actually identified as dates. If you are bringing in fields from other tables via a JOIN then those fields will not have any entries in $this->fieldspec, therefore there is no information on how they should be formatted.

The solution is simple - insert code into the _cm_changeConfig() method to temporarily add the fields you want formatted using code similar to the following:
    $this->fieldspec['date_field'] = array('type' => 'date');


Re: Date formats in PDF [message #1609 is a reply to message #1603] Fri, 05 September 2008 12:43 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Thanks Tony. It's easy when you know how!

I've managed to do quite a lot with the framework and have worked a lot of things out for myself. I am very impressed with Radicore. It's just a bit of a struggle at first while you get to grips with everything.

Your answers are always obvious in hindsight - it just takes a bit of experience to work out the solutions sometimes.
Re: Date formats in PDF [message #1610 is a reply to message #1609] Fri, 05 September 2008 12:49 Go to previous message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
If you think there are some topics which could do with a better explanation then please let me know so that I can look at adding it to the documentation.

Previous Topic: Insert a dialogue screen
Next Topic: Change how radicore displays dates
Goto Forum:
  


Current Time: Tue Nov 19 01:55:26 EST 2024

Total time taken to generate the page: 0.01426 seconds