diff --git a/pytrustnfe/pdf/__init__.py b/pytrustnfe/pdf/__init__.py deleted file mode 100644 index e0c1395..0000000 --- a/pytrustnfe/pdf/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Danimar Ribeiro, Trustcode -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -# from super_table import PdfTable, PdfCell -from pytrustnfe import xml - -inch = 28.34 - - -class Danfe(object): - - objeto = None - - def __init__(self, objetoNFe): - if objetoNFe: - self.objeto = xml.sanitize_response(objetoNFe)[1] - self.NFe = self.objeto.getchildren()[2] - self.infNFe = self.NFe.getchildren()[0] - self.ide = self.infNFe.getchildren()[0] - self.emitente = self.infNFe.getchildren()[1] - self.destinatario = self.infNFe.getchildren()[2] - - def nfe(self): - # danfe = PdfTable(columns=12) - pass - - def gerar(self): - pass - -if __name__ == '__main__': - pass - # import ipdb; ipdb.set_trace() diff --git a/pytrustnfe/pdf/super_table.py b/pytrustnfe/pdf/super_table.py deleted file mode 100644 index 6191567..0000000 --- a/pytrustnfe/pdf/super_table.py +++ /dev/null @@ -1,129 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Danimar Ribeiro, Trustcode -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from reportlab.lib import colors -from reportlab.platypus import SimpleDocTemplate, BaseDocTemplate, Table, TableStyle -from reportlab.lib.pagesizes import A4 -# from reportlab.lib.units import mm - -INCH = 28.34 - - -class PdfTable(object): - - def __init__(self, columns=1, width=100): - self.columns = columns - self.width = width - self.cells = [] - self.cell_width = self.width/float(self.columns) - - def add_cell(self, cell): - cell.width = self.cell_width - if cell.value.__class__ == PdfTable: - cell.value.width = cell.width - cell.value.cell_width = cell.width / float(cell.value.columns) - - if cell.colspan > 1: - colspan_tot = sum([x.colspan for x in self.cells]) - colspan_tot += cell.colspan - # if colspan_tot % self.columns != 0: - # raise Exception('Colspan incompatível') - self.cells.append(cell) - - def render(self): - colspan_tot = sum([x.colspan for x in self.cells]) - if colspan_tot % self.columns != 0: - raise Exception('O número de celulas adicionadas é incompleto') - - style = [] - data = [] - linha = [] - colspan_tot = 0 - i = j = 0 - - for cell in self.cells: - colspan_tot += cell.colspan - style += cell.style(j, i) - j += 1 - - if isinstance(cell.value, PdfTable): - linha.append(cell.value.render()) - else: - linha.append(cell.value) - if cell.colspan > 1: - for xi in range(1, cell.colspan): - linha.append('') - style += cell.style(j, i, colspan=False) - j += 1 - - if colspan_tot % self.columns == 0: - data.append(linha) - colspan_tot = 0 - linha = [] - j = 0 - i += 1 - - t = Table(data, colWidths=[self.cell_width for - k in range(self.columns)]) - t.setStyle(TableStyle(style)) - return t - - -class PdfCell(object): - - def __init__(self, value, colspan=1): - self.width = 1 - self.value = value - self.colspan = colspan - self.background_color = colors.white - self.text_color = colors.black - self.font_size = 5 - self.bold = False - self.border_width = 1 - self.border_color = colors.black - - def style(self, i, j, colspan=True): - span = [] - if self.colspan > 1 and colspan: - span = [('SPAN', (i, j), (i+self.colspan-1, j))] - if not self.border_width == 0: - span += [('INNERGRID', (i, j), (i, j), self.border_width, - self.border_color), - ('BOX', (i, j), (i, j), self.border_width, - self.border_color)] - return span + [ - ('BACKGROUND', (i, j), (i, j), self.background_color), - ('TEXTCOLOR', (i, j), (i, j), self.text_color), - ('TOPPADDING', (i, j), (i, j), 3 if - isinstance(self.value, str) else 0), - ('LEFTPADDING', (i, j), (i, j), 5 if - isinstance(self.value, str) else 0), - ('RIGHTPADDING', (i, j), (i, j), 5 if - isinstance(self.value, str) else 0), - ('BOTTOMPADDING', (i, j), (i, j), 3 if - isinstance(self.value, str) else 0), - ('FONTSIZE', (i, j), (i, j), self.font_size), - ] - - -if __name__ == '__main__': - - table = PdfTable(columns=30, width=(20 * INCH)*1.7) - - table2 = PdfTable(columns=12) - - table2.add_cell(PdfCell('RECEBEMOS DE ISOCOMPÓSITOS EIRELI ME OS PRODUTOS \ -E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA AO LADO', - colspan=12)) - table2.add_cell(PdfCell('Data de Recebimento', colspan=2)) - table2.add_cell(PdfCell('Assinatura', colspan=10)) - - table.add_cell(PdfCell(table2, colspan=10)) - table.add_cell(PdfCell(table2, colspan=20)) - - table = table.render() - - doc = SimpleDocTemplate("ola.pdf", pagesize=A4, leftMargin=0, - rightMargin=0, topMargin=0, bottomMargin=0) - doc.build([table]) diff --git a/pytrustnfe/test/test_danfe.py b/pytrustnfe/test/test_danfe.py deleted file mode 100644 index 6f0e2bd..0000000 --- a/pytrustnfe/test/test_danfe.py +++ /dev/null @@ -1,11 +0,0 @@ -# coding=utf-8 - -import unittest -from pytrustnfe.pdf import Danfe - - -class test_danfe(unittest.TestCase): - - def test_generate_danfe(self): - danfe = Danfe(None) - danfe.gerar()