# Path: velo/core/pdf.py
# class InvoiceCanvas(canvas.Canvas):
#     def __init__(self, *args, **kwargs):
#         canvas.Canvas.__init__(self, *args, **kwargs)
#         self.pages = []
# 
#     def showPage(self):
#         """
#         On a page break, add information to the list
#         """
#         self.pages.append(dict(self.__dict__))
#         self._startPage()
# 
#     def save(self):
#         """
#         Add the page number to each page (page x of y)
#         """
#         for page in self.pages:
#             self.__dict__.update(page)
#             # self.draw_header()
#             self.draw_footer()
#             canvas.Canvas.showPage(self)
# 
#         canvas.Canvas.save(self)
# 
#     # def draw_header(self):
#     #     img = os.path.join(settings.MEDIA_ROOT, "adverts", "2018_invoice_header.jpg")
#     #     self.drawImage(img, 0.5*cm, 24 * cm, width=self._pagesize[0]-cm, height=153, preserveAspectRatio=True)
# 
#     def draw_footer(self):
#         pass
#         # img = os.path.join(settings.MEDIA_ROOT, "adverts", "2019_invoice_footer.jpg")
#         # img = "velo/test_media/2019_invoice_footer.jpg"
#         # self.drawImage(img, 0.5*cm, 0.5*cm, width=self._pagesize[0]-cm, height=86, preserveAspectRatio=True)


import os
from django.conf import settings
from reportlab.lib import colors
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, TableStyle, Spacer, Image
from reportlab.lib.units import mm
from reportlab.lib.colors import HexColor
from reportlab.platypus import Table
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.enums import TA_CENTER
from reportlab.graphics.barcode import code128
from io import BytesIO
from velo.core.pdf import InvoiceCanvas
from velo.payment.pdf_utils import BreakingParagraph
from velo.payment.skaitlis import num_to_text
            [code128.Code128("*%s*%s*" % (self.invoice.get('name'), str(final_amount)), humanReadable=1),
             'Vēlam veiksmīgu un pozitīvām emocijām bagātu sezonu!']
        ]

        bottom_table = Table(data, colWidths=(self.doc.width*0.3, self.doc.width*0.7))
        bottom_table.setStyle(
            TableStyle([
                ('FONT', (0, 0), (-1, -1), 'UbuntuB'),
                ('SIZE', (0, 0), (-1, -1), 14),
            ]))

        self.elements.append(bottom_table)

    def _build_footer(self):
        # pass
        # if self.competition.id in (89, 90, 91, 92, 93, 94, 95, 96, 97):
        adv = os.path.join(settings.MEDIA_ROOT, "adverts", "2020_lvm.jpg")
        im = Image(adv, 567, 91)
        self.elements.append(im)

    def build(self):
        self._build_top()
        self._build_sender_top()
        self._build_receiver_top()
        self._build_info_top()
        self._build_items()
        self.elements.append(Spacer(10 * mm, 10 * mm))
        # self.elements.append(Paragraph("", normal))
        self._build_footer()


# Path: velo/core/pdf.py
# class InvoiceCanvas(canvas.Canvas):
#     def __init__(self, *args, **kwargs):
#         canvas.Canvas.__init__(self, *args, **kwargs)
#         self.pages = []
# 
#     def showPage(self):
#         """
#         On a page break, add information to the list
#         """
#         self.pages.append(dict(self.__dict__))
#         self._startPage()
# 
#     def save(self):
#         """
#         Add the page number to each page (page x of y)
#         """
#         for page in self.pages:
#             self.__dict__.update(page)
#             # self.draw_header()
#             self.draw_footer()
#             canvas.Canvas.showPage(self)
# 
#         canvas.Canvas.save(self)
# 
#     # def draw_header(self):
#     #     img = os.path.join(settings.MEDIA_ROOT, "adverts", "2018_invoice_header.jpg")
#     #     self.drawImage(img, 0.5*cm, 24 * cm, width=self._pagesize[0]-cm, height=153, preserveAspectRatio=True)
# 
#     def draw_footer(self):
#         pass
#         # img = os.path.join(settings.MEDIA_ROOT, "adverts", "2019_invoice_footer.jpg")
#         # img = "velo/test_media/2019_invoice_footer.jpg"
#         # self.drawImage(img, 0.5*cm, 0.5*cm, width=self._pagesize[0]-cm, height=86, preserveAspectRatio=True)


# Path: velo/payment/pdf.py
import os
from django.conf import settings
from reportlab.lib import colors
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, TableStyle, Spacer, Image
from reportlab.lib.units import mm
from reportlab.lib.colors import HexColor
from reportlab.platypus import Table
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.enums import TA_CENTER
from reportlab.graphics.barcode import code128
from io import BytesIO
from velo.core.pdf import InvoiceCanvas
from velo.payment.pdf_utils import BreakingParagraph
from velo.payment.skaitlis import num_to_text

            [code128.Code128("*%s*%s*" % (self.invoice.get('name'), str(final_amount)), humanReadable=1),
             'Vēlam veiksmīgu un pozitīvām emocijām bagātu sezonu!']
        ]

        bottom_table = Table(data, colWidths=(self.doc.width*0.3, self.doc.width*0.7))
        bottom_table.setStyle(
            TableStyle([
                ('FONT', (0, 0), (-1, -1), 'UbuntuB'),
                ('SIZE', (0, 0), (-1, -1), 14),
            ]))

        self.elements.append(bottom_table)

    def _build_footer(self):
        # pass
        # if self.competition.id in (89, 90, 91, 92, 93, 94, 95, 96, 97):
        adv = os.path.join(settings.MEDIA_ROOT, "adverts", "2020_lvm.jpg")
        im = Image(adv, 567, 91)
        self.elements.append(im)

    def build(self):
        self._build_top()
        self._build_sender_top()
        self._build_receiver_top()
        self._build_info_top()
        self._build_items()
        self.elements.append(Spacer(10 * mm, 10 * mm))
        # self.elements.append(Paragraph("", normal))
        self._build_footer()


        self.doc.build(self.elements, canvasmaker=InvoiceCanvas)