Ejemplo n.º 1
0
def cheques(request):
    cheques = ChequePayment.objects.all().order_by('date', 'number', 'id')

    field_names = [
        'artistid', 'name', 'artistname', 'payee', 'date', 'number', 'amount'
    ]

    field_names_d = {}
    for n in field_names:
        field_names_d[n] = n

    response = HttpResponse(mimetype="text/csv")
    response['Content-Disposition'] = "attachment; filename=cheques.csv"
    c = unicodewriter.UnicodeDictWriter(response, field_names)
    c.writerow(field_names_d)

    for q in cheques:
        d = dict(artistid=q.artist.artistid,
                 name=q.artist.name(),
                 artistname=q.artist.artistname(),
                 payee=q.payee,
                 date=q.date,
                 number=q.number,
                 amount=format_money(-q.amount))
        c.writerow(d)

    return response
Ejemplo n.º 2
0
def cheques(request):
    cheques = ChequePayment.objects.all().order_by('date', 'number', 'id')

    field_names = ['artistid', 'name', 'artistname', 'payee', 'date', 'number', 'amount']

    field_names_d = {}
    for n in field_names:
        field_names_d[n] = n

    response = HttpResponse(mimetype="text/csv")
    response['Content-Disposition'] = "attachment; filename=cheques.csv"
    c = unicodewriter.UnicodeDictWriter(response, field_names)
    c.writerow(field_names_d)

    for q in cheques:
        d = dict(
            artistid=q.artist.artistid, name=q.artist.name(), artistname=q.artist.artistname(),
            payee=q.payee, date=q.date, number=q.number, amount=format_money(-q.amount))
        c.writerow(d)

    return response
Ejemplo n.º 3
0
def invoice_to_pdf(invoice, outf):
    normal_style = ParagraphStyle("normal", fontName="Helvetica")
    piece_condition_style = ParagraphStyle("piececondition", normal_style, fontSize=normal_style.fontSize - 2,
                                           leading=normal_style.leading - 2)
    piece_details_style = ParagraphStyle("pieceseller", piece_condition_style)

    def invoice_header(canvas, doc):
        draw_invoice_header(canvas, doc, invoice, "Invoice for:")

    doc = SimpleDocTemplate(outf, pagesize=LETTER,
                            leftMargin=0.75 * inch, rightMargin=0.75 * inch,
                            topMargin=1.75 * inch, bottomMargin=0.75 * inch,
                            onFirstPage=invoice_header, onLaterPages=invoice_header)

    story = []

    body_data = [["Code", "Description", "Amount (" + settings.ARTSHOW_MONEY_CURRENCY + ")"]]

    num_items = 0
    for item in invoice.invoiceitem_set.order_by("piece__artist__artistid", "piece__pieceid"):
        num_items += 1
        piece = item.piece
        paragraphs = [
            Paragraph("<i>" + escape(piece.name) + u"</i> \u2014 by " + escape(piece.artistname()), normal_style)]
        details_body_parts = [escape(piece.media)]
        if piece.condition:
            details_body_parts.append(escape(piece.condition))
        if piece.other_artist:
            details_body_parts.append(escape("sold by " + piece.artist.artistname()))
        paragraphs.append(Paragraph(u" \u2014 ".join(details_body_parts), piece_details_style))
        body_data.append([item.piece.code, paragraphs, format_money(item.price)])

    if invoice.tax_paid:
        subtotal_row = len(body_data)
        body_data.append(["", "Subtotal", format_money(invoice.item_total())])
        body_data.append(["", settings.ARTSHOW_TAX_DESCRIPTION, format_money(invoice.tax_paid)])
    else:
        subtotal_row = None

    total_row = len(body_data)
    body_data.append(["", str(num_items) + u" items \u2014 Total Due", format_money(invoice.item_and_tax_total())])

    body_data.append(["", "", ""])

    for payment in invoice.invoicepayment_set.all():
        body_data.append(["", payment.get_payment_method_display(), format_money(payment.amount)])

    body_data.append(["", "Total Paid", unicode(invoice.total_paid())])

    body_table_style = [
        ("FONTSIZE", (0, 0), (-1, 0), normal_style.fontSize - 4),
        ("FONT", (0, 0), (-1, 0), "Helvetica-Bold"),
        ("LEADING", (0, 0), (-1, 0), normal_style.leading - 4),
        ("VALIGN", (0, 0), (-1, -1), "TOP"),
        ("ALIGN", (2, 0), (2, -1), "RIGHT"),
        ("ALIGN", (1, total_row), (1, -1), "RIGHT"),
        ("FONT", (2, total_row), (2, total_row), "Helvetica-Bold"),
        ("FONT", (2, -1), (2, -1), "Helvetica-Bold"),
        ("LINEBELOW", (0, 0), (-1, -1), 0.1, colors.black),
        ("LINEABOVE", (0, total_row), (-1, total_row), 0.75, colors.black),
        ("LINEABOVE", (0, -1), (-1, -1), 0.75, colors.black),
    ]

    if subtotal_row is not None:
        body_table_style.append(("ALIGN", (1, subtotal_row), (1, subtotal_row + 1), "RIGHT"))
        body_table_style.append(("LINEABOVE", (0, subtotal_row), (-1, subtotal_row), 0.75, colors.black))

    body_table = Table(body_data, colWidths=[0.75 * inch, 5.0 * inch, 1.25 * inch], style=body_table_style,
                       repeatRows=1)
    story.append(body_table)

    # TODO - Figure out a better way of handling this horrible hack.
    # "Paragraph" does not use the sequencer inside the Document, but instead the global sequencer :(
    getSequencer().reset("pageno", 0)

    doc.build(story, onFirstPage=invoice_header, onLaterPages=invoice_header)
Ejemplo n.º 4
0
def invoice_to_pdf(invoice, outf):
    normal_style = ParagraphStyle("normal", fontName="Helvetica")
    piece_condition_style = ParagraphStyle("piececondition", normal_style, fontSize=normal_style.fontSize - 2,
                                           leading=normal_style.leading - 2)
    piece_details_style = ParagraphStyle("pieceseller", piece_condition_style)

    def invoice_header(canvas, doc):
        draw_invoice_header(canvas, doc, invoice, "Invoice for:")

    doc = SimpleDocTemplate(outf, pagesize=LETTER,
                            leftMargin=0.75 * inch, rightMargin=0.75 * inch,
                            topMargin=1.75 * inch, bottomMargin=0.75 * inch,
                            onFirstPage=invoice_header, onLaterPages=invoice_header)

    story = []

    body_data = [["Code", "Description", "Amount (" + settings.ARTSHOW_MONEY_CURRENCY + ")"]]

    num_items = 0
    for item in invoice.invoiceitem_set.order_by("piece__artist__artistid", "piece__pieceid"):
        num_items += 1
        piece = item.piece
        paragraphs = [
            Paragraph("<i>" + escape(piece.name) + "</i> \u2014 by " + escape(piece.artistname()), normal_style)]
        details_body_parts = [escape(piece.media)]
        if piece.condition:
            details_body_parts.append(escape(piece.condition))
        if piece.other_artist:
            details_body_parts.append(escape("sold by " + piece.artist.artistname()))
        paragraphs.append(Paragraph(" \u2014 ".join(details_body_parts), piece_details_style))
        body_data.append([item.piece.code, paragraphs, format_money(item.price)])

    if invoice.tax_paid:
        subtotal_row = len(body_data)
        body_data.append(["", "Subtotal", format_money(invoice.item_total())])
        body_data.append(["", settings.ARTSHOW_TAX_DESCRIPTION, format_money(invoice.tax_paid)])
    else:
        subtotal_row = None

    total_row = len(body_data)
    body_data.append(["", str(num_items) + " items \u2014 Total Due", format_money(invoice.item_and_tax_total())])

    body_data.append(["", "", ""])

    for payment in invoice.invoicepayment_set.all():
        body_data.append(["", payment.get_payment_method_display(), format_money(payment.amount)])

    body_data.append(["", "Total Paid", str(invoice.total_paid())])

    body_table_style = [
        ("FONTSIZE", (0, 0), (-1, 0), normal_style.fontSize - 4),
        ("FONT", (0, 0), (-1, 0), "Helvetica-Bold"),
        ("LEADING", (0, 0), (-1, 0), normal_style.leading - 4),
        ("VALIGN", (0, 0), (-1, -1), "TOP"),
        ("ALIGN", (2, 0), (2, -1), "RIGHT"),
        ("ALIGN", (1, total_row), (1, -1), "RIGHT"),
        ("FONT", (2, total_row), (2, total_row), "Helvetica-Bold"),
        ("FONT", (2, -1), (2, -1), "Helvetica-Bold"),
        ("LINEBELOW", (0, 0), (-1, -1), 0.1, colors.black),
        ("LINEABOVE", (0, total_row), (-1, total_row), 0.75, colors.black),
        ("LINEABOVE", (0, -1), (-1, -1), 0.75, colors.black),
    ]

    if subtotal_row is not None:
        body_table_style.append(("ALIGN", (1, subtotal_row), (1, subtotal_row + 1), "RIGHT"))
        body_table_style.append(("LINEABOVE", (0, subtotal_row), (-1, subtotal_row), 0.75, colors.black))

    body_table = Table(body_data, colWidths=[0.75 * inch, 5.0 * inch, 1.25 * inch], style=body_table_style,
                       repeatRows=1)
    story.append(body_table)

    # TODO - Figure out a better way of handling this horrible hack.
    # "Paragraph" does not use the sequencer inside the Document, but instead the global sequencer :(
    getSequencer().reset("pageno", 0)

    doc.build(story, onFirstPage=invoice_header, onLaterPages=invoice_header)