def get_total(self, entity):
        """
        Gives the table that contains the total.

        entity: Entity. Any entity of class Refund.
        Returns: Flowable (very likely a Table).
        """
        _ = entity._cw._
        lin_data = []

        s = "<b>%s</b>" % xml_escape(_(u"To refund (EUR)"))
        lin_data.append(Paragraph(s, style_table_data))

        s = u"<b>%s</b>" % format_number(entity.total, 2)
        lin_data.append(Paragraph(s, style_table_data_num))

        # Builds the total table
        tot_table = Table([lin_data], [3.25 * cm, 2.75 * cm])
        tot_table.setStyle(
            TableStyle([
                ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
                ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                ('LEFTPADDING', (0, 0), (-1, -1), 0.2 * cm),
                ('RIGHTPADDING', (0, 0), (-1, -1), 0.2 * cm),
                ('TOPPADDING', (0, 0), (-1, -1), 0.2 * cm),
                ('BOTTOMPADDING', (0, 0), (-1, -1), 0.2 * cm),
                ('BOX', (0, 0), (-1, -1), 0.05 * cm, black),
                ('INNERGRID', (0, 0), (-1, -1), 0.02 * cm, black),
            ]))

        return tot_table
    def get_total(self, entity):
        """
        Gives the table that contains the total.

        entity: Entity. Any entity of class Expense.
        Returns: Flowable (very likely a Table).
        """
        _ = entity._cw._
        tab_data = []

        # First line
        lin_data = []
        s = "<b>%s</b>" % xml_escape(_(u"Total (EUR)"))
        lin_data.append(Paragraph(s, style_table_data))

        s = u"<b>%s</b>" % format_number(entity.total, 2)
        lin_data.append(Paragraph(s, style_table_data_num))

        tab_data.append(lin_data)

        # Second line
        lin_data = []
        s = "<i>%s</i>" % xml_escape(_(u"included taxes (EUR)"))
        lin_data.append(Paragraph(s, style_table_data))

        s = u"<i>%s</i>" % format_number(entity.euro_taxes(), 2)
        lin_data.append(Paragraph(s, style_table_data_num))

        tab_data.append(lin_data)

        tot_table = Table(tab_data, [3.25 * cm, 2.75 * cm])
        tot_table.setStyle(
            TableStyle([
                ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
                ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                ('LEFTPADDING', (0, 0), (-1, -1), 0.2 * cm),
                ('RIGHTPADDING', (0, 0), (-1, -1), 0.2 * cm),
                ('TOPPADDING', (0, 0), (-1, -1), 0.2 * cm),
                ('BOTTOMPADDING', (0, 0), (-1, -1), 0.2 * cm),
                ('BOX', (0, 0), (-1, -1), 0.05 * cm, black),
                ('INNERGRID', (0, 0), (-1, -1), 0.02 * cm, black),
            ]))

        return tot_table
    def get_total_relative_data(self, entity):
        """
        Gives the table that contains useful data relative to the total
        (subtotals, payment information, etc.)

        entity: Entity. Any entity of class Expense.
        Returns: Flowable (very likely a Table).
        """
        _ = entity._cw._
        col_data = []

        refundable_tot = entity.totals_paid_by()
        for euser in refundable_tot.keys():
            s = u"%s %s %s %s" % (format_number(
                refundable_tot[euser], 2), xml_escape(
                    _(u"EUR")), xml_escape(
                        _(u"to be refunded to")), xml_escape(euser.dc_title()))
            col_data.append(Paragraph(s, style_table_data))

        if col_data != []:
            rel_table = Table([
                [col_data],
            ], [12.5 * cm])
            rel_table.setStyle(
                TableStyle([
                    ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
                    ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                    ('LEFTPADDING', (0, 0), (-1, -1), 0.2 * cm),
                    ('RIGHTPADDING', (0, 0), (-1, -1), 0.2 * cm),
                    ('TOPPADDING', (0, 0), (-1, -1), 0.2 * cm),
                    ('BOTTOMPADDING', (0, 0), (-1, -1), 0.2 * cm),
                    ('BOX', (0, 0), (-1, -1), 0.05 * cm, black),
                ]))

            return rel_table

        else:
            return Spacer(0, 0 * cm)
    def get_expenses_table(self, entity):
        """
        Gives the main table of the document (that contains lines describing
        the actual expenses).

        entity: Entity. Any entity of class Refund.
        Returns: Flowable (very likely a Table).
        """
        _ = entity._cw._
        tab_data = []

        # Writes the header line
        lin_data = []

        s = u"<b>%s</b>" % xml_escape(_(u"Date"))
        lin_data.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Description"))
        lin_data.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Workcase"))
        lin_data.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Amount"))
        lin_data.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Curr."))
        lin_data.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Rate"))
        lin_data.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Amount (EUR)"))
        lin_data.append(Paragraph(s, style_table_header))

        tab_data.append(lin_data)

        # Writes the accounting lines
        for exp_line in entity.has_lines:
            lin_data = []

            s = xml_escape(exp_line.printable_value('diem'))
            lin_data.append(Paragraph(s, style_table_data))

            s = xml_escape(exp_line.title)
            lin_data.append(Paragraph(s, style_table_data))

            s = u''
            expense = exp_line.parent_expense
            if expense:
                # XXX use if 'spent_for' in schema
                try:
                    wcase = expense.spent_for[0]
                except (IndexError, AttributeError, KeyError):
                    pass
                else:
                    s = xml_escape(wcase.ref)
            lin_data.append(Paragraph(s, style_table_data))

            s = format_number(exp_line.amount, 2)
            lin_data.append(Paragraph(s, style_table_data_num))

            s = xml_escape(exp_line.currency)
            lin_data.append(Paragraph(s, style_table_data))

            s = format_number(exp_line.exchange_rate, 5)
            lin_data.append(Paragraph(s, style_table_data_num))

            s = format_number(exp_line.euro_amount(), 2)
            lin_data.append(Paragraph(s, style_table_data_num))

            tab_data.append(lin_data)

        # Builds the main table containing the expenses lines
        main_table = Table(tab_data, [
            2.25 * cm, 7 * cm, 1.75 * cm, 2.25 * cm, 1.25 * cm, 1.75 * cm,
            2.75 * cm
        ])
        main_table.repeatRows = 1
        main_table.setStyle(
            TableStyle([
                ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
                ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                ('LEFTPADDING', (0, 0), (-1, -1), 0.1 * cm),
                ('RIGHTPADDING', (0, 0), (-1, -1), 0.1 * cm),
                ('TOPPADDING', (0, 0), (-1, -1), 0.1 * cm),
                ('BOTTOMPADDING', (0, 0), (-1, -1), 0.1 * cm),
                ('BOX', (0, 0), (-1, -1), 0.05 * cm, black),
                ('LINEAFTER', (0, 0), (0, -1), 0.02 * cm, black),
                ('LINEAFTER', (1, 0), (1, -1), 0.02 * cm, black),
                ('LINEAFTER', (2, 0), (2, -1), 0.05 * cm, black),
                ('LINEAFTER', (3, 0), (3, -1), 0.02 * cm, black),
                ('LINEAFTER', (4, 0), (4, -1), 0.02 * cm, black),
                ('LINEAFTER', (5, 0), (5, -1), 0.05 * cm, black),
                ('LINEBELOW', (0, 0), (-1, 0), 0.05 * cm, black),
            ]))

        return main_table
    def get_expenses_table(self, entity):
        """
        Gives the main table of the document (that contains lines describing
        the actual expenses).

        This table contains only one column. In this column, a table is
        inserted for each expense line. This table also contains one column.
        In this column, we insert two tables (one per line) because each line
        has different column sizes. See the _build_inner_tables method for
        details.

        entity: Entity. Any entity of class Expense.
        Returns: Flowable (very likely a Table).
        """
        _ = entity._cw._
        tab_data = []

        # Writes the header lines

        # First line
        lin_data_1 = []

        s = u"<b>%s</b>" % xml_escape(_(u"Date"))
        lin_data_1.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Description"))
        lin_data_1.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Expense Type"))
        lin_data_1.append(Paragraph(s, style_table_header))

        # Second line
        lin_data_2 = []

        s = u"<b>%s</b>" % xml_escape(_(u"Paid by"))
        lin_data_2.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Paid for"))
        lin_data_2.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Amount"))
        lin_data_2.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Curr."))
        lin_data_2.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Rate"))
        lin_data_2.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Amount (EUR)"))
        lin_data_2.append(Paragraph(s, style_table_header))

        s = u"<b>%s</b>" % xml_escape(_(u"Taxes (EUR)"))
        lin_data_2.append(Paragraph(s, style_table_header))

        # adds a table built with the two previously defined lines
        tab_data.append([self._build_inner_tables(lin_data_1, lin_data_2)])

        # Writes the accounting lines
        for exp_line in entity.has_lines:

            # First line
            lin_data_1 = []

            s = xml_escape(exp_line.printable_value('diem'))
            lin_data_1.append(Paragraph(s, style_table_data))

            s = xml_escape(exp_line.title)
            lin_data_1.append(Paragraph(s, style_table_data))

            s = xml_escape(_(exp_line.type))
            lin_data_1.append(Paragraph(s, style_table_data))

            # Second line
            lin_data_2 = []

            s = xml_escape(exp_line.paid_by[0].label)
            lin_data_2.append(Paragraph(s, style_table_data))

            col_data = []
            for dest in exp_line.paid_for:
                s = xml_escape(dest.label)
                col_data.append(Paragraph(s, style_table_data))
            lin_data_2.append(col_data)

            s = format_number(exp_line.amount, 2)
            lin_data_2.append(Paragraph(s, style_table_data_num))

            s = xml_escape(exp_line.currency)
            lin_data_2.append(Paragraph(s, style_table_data))

            s = format_number(exp_line.exchange_rate, 5)
            lin_data_2.append(Paragraph(s, style_table_data_num))

            s = "<b>%s</b>" \
                % format_number(exp_line.euro_amount(), 2)
            lin_data_2.append(Paragraph(s, style_table_data_num))

            s = "<i>%s</i>" % format_number(exp_line.euro_taxes(), 2)
            lin_data_2.append(Paragraph(s, style_table_data_num))

            # adds a table built with the two previously defined lines
            tab_data.append([self._build_inner_tables(lin_data_1, lin_data_2)])

        # Builds the main table that will be returned
        main_table = Table(tab_data, [19 * cm])
        main_table.repeatRows = 1
        main_table.setStyle(
            TableStyle([
                ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
                ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                ('LEFTPADDING', (0, 0), (-1, -1), 0 * cm),
                ('RIGHTPADDING', (0, 0), (-1, -1), 0 * cm),
                ('TOPPADDING', (0, 0), (-1, -1), 0 * cm),
                ('BOTTOMPADDING', (0, 0), (-1, -2), 0.3 * cm),
                ('BOTTOMPADDING', (0, -1), (-1, -1), 0 * cm),
                ('BOX', (0, 0), (-1, -1), 0.05 * cm, black),
            ]))

        return main_table