How can I take breaks and subtotals in a report?

I need to create a business report using perl + Template Toookit and LaTeX.

Everything works very well, but I am struggling with the problem of breaks (for example, page breaks or special headings) and subtotals whenever the field changes.

So, for example, every time the "category" field changes, I need to have the total sales for this category, and a heading that indicates that the launch of another category begins; and then do the same when the "group" field - with the additional interest that the "group" consists of categories, so two things should be invested.

I assume that someone who has created reports with Microsoft Access (or perhaps any other business reporting application) should be familiar with this problem.

Ideally, this will be solved at the meta level, so I don’t need to rebuild the code every time, but only to indicate which fields should generate breaks or subtotals.

I am (voluntarily) attached to LaTeX and TT: LaTeX because of the control it gives over typography, and the ability to generate custom graphics, as well as TT (or anything else that works in perl) due to learning curves.

+3
source share
1 answer

TT , Data::Table, "meta", .

, , : NB: ,

[%-
MACRO printrow(rowtype, line) BLOCK;
    # however you print the row as LaTeX
    # rowtype is 'row', 'subtotal' or 'grandtotal' for formatting purposes
END;

SET sumcols = [ 'col3', 'col4', 'col5' ]; # cols to be accumulated
SET s_tot = {}; SET g_tot = {};
FOREACH i IN sumcols;
    SET s_tot.$i = 0; # initialise
    SET g_tot.$i = 0;
END;

FOREACH row IN data;
    IF s_tot.col2 AND s_tot.col2 <> row.col2; # start of new group
        printrow('subtotal', s_tot);
        FOREACH i IN sumcols;
            SET s_tot.$i = 0; #re-init
        END;
    END;
    printrow('row', row);
    SET s_tot.col2 = row.col2; # keep track of group level

    FOREACH i IN sumcols;
        SET s_tot.$i = s_tot.$i + row.$i;
        SET g_tot.$i = g_tot.$i + row.$i;
    END;
END;
printrow('grandtotal', g_tot);
-%]

, , . s_tot , . , .

0

All Articles