Beispiel #1
0
    def get_context_data(self, **kwargs):
        ctx = super().get_context_data()

        subevent = None
        if self.request.GET.get("subevent", "") != "" and self.request.event.has_subevents:
            i = self.request.GET.get("subevent", "")
            try:
                subevent = self.request.event.subevents.get(pk=i)
            except SubEvent.DoesNotExist:
                pass

        ctx['items_by_category'], ctx['total'] = order_overview(self.request.event, subevent=subevent)
        ctx['subevent_warning'] = self.request.event.has_subevents and subevent and (
            self.request.event.orders.filter(payment_fee__gt=0).exists()
        )
        return ctx
Beispiel #2
0
 def get_context_data(self, **kwargs):
     ctx = super().get_context_data()
     ctx['items_by_category'], ctx['total'] = order_overview(self.request.event)
     return ctx
Beispiel #3
0
    def get_story(self, doc):
        from reportlab.platypus import Paragraph, Spacer, TableStyle, Table
        from reportlab.lib.units import mm

        headlinestyle = self.get_style()
        headlinestyle.fontSize = 15
        headlinestyle.fontName = 'OpenSansBd'
        colwidths = [a * doc.width for a in (.30, .06, .08, .06, .08, .06, .08, .06, .08, .06, .08)]
        tstyledata = [
            ('SPAN', (1, 0), (2, 0)),
            ('SPAN', (3, 0), (4, 0)),
            ('SPAN', (5, 0), (6, 0)),
            ('SPAN', (7, 0), (8, 0)),
            ('SPAN', (9, 0), (10, 0)),
            ('ALIGN', (0, 0), (-1, 0), 'CENTER'),
            ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ('FONTNAME', (0, 0), (-1, 0), 'OpenSansBd'),
            ('FONTNAME', (0, -1), (-1, -1), 'OpenSansBd'),
        ]

        story = [
            Paragraph(_('Orders by product'), headlinestyle),
            Spacer(1, 5 * mm)
        ]
        tdata = [
            [
                _('Product'), _('Total orders'), '', _('Pending'), '', _('Cancelled'), '', _('Refunded'), '',
                _('Paid'), ''
            ],
            [
                '',
                _('Number'), self.event.currency,
                _('Number'), self.event.currency,
                _('Number'), self.event.currency,
                _('Number'), self.event.currency,
                _('Number'), self.event.currency
            ],
        ]

        items_by_category, total = order_overview(self.event)

        for tup in items_by_category:
            if tup[0]:
                tstyledata.append(('FONTNAME', (0, len(tdata)), (-1, len(tdata)), 'OpenSansBd'))
                tdata.append([
                    tup[0].name,
                    str(tup[0].num_total[0]), str(tup[0].num_total[1]),
                    str(tup[0].num_pending[0]), str(tup[0].num_pending[1]),
                    str(tup[0].num_cancelled[0]), str(tup[0].num_cancelled[1]),
                    str(tup[0].num_refunded[0]), str(tup[0].num_refunded[1]),
                    str(tup[0].num_paid[0]), str(tup[0].num_paid[1])
                ])
            for item in tup[1]:
                tdata.append([
                    "     " + str(item.name),
                    str(item.num_total[0]), str(item.num_total[1]),
                    str(item.num_pending[0]), str(item.num_pending[1]),
                    str(item.num_cancelled[0]), str(item.num_cancelled[1]),
                    str(item.num_refunded[0]), str(item.num_refunded[1]),
                    str(item.num_paid[0]), str(item.num_paid[1])
                ])
                if item.has_variations:
                    for var in item.all_variations:
                        tdata.append([
                            "          " + str(var),
                            str(var.num_total[0]), str(var.num_total[1]),
                            str(var.num_pending[0]), str(var.num_pending[1]),
                            str(var.num_cancelled[0]), str(var.num_cancelled[1]),
                            str(var.num_refunded[0]), str(var.num_refunded[1]),
                            str(var.num_paid[0]), str(var.num_paid[1])
                        ])

        tdata.append([
            _("Total"),
            str(total['num_total'][0]), str(total['num_total'][1]),
            str(total['num_pending'][0]), str(total['num_pending'][1]),
            str(total['num_cancelled'][0]), str(total['num_cancelled'][1]),
            str(total['num_refunded'][0]), str(total['num_refunded'][1]),
            str(total['num_paid'][0]), str(total['num_paid'][1])
        ])

        table = Table(tdata, colWidths=colwidths, repeatRows=2)
        table.setStyle(TableStyle(tstyledata))
        story.append(table)
        return story
Beispiel #4
0
    def _table_story(self, doc, form_data, net=False):
        from reportlab.lib.units import mm
        from reportlab.platypus import Paragraph, Spacer, Table, TableStyle

        headlinestyle = self.get_style()
        headlinestyle.fontSize = 15
        headlinestyle.fontName = 'OpenSansBd'
        colwidths = [
            a * doc.width for a in (
                1 - (0.05 + 0.075) * 6,
                0.05, .075,
                0.05, .075,
                0.05, .075,
                0.05, .075,
                0.05, .075,
                0.05, .075
            )
        ]
        tstyledata = [
            ('SPAN', (1, 0), (2, 0)),
            ('SPAN', (3, 0), (4, 0)),
            ('SPAN', (5, 0), (6, 1)),
            ('SPAN', (7, 0), (-1, 0)),
            ('SPAN', (7, 1), (8, 1)),
            ('SPAN', (9, 1), (10, 1)),
            ('SPAN', (11, 1), (12, 1)),
            ('ALIGN', (0, 0), (-1, 1), 'CENTER'),
            ('ALIGN', (1, 2), (-1, -1), 'RIGHT'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ('FONTNAME', (0, 0), (-1, 1), 'OpenSansBd'),
            ('FONTNAME', (0, -1), (-1, -1), 'OpenSansBd'),
            ('FONTSIZE', (0, 0), (-1, -1), 8),
            ('LINEBEFORE', (1, 0), (1, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (3, 0), (3, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (5, 0), (5, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (7, 0), (7, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (9, 1), (9, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (11, 1), (11, -1), 1, colors.lightgrey),
        ]
        tstyle = copy.copy(self.get_style())
        tstyle.fontSize = 8
        tstyle_bold = copy.copy(tstyle)
        tstyle_bold.fontSize = 8
        tstyle_bold.fontName = 'OpenSansBd'
        tstyle_th = copy.copy(tstyle_bold)
        tstyle_th.alignment = TA_CENTER
        story = [
            Paragraph(_('Orders by product') + ' ' + (_('(excl. taxes)') if net else _('(incl. taxes)')), headlinestyle),
            Spacer(1, 5 * mm)
        ]
        if form_data.get('date_axis'):
            story += [
                Paragraph(_('{axis} between {start} and {end}').format(
                    axis=dict(OverviewFilterForm(event=self.event).fields['date_axis'].choices)[form_data.get('date_axis')],
                    start=date_format(form_data.get('date_from'), 'SHORT_DATE_FORMAT') if form_data.get('date_from') else '–',
                    end=date_format(form_data.get('date_until'), 'SHORT_DATE_FORMAT') if form_data.get('date_until') else '–',
                ), self.get_style()),
                Spacer(1, 5 * mm)
            ]

        if form_data.get('subevent'):
            try:
                subevent = self.event.subevents.get(pk=self.form_data.get('subevent'))
            except SubEvent.DoesNotExist:
                subevent = self.form_data.get('subevent')
            story.append(Paragraph(pgettext('subevent', 'Date: {}').format(subevent), self.get_style()))
            story.append(Spacer(1, 5 * mm))
        tdata = [
            [
                _('Product'),
                Paragraph(_('Canceled'), tstyle_th),
                '',
                Paragraph(_('Expired'), tstyle_th),
                '',
                Paragraph(_('Approval pending'), tstyle_th),
                '',
                Paragraph(_('Purchased'), tstyle_th),
                '', '', '', '', ''
            ],
            [
                '', '', '', '', '', '', '', _('Pending'), '', _('Paid'), '', _('Total'), ''
            ],
            [
                '',
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
            ],
        ]

        items_by_category, total = order_overview(
            self.event,
            subevent=form_data.get('subevent'),
            date_filter=form_data.get('date_axis'),
            date_from=form_data.get('date_from'),
            date_until=form_data.get('date_until'),
            fees=True
        )
        places = settings.CURRENCY_PLACES.get(self.event.currency, 2)
        states = (
            ('canceled', Order.STATUS_CANCELED),
            ('expired', Order.STATUS_EXPIRED),
            ('unapproved', 'unapproved'),
            ('pending', Order.STATUS_PENDING),
            ('paid', Order.STATUS_PAID),
            ('total', None),
        )

        for tup in items_by_category:
            if tup[0]:
                tdata.append([
                    Paragraph(str(tup[0].name), tstyle_bold)
                ])
                for l, s in states:
                    tdata[-1].append(str(tup[0].num[l][0]))
                    tdata[-1].append(floatformat(tup[0].num[l][2 if net else 1], places))
            for item in tup[1]:
                tdata.append([
                    str(item)
                ])
                for l, s in states:
                    tdata[-1].append(str(item.num[l][0]))
                    tdata[-1].append(floatformat(item.num[l][2 if net else 1], places))
                if item.has_variations:
                    for var in item.all_variations:
                        tdata.append([
                            Paragraph("          " + str(var), tstyle)
                        ])
                        for l, s in states:
                            tdata[-1].append(str(var.num[l][0]))
                            tdata[-1].append(floatformat(var.num[l][2 if net else 1], places))

        tdata.append([
            _("Total"),
        ])
        for l, s in states:
            tdata[-1].append(str(total['num'][l][0]))
            tdata[-1].append(floatformat(total['num'][l][2 if net else 1], places))

        table = Table(tdata, colWidths=colwidths, repeatRows=3)
        table.setStyle(TableStyle(tstyledata))
        story.append(table)
        return story
Beispiel #5
0
 def get_context_data(self, **kwargs):
     ctx = super().get_context_data()
     ctx['items_by_category'], ctx['total'] = order_overview(
         self.request.event)
     return ctx
Beispiel #6
0
    def get_story(self, doc, form_data):
        from reportlab.platypus import Paragraph, Spacer, TableStyle, Table
        from reportlab.lib.units import mm

        headlinestyle = self.get_style()
        headlinestyle.fontSize = 15
        headlinestyle.fontName = 'OpenSansBd'
        colwidths = [
            a * doc.width for a in (.33, 0.05, .075, 0.05, .075, 0.05, .075,
                                    0.05, .075, 0.05, .075)
        ]
        tstyledata = [
            ('SPAN', (1, 0), (2, 0)),
            ('SPAN', (3, 0), (4, 0)),
            ('SPAN', (5, 0), (-1, 0)),
            ('SPAN', (5, 1), (6, 1)),
            ('SPAN', (7, 1), (8, 1)),
            ('SPAN', (9, 1), (10, 1)),
            ('ALIGN', (0, 0), (-1, 1), 'CENTER'),
            ('ALIGN', (1, 2), (-1, -1), 'RIGHT'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ('FONTNAME', (0, 0), (-1, 1), 'OpenSansBd'),
            ('FONTNAME', (0, -1), (-1, -1), 'OpenSansBd'),
            ('FONTSIZE', (0, 0), (-1, -1), 9),
            ('LINEBEFORE', (1, 0), (1, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (3, 0), (3, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (5, 0), (5, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (7, 1), (7, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (9, 1), (9, -1), 1, colors.lightgrey),
        ]

        story = [
            Paragraph(_('Orders by product'), headlinestyle),
            Spacer(1, 5 * mm)
        ]
        if self.form_data.get('subevent'):
            try:
                subevent = self.event.subevents.get(
                    pk=self.form_data.get('subevent'))
            except SubEvent.DoesNotExist:
                subevent = self.form_data.get('subevent')
            story.append(
                Paragraph(
                    pgettext('subevent', 'Date: {}').format(subevent),
                    self.get_style()))
            story.append(Spacer(1, 5 * mm))
        tdata = [
            [
                _('Product'),
                _('Canceled'), '',
                _('Expired'), '',
                _('Purchased'), '', '', '', '', ''
            ],
            [
                '', '', '', '', '',
                _('Pending'), '',
                _('Paid'), '',
                _('Total'), ''
            ],
            [
                '',
                _('#'),
                self.event.currency,
                _('#'),
                self.event.currency,
                _('#'),
                self.event.currency,
                _('#'),
                self.event.currency,
                _('#'),
                self.event.currency,
            ],
        ]

        items_by_category, total = order_overview(
            self.event, subevent=self.form_data.get('subevent'))
        places = settings.CURRENCY_PLACES.get(self.event.currency, 2)
        states = (
            ('canceled', Order.STATUS_CANCELED),
            ('expired', Order.STATUS_EXPIRED),
            ('pending', Order.STATUS_PENDING),
            ('paid', Order.STATUS_PAID),
            ('total', None),
        )

        for tup in items_by_category:
            if tup[0]:
                tstyledata.append(('FONTNAME', (0, len(tdata)),
                                   (-1, len(tdata)), 'OpenSansBd'))
                tdata.append([
                    tup[0].name,
                ])
                for l, s in states:
                    tdata[-1].append(str(tup[0].num[l][0]))
                    tdata[-1].append(floatformat(tup[0].num[l][1], places))
            for item in tup[1]:
                tdata.append([str(item)])
                for l, s in states:
                    tdata[-1].append(str(item.num[l][0]))
                    tdata[-1].append(floatformat(item.num[l][1], places))
                if item.has_variations:
                    for var in item.all_variations:
                        tdata.append([
                            "          " + str(var),
                        ])
                        for l, s in states:
                            tdata[-1].append(str(var.num[l][0]))
                            tdata[-1].append(floatformat(
                                var.num[l][1], places))

        tdata.append([
            _("Total"),
        ])
        for l, s in states:
            tdata[-1].append(str(total['num'][l][0]))
            tdata[-1].append(floatformat(total['num'][l][1], places))

        table = Table(tdata, colWidths=colwidths, repeatRows=3)
        table.setStyle(TableStyle(tstyledata))
        story.append(table)
        return story
Beispiel #7
0
    def get_story(self, doc, form_data):
        from reportlab.platypus import Paragraph, Spacer, TableStyle, Table
        from reportlab.lib.units import mm

        headlinestyle = self.get_style()
        headlinestyle.fontSize = 15
        headlinestyle.fontName = 'OpenSansBd'
        colwidths = [
            a * doc.width for a in (.25, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075)
        ]
        tstyledata = [
            ('SPAN', (1, 0), (2, 0)),
            ('SPAN', (3, 0), (4, 0)),
            ('SPAN', (5, 0), (6, 0)),
            ('SPAN', (7, 0), (-1, 0)),
            ('SPAN', (7, 1), (8, 1)),
            ('SPAN', (9, 1), (10, 1)),
            ('SPAN', (11, 1), (12, 1)),
            ('ALIGN', (0, 0), (-1, 1), 'CENTER'),
            ('ALIGN', (1, 2), (-1, -1), 'RIGHT'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ('FONTNAME', (0, 0), (-1, 1), 'OpenSansBd'),
            ('FONTNAME', (0, -1), (-1, -1), 'OpenSansBd'),
            ('FONTSIZE', (0, 0), (-1, -1), 9)
        ]

        story = [
            Paragraph(_('Orders by product'), headlinestyle),
            Spacer(1, 5 * mm)
        ]
        if self.form_data.get('subevent'):
            try:
                subevent = self.event.subevents.get(pk=self.form_data.get('subevent'))
            except SubEvent.DoesNotExist:
                subevent = self.form_data.get('subevent')
            story.append(Paragraph(pgettext('subevent', 'Date: {}').format(subevent), self.get_style()))
            story.append(Spacer(1, 5 * mm))
        tdata = [
            [
                _('Product'), _('Canceled'), '', _('Refunded'), '', _('Expired'), '', _('Purchased'),
                '', '', '', '', ''
            ],
            [
                '', '', '', '', '', '', '', _('Pending'), '', _('Paid'), '', _('Total'), ''
            ],
            [
                '',
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
            ],
        ]

        items_by_category, total = order_overview(self.event, subevent=self.form_data.get('subevent'))

        for tup in items_by_category:
            if tup[0]:
                tstyledata.append(('FONTNAME', (0, len(tdata)), (-1, len(tdata)), 'OpenSansBd'))
                tdata.append([
                    tup[0].name,
                    str(tup[0].num_canceled[0]), localize(tup[0].num_canceled[1]),
                    str(tup[0].num_refunded[0]), localize(tup[0].num_refunded[1]),
                    str(tup[0].num_expired[0]), localize(tup[0].num_expired[1]),
                    str(tup[0].num_pending[0]), localize(tup[0].num_pending[1]),
                    str(tup[0].num_paid[0]), localize(tup[0].num_paid[1]),
                    str(tup[0].num_total[0]), localize(tup[0].num_total[1]),
                ])
            for item in tup[1]:
                tdata.append([
                    "     " + str(item.name),
                    str(item.num_canceled[0]), localize(item.num_canceled[1]),
                    str(item.num_refunded[0]), localize(item.num_refunded[1]),
                    str(item.num_expired[0]), localize(item.num_expired[1]),
                    str(item.num_pending[0]), localize(item.num_pending[1]),
                    str(item.num_paid[0]), localize(item.num_paid[1]),
                    str(item.num_total[0]), localize(item.num_total[1]),
                ])
                if item.has_variations:
                    for var in item.all_variations:
                        tdata.append([
                            "          " + str(var),
                            str(var.num_canceled[0]), localize(var.num_canceled[1]),
                            str(var.num_refunded[0]), localize(var.num_refunded[1]),
                            str(var.num_expired[0]), localize(var.num_expired[1]),
                            str(var.num_pending[0]), localize(var.num_pending[1]),
                            str(var.num_paid[0]), localize(var.num_paid[1]),
                            str(var.num_total[0]), localize(var.num_total[1]),
                        ])

        tdata.append([
            _("Total"),
            str(total['num_canceled'][0]), localize(total['num_canceled'][1]),
            str(total['num_refunded'][0]), localize(total['num_refunded'][1]),
            str(total['num_expired'][0]), localize(total['num_expired'][1]),
            str(total['num_pending'][0]), localize(total['num_pending'][1]),
            str(total['num_paid'][0]), localize(total['num_paid'][1]),
            str(total['num_total'][0]), localize(total['num_total'][1]),
        ])

        table = Table(tdata, colWidths=colwidths, repeatRows=3)
        table.setStyle(TableStyle(tstyledata))
        story.append(table)
        return story
Beispiel #8
0
    def get_story(self, doc, form_data):
        from reportlab.platypus import Paragraph, Spacer, TableStyle, Table
        from reportlab.lib.units import mm

        headlinestyle = self.get_style()
        headlinestyle.fontSize = 15
        headlinestyle.fontName = 'OpenSansBd'
        colwidths = [
            a * doc.width for a in (.33, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075)
        ]
        tstyledata = [
            ('SPAN', (1, 0), (2, 0)),
            ('SPAN', (3, 0), (4, 0)),
            ('SPAN', (5, 0), (-1, 0)),
            ('SPAN', (5, 1), (6, 1)),
            ('SPAN', (7, 1), (8, 1)),
            ('SPAN', (9, 1), (10, 1)),
            ('ALIGN', (0, 0), (-1, 1), 'CENTER'),
            ('ALIGN', (1, 2), (-1, -1), 'RIGHT'),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ('FONTNAME', (0, 0), (-1, 1), 'OpenSansBd'),
            ('FONTNAME', (0, -1), (-1, -1), 'OpenSansBd'),
            ('FONTSIZE', (0, 0), (-1, -1), 9),
            ('LINEBEFORE', (1, 0), (1, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (3, 0), (3, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (5, 0), (5, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (7, 1), (7, -1), 1, colors.lightgrey),
            ('LINEBEFORE', (9, 1), (9, -1), 1, colors.lightgrey),
        ]

        story = [
            Paragraph(_('Orders by product'), headlinestyle),
            Spacer(1, 5 * mm)
        ]
        if self.form_data.get('subevent'):
            try:
                subevent = self.event.subevents.get(pk=self.form_data.get('subevent'))
            except SubEvent.DoesNotExist:
                subevent = self.form_data.get('subevent')
            story.append(Paragraph(pgettext('subevent', 'Date: {}').format(subevent), self.get_style()))
            story.append(Spacer(1, 5 * mm))
        tdata = [
            [
                _('Product'), _('Canceled'), '', _('Expired'), '', _('Purchased'),
                '', '', '', '', ''
            ],
            [
                '', '', '', '', '', _('Pending'), '', _('Paid'), '', _('Total'), ''
            ],
            [
                '',
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
                _('#'), self.event.currency,
            ],
        ]

        items_by_category, total = order_overview(self.event, subevent=self.form_data.get('subevent'))
        places = settings.CURRENCY_PLACES.get(self.event.currency, 2)
        states = (
            ('canceled', Order.STATUS_CANCELED),
            ('expired', Order.STATUS_EXPIRED),
            ('pending', Order.STATUS_PENDING),
            ('paid', Order.STATUS_PAID),
            ('total', None),
        )

        for tup in items_by_category:
            if tup[0]:
                tstyledata.append(('FONTNAME', (0, len(tdata)), (-1, len(tdata)), 'OpenSansBd'))
                tdata.append([
                    tup[0].name,
                ])
                for l, s in states:
                    tdata[-1].append(str(tup[0].num[l][0]))
                    tdata[-1].append(floatformat(tup[0].num[l][1], places))
            for item in tup[1]:
                tdata.append([
                    str(item)
                ])
                for l, s in states:
                    tdata[-1].append(str(item.num[l][0]))
                    tdata[-1].append(floatformat(item.num[l][1], places))
                if item.has_variations:
                    for var in item.all_variations:
                        tdata.append([
                            "          " + str(var),
                        ])
                        for l, s in states:
                            tdata[-1].append(str(var.num[l][0]))
                            tdata[-1].append(floatformat(var.num[l][1], places))

        tdata.append([
            _("Total"),
        ])
        for l, s in states:
            tdata[-1].append(str(total['num'][l][0]))
            tdata[-1].append(floatformat(total['num'][l][1], places))

        table = Table(tdata, colWidths=colwidths, repeatRows=3)
        table.setStyle(TableStyle(tstyledata))
        story.append(table)
        return story