Example #1
0
def manuals(filename, bills):
    doc = SimpleDocTemplate(filename, pagesize=A4, leftMargin=MARGIN, topMargin=MARGIN+LOGO_HEIGHT, rightMargin=MARGIN, bottomMargin=MARGIN)
    story = []
    bills = bills[:]
    while bills:
        bill = bills.pop()
        positions = []
        for pos in bill.positions:
            positions.append([Paragraph(pos.tarif_description, MANUAL_STYLE), '%0.2f' % ((pos.quantity * pos.price_cts) / 100)])
        for reminder in bill.reminders:
            positions.append([Paragraph("Rappel du %s" % reminder.reminder_date.strftime(DATE_FMT), MANUAL_STYLE), '%0.2f' % (reminder.amount_cts / 100)])
        if len(positions) > 1:
            positions.append([Paragraph("Total", MANUAL_STYLE), 'CHF %0.2f' % (bill.total_cts / 100)])
        story += [CallerMacro(render_head)]

        if bill.author_rcc:
            rcc = 'RCC ' + bill.author_rcc
        else:
            rcc = bill.author_rcc
        therapeute = '{} {}\n{}\n\n{}'.format(bill.author_firstname, bill.author_lastname, rcc, labels_text.adresse_pog)
        address = '{}\n{} {}\n{}\n{}\n{} {}'.format(bill.title, bill.firstname, bill.lastname, bill.complement, bill.street, bill.zip, bill.city)
        story += [Table([[[ParagraphOrSpacer(line, MANUAL_STYLE) for line in therapeute.splitlines()],
                          [ParagraphOrSpacer(line, MANUAL_STYLE) for line in address.splitlines()]]],
                        colWidths=['66%', '34%'],
                        style=[('ALIGN', (0, 0), (0, 0), 'LEFT'), ('ALIGN', (1, 0), (1, 0), 'RIGHT')]),
                  Spacer(0, MARGIN),
                  Paragraph('', MANUAL_STYLE),
                  Spacer(0, 1*MARGIN),
                  Paragraph('FACTURE', FACTURE_STYLE),
                  Spacer(0, 1*MARGIN),
                  Table(positions, colWidths=['*', 5*cm], style=TSTYLE),
                  ]
        if bill.comment:
            story.append(Spacer(0, 1*MARGIN))
            story.append(Table([[Paragraph("Remarque:", MANUAL_STYLE), Paragraph(bill.comment, MANUAL_STYLE)]],
                               colWidths=[3*cm, '*'],
                               style=[('ALIGN', (0, 0), (1, 0), 'LEFT')]))
        story += [Spacer(0, 1.5*MARGIN),
                  Paragraph("Avec mes remerciements.", MANUAL_STYLE),
                  ]

        if len(' '.join((bill.firstname, bill.lastname))) < 25:
            identite = [' '.join((bill.firstname, bill.lastname))]
        else:
            identite = [bill.firstname, bill.lastname]
        address_patient = '\n'.join(identite + [bill.street, bill.zip + ' ' + bill.city])

        def render_bvr(flowable, address_patient=address_patient, bill=bill):
            canvas = flowable.canv
            x = flowable._frame._x + flowable._frame._leftExtraIndent
            y = flowable._frame._y
            canvas.translate(-x, -y)
            draw_bvr(canvas, bill.total_cts, address_patient, bill.bv_ref)
        story += [CallerMacro(render_bvr)]
        if bills:
            story.append(PageBreak())
    doc.build(story)
Example #2
0
def positions(bill):
    VAT = "0.0%"
    data = [[
        "Date", "Tarif", "Code tarifaire", "Quan.", "Prix", "VPt", "TVA",
        "Montant"
    ]]
    for position in bill.positions:
        data += [[
            position.position_date.strftime(DATE_FMT), 590,
            position.tarif_code, position.quantity,
            '%0.2f' % (position.price_cts / 100), 1.0, VAT,
            '%0.2f' % (position.total_cts / 100)
        ], ["", "", position.tarif_description]]
    for reminder in bill.reminders:
        data += [[
            reminder.reminder_date.strftime(DATE_FMT), 590, 999, 1,
            '%0.2f' % (reminder.amount_cts / 100), 1.0, VAT,
            '%0.2f' % (reminder.amount_cts / 100)
        ], ["", "", "Frais de rappels"]]
    tstyle = (POSITION_TSTYLE + [('FONT', (0, row),
                                  (-1, row), TITLE_STYLE.fontName, 6)
                                 for row in range(2, len(data), 2)] +
              [('SPAN', (2, row), (-1, row))
               for row in range(2, len(data), 2)])
    amount_label = {
        'Cash': 'Paiement cash',
        'Carte': 'Paiement par carte',
        'BVR': 'Paiement par BVR',
        'Dû': 'Paiement dû',
        'PVPE': 'Paiement par BVR'
    }.get(bill.payment_method, "Total")

    if bill.signature:

        def render_sig(flowable, signature=datamatrix(bill.signature)):
            flowable.canv.drawImage(ImageReader(signature), 0, 0)

        signature = CallerMacro(render_sig)
        signature = Signature(datamatrix(bill.signature))
    else:
        signature = ""

    total = [[
        signature, "", "", "", amount_label, "", "",
        '%0.2f' % (bill.total_cts / 100)
    ]]

    return [
        Table(data,
              colWidths=[
                  2 * cm, 1 * cm, '*', 1 * cm, 1 * cm, 1 * cm, 1 * cm, 1.5 * cm
              ],
              style=tstyle),
        Spacer(0, 1 * cm),
        Table(total,
              colWidths=[
                  2 * cm, 1 * cm, '*', 1 * cm, 1 * cm, 1 * cm, 1 * cm, 1.5 * cm
              ],
              style=TOTAL_TSTYLE),
    ]
Example #3
0
def consultations(filename, bills):
    doc = SimpleDocTemplate(filename,
                            pagesize=A4,
                            leftMargin=LEFT_MARGIN,
                            topMargin=TOP_MARGIN,
                            rightMargin=RIGHT_MARGIN,
                            bottomMargin=BOTTOM_MARGIN)
    story = []
    bills = bills[:]
    while bills:
        bill = bills.pop()
        page = [
            Paragraph("Facture", TITLE_STYLE),
            therapeute(bill),
            patient(bill),
            mandant(bill),
            diagnostic(bill),
            therapy(bill),
            comment(bill),
        ]
        page += positions(bill)
        if bill.payment_method in ('BVR', 'PVPE'):
            if len(' '.join((bill.firstname, bill.lastname))) < 25:
                identite = [' '.join((bill.firstname, bill.lastname))]
            else:
                identite = [bill.firstname, bill.lastname]
            address_patient = '\n'.join(
                identite + [bill.street, bill.zip + ' ' + bill.city])

            def render_bvr(flowable,
                           address_patient=address_patient,
                           bill=bill):
                canvas = flowable.canv
                x = flowable._frame._x + flowable._frame._leftExtraIndent
                y = flowable._frame._y
                canvas.translate(-x, -y)
                draw_bvr(canvas, bill.total_cts, address_patient, bill.bv_ref)

            page += [CallerMacro(render_bvr)]
        story += page
        if bill.copy:
            story.append(PageBreak())
            story.append(Paragraph("Facture (copie)", TITLE_STYLE))
            story += page[1:]
        if bills:
            story.append(PageBreak())
    doc.build(story)