Skip to content

Commit

Permalink
Add print entry service order and print budget.
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique-Miranda committed May 3, 2019
1 parent ffb73ff commit 6454ee3
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 99 deletions.
4 changes: 1 addition & 3 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ def createDB(self):
self.cursor.execute(
'''
CREATE TABLE IF NOT EXISTS os_itens (
id INTEGER PRIMARY KEY AUTOINCREMENT,
osId INTEGER,
description TEXT NOT NULL,
amount REAL NOT NULL,
amount INTEGER NOT NULL,
value REAL NOT NULL,
subTotal REAL NOT NULL,
FOREIGN KEY(osId) REFERENCES service_order(id) ON UPDATE CASCADE);
'''
)
Expand Down
264 changes: 242 additions & 22 deletions exportPDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
from reportlab.lib.enums import TA_CENTER, TA_LEFT
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.platypus.tables import Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import mm
from reportlab.lib import colors
paper = '58mm'

def makePDF(compId, osId, paper):
def makePDF(osId = 1, osType = 2):
banco = Database('database.db')
# Company info
result = resultc = banco.queryDB(f"""SELECT logo, name, slogan, adress, number,
adress2, district, city, state, tel, cell1, cell2, email, site FROM company WHERE id={compId}""")
adress2, district, city, state, tel, cell1, cell2, email, site FROM company WHERE id=1""")
logo = resultc[0][0]
compName = resultc[0][1]
slogan = resultc[0][2]
compAdress = f'{resultc[0][3]}, {resultc[0][4]}, {resultc[0][5]}, {resultc[0][6]}, {resultc[0][7]} - {resultc[0][8]}'
compTel = f'{resultc[0][9]} / {resultc[0][10]} / {resultc[0][11]}'
compTel = f'{resultc[0][9]} / {resultc[0][10]}'
compEmail = resultc[0][12]
compSite = resultc[0][13]
# END Company info

# OS info
result = banco.queryDB(f'SELECT clients.name, entryDate, clients.adress, clients.number,clients.adress2, clients.district, clients.city, clients.state, clients.tel, clients.cell1, clients.cell2, deviceType, brand, model, color, acessories, deviceStatus, defect, obs1, status FROM service_order INNER JOIN clients ON clients.id=service_order.idCli WHERE service_order.id={osId}')
result = banco.queryDB(f'SELECT clients.name, entryDate, clients.adress, clients.number,clients.adress2, clients.district, clients.city, clients.state, clients.tel, clients.cell1, clients.cell2, deviceType, brand, model, color, acessories, deviceStatus, defect, defectFound, obs1, obs2, status, partTotalValue, serviceValue, total FROM service_order INNER JOIN clients ON clients.id=service_order.idCli WHERE service_order.id={osId}')
print('RES: ', result)
osNumber = osId
cliName = result[0][0]
Expand All @@ -35,16 +38,25 @@ def makePDF(compId, osId, paper):
acessories = result[0][15]
deviceStatus = result[0][16]
defect = result[0][17]
obs = result[0][18]
status = result[0][19]
defectFound = result[0][18]
obs = result[0][19]
obs2 = result[0][19]
status = result[0][21]
partTotalValue = result[0][22]
serviceValue = result[0][23]
total = result[0][24]
printDate = time.strftime("%d/%m/%Y %H:%M:%S")
warrantyTerms = [
Terms = [
'Ao deixar seu equipamento retire o chip e cartão de memória, não nos responsabilizamos por estes itens.',
'Os aparelhos não retirados no prazo máximo de 90 dias contados a partir da data em que for orçado, será cobrado uma taxa de R$10,00 por dia para cobrir custos de armazenamento.',
'O aparelho só será devolvido para o titular deste documento, caso necessário o titular poderá solicitar retirada por terceiros.']
warrantyTerms = [
'A empresa da 90 dias de garantia nas peças aplicadas e serviços realizados.',
'A garantia não cobre defeitos causados pelo usuário ou mau uso do aparelho, como quebra ou arranhões nas peças trocas.',
'A violação do lacre de garantia ou a desmontagem do aparelho por pessoas não autorizadas acarretará na perca da garantia.']
# END OS info

def docA4():
def entryA4():
fileName = f'{os.getcwd()}/OS_DIR/os{osNumber}.pdf'
doc = SimpleDocTemplate(fileName ,pagesize=A4, rightMargin=72, leftMargin=72, topMargin=30, bottomMargin=18)
Story=[]
Expand Down Expand Up @@ -83,7 +95,7 @@ def docA4():
Story.append(Spacer(1, 12))
ptext = f"<b>Nome:</b> {cliName}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Endereço:</b> {adress}"
ptext = f"<b>End'80mm'ereço:</b> {adress}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Tel.:</b> { tel}"
Story.append(Paragraph(ptext, style["left"]))
Expand Down Expand Up @@ -116,7 +128,7 @@ def docA4():
ptext = '<b>CONDIÇÕES DE SERVIÇOS:</b>'
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 12))
for n, l in enumerate(warrantyTerms, 1):
for n, l in enumerate(Terms, 1):
ptext = f'<b>{n}</b> - {l}'
Story.append(Paragraph(ptext, style["left"]))
Story.append(Spacer(1, 20))
Expand All @@ -141,10 +153,104 @@ def docA4():

doc.build(Story)

def doc58mm():
def budgetA4():
fileName = f'{os.getcwd()}/OS_DIR/os{osNumber}.pdf'
doc = SimpleDocTemplate(fileName ,pagesize=A4, rightMargin=72, leftMargin=72, topMargin=30, bottomMargin=18)
Story=[]
# LOGO
im = Image(logo, 30*mm, 30*mm, hAlign='CENTER')
Story.append(im)
Story.append(Spacer(1, 12))
# END LOGO

# HEAD
style=getSampleStyleSheet()
style.add(ParagraphStyle(name='center', fontSize=12, alignment=TA_CENTER, spaceAfter=3))
ptext = f"<b>{compName}</b>"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{slogan}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{compTel}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{compEmail}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{compSite}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{compAdress}"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 12))
# END HEAD
# OS DATA
trace = f"{'-'*109}"
Story.append(Paragraph(trace, style["center"]))
Story.append(Spacer(1, 12))
style.add(ParagraphStyle(name='left', fontSize=12, spaceAfter=3, alignment=TA_LEFT))
ptext = f"<b>ORÇAMENTO ORDEM DE SERVIÇO Nº</b>{osNumber}"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph(trace, style["center"]))
Story.append(Spacer(1, 12))
ptext = f"<b>Nome:</b> {cliName}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Tel.:</b> { tel}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Equipamento:</b> {device}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Marca:</b> {brand}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Modelo:</b> {model}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Cor:</b> {color}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Problema relatado:</b> {defect}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Defeito encontrado:</b> {defectFound}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Observações:</b> {obs2}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Data de Entrada:</b> {entryDate}"
Story.append(Paragraph(ptext, style["left"]))
Story.append(Spacer(1, 12))
# END OS DATA

ptext = '<b>PEÇAS APLICADAS:</b>'
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 20))
data=[('Descrição', 'Quantidade', 'Valor Un', 'Subtotal'),
('Touch Samsung G530', 1, 15, 15)]
table = Table(data)
table.setStyle(TableStyle([('INNERGRID', (0,0), (-1, -1), 0.25, colors.black),
('BOX', (0,0), (-1, -1), 0.25, colors.black),
('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'),
('ALIGN', (0,0), (-1,-1), 'CENTER')]))
Story.append(table)
Story.append(Spacer(1, 20))
ptext = f'<b>Valor total de peças:</b> {partTotalValue}'
Story.append(Paragraph(ptext, style["center"]))
ptext = f'<b>Valor da Mão de Obra</b>: {serviceValue}'
Story.append(Paragraph(ptext, style["center"]))
ptext = f'<b>Valor Total a Pagar:</b> {total}'
Story.append(Paragraph(ptext, style["center"]))
ptext = 'Orçamento válido por 10 dias.'
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 12))
ptext = f'Hoje {printDate} declaro ter recebido e assinado este orçamento e autorizo o andamento do serviço.'
Story.append(Paragraph(ptext, style["center"]))
# Assignature
Story.append(Spacer(1, 12))
ptext = "_________________________________________________"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 20))
ptext = f'Visto: {cliName}'
Story.append(Paragraph(ptext, style["center"]))
# END Assignature

doc.build(Story)

def entry58mm():
fileName = f'{os.getcwd()}/OS_DIR/os{osNumber}.pdf'
pagesize=(57.86*mm, 209.9*mm)
doc = SimpleDocTemplate(fileName ,pagesize=pagesize, rightMargin=5, leftMargin=10, topMargin=5, bottomMargin=5)
doc = SimpleDocTemplate(fileName ,pagesize=pagesize, rightMargin=7, leftMargin=8, topMargin=0, bottomMargin=0)
Story=[]
# LOGO
im = Image(logo, 15*mm, 15*mm, hAlign='CENTER')
Expand All @@ -170,7 +276,7 @@ def doc58mm():
Story.append(Spacer(1, 3))
# END HEAD

ptext = f"------------------------------------"
ptext = "------------------------------------"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 3))

Expand All @@ -179,7 +285,7 @@ def doc58mm():
ptext = f"<b>COMPROVANTE DE ENTRADA OS Nº</b>{osNumber}"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 3))
ptext = f"------------------------------------"
ptext = "------------------------------------"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 3))
ptext = f"<b>Nome:</b> {cliName}"
Expand Down Expand Up @@ -219,7 +325,7 @@ def doc58mm():
ptext = '<b>CONDIÇÕES DE SERVIÇOS:</b>'
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 3))
for n, l in enumerate(warrantyTerms, 1):
for n, l in enumerate(Terms, 1):
ptext = f'<b>{n}</b> - {l}'
Story.append(Paragraph(ptext, style["left"]))
Story.append(Spacer(1, 5))
Expand All @@ -244,15 +350,129 @@ def doc58mm():

doc.build(Story)

def doc80mm():
def budget58mm():
fileName = f'{os.getcwd()}/OS_DIR/os{osNumber}.pdf'
pagesize=(57.86*mm, 209.9*mm)
doc = SimpleDocTemplate(fileName ,pagesize=pagesize, rightMargin=7, leftMargin=8, topMargin=0, bottomMargin=0)
Story=[]
# LOGO
im = Image(logo, 15*mm, 15*mm, hAlign='CENTER')
Story.append(im)
Story.append(Spacer(1, 3))
# END LOGO

# HEAD
style=getSampleStyleSheet()
style.add(ParagraphStyle(name='center', fontsize=9, alignment=TA_CENTER))
ptext = f"<b>{compName}</b>"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{slogan}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{compTel}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{compEmail}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{compSite}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"{compAdress}"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 3))
# END HEAD

ptext = f"------------------------------------"
Story.append(Paragraph(ptext, style["center"]))

# OS DATA
style.add(ParagraphStyle(name='left', fontsize=9, spaceAfter=1, alignment=TA_LEFT))
ptext = f"<b>ORÇAMENTO OS Nº</b>{osNumber}"
Story.append(Paragraph(ptext, style["center"]))
ptext = f"------------------------------------"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 3))
ptext = f"<b>Nome:</b> {cliName}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Tel.:</b> { tel}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Equipamento:</b> {device}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Marca:</b> {brand}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Modelo:</b> {model}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Cor:</b> {color}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Problema relatado:</b> {defect}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Defeito encontrado:</b> {defectFound}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Observações:</b> {obs2}"
Story.append(Paragraph(ptext, style["left"]))
ptext = f"<b>Data de Entrada:</b> {entryDate}"
Story.append(Paragraph(ptext, style["left"]))
Story.append(Spacer(1, 3))
# END OS DATA

ptext = '<b>PEÇAS APLICADAS:</b>'
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 3))
data=[('Des.', 'Quan.', 'Val.Un', 'Sub.'),
('Touch Samsung G530', 1, 15, 15)]
table = Table(data)
table.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.50, colors.black),
('BOX', (0,0), (-1, -1), 0.50, colors.black),
('FONTNAME', (0,0), (-1,-1), 'Helvetica-Bold'),
('ALIGN', (0,0), (-1,-1), 'CENTER'),
('FONTSIZE', (0,0), (-1,-1), 5),
('VALIGN', (0,0), (-1,-1), 'MIDDLE')]))
Story.append(table)
Story.append(Spacer(1, 3))
ptext = f'<b>Valor total de peças:</b> {partTotalValue}'
Story.append(Paragraph(ptext, style["center"]))
ptext = f'<b>Valor da Mão de Obra</b>: {serviceValue}'
Story.append(Paragraph(ptext, style["center"]))
ptext = f'<b>Valor Total a Pagar:</b> {total}'
Story.append(Paragraph(ptext, style["center"]))
ptext = 'Orçamento válido por 10 dias.'
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 12))
ptext = f'Hoje {printDate} declaro ter recebido e assinado este orçamento e autorizo o andamento do serviço.'
Story.append(Paragraph(ptext, style["center"]))
# Assignature
Story.append(Spacer(1, 12))
ptext = "_______________________"
Story.append(Paragraph(ptext, style["center"]))
Story.append(Spacer(1, 20))
ptext = f'Visto: {cliName}'
Story.append(Paragraph(ptext, style["center"]))
# END Assignature

doc.build(Story)

def entry80mm():
pass

if not 'OS_DIR' in os.listdir():
os.mkdir('OS_DIR')

if paper == 'A4':
docA4()
elif paper == '58mm':
doc58mm()
elif paper == '80mm':
doc80mm()
if osType == 1:
if paper == 'A4':
entryA4()
if paper == '58mm':
entry58mm()
if paper == '80mm':
entry80mm()
elif osType == 2:
if paper == 'A4':
budgetA4()
if paper == '58mm':
budget58mm()
if paper == '80mm':
budget80mm()

elif osType == 3:
if paper == 'A4':
outA4()
if paper == '58mm':
out58mm()
if paper == '80mm':
out80mm()
Loading

0 comments on commit 6454ee3

Please sign in to comment.