Beispiel #1
0
    def __reminders(self):
        self.l = 800
        p = PageBreak()
        p.drawOn(self.c, 0, 1000)
        self.c.showPage()

        self.c.setFont('Courier', 14)
        self.c.drawString(30, self.l, 'Recordatorio de pagos')

        header = ['Fecha', 'Descripcion', 'Monto']
        data = [header]

        for rem in self.reminders:
            data.append([rem.start_date, rem.description,
                rem.amount])

        self.l -= len(data) * 19
        t = Table(data)
        t.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.25, black),
            ('BOX', (0,0), (-1,-1), 0.25, black),
            ('FONTNAME', (0,0), (-1,0), 'Courier-Bold'),
            ('BACKGROUND', (0,0), (-1,0), HexColor('#efeded')),
            ('BACKGROUND', (0,0), (0,-1), HexColor('#efeded')),
            ('FONTSIZE', (0,0), (-1,0), 12),
            ('FONTSIZE', (0,1), (-1,-1), 8),
            ('FONTNAME', (0,1), (-1,-1), 'Courier')]))
        t.wrapOn(self.c, 30, self.l)
        t.drawOn(self.c, 30, self.l)
Beispiel #2
0
    def __budgets_spent(self):
        self.l = 800
        p = PageBreak()
        p.drawOn(self.c, 0, 1000)
        self.c.showPage()

        self.c.setFont('Courier', 14)
        self.c.drawString(30, self.l, 'Budgets')

        header = ['Nombre', 'Gastado', 'Balance', 'Limite']
        data = [header]

        for bud in self.budgets:
            data.append([bud.name, bud.spent,
                bud.balance, bud.limit])

        self.l -= len(data) * 19
        t = Table(data)
        t.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.25, black),
            ('BOX', (0,0), (-1,-1), 0.25, black),
            ('FONTNAME', (0,0), (-1,0), 'Courier-Bold'),
            ('BACKGROUND', (0,0), (-1,0), HexColor('#efeded')),
            ('BACKGROUND', (0,0), (0,-1), HexColor('#efeded')),
            ('FONTSIZE', (0,0), (-1,0), 12),
            ('FONTSIZE', (0,1), (-1,-1), 8),
            ('FONTNAME', (0,1), (-1,-1), 'Courier')]))
        t.wrapOn(self.c, 30, self.l)
        t.drawOn(self.c, 30, self.l)
Beispiel #3
0
def genera_segnaposto_bottiglia(lista_nomi):
    path_file = '%s/segnaposto_bottiglie.pdf' % (settings.DOCDIR)
    dimensione = pagesizes.A4
    c = canvas.Canvas(path_file, pagesize=dimensione)

    spazio_x = 1*units.cm
    spazio_y = 2.5*units.cm
    larghezza = 2.5*units.cm
    altezza = 3.3*units.cm

    orig_x1 = 0.5 * units.cm
    orig_y1 = 1 * units.cm


    qta_per_riga = int(pagesizes.A4[1] / (altezza + spazio_y))
    qta_per_colonna = int(pagesizes.A4[0] / (larghezza + spazio_x))
    for index, t_nome in enumerate(lista_nomi):
        nome = t_nome[0]
        tavolo = t_nome[1]
        indice = index % (qta_per_colonna * qta_per_riga)
        if index % (qta_per_colonna * qta_per_riga) == 0 and index:
            P = PageBreak()
            P.drawOn(c, 0, 1000)
            c.showPage()

        riga = int(indice /qta_per_riga)
        colonna = indice - riga*qta_per_riga


        x1 = orig_x1 + riga * (larghezza + spazio_x)
        y1 = orig_y1 + colonna * (altezza+ spazio_y)

        c.line(x1, y1, x1, y1+altezza) # |
        c.line(x1, y1, x1+larghezza, y1) # _
        c.line(x1+larghezza, y1, x1+larghezza, y1+altezza) #  |


        lista_nomi = nome.split(' ')
        qta_nomi = len(lista_nomi)

        for parte, parte_nome in enumerate(lista_nomi):
            altezza_font = round(altezza / units.cm / (len(parte_nome) + 1), 2)
            c.setFont('ink-free-normal', altezza_font * units.cm)
            count = 0
            for lettera in parte_nome.upper()[::-1]:
                count += 1
                c.drawCentredString(x1+larghezza/(qta_nomi+1)*(parte+1) , y1+altezza_font*units.cm * count, lettera)
            c.setFont('mvboli', 0.3*units.cm)
            c.drawCentredString(x1+larghezza/2, y1-0.3*units.cm, tavolo)
    c.save()
Beispiel #4
0
    def __get_tags_statistics(self):
        monto_categorias = dict()
        for tra in self.transactions:
            if len(tra.tags) > 0:
                for tag in tra.tags:
                    if tag in monto_categorias.keys():
                        monto_categorias[tag] += tra.amount
                    else:
                        monto_categorias[tag] = tra.amount

        labels = [lab.encode('utf-8') for lab in monto_categorias.keys()]
        data = monto_categorias.values()

        p = PageBreak()
        p.drawOn(self.c, 0, 1000)
        self.c.showPage()
        self.l = 600

        self.c.setFont('Courier', 14)
        self.c.drawString(30, 800, 'Categorias')

        drawing = Drawing(200, 200)

        pie = Pie()
        pie.x = 30
        pie.y = self.l - 130
        pie.height = 300
        pie.width = 300
        pie.data = data
        pie.labels = labels
        pie.simpleLabels = 1
        pie.slices.strokeWidth = 1
        pie.slices.strokeColor = black
        pie.slices.label_visible = 0

        legend = Legend()
        legend.x = 400
        legend.y = self.l
        legend.dx              = 8
        legend.dy              = 8
        legend.fontName        = 'Helvetica'
        legend.fontSize        = 7
        legend.boxAnchor       = 'w'
        legend.columnMaximum   = 10
        legend.strokeWidth     = 1
        legend.strokeColor     = black
        legend.deltax          = 75
        legend.deltay          = 10
        legend.autoXPadding    = 5
        legend.yGap            = 0
        legend.dxTextSpace     = 5
        legend.alignment       = 'right'
        legend.dividerLines    = 1|2|4
        legend.dividerOffsY    = 4.5
        legend.subCols.rpad    = 30
        n = len(pie.data)
        self.__setItems(n,pie.slices,
            'fillColor',self.pdf_chart_colors)

        legend.colorNamePairs = [(pie.slices[i].fillColor, 
            (pie.labels[i][0:20],'$%0.2f' % pie.data[i])) for i in xrange(n)]

        drawing.add(pie)
        drawing.add(legend)
        x, y = 0, 10

        renderPDF.draw(drawing, self.c, x, y, showBoundary=False)
Beispiel #5
0
    def __per_account_statistic(self):

        for acc in self.accounts:
            p = PageBreak()
            p.drawOn(self.c, 0, 1000)
            self.c.showPage()
            self.l = 760

            self.c.setFont('Courier', 14)
            self.c.drawString(30, 800, 'Cuenta: %s' % \
                acc.name)

            header = ['Fecha', 'Tipo', 'Monto', 'Description']
            data   = [header]
            g_data = list()
            g_labe = list()
            total  = 0

            for tra in self.transactions:
                if tra.account == acc.name:
                    if tra.t_type in ['expense', 'transfer']:
                        tipo = self.__translate_type(tra.t_type)
                        data.append([tra.date, tipo.upper(),
                            '$%2.f' % tra.amount, tra.description])
                        total += tra.amount

                        g_data.append(tra.amount)
                        g_labe.append(tra.description.encode('utf-8'))

            data.append(['TOTAL', '', '$%.2f' % total, ''])

            if len(g_data) == 0 or len(g_labe) == 0:
                self.c.setFont('Courier', 12)
                self.c.drawString(30, 770, 'Sin movimientos negativos')
                continue
 
            from_title = 35
            if len(data) != 2:
                self.l -= ((len(data) * len(data)) + len(data)) + from_title

            t = Table(data)
            t.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.25, black),
                ('BOX', (0,0), (-1,-1), 0.25, black),
                ('FONTNAME', (0,0), (-1,0), 'Courier-Bold'),
                ('BACKGROUND', (0,0), (-1,0), HexColor('#efeded')),
                ('BACKGROUND', (0,0), (0,-1), HexColor('#efeded')),
                ('FONTSIZE', (0,0), (-1,0), 12),
                ('FONTSIZE', (0,1), (-1,-1), 8),
                ('FONTNAME', (0,1), (-1,-1), 'Courier'),
                ('BACKGROUND', (0,-1), (-1,-1), red),
                ('TEXTCOLOR', (0,-1), (-1,-1), white)]))

            t.wrapOn(self.c, 30, self.l)
            t.drawOn(self.c, 30, self.l)

            drawing = Drawing(200, 100)

            pie = Pie()
            pie.x = 30
            pie.y = self.l - 300
            pie.height = 200
            pie.width = 200
            pie.data = g_data
            pie.labels = g_labe
            pie.simpleLabels = 1
            pie.slices.strokeWidth = 1
            pie.slices.strokeColor = black
            pie.slices.label_visible = 0
            pie.slices.popout        = 1
            #pie.labels   = map(str, pie.data)

            
            legend = Legend()
            legend.x = 250
            legend.y = self.l - 250
            legend.dx              = 8
            legend.dy              = 8
            legend.fontName        = 'Helvetica'
            legend.fontSize        = 7
            legend.boxAnchor       = 'w'
            legend.columnMaximum   = 10
            legend.strokeWidth     = 1
            legend.strokeColor     = black
            legend.deltax          = 75
            legend.deltay          = 10
            legend.autoXPadding    = 5
            legend.yGap            = 0
            legend.dxTextSpace     = 5
            legend.alignment       = 'right'
            legend.dividerLines    = 1|2|4
            legend.dividerOffsY    = 4.5
            legend.subCols.rpad    = 30
            n = len(pie.data)
            self.__setItems(n,pie.slices,
                'fillColor',self.pdf_chart_colors)

            legend.colorNamePairs = [(pie.slices[i].fillColor, 
                (pie.labels[i][0:20],'$%0.2f' % pie.data[i])) for i in xrange(n)]
            

            drawing.add(pie)
            drawing.add(legend)
            x, y = 0, 10

            renderPDF.draw(drawing, self.c, x, y, showBoundary=False)
Beispiel #6
0
    def __transactions(self):
        self.l -= 20
        self.c.setFont('Courier', 14)
        self.c.drawString(30, self.l, 'Movimientos')

        header = ['Fecha', 'Tipo', 'Cuenta', 'Monto', 'Description']
        data = [header]

        for tra in self.transactions:
            tipo = self.__translate_type(tra.t_type)
            data.append([tra.date, tipo.upper(), tra.account,
                '$%.2f' % tra.amount, tra.description])

        registros = 24
        filas = len(data) / float(registros)
        coheficiente = math.ceil(len(data) / filas)
        look = 0
        datas = list()
        datas_new = list()

        while look < len(data):
            second = int(look+coheficiente)
            datas.append(data[look:second])
            look = int(look+coheficiente)

        datas_new.append(datas[0])

        for dd in datas[1:][::-1]:
            datas_new.append([header] + dd)

        data1 = datas_new[0]
        self.l -= len(data1) * 19
        t = Table(data1)
        t.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.25, black),
            ('BOX', (0,0), (-1,-1), 0.25, black),
            ('FONTNAME', (0,0), (-1,0), 'Courier-Bold'),
            ('BACKGROUND', (0,0), (-1,0), HexColor('#efeded')),
            ('BACKGROUND', (0,0), (0,-1), HexColor('#efeded')),
            ('FONTSIZE', (0,0), (-1,0), 12),
            ('FONTSIZE', (0,1), (-1,-1), 8),
            ('FONTNAME', (0,1), (-1,-1), 'Courier')]))
        t.wrapOn(self.c, 30, self.l)
        t.drawOn(self.c, 30, self.l)

        for dd in datas_new[1:][::-1]:
            p = PageBreak()
            p.drawOn(self.c, 0, 1000)
            self.c.showPage()
            self.l = 800 - (len(dd) * 19)

            t2 = Table(dd)
            t2.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.25, black),
                ('BOX', (0,0), (-1,-1), 0.25, black),
                ('FONTNAME', (0,0), (-1,0), 'Courier-Bold'),
                ('BACKGROUND', (0,0), (-1,0), HexColor('#efeded')),
                ('BACKGROUND', (0,0), (0,-1), HexColor('#efeded')),
                ('FONTSIZE', (0,0), (-1,0), 12),
                ('FONTSIZE', (0,1), (-1,-1), 8),
                ('FONTNAME', (0,1), (-1,-1), 'Courier')]))
            t2.wrapOn(self.c, 30, self.l)
            t2.drawOn(self.c, 30, self.l)
    def make_dir(self, action=False):
        desktop = os.path.expanduser("~/Desktop")

        dir = "NYMUN FORMS"
        directory = os.path.join(desktop, dir)
        dirs = ["Individual", "3", "4", "5", "6"]

        logging.debug("Action => {}".format(action))
        if (action == False):
            if os.path.isdir(directory) != True:
                os.chdir(desktop)
                logging.info(
                    "Changed working directory to => '{}' and creating a new directory => '{}'"
                    .format(os.getcwd(), dir))
                os.mkdir(dir)
                os.chdir(dir)
                for dir in dirs:
                    os.mkdir(dir)
                return True

            else:
                logging.info(
                    "Changed working directory to => '{}' and directory => '{}' already exists!"
                    .format(os.getcwd(), dir))
                return False

        elif (action == True):
            os.chdir(directory)
            logging.info("Current working directory => '{}'".format(
                os.getcwd()))

            files_to_create, files_created, errors = len(self.info), 0, 0
            logging.info("No of files to create => {}".format(files_to_create))

            for serial_no in self.info:
                try:
                    detail = self.info[serial_no]
                    os.chdir(detail[2])
                    logging.info("Current working directory => '{}'".format(
                        os.getcwd()))

                    #Beginning of pdf
                    ## Creating a serial_no for pdf file
                    file = "{}.pdf".format(str(serial_no))
                    logging.info("Creating a new file => '{}'".format(file))

                    c = canvas.Canvas(file)
                    c.setAuthor(("Team (NYMUN {} 2018)".format(chr(0xa9))))
                    c.setTitle("Delegate Information (NYMUN {} 2018)".format(
                        (chr(0xa9))))
                    c.setSubject("Complete Delegate Information")
                    c.setFont("Helvetica", 18)
                    c.drawString(70, 800, "REGISTRATION INFO OF TS :")
                    # Image("logo.png")
                    c.drawInlineImage(
                        (os.path.join(self.original_path, "img\\logo.png")), 5,
                        795, 40, 40)
                    c.setFont("Helvetica", 16)
                    c.drawString(550, 800, "1 / 2")
                    c.setFont("Helvetica", 18)

                    x, y = 15, 766
                    name_list, experience_list = [], []
                    for index in range(len(detail)):
                        rem_country, rem_name, rem_experience = False, False, False
                        if (index == 0):
                            c.drawString(330, 800, detail[index][0:-5])
                            c.line(0, 792, 600, 792)
                            c.setFont("Helvetica-Bold", 12)

                        elif (index == 2):
                            continue

                        else:
                            opt = str(
                                self.info_pattern[detail[2]][index]) + " :"

                            # a line space for photo url
                            if opt.startswith("Photo"):
                                c.drawString(x, y, opt)
                                y -= 22
                                c.drawString(x, y, "")

                            # Gender will on the same line as name
                            elif opt.startswith("Gender"):
                                y += 22
                                c.drawString(380, y, opt)
                                pass

                            # Country preference will be on the same line as Committee
                            elif opt.startswith("Country"):
                                rem_country = True
                                y += 22
                                c.drawString(322, y, opt)
                                pass

                            # PREVIOUS EXPERIENCE will be on the next page
                            elif opt.startswith("Previous"):
                                rem_experience = True
                                pass

                            elif opt.startswith("Committee"):
                                c.drawString(x, y, opt)

                            elif "Name" in opt and "Private" not in opt:
                                rem_name = True
                                c.drawString(x, y, opt)

                            else:
                                c.drawString(x, y, opt)
                            c.setFont("Helvetica", 12)

                            Gender = ["Male", "Female", "Other"]
                            if detail[index].startswith("https"):
                                c.drawString(x, y, detail[index])

                            elif detail[index] in Gender:
                                c.drawString(450, y, detail[index])

                            elif rem_country == True:
                                c.drawString(450, y, detail[index])
                                c.line(x, y - 8.5, 575, y - 8.5)
                                y += 10

                            elif rem_name == True:
                                c.drawString(240, y, detail[index])
                                name_list.append(detail[index])

                            elif rem_experience == True:
                                experience_list.append(detail[index])

                            else:
                                c.drawString(240, y, detail[index])
                            c.setLineWidth(0.2)
                            c.setFont("Helvetica-Bold", 12)
                            y -= 22

                    #Ending of first page
                    c.setFont("Courier-BoldOblique", 10)
                    c.line(0, 15, 600, 15)
                    c.drawString(x, 3, "NYMUN FORMS {} 2018".format(chr(0xa9)))
                    c.drawString(350, 3,
                                 "Credits: Faizan Ahmad(Asst.Director IT)")
                    c.showPage()

                    # start of second page
                    p = PageBreak()
                    p.drawOn(c, 0, 1000)
                    c.drawInlineImage(
                        (os.path.join(self.original_path, "img\\logo.png")), 5,
                        795, 40, 40)
                    c.setFont("Helvetica", 18)
                    c.drawString(80, 800,
                                 "DELEGATE/DELEGATION PREVIOUS EXPERIENCE")
                    c.setFont("Helvetica", 16)
                    c.drawString(550, 800, "2 / 2")
                    c.line(0, 792, 600, 792)
                    x, y = 15, 766
                    style = ParagraphStyle(name='Normal',
                                           fontName='Helvetica-Oblique',
                                           fontSize=12)
                    for index in range(len(name_list)):
                        c.setFont("Helvetica-BoldOblique", 16)
                        c.drawString(
                            x, y, "{}'s Previous Experience :".format(
                                name_list[index]))
                        y -= 55
                        c.setFont("Helvetica-Oblique", 12)
                        if experience_list[index] != "":
                            para = Paragraph(experience_list[index], style)
                            para.wrapOn(c, 450, 108)
                            para.drawOn(c, x + 20, y)

                        else:
                            c.drawString(x + 20, y, "NO INFO. PROVIDED")
                        y -= 73
                        c.line(x, y + 16.5, 575, y + 16.5)

                    #Ending of second page
                    c.setFont("Courier-BoldOblique", 10)
                    c.line(0, 15, 600, 15)
                    c.drawString(x, 3, "NYMUN FORMS {} 2018".format(chr(0xa9)))
                    c.drawString(350, 3,
                                 "Credits: Faizan Ahmad(Asst.Director IT)")
                    c.showPage()
                    c.save()
                    logging.info(
                        "File => '{}' was created successfully with no errors reported."
                        .format(file))
                    os.chdir("..")
                    files_created += 1

                except Exception as exp:
                    logging.warn(
                        "Exception raised => {0} , while creating file => '{1}.pdf'"
                        .format(exp, serial_no))
                    errors += 1
                    os.chdir("..")
                    pass

            logging.info("No of files created => {}".format(files_created))
            self.files_created = files_created
            self.dir = dir
            self.errors = errors
            return True

        else:
            return False