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

Home » RADICORE » How To » Sub totals and Page Breaks
Sub totals and Page Breaks [message #2392] Sat, 16 January 2010 12:38 Go to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Tony,

I'm struggling achieving the desired output with the ListView print_before and print_after methods - can you confirm if the following is possible with existing methods?:

I am producing a listview output for a number of entities, each of which has one or more items belonging to it, containing an amount.
I want to produce a separate page for each entiy and have a subtotal for each entity at the bottom of each page.

The page break is easy, but I can't get the subtotal to appear with the correct entity at the same time as it needs to go in the print_before method with the page break. Therefore, the total always goes at the top of the next page.

How can I achieve this?

Thanks,

Graham

Re: Sub totals and Page Breaks [message #2393 is a reply to message #2392] Sat, 16 January 2010 17:15 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
Surely you want to print the subtotals for an entity using the print_after method, not the print_before method. The page break should then be processed after the print_after method, or within the print_before method of the next entity.

Re: Sub totals and Page Breaks [message #2394 is a reply to message #2392] Sat, 16 January 2010 17:36 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Well maybe I'm missing something and you can point me in the right direction, but my thinking is this:

I can't print the subtotals in the print_after method because I don't know at that stage that the entity will change and this is the last item for that entity.

I think I only know that I want to print subtotals and break a page at the same point - in the print_before method.

I am thinking that I need to be ale to tell the system to page break before or after the additionally generated lines are printed (in this case after) and I can't figure out a way to do that.

Hope this makes sense. Perhaps you can figure a way to achieve this?
Re: Sub totals and Page Breaks [message #2395 is a reply to message #2394] Sun, 17 January 2010 03:19 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
I have played around with some test data in the EXAMPLE subsystem to see if I can achieve the result you desire. The only way I could do this was to modify the _cm_ListView_print_after() method to include a second argument for $next_row. My 'before' and 'after' methods are as follows:
    // ****************************************************************************
    function _cm_ListView_print_before ($prev_row, $curr_row)
    // allow extra rows to be created in List View
    {
        $output = array();

        if (!empty($prev_row)) {
            // row has changed
            if (substr($prev_row['last_name'], 0, 1) != substr($curr_row['last_name'], 0, 1)) {
                // first character of last name has changed
            	$this->pdf->AddPage();
            } // if
        } // if

        return $output;

    } // _cm_ListView_print_before

    // ****************************************************************************
    function _cm_ListView_print_after ($curr_row, $next_row)
    // allow extra rows to be created in List View
    {
        $output = array();

        if (substr($next_row['last_name'], 0, 1) != substr($curr_row['last_name'], 0, 1)) {
            // first character of last name has changed
            $output[0]['pers_type_desc'] = 'after ' .$curr_row['person_id'];
        } // if

        return $output;

    } // _cm_ListView_print_after

Attached are the framework scripts which I have modified. Try them out and let me know if they solve your problem.


Re: Sub totals and Page Breaks [message #2396 is a reply to message #2392] Sun, 17 January 2010 04:56 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I'm finding that $this->pdf->AddPage() is not working when called within _cm_ListView_print_before().

I ran my existing code (page breaks but no subtotals) which uses the deprecated _cm_ListView_pre_print() method and it behaves correctly. If I make the simple change to the new method it doesn't throw page breaks.
Re: Sub totals and Page Breaks [message #2397 is a reply to message #2396] Sun, 17 January 2010 05:13 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
In my test the call to $this->pdf->AddPage() within _cm_ListView_print_before() is conditional, so are you sure the condition is being met? If it is called it will ALWAYS generate a new page, so step through with your debugger to see that it is actually being called.

Re: Sub totals and Page Breaks [message #2398 is a reply to message #2392] Sun, 17 January 2010 05:33 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I'll try debugging later today. However, I did use exactly the same code from the deprecated method which worked. (I effectively just changed the name of the function).
Re: Sub totals and Page Breaks [message #2399 is a reply to message #2392] Sun, 17 January 2010 10:30 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I've solved the AddPage issue. The class I am using is an extension of another class, and that class contained the deprecated _cm_ListView_pre_print() method. This was causing _cm_ListView_print_before() not to be executed.

However, the updates sre not working correctly because of the following:

In _print_after() the field I am comparing to see if the entity is changed from $current_row to $next_row does not have the same formatting applied, so the comparison ALWAYS returns false. $current_row contains the ValRep representation of the entity, whilst the $next_row contains the entity id.
Re: Sub totals and Page Breaks [message #2400 is a reply to message #2399] Sun, 17 January 2010 10:37 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
The solution is simple - either:
(a) apply the same formatting to both values
(b) do not apply any formatting to either value


Re: Sub totals and Page Breaks [message #2401 is a reply to message #2392] Sun, 17 January 2010 11:31 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
But I think the formatting is being applied / not applied by the framework - and is not consistent.

In the print_before() method the formats of all fields in $previous_row and $current_row are the same, without any specific coding. However, in the print_after() method the formats are not the same for the $current_row and $next_row.

Do I specifically need to apply formatting in the print_after() method?
Re: Sub totals and Page Breaks [message #2402 is a reply to message #2401] Sun, 17 January 2010 11:53 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
Try the attached fix. This should not apply any formatting to the previous/current/next record until AFTER it has been examined and just BEFORE it is printed.

(attachment deleted)


[Updated on: Sun, 17 January 2010 12:11]

Report message to a moderator

Re: Sub totals and Page Breaks [message #2403 is a reply to message #2402] Sun, 17 January 2010 12:12 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
The previous fix wasn't quite right, so here's another.

(attachment deleted)


[Updated on: Sun, 17 January 2010 12:46]

Report message to a moderator

Re: Sub totals and Page Breaks [message #2404 is a reply to message #2392] Sun, 17 January 2010 12:19 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
This is giving strange results. I am now seeing the entity id as NULL in some cases, an id in some cases and a value representation in others.

I will need to debug in detail to see what is happening where.

Hold this - just spotted your later post!

[Updated on: Sun, 17 January 2010 12:20]

Report message to a moderator

Re: Sub totals and Page Breaks [message #2405 is a reply to message #2392] Sun, 17 January 2010 12:24 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Tony,

The later fix gives an error:

Fatal error: Call to a member function formatData() on a non-object in C:\xampp\includes\std.pdf.class.inc on line 924
Re: Sub totals and Page Breaks [message #2406 is a reply to message #2405] Sun, 17 January 2010 12:45 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
Third time lucky (I hope) Razz

Re: Sub totals and Page Breaks [message #2407 is a reply to message #2392] Sun, 17 January 2010 13:24 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Not having much luck I'm afraid. This version has caused a fatal SQL syntax error...

In my _cm_formatData() method I use rdcaccount_id from $rowdata to build a query to check a user format preference. The query being produced has rdcaccount_id set to NULL, so for some reason $rowdata doesn't contain rdcaccount_id when you call it.

A solution would be for me to only execute the query conditionally (i.e. if rdcaccount_id != NULL).

I'll do this unless you think there might be a further issue in your code somewhere.
Re: Sub totals and Page Breaks [message #2408 is a reply to message #2407] Sun, 17 January 2010 15:49 Go to previous message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
What happens in cm_formatData() is under your control, so if you have code there which produces an invalid sql query I'm afraid you'll have to correct it yourself.


Previous Topic: $fieldarray problem
Next Topic: PDF Footer
Goto Forum:
  


Current Time: Mon Nov 18 20:39:30 EST 2024

Total time taken to generate the page: 0.01506 seconds