-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunciones.py
More file actions
executable file
·223 lines (179 loc) · 6.62 KB
/
funciones.py
File metadata and controls
executable file
·223 lines (179 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/env python
# coding: utf-8
# In[71]:
from pathlib import Path
import sqlite3
from sqlite3 import Error
from datetime import date
database = Path('FacturasAFIP.db')
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by db_file
:param db_file: database file
:return: Connection object or None
"""
try:
conn = sqlite3.connect(db_file)
return conn
except Error as e:
print(e)
return None
def create_table(conn, sql):
"""
Crear tabla
"""
cur = conn.cursor()
cur.execute('DROP TABLE facturas')
conn.commit()
cur.execute(sql)
conn.commit()
cur.close()
def create_tables(conn,database):
tabla_facturas = """ CREATE TABLE IF NOT EXISTS facturas (
id integer PRIMARY KEY,
destinatario text NOT NULL,
cuit text NOT NULL,
concepto text NOT NULL,
monto real,
desde text,
hasta text
); """
# create a database connection
conn = create_connection(database)
if conn is not None:
# create projects table
print("Creando tabla Facturas")
create_table(conn, tabla_facturas)
# create tasks table
else:
print("Error! cannot create the database connection.")
def eliminar_registro(conn, nro):
cur = conn.cursor()
cur.execute("DELETE FROM facturas WHERE nro_comprobante=?", (nro,))
conn.commit()
#cur.execute("update sqlite_sequence set seq=0 where name='facturas'")
#cur = conn.cursor()
#cur.execute("VACUUM")
cur.close()
def limpiar_db(conn):
cur = conn.cursor()
cur.execute("DELETE FROM facturas")
conn.commit()
#cur.execute("update sqlite_sequence set seq=0 where name='facturas'")
#cur = conn.cursor()
#cur.execute("VACUUM")
cur.close()
def insertar_factura(conn, datos):
"""
Guardar nueva factura
:param conn:
:param datos:
:return: facturas id
"""
fecha_factura = date.today().strftime("%Y-%m-%d")
sql = "INSERT INTO facturas ( \
nro_comprobante, \
cuit,destinatario, \
monto, \
concepto, \
desde, \
hasta, \
fecha_factura)\
VALUES (?,?,?,?,?,?,?,'"+fecha_factura+"')"
cur = conn.cursor()
cur.execute(sql, datos)
conn.commit()
cur.close()
return cur.lastrowid
def consulta_factura(conn, sql):
#sql = """ SELECT * FROM facturas WHERE strftime( '%m', desde )='10' """
cur = conn.cursor()
cur.execute(sql)
r = cur.fetchall()
cur.close()
return r
def guardar_factura(conn, factura_campos):
# guardar nueva factura
factura_id = insertar_factura(conn, factura_campos)
return factura_id
# Si lo estoy ejecutando como programa principal
# y no es un módulo de otro programa
#if __name__ == '__main__':
# guardar_factura()
#create_tables(conn,database)
#limpiar_db(conn)
#eliminar_registro(conn,'1')
def mostrar_facturas(conn):
sql = """ SELECT nro_comprobante,destinatario,monto,fecha_factura,desde,hasta FROM facturas ORDER BY nro_comprobante ASC """
facturas = consulta_factura(conn, sql)
# Imprimir encabezado de las columnas, que son: "Nº comp.", Destinatario, Monto, Fecha, factura, Desde, Hasta, teniendo en cuenta la longitud de los datos a mostrar en el for
columna1 = "Nº comp.".ljust(10)
columna2 = "Destinatario".ljust(45)
columna3 = "Monto".ljust(10)
columna4 = "Fecha Factura".ljust(15)
columna5 = "Desde".ljust(15)
columna6 = "Hasta".ljust(15)
print(columna1+columna2+"\t"+columna3+"\t"+columna4+"\t"+columna5+"\t"+columna6)
for factura in facturas:
nroFactura = str(factura[0])
entidad = str(factura[1])
monto = str(factura[2])
# rellenar nro de factura a 5 caracteres con espacios a la derecha
nroFactura = nroFactura.ljust(10)
# rellenar entidad a 45 caracteres con espacios a la derecha
entidad = entidad.ljust(45)
# rellenar monto a 10 caracteres con espacios a la derecha
monto = monto.rjust(10)
print(nroFactura+
entidad+
monto+"\t"+
str(factura[3])+"\t"+
str(factura[4])+"\t"+
str(factura[5]))
def mostrar_montos_DDJJ(conn):
sql = """SELECT sum(monto) AS monto,strftime('%m/%Y',fecha_factura) AS periodo FROM facturas
GROUP BY periodo
ORDER BY hasta ASC """
ddjjs = consulta_factura(conn, sql)
print("\nMENSUALES\n__________________________\nPeríodo\t Monto Facturado\n")
for ddjj in ddjjs:
print(str(ddjj[1])+"\t| "+
str(ddjj[0]))
sql = """SELECT sum(monto) AS monto,strftime('%Y',fecha_factura) AS periodo FROM facturas
GROUP BY periodo
ORDER BY hasta ASC """
ddjjs = consulta_factura(conn, sql)
print("\nANUALES\n__________________________\nPeríodo\t Monto\n")
for ddjj in ddjjs:
print(str(ddjj[1])+"\t| "+
str(ddjj[0]))
def mostrar_ingresos_mes(conn):
sql = """SELECT sum(monto) AS monto,strftime('%m/%Y',hasta) AS periodo FROM facturas
GROUP BY periodo
ORDER BY hasta ASC """
ddjjs = consulta_factura(conn, sql)
print("\nMENSUALES\n__________________________\nPeríodo\t Monto\n")
for ddjj in ddjjs:
print(str(ddjj[1])+"\t| "+
str(ddjj[0]))
sql = """SELECT sum(monto) AS monto,strftime('%Y',hasta) AS periodo FROM facturas
GROUP BY periodo
ORDER BY hasta ASC """
ddjjs = consulta_factura(conn, sql)
print("\nANUALES\n__________________________\nPeríodo\t Monto\n")
for ddjj in ddjjs:
print(str(ddjj[1])+"\t| "+
str(ddjj[0]))
# nro_comprobante,destinatario,monto,desde,hasta
#conn = create_connection(database)
"""
factura_campos = ('30677980032',
'FUNDACION DE LA FACULTAD DE INGENIERIA',
'5000',
'Mantenimiento DB y carga de personal en lectores biométricos',
'2019-03-01',
'2019-03-01')
guardar_factura(conn,factura_campos)
"""
#mostrar_facturas(conn)
#conn.close()