
| Current Path : /usr/local/lib/python3.8/dist-packages/konto/parser/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //usr/local/lib/python3.8/dist-packages/konto/parser/invoice.py |
# coding: utf8
import os,sys,re,glob,time
try:
from konto_custom import config
except:
from konto.base import config
#*********************************************************************************
class Invoice (object):
def __init__ (self,dir="."):
self.dir = dir
#*********************************************************************************
def mark (self,remark=""):
t = time.perf_counter()
if 't0' in vars(self):
print ( ("%9.2f" % ((t-self.t0)*1000)) + " ms for: " + remark )
self.t0 = t
#********************************************************************************
def correct_invoice (self,*pars): # not ktosafe
file = pars[0]
text = open(file).read()
open(pars[0]+"~","w").write(text)
m = re.search(r"^(\d\d)(\d\d)(\d\d)\.([qw][qw]_|)(\d+\_\d\d)\_\_(\d+)\_(\d+)\_\_(.*)\.md$",file)
datum = ""
datum0 = ""
remark = ""
kdnr = ""
rechnr = ""
if m:
datum0 = m.group(1) + m.group(2) + m.group(3)
datum = m.group(3) + "." + m.group(2) + ".20" + m.group(1)
kdnr = "%1u" % int(m.group(6))
rechnr = "%05u" % int(m.group(7))
remark = m.group(8)
text1 = ""
lfd_nr = 0
netges = 0.00
vatges = 0.00
sumges = 0.00
vat = 0.00
m = re.search(r"\>VAT +(\d+)\%\<",text)
if m:
vat = float(m.group(1))
ustm = ""
if (19-0.01) < vat < (19+0.01): ustm = "qq_"
if (20-0.01) < vat < (20+0.01): ustm = "qq_"
if (10-0.01) < vat < (10+0.01): ustm = "qw_"
if (7-0.01) < vat < (7+0.01): ustm = "qw_"
while 0 == 0:
m = re.search(r"^(.*?\>)(\d+)(\<\/TD\>.*?\>)(\d+|\d+\,\d+)(\<\/TD\>.*?\>)(\d+\,\d\d)(\<\/TD\>.*?\>)(\d+\,\d\d)(\<\/TD\>.*?\>)(\d+\,\d\d)(\<\/TD\>.*?\>)(\d+\,\d\d)(\<\/TD\>.*?\>.*)$",text,re.DOTALL)
if m:
a1 = m.group(1)
nr = m.group(2)
a2 = m.group(3)
anzahl = m.group(4)
a3 = m.group(5)
price = m.group(6)
a4 = m.group(7)
netto = m.group(8)
a5 = m.group(9)
vatval = m.group(10)
a6 = m.group(11)
brutto = m.group(12)
a7 = m.group(13)
if ">SUM</TD" in a7:
anzahl = float(re.sub(",",".",anzahl))
price = float(re.sub(",",".",price))
text1 = text1 + a1
lfd_nr = lfd_nr + 1
text2 = ("%1u" % lfd_nr) + a2
text2 = text2 + re.sub(r"\.",",","%1.0f" % anzahl) + a3
text2 = text2 + re.sub(r"\.",",","%3.2f" % price) + a4
text2 = text2 + re.sub(r"\.",",","%3.2f" % (price*anzahl)) + a5
netges = netges + price*anzahl
text2 = text2 + re.sub(r"\.",",","%3.2f" % (price*anzahl*vat/100)) + a6
vatges = vatges + price*anzahl*vat/100
text2 = text2 + re.sub(r"\.",",","%3.2f" % (price*anzahl*(1+vat/100)))
sumges = sumges + price*anzahl*(1+vat/100)
text1 = text1 + text2
text = a7
continue
m = re.search(r"^(.*?\>)SUM(\<\/TD\>.*?\>)(\d+\,\d\d)(\<\/TD\>.*?\>)(\d+\,\d+\d+)(\<\/TD\>.*?\>)(\d+\,\d\d)(\<\/TD\>.*? +)(\d+\,\d\d)( +.*)$",text,re.DOTALL)
if m:
a1 = m.group(1)
a2 = m.group(2)
a3 = m.group(4)
a4 = m.group(6)
a5 = m.group(8)
a6 = m.group(10)
text1 = text1 + a1 + "SUM" + a2
text1 = text1 + re.sub(r"\.",",","%3.2f" % netges) + a3
text1 = text1 + re.sub(r"\.",",","%3.2f" % vatges) + a4
text1 = text1 + re.sub(r"\.",",","%3.2f" % sumges) + a5
text1 = text1 + re.sub(r"\.",",","%3.2f" % sumges) + a6
break
if len(datum) > 0:
m = re.search(r"^(.*?)\> *\d\d\.\d\d\.2\d\d\d *\<(.*?2)\d\d\d\/\d+(.*?) \d+(.*)$",text1,re.DOTALL)
if m:
text1 = m.group(1) + "> " + datum + " <" + m.group(2) + datum[7:10] + "/" + rechnr + m.group(3) + " " + kdnr + m.group(4)
os.unlink(file)
file = datum0 + "." + ustm + re.sub(r"\.","_","%3.2f"%sumges) + "__" + kdnr + "_" + rechnr + "__" + remark + ".md"
# m = re.search(r"\> *\d\d\.\d\d\.2\d\d\d *\<(.*?2)\d\d\d\/\d+(.*?) \d+",text1,re.DOTALL)
# print(kdnr,rechnr,m.group(1),m.group(2))
open(file,"w").write(text1)
#******************************************************************************
if __name__ == "__main__":
# Invoice.__dict__[sys.argv[1]](Invoice(),*sys.argv[2:])
if len(sys.argv) > 1 and sys.argv[1].startswith("test"):
Invoice.__dict__[sys.argv[1]](Invoice(),*sys.argv[2:])
elif len(sys.argv) > 1 and sys.argv[1] == "sort":
Invoice.__dict__["sort"](Invoice(),*sys.argv[2:])
elif len(sys.argv) > 1 and sys.argv[1] == "saldo":
print(Invoice.__dict__["read_saldo"](Invoice(),*sys.argv[2:]))
else:
Invoice.__dict__["correct_invoice"](Invoice(),*sys.argv[1:])