
| Current Path : /home/ift/52_procpy/dataninja/test/ |
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 : //home/ift/52_procpy/dataninja/test/kto.py |
# coding: utf8
import os,re,sys,sqlite3,time,glob
import procpy
import procpy.fibu.fibu1
import procpy.fibu.kto
import procpy.fibu.sync
import procpy.fibu.parser
import procpy.fibu.auswertung
import procpy.test.account_examples
# import fibu
#**************************************************************************
class Kto (object):
def __init__ (self,*pars):
self.__class__.__dict__[pars[0]](self,pars[1:])
def mark (self,remark=""): # <---
t = time.clock()
if 't0' in vars(self):
print ( ("%9.2f" % ((t-self.t0)*1000)) + " ms for: " + remark )
self.t0 = t
def compute_kto (self,pars):
kto = procpy.fibu.kto.Kto("10-1202")
ukto = pars[0]
kto1 = pars[1]
uniqu = []
ktox = kto.parse_ktotext_compute_kto(ukto,kto1,uniqu)
print (ktox,uniqu)
def parse_ktotext (self,pars):
kto.mark("100")
kto.parse_ktotext(procpy.test.account_examples.beispiel2)
kto.mark("110")
# print( kto.buchungen )
def parse_ktotext1 (self,pars):
kto = procpy.fibu.kto.Kto("10-1202")
kto.parse_ktotext(procpy.test.account_examples.beispiel2)
kto.write_ktotext(0.00,3,4)
# print( kto.buchungen )
def write_ktotext (self,pars):
kto = procpy.fibu.kto.Kto("10-1202")
kto.parse_ktotext(procpy.test.account_examples.beispiel3)
kto.write_ktotext(0.00,3,4)
kto.write_ktotext(0.00,kto.maxa,kto.maxb)
print(kto.ktotext)
def import_to_db (self,pars):
# os.unlink("kto1.db")
kto = procpy.fibu.kto.Kto("10-1202")
kto.parse_ktotext(procpy.test.account_examples.beispiel3)
dbh = sqlite3.connect("kto1.db")
sync = procpy.fibu.sync.Sync(dbh)
kto.delete_from_db(dbh)
kto.import_to_db(dbh)
dbh.commit()
# print(kto.ktotext)
def vergleich (self,pars):
sync = procpy.fibu.sync.Sync()
sync.find_vergleich(open(pars[0]).read(),open(pars[1]).read())
def import_export (self,pars):
# os.unlink("kto1.db")
kto = procpy.fibu.kto.Kto("10-1202")
kto.parse_ktotext(procpy.test.account_examples.beispiel3)
dbh = sqlite3.connect("kto1.db")
sync = procpy.fibu.sync.Sync(dbh)
kto.delete_from_db(dbh)
kto.import_to_db(dbh)
kto.export_from_db(dbh)
dbh.commit()
kto.write_ktotext(0.00)
kto.write_ktotext(0.00)
kto1 = procpy.fibu.kto.Kto("10-1202-a")
kto1.export_from_db(dbh)
kto1.write_ktotext(0.00)
kto1.write_ktotext(0.00)
print(kto1.ktotext)
# print(kto.ktotext)
def make_addtext (self,pars):
# os.unlink("kto1.db")
kto = procpy.fibu.kto.Kto("10-1202")
kto.mark("100")
kto.parse_ktotext(procpy.test.account_examples.beispiel3)
kto.mark("111")
a = kto.make_addtext(".")
print (a)
# print(kto.ktotext)
def find_ukto_and_interval (self,pars):
kto = procpy.fibu.kto.Kto("10-1202")
kto.find_ukto_and_interval(pars[0])
# kto.find_ukto_and_interval("/home/cgabriel/O.1004__Finance/25/11-1500__KK/_LL.kto")
print (kto.ukto,kto.startdatum,kto.enddatum)
def synctest1 (self,pars):
try:
os.unlink("kto3.db")
except:
pass
dbh = sqlite3.connect("kto3.db")
sync = procpy.fibu.sync.Sync(dbh)
sync.sync1(["x/home/cgabriel/O.1004__Finance/25/10-1202__Sparkasse",
"x/home/cgabriel/O.1004__Finance/25/10-1204__Flessabank",
"/home/cgabriel/O.1004__Finance/25/11-1500__Lohnkonten/AN-swonneberger",
"/home/cgabriel/O.1004__Finance/25/11-1500__Lohnkonten",
"/home/cgabriel/O.1004__Finance/25/11-1500__Lohnkonten/AN-hparfuss",
"x"])
dbh.commit()
def synctest2 (self,pars):
self.mark("A")
try:
os.unlink("kto3.db")
except:
pass
dbh = sqlite3.connect(":memory:")
sync = procpy.fibu.sync.Sync(dbh)
self.mark("B")
sync.sync(["x/home/cgabriel/O.1004__Finance/26/10-1202__Sparkasse",
"/home/cgabriel/O.1004__Finance/26/10-1204__Flessabank",
"x/home/cgabriel/O.1004__Finance/26/11-1500__Lohnkonten/AN-swonneberger",
"/home/cgabriel/O.1004__Finance/26/11-1500__Lohnkonten",
"x/home/cgabriel/O.1004__Finance/26/11-1500__Lohnkonten/AN-hparfuss",
"x"])
self.mark("C")
dbh.commit()
self.mark("D")
def y (self,pars): # <---
if fibu.name == "":
os.system("python3 iey.py")
return()
sync = procpy.fibu.sync.Sync()
# sync.dbh_staticfile = ":memory:"
ktolist = []
if len(pars) == 1:
if os.path.isfile(pars[0]):
ktolist = open(pars[0]).read().split("\n")
elif os.path.isfile("ktolist"):
ktolist = open("ktolist").read().split("\n")
elif pars[0] == ".":
ktolist = [ os.path.abspath(".") ]
elif pars[0] == "u":
ktolist = self.find([])
elif pars[0] == "..":
ktolist = [ os.path.abspath(".."), os.path.abspath(".") ]
elif pars[0] == "*":
ktolist = self.find([])
elif pars[0] == "r":
print("")
ktolist = self.find(["rule.py"]) + [ os.path.abspath(".") ]
# print("\n".join(ktolist))
print("\n*********************************************\n")
else:
dir = os.path.abspath(".")
uktodir = os.path.abspath(pars[0])
if not os.path.isdir( uktodir ):
os.mkdir(uktodir)
# open(uktodir+"/kto.kto","w").write(" ()\n\n")
# dirtext = open(glob.glob(dir+"/*.kto")[0]).read() # jetzt den jeweiligen Kontotext einlesen
# m = re.search(r"^[^\n]+\(([A-Za-z0-9\_\+\-]{6})([A-Za-z0-9\_\+\-]{6})\)",dirtext)
# m = re.search(r"\n==== +(\d\d)-(\d\d)-(\d\d) +([A-Za-z0-9]{8})(\*?) +([A-Za-z0-9]{8})",
# dirtext[max(0,len(dirtext)-500):],flags=re.DOTALL)
# open(uktodir+"/kto.kto","w").write("\n\n==== 10-14-14 newktoxx " + m.group(4) + "\n")
# open(uktodir+"/kto.kto","w").write(" (newktoxx" + m.group(4) + ")\n\n")
ktolist = [ dir, uktodir ]
if ktolist[0] == ktolist[1]:
ktolist = [ ktolist[0] ]
else:
ktolist = [ ktolist[1] ]
elif len(pars) > 1:
ktolist = []
for dir in pars:
ktolist.append( os.path.abspath(dir) )
else:
print("")
ktolist = self.find([]) + [ os.path.abspath(".") ]
print("\n*********************************************\n")
if len(ktolist) == 0:
ktolist = [ os.path.abspath(".") ]
# for o in ktolist:
# print(o)
fehlerliste = sync.sync3(ktolist)
# print("\n".join(ktolist))
self.mark("")
if fehlerliste:
print("CONFLICTS:")
for kto in fehlerliste:
print(kto.dir)
def ya (self,pars): # <---
self.y(["___ALL___"])
def cx (self,pars):
try:
import fibu
fibuname = fibu.name
except:
fibuname = "acc"
akt_kto = os.path.abspath(".")
if len(pars) == 0:
m = re.search("^(.*)[\\\/](.*)$",akt_kto)
if m:
parent_kto = m.group(1)
self.y([parent_kto,akt_kto])
else:
print("WARNING 177")
else:
ukto_dir = akt_kto + "/" + pars[0]
try:
os.mkdir(ukto_dir)
except:
pass
if len(glob.glob(ukto_dir + "/*.kto")) == 0:
ukto = procpy.fibu.kto.Kto("")
ukto.find_ukto_and_interval(ukto_dir)
new_kto_name = fibuname + "-" + ukto.ukto + ".kto"
open(ukto_dir + "/" + fibuname + "-" + ukto.ukto + ".kto","w").write("\n")
print("new kto " + ukto.ukto)
else:
self.y([akt_kto,ukto_dir])
def git (self):
sync = procpy.fibu.sync.Sync(sqlite3.connect(":memory:"))
sync.sync(2)
def kto_id (self,pars):
kto = procpy.fibu.kto.Kto()
ktofile = pars[0] # "/home/cgabriel/O.1004__Finance/26/10-1204__Flessabank"
kto.find_ukto_and_interval(ktofile)
print(kto.kto_id(ktofile),kto.id,kto.parent)
def sync_template (self,pars):
sync = procpy.fibu.sync.Sync(sqlite3.connect(":memory:"))
print( sync.sync_template("/home/cgabriel/O.1004__Finance/26/10-1204__Flessabank.kto","abcdefgh") )
print( sync.sync_template("/home/cgabriel/O.1004__Finance/26/10-1204__Flessabank__klrzhfuj.kto","abcdefgh") )
def sort (self,pars): # <---
sync = procpy.fibu.sync.Sync()
if len(pars) > 1:
sync.sort(pars[0],pars[1])
else:
sync.sort(pars[0], glob.glob("*.kto")[0])
def fq (self,pars): # <---
sync = procpy.fibu.sync.Sync()
sync.find_quittung(pars[0],pars[1],pars[2])
def aq (self,pars): # <---
parser = procpy.fibu.parser.Parser()
datei = "../../../acc.kto"
try:
ktotext = open(datei).read()
except:
ktotext = ""
text = parser.assign_quittungen(pars[0],ktotext,",90-1200,10-1202,10-1203,10-1204,10-1205,")
print(text)
def mv (self,pars): # <---
text = open(pars[0]).read()
text1 = ""
while (0 == 0):
m = re.search(r"^(.*?)fbgs -l +(\S+\.pdf)\s(.*?)\n(\d\d\d\d\d\d\..*?\.pdf)(.*$)",text,re.DOTALL)
if m:
text1 = text1 + "mv " + m.group(2) + " " + m.group(4) + "\n"
text = m.group(1) + m.group(3) + m.group(5)
else:
break
print(text1)
def cp (self,pars): # <---
dirs = glob.glob("*")
for dir in dirs:
if os.path.isdir(dir):
os.system("cp " + pars[0] + " " + dir)
def write_csv (self,pars):
files = ( glob.glob("*/*/*/*/*/*/*/*/*") +
glob.glob("*/*/*/*/*/*/*/*") +
glob.glob("*/*/*/*/*/*/*") +
glob.glob("*/*/*/*/*/*") +
glob.glob("*/*/*/*/*") +
glob.glob("*/*/*/*") +
glob.glob("*/*/*") +
glob.glob("*/*") +
glob.glob("*"))
for file in files:
m = re.search(r"^(.*)\.kto$",file)
if not m:
continue
kto = procpy.fibu.kto.Kto()
kto.ktotext = open(file).read()
text = kto.write_csv()
try:
os.unlink(m.group(1)+".csv")
except:
pass
try:
os.unlink(m.group(1)+".")
except:
pass
try:
pars[0]
except:
open(m.group(1)+".csv","w").write(text)
def write_datev (self,pars):
files = glob.glob("../*")
for file in files:
m = re.search(r"^(.*)[\\\/](.*)\.kto$",file)
if not m:
continue
fileroot = m.group(2)
kto = procpy.fibu.kto.Kto()
kto.ktotext = open(file).read()
text = kto.write_datev(pars[0],pars[1])
for file1 in glob.glob("DTVF_*.*"):
os.unlink(file1)
for jahr in text.keys():
open("DTVF_"+fileroot+"_"+jahr+".csv","w").write(text[jahr])
def auswertung (self,pars): # <---
try:
startdate = pars[0]
enddate = pars[1]
buchh = pars[2]
except:
startdate = pars[0]
enddate = pars[0]
buchh = pars[1]
ausw = procpy.fibu.auswertung.Auswertung(buchh+"0-7000-cgabriel",startdate,enddate,buchh)
ausw.evaluate_kontenrahmen()
journal = ausw.make_journal()
ausw.salden()
text1 = "\n".join(journal) + "\n"
text2 = ""
for zeile in ausw.bilanz:
text2 = text2 + zeile + "\n"
text2 = text2 + ",,,\n"
text2 = text2 + ",,,\n"
text2 = text2 + ",,,\n"
for zeile in ausw.guv:
text2 = text2 + zeile + "\n"
text2 = ""
for zeile in ausw.gesamtkonten:
text2 = text2 + zeile + "\n"
# text2 = text2 + ",,,\n"
#
# for zeile in ausw.gewinn:
# text2 = text2 + zeile + "\n"
#
text2 = text2 + ",,,\n"
text2 = text2 + ",,,\n"
text2 = text2 + ",,,\n"
text2 = text2 + ",,,\n"
for zeile in ausw.einzelkonten:
text2 = text2 + zeile + "\n"
text20 = ""
for zeile in text2.split("\n"):
zeile = zeile.split(",") + ["","",""]
zeile = ("%-10s"%zeile[0]) + ("%-45s"%zeile[1][0:45]) + ("%20s"%zeile[2]) + "\n"
text20 = text20 + re.sub(r"^(.*?) *$","\\1",zeile )
# print(text20)
# text2 = text2 + ",,,\n"
# text2 = text2 + ",,,\n"
# text2 = text2 + ",,,\n"
# text2 = text2 + ",,,\n"
#
# for zeile in ausw.debitoren:
# text2 = text2 + zeile + "\n"
if startdate == enddate:
filename = startdate
else:
filename = startdate + "_" + enddate
text3 = ""
for o in ausw.saldovortrag:
if int(o) > 9999:
gegenkonto = "9008"
else:
gegenkonto = "9000"
text3 = text3 + "01.01." + str(int(startdate)+1) + ";" + re.sub(r"\.",",",ausw.saldovortrag[o]) + ";" + o + ";" + gegenkonto + ";0;Saldovortrag\n"
text4 = "%18.2f" % (ausw.gewinn)
open("B" + buchh + "_"+filename+"_journal.csv","w").write(text1)
open("B" + buchh + "_"+filename+"_bilanz.csv","w").write(text20)
open("B" + buchh + "_"+filename+"_endsalden.csv","w").write(text3)
open("B" + buchh + "_"+filename+"_ergebnis.csv","w").write(filename+text4+"\n")
try:
os.unlink("B" + buchh + "_"+filename+"_saldenbilanz.csv")
except:
pass
try:
text4 = open("B" + buchh + "_"+ str(int(filename)-1)+"_endsalden.csv").read()
except:
return()
for zeile in text1.split("\n"):
if zeile[6:10] == filename:
text4 = text4 + zeile + "\n"
open("B" + buchh + "_"+filename+"_saldenjournal.csv","w").write(text4)
def find (self,pars):
paths = ['*/*/*/*/*/*/*/*/*/*/',
'*/*/*/*/*/*/*/*/*/',
'*/*/*/*/*/*/*/*/',
'*/*/*/*/*/*/*/',
'*/*/*/*/*/*/',
'*/*/*/*/*/',
'*/*/*/*/',
'*/*/*/',
'*/*/',
'*/']
ktolist = []
for path in paths:
for ktodir in glob.glob(path):
if "EXCLUDE" in ktodir.upper():
continue
if len(glob.glob(ktodir+"/*EXCLUDE*")) > 0:
continue
if len(glob.glob(ktodir+"/*exclude*")) > 0:
continue
if re.search(r"SKIP",ktodir,re.IGNORECASE):
continue
if "__pycache__" in ktodir:
continue
if len(pars) > 0 and len(glob.glob(ktodir+"/"+pars[0])) == 0:
continue
ktolist.append(os.path.abspath(ktodir))
# ktodirs = {}
# for path in paths:
# for ktofile in glob.glob(path):
# m = re.search(r"^(.*)[\\\/].+.kto",os.path.abspath(ktofile))
# if m.group(1) in ktodirs:
# ktodirs[m.group(1)] = 0
# else:
# ktodirs[m.group(1)] = 1
#
#
# for o in ktodirs:
# if ktodirs[o] == 1:
# ktolist.append(o)
#
ktolist.sort()
# for o in ktolist:
# print(o)
return(ktolist)
def sync3 (self,kto):
# dbh = sqlite3.connect("test5.db")
# dbh = sqlite3.connect("test3.db")
sync = procpy.fibu.sync.Sync()
print(sync.common_string(["abcd","abce","ab/U","a/uiu"]))
sync.sync3(".")
def nex (self,pars):
maxlen = pars[0]
pointer = []
zaehler = 1
while (0 == 0):
pointer = procpy.fibu.parser.Parser().next_pointer(pointer,int(maxlen))
if not pointer:
break
print(zaehler,pointer)
zaehler = zaehler + 1
def read_datev (self,pars):
text = open(pars[0]).read()
text1 = ""
m = re.search(r"^(.*?)\;(\d\d\d\d)(\d\d\d\d)\;",text)
if m:
jahr = m.group(2)
else:
print("Jahr nicht gefunden")
return()
for zeile in text.split("\n"):
zeile1 = re.sub(r'"','',zeile,99999999).split(";")
if len(zeile1) < 15:
continue
datum = jahr + zeile1[9][2:4] + zeile1[9][0:2]
betrag = re.sub(r",",".",zeile1[0],99)
try:
ktoa = "-" + ("%04u" % int(zeile1[7]))
except:
continue
ktob = "-" + ("%04u" % int(zeile1[6]))
remark = re.sub(r"^ *(.*) .*$","\\1",zeile1[13])
if remark == "":
remark = "x"
buchung = datum + " " + ("%13.2f" % float(betrag)) + " " + ktoa + " " + ktob + " 0.00 " + remark
text1 = text1 + buchung + "\n"
print(text1)
return(text1)
def l (self,pars):
sync = procpy.fibu.sync.Sync()
ktofile = glob.glob("../0000_9999/*.kto")
sync.liqui(pars[0],ktofile,pars[1])
def d (self,pars):
main_dir = os.path.abspath( re.sub(r"^(.*)[\\\/](.*)$","\\1",fibu.__file__) )
paths = [main_dir + '/*/*/*/*/*/*/*/*/*/*/__cache__.db',
main_dir + '/*/*/*/*/*/*/*/*/*/__cache__.db',
main_dir + '/*/*/*/*/*/*/*/*/__cache__.db',
main_dir + '/*/*/*/*/*/*/*/__cache__.db',
main_dir + '/*/*/*/*/*/*/__cache__.db',
main_dir + '/*/*/*/*/*/__cache__.db',
main_dir + '/*/*/*/*/__cache__.db',
main_dir + '/*/*/*/__cache__.db',
main_dir + '/*/*/__cache__.db',
main_dir + '/*/__cache__.db',
main_dir + '/__cache__.db' ]
ktolist = []
for path in paths:
for file in glob.glob(path):
os.unlink(file)
def sy (self,pars):
fibu = procpy.fibu.fibu1.Fibu1()
if len(pars) > 0:
fibu.sync5(".",pars[0])
else:
fibu.sync5(".")
#**************************************************************************
if __name__ == "__main__":
Kto(*tuple(sys.argv[1:]))