From a52388e1a55bb973c401350d9fb4633ef185ee61 Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Wed, 2 Jun 2021 21:40:23 +0200 Subject: initial commit to add display ubo feature --- db_creation.py | 50 ++++++++++++++++++++++---- justice_build.py | 2 +- models.py | 15 +++++++- templates/extract-actual.html | 84 +++++++++++++++---------------------------- templates/extract.html | 50 +++++++++++++------------- update_db.py | 26 ++++++++++++++ 6 files changed, 136 insertions(+), 91 deletions(-) diff --git a/db_creation.py b/db_creation.py index a8fefe7..55e7f32 100644 --- a/db_creation.py +++ b/db_creation.py @@ -94,7 +94,7 @@ def create_tables(conn): "clenstvi_od" DATE, "clenstvi_do" DATE, "funkce" TEXT, - FOREIGN KEY("adresa_id") REFERENCES "adresy"("id"), + FOREIGN KEY("adresa_id") REFERENCES "adresy_v2"("id"), FOREIGN KEY("dozorci_rada_id") REFERENCES "dozorci_rada_relation"("id"), FOREIGN KEY("osoba_id") REFERENCES "fyzicke_osoby"("id"), PRIMARY KEY("id" AUTOINCREMENT) @@ -138,7 +138,7 @@ def create_tables(conn): "akcionar_po_id" INTEGER, "akcionar_fo_id" INTEGER, "adresa_id" INTEGER, - FOREIGN KEY("adresa_id") REFERENCES "adresy"("id"), + FOREIGN KEY("adresa_id") REFERENCES "adresy_v2"("id"), FOREIGN KEY("company_id") REFERENCES "companies"("id"), FOREIGN KEY("akcionar_po_id") REFERENCES "pravnicke_osoby"("id"), FOREIGN KEY("akcionar_fo_id") REFERENCES "fyzicke_osoby"("id"), @@ -292,7 +292,7 @@ def create_tables(conn): "prokurista_fo_id" INTEGER, "adresa_id" INTEGER, "text_prokurista" TEXT, - FOREIGN KEY("adresa_id") REFERENCES "adresy"("id"), + FOREIGN KEY("adresa_id") REFERENCES "adresy_v2"("id"), FOREIGN KEY("prokurista_fo_id") REFERENCES "fyzicke_osoby"("id"), FOREIGN KEY("company_id") REFERENCES "companies"("id"), PRIMARY KEY("id" AUTOINCREMENT) @@ -318,7 +318,7 @@ def create_tables(conn): "vymaz_datum" DATE, "adresa_id" INTEGER, "text_spolecnik" TEXT, - FOREIGN KEY("adresa_id") REFERENCES "adresy"("id"), + FOREIGN KEY("adresa_id") REFERENCES "adresy_v2"("id"), PRIMARY KEY("id" AUTOINCREMENT), FOREIGN KEY("spolecnik_fo_id") REFERENCES "fyzicke_osoby"("id"), FOREIGN KEY("company_id") REFERENCES "companies"("id") @@ -339,7 +339,7 @@ def create_tables(conn): "funkce" TEXT, FOREIGN KEY("osoba_id") REFERENCES "fyzicke_osoby"("id"), FOREIGN KEY("statutarni_organ_id") REFERENCES "statutarni_organ_relation"("id"), - FOREIGN KEY("adresa_id") REFERENCES "adresy"("id"), + FOREIGN KEY("adresa_id") REFERENCES "adresy_v2"("id"), PRIMARY KEY("id" AUTOINCREMENT) ); """ @@ -360,6 +360,28 @@ def create_tables(conn): PRIMARY KEY("id" AUTOINCREMENT) ); """ + ubo = """ CREATE TABLE "ubo" ( + "id" INTEGER NOT NULL UNIQUE, + "company_id" INTEGER NOT NULL, + "UBO_id" INTEGER NOT NULL, + "zapis_datum" DATE, + "vymaz_datum" DATE, + "UBO_valid" TEXT, + "spravce" TEXT, + "T_TBC" TEXT, + "postaveni_jinak" TEXT, + "postaveni" TEXT, + "primaUcast" TEXT, + "primaUcastPodil" TEXT, + "rozdeleniProstredku" TEXT, + "slovni_vyjadreni" TEXT, + "urcenPoziciVeStatOrg" TEXT, + "email" TEXT, + FOREIGN KEY("company_id") REFERENCES "companies"("id"), + FOREIGN KEY("UBO_id") REFERENCES "fyzicke_osoby"("id"), + PRIMARY KEY("id" AUTOINCREMENT) + ); """ + ucel = """ CREATE TABLE "ucel" ( "id" INTEGER NOT NULL, "ucel" TEXT NOT NULL UNIQUE, @@ -422,7 +444,7 @@ def create_tables(conn): list_of_tables = [companies, adresy_v2, akcie, dr_relation, dr_organ_clen_relation, druhy_podilu, fyzicke_osoby, insolvency_events, jediny_akcionar, konkurz_events, nazvy, ostatni_skutecnosti, pocty_clenu_DR, pocty_clenu_organu, podily, pravni_formy, pravni_formy_relation, pravnicke_osoby, predmety_cinnosti, predmety_cinnosti_relation, prdmety_podnikani, predmety_podnikani_relation, - prokura_common_texts, prokuriste, sidlo_relation, spolecnici, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, + prokura_common_texts, prokuriste, sidlo_relation, spolecnici, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, ubo, ucel, ucel_relation, zakladni_kapital, zapis_soudy, zpusoby_jednani, zpusoby_jednani_relation] for elem in list_of_tables: try: @@ -689,6 +711,20 @@ def create_indices(conn): "company_id" ); """ + + ubo1 = """ CREATE INDEX "index ubo1" ON "ubo" ( + "id" +); """ + + ubo2 = """ CREATE INDEX "index ubo2" ON "ubo" ( + "company_id" +); """ + + ubo3 = """ CREATE INDEX "index ubo3" ON "ubo" ( + "UBO_id" +); """ + + ucel1 = """ CREATE INDEX "index ucel1" ON "ucel" ( "ucel" ); """ @@ -767,7 +803,7 @@ def create_indices(conn): prokuriste2, prokuriste3, prokuriste4, sidlo_relation1, sidlo_relation_2, sidlo_relation_3, soudni_zapis1, soudni_zapis2, spolecnici1, spolecnici2, spolecnici3, spolecnici4, spolecnici5, statutarni_organy, statutarni_organy_relation1, statutarni_organy_relation2, statutarni_organy_relation_3, statutarni_organy_relation_4, zakladni_kapital1, zakladni_kapital2, zpusob_jednani, zpusob_jednani_relation1, zpusob_jednani_relation2, - zpusob_jednani_relation3, pravnicke_osoby1, pravnicke_osoby2, pravnicke_osoby3, pravnicke_osoby4, statutarni_organy_relation_5, fyzicke_osoby1, ucel1, ucel2, ucel_relation1, ucel_relation2, ucel_relation3] + zpusob_jednani_relation3, pravnicke_osoby1, pravnicke_osoby2, pravnicke_osoby3, pravnicke_osoby4, statutarni_organy_relation_5, fyzicke_osoby1, ubo1, ubo2, ubo3, ucel1, ucel2, ucel_relation1, ucel_relation2, ucel_relation3] i = 0 for elem in list_of_indices: i += 1 diff --git a/justice_build.py b/justice_build.py index 287e3e6..9a48f55 100644 --- a/justice_build.py +++ b/justice_build.py @@ -13,5 +13,5 @@ def main(): for valid_file in valid_files: modified_file_name = os.path.join(str(os.getcwd()), "data", valid_file + ".xml") update_DB(modified_file_name, DB_name) - + main() diff --git a/models.py b/models.py index 797a5b1..7263177 100644 --- a/models.py +++ b/models.py @@ -300,6 +300,17 @@ class Spolecnici_Association(db.Model): podily = db.relationship("Podily_Association") company = db.relationship("Company") +class Ubo(db.Model): + __tablename__ = "ubo" + id = db.Column(db.Integer, primary_key=True) + company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) + UBO_id = db.Column(db.Integer, db.ForeignKey('fyzicke_osoby.id')) + zapis_datum = db.Column(MyType) + vymaz_datum = db.Column(MyType) + slovni_vyjadreni = db.Column(db.String) + jmeno = db.relationship("Fyzicka_Osoba") + company = db.relationship("Company") + class Prokurista_Association(db.Model): __tablename__ = "prokuriste" id = db.Column(db.Integer, primary_key=True) @@ -397,6 +408,7 @@ class Company(db.Model): prokura_common_text = db.relationship("Prokura_Common_Text_Association") jediny_akcionar = db.relationship("Jediny_Akcionar_Association") sidlo_text = db.relationship("Sidlo_Association") + ubo = db.relationship("Ubo") def current_legal_form_text(self): for elem in self.pravni_forma_text: @@ -715,7 +727,8 @@ class Akcie(db.Model): elif self.akcie_podoba == "IMOBILIZOVANA": joined_share_descr += "v imobilizované podobě " - joined_share_descr += "ve jmenovité hodnotě " + self.akcie_hodnota_value + if self.akcie_hodnota_value != "0": + joined_share_descr += "ve jmenovité hodnotě " + self.akcie_hodnota_value if self.akcie_hodnota_typ == "KORUNY": joined_share_descr += "Kč" diff --git a/templates/extract-actual.html b/templates/extract-actual.html index 6bf6087..a1f0241 100644 --- a/templates/extract-actual.html +++ b/templates/extract-actual.html @@ -56,6 +56,13 @@ {% endif %} {% endfor %} +{% set ubo_notes = [] %} +{% for i in range (row.ubo|length) %} + {% if row.ubo[i].vymaz_datum == 0 %} + {% set ubo_notes = ubo_notes.append(row.ubo[i]) %} + {% endif %} +{% endfor %} + {% set shares_notes = [] %} {% for i in range (row.akcie|length) %} {% if row.akcie[i].vymaz_datum == 0 %} @@ -193,33 +200,9 @@ {% if zakladni_kapital_notes|length > 0 %} - {% if zakladni_kapital_notes[0].vklad_typ == "KORUNY" %} - {% set vklad_typ_symbol = "Kč" %} - {% set vklad_typ_description = zakladni_kapital_notes[0].vklad_hodnota %} - {% elif zakladni_kapital_notes[0].vklad_typ == "EURA" %} - {% set vklad_typ_symbol = "euro" %} - {% set vklad_typ_description = zakladni_kapital_notes[0].vklad_hodnota %} - {% else %} - {% set vklad_typ_symbol = "" %} - {% set vklad_typ_description = zakladni_kapital_notes[0].vklad_hodnota %} - {% endif %} - - {% if zakladni_kapital_notes[0].splaceni_typ == "KORUNY" %} - {% set splaceni_typ_symbol = "Kč" %} - {% set splaceni_typ_description = zakladni_kapital_notes[0].splaceni_hodnota %} - {% elif zakladni_kapital_notes[0].splaceni_typ == "PROCENTA" %} - {% set splaceni_typ_symbol = "%" %} - {% set splaceni_typ_description = zakladni_kapital_notes[0].splaceni_hodnota %} - {% elif zakladni_kapital_notes[0].splaceni_typ == "EURA" %} - {% set splaceni_typ_symbol = "euro" %} - {% set splaceni_typ_description = zakladni_kapital_notes[0].splaceni_hodnota %} - {% else %} - {% set splaceni_typ_symbol = "" %} - {% set splaceni_typ_description = zakladni_kapital_notes[0].splaceni_hodnota %} - {% endif %} Základní kapitál: - {{ underlne_style_open|safe }} {{ vklad_typ_description }} {{ vklad_typ_symbol }} {% if splaceni_typ_description != "0" %}
Splaceno: {{ splaceni_typ_description }} {{ splaceni_typ_symbol }} {% endif %} {{ underlne_style_close|safe }} + {% for elem in zakladni_kapital_notes[0].my_rep() %} {{elem}}
{% endfor %} {% endif %} @@ -406,37 +389,11 @@ {% for k in range (spolecnik_podily|length) %} - Podíl: - - {% if spolecnik_podily[k].vklad_typ == "KORUNY" %} - {% set vklad_typ_string = "Kč" %} - {% elif spolecnik_podily[k].vklad_typ == "EURA" %} - {% set vklad_typ_string = "Euro" %} - {% else %} - {% set vklad_typ_string = "" %} - {% endif %} - - - {% if spolecnik_podily[k].splaceni_typ == "KORUNY" %} - {% set splaceni_typ_string = "Kč" %} - {% elif spolecnik_podily[k].splaceni_typ == "PROCENTA" %} - {% set splaceni_typ_string = "%" %} - {% elif spolecnik_podily[k].splaceni_typ == "EURA" %} - {% set splaceni_typ_string = "Euro" %} - {% else %} - {% set splaceni_typ_string = "" %} - {% endif %} - - - {% if spolecnik_podily[k].souhrn_typ == "PROCENTA" %} - {% set souhrn_typ_string = "%" %} - {% else %} - {% set souhrn_typ_string = "" %} - {% endif %} - Vklad: {{ spolecnik_podily[k].vklad_text }} {{ vklad_typ_string }}
- Splaceno: {{ spolecnik_podily[k].splaceni_text }} {{ splaceni_typ_string }}
- {% if spolecnik_podily[k].souhrn_text != "0"%}Podíl: {{ spolecnik_podily[k].souhrn_text }} {{ souhrn_typ_string }}{% endif %} - {% if spolecnik_podily[k].druh_podilu.druh_podilu != "0" %}
Druh podílu: {{ spolecnik_podily[k].druh_podilu.druh_podilu }}{% endif %} + Podíl: + + {% for elem in spolecnik_podily[k].my_rep() %} + {{ elem }}
+ {% endfor %} {% endfor %} @@ -444,6 +401,21 @@ {% endif %} + + {% if ubo_notes|length > 0 %} + + Konečný vlastník: + + + {% for i in range (ubo_notes|length) %} + + + {{ubo_notes[i].jmeno }}
{{ubo_notes[i].jmeno.adresa }} {% if ubo_notes[i].slovni_vyjadreni != "0" %}
{{ ubo_notes[i].slovni_vyjadreni }}
{% endif %} + + {% endfor %} + {% endif %} + + {% if shares_notes|length > 0 %} {% for i in range (shares_notes|length) %} diff --git a/templates/extract.html b/templates/extract.html index 0c4efd0..6ff31de 100644 --- a/templates/extract.html +++ b/templates/extract.html @@ -137,32 +137,6 @@ {% set underlne_style_close = "" %} {% endif %} - - {% if row.zakladni_kapital[i].vklad_typ == "KORUNY" %} - {% set vklad_typ_symbol = "Kč" %} - {% set vklad_typ_description = row.zakladni_kapital[i].vklad_hodnota %} - {% elif row.zakladni_kapital[i].vklad_typ == "EURA" %} - {% set vklad_typ_symbol = "euro" %} - {% set vklad_typ_description = row.zakladni_kapital[i].vklad_hodnota %} - {% else %} - {% set vklad_typ_symbol = "" %} - {% set vklad_typ_description = row.zakladni_kapital[i].vklad_hodnota %} - {% endif %} - - {% if row.zakladni_kapital[i].splaceni_typ == "KORUNY" %} - {% set splaceni_typ_symbol = "Kč" %} - {% set splaceni_typ_description = row.zakladni_kapital[i].splaceni_hodnota %} - {% elif row.zakladni_kapital[i].splaceni_typ == "PROCENTA" %} - {% set splaceni_typ_symbol = "%" %} - {% set splaceni_typ_description = row.zakladni_kapital[i].splaceni_hodnota %} - {% elif row.zakladni_kapital[i].splaceni_typ == "EURA" %} - {% set splaceni_typ_symbol = "euro" %} - {% set splaceni_typ_description = row.zakladni_kapital[i].splaceni_hodnota %} - {% else %} - {% set splaceni_typ_symbol = "" %} - {% set splaceni_typ_description = row.zakladni_kapital[i].splaceni_hodnota %} - {% endif %} - {{ underlne_style_open|safe }} {% for elem in row.zakladni_kapital[i].my_rep() %} {{elem}}
{% endfor %} {{ underlne_style_close|safe }} {{ underlne_style_open|safe }} Zapsáno: {{ row.zakladni_kapital[i].zapis_datum }} {% if row.zakladni_kapital[i].vymaz_datum != 0 %}
Vymazáno: {{ row.zakladni_kapital[i].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }} @@ -498,6 +472,30 @@ {% endif %} + + {% if row.ubo|length > 0 %} + + Konečný vlastník: + + + + {% for i in range (row.ubo|length) %} + + + {% if row.ubo[i].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + {{ underlne_style_open|safe }} {{row.ubo[i].jmeno }}
{{ubo_notes[i].jmeno.adresa }} {% if row.ubo[i].slovni_vyjadreni != "0" %}
{{row.ubo[i].slovni_vyjadreni }}
{% endif %} {{ underlne_style_close|safe }} + {{ underlne_style_open|safe }} Zapsáno: {{ row.ubo[i].zapis_datum }} {% if row.ubo[i].vymaz_datum != 0 %}
Vymazáno: {{ row.ubo[i].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }} + + {% endfor %} + {% endif %} + + {% if row.akcie|length > 0 %} {% for i in range (row.akcie|length) %} diff --git a/update_db.py b/update_db.py index 6e51e78..6c50b70 100644 --- a/update_db.py +++ b/update_db.py @@ -111,6 +111,9 @@ def find_other_properties(c, ICO, element, conn, primary_sql_key): find_insolvency(c, ICO, elem2, conn, primary_sql_key) elif udajTyp_name == "KONKURS_SEKCE": find_konkurz(c, ICO, elem2, conn, primary_sql_key) + elif udajTyp_name == "SKUTECNY_MAJITEL_SEKCE": + find_UBO(c, ICO, elem2, conn, primary_sql_key, element) + except: pass @@ -184,6 +187,29 @@ def find_statutar(c, ICO, elem2, conn, primary_sql_key, element): except Exception as f: print(f) +def find_UBO(c, ICO, elem2, conn, primary_sql_key, element): + try: + my_iter = elem2.findall("podudaje/Udaj") + for elem in my_iter: + zapis_datum = str(get_prop(elem, "zapisDatum")) + vymaz_datum = str(get_prop(elem, "vymazDatum")) + UBO_valid = str(get_prop(elem, "hodnotaUdaje/valid")) + spravce = str(get_prop(elem, "hodnotaUdaje/spravce")) + T_TBC = str(get_prop(elem, "hodnotaUdaje/T")) + postaveni_jinak = str(get_prop(elem, "hodnotaUdaje/postaveniJinak")) + postaveni = str(get_prop(elem, "hodnotaUdaje/postaveni")) + primaUcast = str(get_prop(elem, "hodnotaUdaje/PrimaUcast")) + primaUcastPodil = str(get_prop(elem, "hodnotaUdaje/primaUcastPodil")) + rozdeleniProstredku = str(get_prop(elem, "hodnotaUdaje/PrimaUcast")) + slovni_vyjadreni = str(get_prop(elem, "hodnotaUdaje/slovniVyjadreni")) + urcenPoziciVeStatOrg = str(get_prop(elem, "hodnotaUdaje/urcenPoziciVeStatOrg")) + email = str(get_prop(elem, "hodnotaUdaje/email")) + adresa_id = find_sidlo(c, elem, primary_sql_key) + UBO_id = find_fyzicka_osoba(c, ICO, elem, conn, primary_sql_key, element, adresa_id) + c.execute("INSERT INTO ubo (company_id, UBO_id, zapis_datum, vymaz_datum, UBO_valid, spravce, T_TBC, postaveni_jinak, postaveni, primaUcast, primaUcastPodil, rozdeleniProstredku, slovni_vyjadreni, urcenPoziciVeStatOrg, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (primary_sql_key, UBO_id, zapis_datum, vymaz_datum, UBO_valid, spravce, T_TBC, postaveni_jinak, postaveni, primaUcast, primaUcastPodil, rozdeleniProstredku, slovni_vyjadreni, urcenPoziciVeStatOrg, email,)) + except Exception as f: + print(f) + def find_spolecnik(c, ICO, elem2, conn, primary_sql_key, element): try: my_iter = elem2.findall("podudaje/Udaj") -- cgit From cc86be247b6e10ccc0d21771c8d3583eb501b54e Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Thu, 10 Jun 2021 23:36:54 +0200 Subject: updating the ubo feature --- db_creation.py | 27 +++++++++++++---------- justice_build.py | 8 +++---- main.py | 50 +++++++++++++++++++++++++++++++++++++++--- models.py | 11 +++++++--- templates/extract-actual.html | 5 ++++- templates/extract.html | 4 +++- templates/most_common_ubo.html | 24 ++++++++++++++++++++ templates/results_persons.html | 18 +++++++++++++++ templates/trivia.html | 1 + update_db.py | 22 +++++++++---------- 10 files changed, 134 insertions(+), 36 deletions(-) create mode 100644 templates/most_common_ubo.html diff --git a/db_creation.py b/db_creation.py index 55e7f32..cf9d504 100644 --- a/db_creation.py +++ b/db_creation.py @@ -363,22 +363,22 @@ def create_tables(conn): ubo = """ CREATE TABLE "ubo" ( "id" INTEGER NOT NULL UNIQUE, "company_id" INTEGER NOT NULL, - "UBO_id" INTEGER NOT NULL, + "UBO_id" INTEGER NOT NULL, + "adresa_id" INTEGER, "zapis_datum" DATE, "vymaz_datum" DATE, - "UBO_valid" TEXT, - "spravce" TEXT, - "T_TBC" TEXT, - "postaveni_jinak" TEXT, - "postaveni" TEXT, - "primaUcast" TEXT, - "primaUcastPodil" TEXT, - "rozdeleniProstredku" TEXT, - "slovni_vyjadreni" TEXT, - "urcenPoziciVeStatOrg" TEXT, - "email" TEXT, + "postaveni" TEXT, + "koncovyPrijemceText" TEXT, + "skutecnymMajitelemOd" TEXT, + "vlastniPodilNaProspechu" TEXT, + "vlastniPodilNaProspechu_typ" TEXT, + "vlastniPodilNaProspechu_textValue" TEXT, + "vlastniPodilNaHlasovani" TEXT, + "vlastniPodilNaHlasovani_typ" TEXT, + "vlastniPodilNaHlasovani_value" TEXT, FOREIGN KEY("company_id") REFERENCES "companies"("id"), FOREIGN KEY("UBO_id") REFERENCES "fyzicke_osoby"("id"), + FOREIGN KEY("adresa_id") REFERENCES "adresy_v2"("id"), PRIMARY KEY("id" AUTOINCREMENT) ); """ @@ -724,6 +724,9 @@ def create_indices(conn): "UBO_id" ); """ + ubo4 = """ CREATE INDEX "index ubo4" ON "ubo" ( + "UBO_adresa_id" +); """ ucel1 = """ CREATE INDEX "index ucel1" ON "ucel" ( "ucel" diff --git a/justice_build.py b/justice_build.py index 9a48f55..380d32b 100644 --- a/justice_build.py +++ b/justice_build.py @@ -11,7 +11,7 @@ def main(): for valid_file in valid_files: download_data(valid_file) for valid_file in valid_files: - modified_file_name = os.path.join(str(os.getcwd()), "data", valid_file + ".xml") - update_DB(modified_file_name, DB_name) - -main() + modified_file_name = os.path.join(str(os.getcwd()), "data", valid_file + ".xml") + update_DB(modified_file_name, DB_name) + +main() \ No newline at end of file diff --git a/main.py b/main.py index 5d43f97..deb9d51 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ from app import app from forms import GeneralSearchForm, JusticeSearchForm, CompanyForm, PersonSearchForm, EntitySearchForm from flask import flash, render_template, request, redirect -from models import Company, Insolvency_Events, Konkurz_Events, Predmet_Podnikani, Predmety_Podnikani_Association, Predmet_Cinnosti, Predmety_Cinnosti_Association +from models import Company, Insolvency_Events, Konkurz_Events, Predmet_Podnikani, Predmety_Podnikani_Association, Predmet_Cinnosti, Predmety_Cinnosti_Association, Ubo from models import Zakladni_Kapital, Akcie, Nazvy, Sidlo, Sidlo_Association, Pravni_Forma_Association_v2, Pravni_Formy, Statutarni_Organ_Association, Statutarni_Organy, Pocty_Clenu_Organu from models import Zpusob_Jednani_Association, Zpusob_Jednani, Statutarni_Organ_Clen_Association, Fyzicka_Osoba, Spolecnici_Association, Podily_Association, Druhy_Podilu, Pravnicka_Osoba from models import Prokurista_Association, Dozorci_Rada_Clen_Association, Jediny_Akcionar_Association, Prokura_Common_Text_Association, Soudni_Zapisy, Ucel, Ucel_Association @@ -425,6 +425,30 @@ def search_results_sidlo(adresa_id): table.border = True return render_template("results2.html", results=results, form=search, show_form = False) + +# UBO reults +@app.route('/results-ubo-', methods=['GET', 'POST']) +def search_results_ubo(ubo_id): + search = JusticeSearchForm(request.form) + + results = [] + qry = Company.query + qry = qry.join(Ubo, Company.ubo) + qry = qry.filter(Ubo.vymaz_datum == 0) + qry = qry.join(Fyzicka_Osoba, Ubo.jmeno) + qry = qry.filter(Fyzicka_Osoba.id == ubo_id) + results = qry.all() + + if not results: + flash('No results found!') + return redirect('/') + + else: + table = Results(results) + table.border = True + return render_template("results2.html", results=results, form=search, show_form = False) + + @app.route("/", methods=['GET', 'POST']) def extract(ico): qry = Company.query @@ -457,7 +481,12 @@ def find_oldest_companies(): @app.route("/most_common_purpose", methods=['GET', 'POST']) def find_most_common_purpose(): most_common_purpose = count_common_purpose() - return render_template("most_common_purpose.html", most_common_purpose = most_common_purpose) + return render_template("most_common_purpose.html", most_common_purpose = most_common_purpose) + +@app.route("/most_common_ubo", methods=['GET', 'POST']) +def find_most_common_ubo(): + most_common_ubo = count_common_ubo() + return render_template("most_common_ubo.html", most_common_ubo = most_common_ubo) @app.route("/most_common_business", methods=['GET', 'POST']) def find_most_common_business(): @@ -537,7 +566,22 @@ def count_common_purpose(): selected_purpose = qry.all() addresses_frequency.append((selected_purpose[0].ucel, elem[1])) conn.close() - return addresses_frequency + return addresses_frequency + +def count_common_ubo(): + engine = create_engine('sqlite:///justice.db', echo=True) + conn = engine.connect() + text_instruction = text("SELECT UBO_id, COUNT(`UBO_id`) AS `value_occurrence` FROM ubo INNER JOIN fyzicke_osoby ON ubo.UBO_id=fyzicke_osoby.id WHERE vymaz_datum = 0 GROUP BY `UBO_id` ORDER BY `value_occurrence` DESC LIMIT 100;") + result = conn.execute(text_instruction).fetchall() + ubo_frequency = [] + for elem in result: + qry = Fyzicka_Osoba.query + qry = qry.filter(Fyzicka_Osoba.id == elem[0]) + selected_ubo = qry.all() + # ubo_frequency.append((selected_ubo[0].jmeno + " " + selected_ubo[0].prijmeni, elem[1], elem[0])) + ubo_frequency.append((selected_ubo[0], elem[1], elem[0])) + conn.close() + return ubo_frequency def count_common_degrees(method): engine = create_engine('sqlite:///justice.db', echo=True) diff --git a/models.py b/models.py index 7263177..6c1b84c 100644 --- a/models.py +++ b/models.py @@ -245,6 +245,7 @@ class Fyzicka_Osoba(db.Model): prokurista_association = db.relationship("Prokurista_Association") sole_shareholder_association = db.relationship("Jediny_Akcionar_Association") supervisory_board_member_association = db.relationship("Dozorci_Rada_Clen_Association") + ubo_association = db.relationship("Ubo") adresa = db.relationship("Adresy_v2") def get_name(self): @@ -304,10 +305,14 @@ class Ubo(db.Model): __tablename__ = "ubo" id = db.Column(db.Integer, primary_key=True) company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) - UBO_id = db.Column(db.Integer, db.ForeignKey('fyzicke_osoby.id')) zapis_datum = db.Column(MyType) vymaz_datum = db.Column(MyType) - slovni_vyjadreni = db.Column(db.String) + UBO_id = db.Column(db.Integer, db.ForeignKey('fyzicke_osoby.id')) + adresa_id = db.Column(db.Integer, db.ForeignKey('adresy_v2.id')) + adresa = db.relationship("Adresy_v2") + postaveni = db.Column(db.String) + koncovyPrijemceText = db.Column(db.String) + skutecnymMajitelemOd = db.Column(MyType) jmeno = db.relationship("Fyzicka_Osoba") company = db.relationship("Company") @@ -458,7 +463,7 @@ class Adresy_v2(db.Model): joined_address += self.psc + " " if self.obec != "0" and self.obec != None: joined_address += self.obec - if (self.stat != "Česká republika") and (self.stat != "Česká republika - neztotožněno"): + if (self.stat != "Česká republika") and (self.stat != "Česká republika - neztotožněno") and (self.stat != "0"): joined_address += ", " + self.stat return joined_address diff --git a/templates/extract-actual.html b/templates/extract-actual.html index a1f0241..6bc51fe 100644 --- a/templates/extract-actual.html +++ b/templates/extract-actual.html @@ -410,7 +410,10 @@ {% for i in range (ubo_notes|length) %} - {{ubo_notes[i].jmeno }}
{{ubo_notes[i].jmeno.adresa }} {% if ubo_notes[i].slovni_vyjadreni != "0" %}
{{ ubo_notes[i].slovni_vyjadreni }}
{% endif %} + {{ubo_notes[i].jmeno }} {{ubo_notes[i].jmeno.adresa }} + {% if ubo_notes[i].postaveni != "0" %}
{{ ubo_notes[i].postaveni }}{% endif %} + {% if ubo_notes[i].koncovyPrijemceText != "0" %}
{{ ubo_notes[i].koncovyPrijemceText }}{% endif %} + {% endfor %} {% endif %} diff --git a/templates/extract.html b/templates/extract.html index 6ff31de..17bdd73 100644 --- a/templates/extract.html +++ b/templates/extract.html @@ -489,7 +489,9 @@ {% set underlne_style_open = "" %} {% set underlne_style_close = "" %} {% endif %} - {{ underlne_style_open|safe }} {{row.ubo[i].jmeno }}
{{ubo_notes[i].jmeno.adresa }} {% if row.ubo[i].slovni_vyjadreni != "0" %}
{{row.ubo[i].slovni_vyjadreni }}
{% endif %} {{ underlne_style_close|safe }} + {{ underlne_style_open|safe }} {{row.ubo[i].jmeno }} {{row.ubo[i].jmeno.adresa}} + {% if row.ubo[i].postaveni != "0" %}
{{row.ubo[i].postaveni }}{% endif %} + {% if row.ubo[i].koncovyPrijemceText != "0" %}
{{row.ubo[i].koncovyPrijemceText }}{% endif %} {{ underlne_style_close|safe }} {{ underlne_style_open|safe }} Zapsáno: {{ row.ubo[i].zapis_datum }} {% if row.ubo[i].vymaz_datum != 0 %}
Vymazáno: {{ row.ubo[i].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }} {% endfor %} diff --git a/templates/most_common_ubo.html b/templates/most_common_ubo.html new file mode 100644 index 0000000..318d52f --- /dev/null +++ b/templates/most_common_ubo.html @@ -0,0 +1,24 @@ +{% include 'header.html' %} + +

Nejčastější koneční vlastníci:

+ + + + + + + + + + + {% for i in range (most_common_ubo|length) %} + + + + + + {% endfor %} + +
#JménoPočet společností
{{ i + 1 }}{{ most_common_ubo[i][0] }}{{ most_common_ubo[i][1] }}
+ +{% include 'footer.html' %} \ No newline at end of file diff --git a/templates/results_persons.html b/templates/results_persons.html index 65fac98..fc90e08 100644 --- a/templates/results_persons.html +++ b/templates/results_persons.html @@ -97,6 +97,24 @@ {% endif %} {% endfor %} + {% for elem in row.ubo_association %} + {% if selection_method == "actual_results" and elem.vymaz_datum != 0 %} + {% set xxx = [] %} + {% else %} + {% set my_dict = {} %} + {% set x = my_dict.__setitem__("adresa", elem.adresa) %} + {% set x = my_dict.__setitem__("funkce", "konečný vlastník") %} + {% set x = my_dict.__setitem__("nazev", elem.company.nazev) %} + {% set x = my_dict.__setitem__("ico", elem.company.ico) %} + {% set x = my_dict.__setitem__("oddil", elem.company.oddil) %} + {% set x = my_dict.__setitem__("vlozka", elem.company.vlozka) %} + {% set x = my_dict.__setitem__("soud", elem.company.soud) %} + {% set x = my_dict.__setitem__("zapis", elem.company.zapis) %} + {% set x = my_dict.__setitem__("pravni_forma", elem.company.current_legal_form_text()) %} + {% set test_list = test_list.append(my_dict) %} + {% endif %} + {% endfor %} + {% for elem in test_list %} {% if count.value % 2 == 0 %} {% set table_style = "table table-light" %} diff --git a/templates/trivia.html b/templates/trivia.html index 750706c..43e82ab 100644 --- a/templates/trivia.html +++ b/templates/trivia.html @@ -6,6 +6,7 @@

Další zajímvavé údaje z obchodního resjtříku:

Seznam nejčastějších sídel

Seznam nejstarších společností

+

Seznam nejčastějších konečných vlastníků

Seznam nejčastějších účelů

Seznam nejčastějších předmětů podnikání

Seznam nejčastějších předmětů činnosti

diff --git a/update_db.py b/update_db.py index 6c50b70..2f86c35 100644 --- a/update_db.py +++ b/update_db.py @@ -193,20 +193,18 @@ def find_UBO(c, ICO, elem2, conn, primary_sql_key, element): for elem in my_iter: zapis_datum = str(get_prop(elem, "zapisDatum")) vymaz_datum = str(get_prop(elem, "vymazDatum")) - UBO_valid = str(get_prop(elem, "hodnotaUdaje/valid")) - spravce = str(get_prop(elem, "hodnotaUdaje/spravce")) - T_TBC = str(get_prop(elem, "hodnotaUdaje/T")) - postaveni_jinak = str(get_prop(elem, "hodnotaUdaje/postaveniJinak")) - postaveni = str(get_prop(elem, "hodnotaUdaje/postaveni")) - primaUcast = str(get_prop(elem, "hodnotaUdaje/PrimaUcast")) - primaUcastPodil = str(get_prop(elem, "hodnotaUdaje/primaUcastPodil")) - rozdeleniProstredku = str(get_prop(elem, "hodnotaUdaje/PrimaUcast")) - slovni_vyjadreni = str(get_prop(elem, "hodnotaUdaje/slovniVyjadreni")) - urcenPoziciVeStatOrg = str(get_prop(elem, "hodnotaUdaje/urcenPoziciVeStatOrg")) - email = str(get_prop(elem, "hodnotaUdaje/email")) + postaveni = str(get_prop(elem, "hodnotaUdaje/postaveni")).split(";")[0] + koncovyPrijemceText = str(get_prop(elem, "hodnotaUdaje/koncovyPrijemceText")) + skutecnymMajitelemOd = str(get_prop(elem, "hodnotaUdaje/skutecnymMajitelemOd")) + vlastniPodilNaProspechu = str(get_prop(elem, "hodnotaUdaje/vlastniPodilNaProspechu")) + vlastniPodilNaProspechu_typ = str(get_prop(elem, "hodnotaUdaje/podilNaProspechu/typ")) + vlastniPodilNaProspechu_textValue = str(get_prop(elem, "hodnotaUdaje/podilNaProspechu/textValue")) + vlastniPodilNaHlasovani = str(get_prop(elem, "hodnotaUdaje/podilNaHlasovani")) + vlastniPodilNaHlasovani_typ = str(get_prop(elem, "hodnotaUdaje/podilNaHlasovani/typ")) + vlastniPodilNaHlasovani_value = str(get_prop(elem, "hodnotaUdaje/podilNaHlasovani/textValue")) adresa_id = find_sidlo(c, elem, primary_sql_key) UBO_id = find_fyzicka_osoba(c, ICO, elem, conn, primary_sql_key, element, adresa_id) - c.execute("INSERT INTO ubo (company_id, UBO_id, zapis_datum, vymaz_datum, UBO_valid, spravce, T_TBC, postaveni_jinak, postaveni, primaUcast, primaUcastPodil, rozdeleniProstredku, slovni_vyjadreni, urcenPoziciVeStatOrg, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (primary_sql_key, UBO_id, zapis_datum, vymaz_datum, UBO_valid, spravce, T_TBC, postaveni_jinak, postaveni, primaUcast, primaUcastPodil, rozdeleniProstredku, slovni_vyjadreni, urcenPoziciVeStatOrg, email,)) + c.execute("INSERT INTO ubo (company_id, UBO_id, adresa_id, zapis_datum, vymaz_datum, postaveni, koncovyPrijemceText, skutecnymMajitelemOd, vlastniPodilNaProspechu, vlastniPodilNaProspechu_typ, vlastniPodilNaProspechu_textValue, vlastniPodilNaHlasovani, vlastniPodilNaHlasovani_typ, vlastniPodilNaHlasovani_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (primary_sql_key, UBO_id, adresa_id, zapis_datum, vymaz_datum, postaveni, koncovyPrijemceText, skutecnymMajitelemOd, vlastniPodilNaProspechu, vlastniPodilNaProspechu_typ, vlastniPodilNaProspechu_textValue, vlastniPodilNaHlasovani, vlastniPodilNaHlasovani_typ, vlastniPodilNaHlasovani_value,)) except Exception as f: print(f) -- cgit From 03a987413afbead574224d11292843105757f673 Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Thu, 17 Jun 2021 22:42:36 +0200 Subject: adding backup feature. Other minor updates --- backup_DB.py | 6 ++++++ justice_build.py | 2 ++ todolist.html | 1 - update_db.py | 18 ++++++++++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 backup_DB.py diff --git a/backup_DB.py b/backup_DB.py new file mode 100644 index 0000000..fb4d9a1 --- /dev/null +++ b/backup_DB.py @@ -0,0 +1,6 @@ +import shutil +import os + +def backup_DB(): + os.makedirs("backup", exist_ok=True) + shutil.move("justice.db", "backup/justice.db") diff --git a/justice_build.py b/justice_build.py index 380d32b..5850340 100644 --- a/justice_build.py +++ b/justice_build.py @@ -1,10 +1,12 @@ from db_creation import create_DB from download_files import download_data, get_valid_filenames from update_db import update_DB +from backup_DB import backup_DB import os def main(): DB_name = "justice.db" + backup_DB() create_DB(DB_name) valid_files = get_valid_filenames() os.makedirs("data", exist_ok=True) diff --git a/todolist.html b/todolist.html index c86b17f..11f618f 100644 --- a/todolist.html +++ b/todolist.html @@ -1,7 +1,6 @@
  1. Add a feature to display other types of ownerhsip interests (joint onwership interest, vacant ownership interest).
  2. Refactor excessive duplications in the main code.
  3. -
  4. Check how to make diacritics work in searches.
  5. Check if I can remove duplication in results when searching for legal or natural persons in a role.
  6. Write some documentation :)
\ No newline at end of file diff --git a/update_db.py b/update_db.py index 2f86c35..d69f777 100644 --- a/update_db.py +++ b/update_db.py @@ -528,8 +528,8 @@ def insert_individual_relations_v2(c, ICO, conn, primary_sql_key, zapis_datum, v def find_fyzicka_osoba(c, ICO, elem, conn, relationship_table_key, element, adresa_id): try: - jmeno = str(get_prop(elem, "osoba/jmeno")) - prijmeni = str(get_prop(elem, "osoba/prijmeni")) + jmeno = lower_names_chars(str(get_prop(elem, "osoba/jmeno"))) + prijmeni = lower_names_chars(str(get_prop(elem, "osoba/prijmeni"))) datum_narozeni = str(get_prop(elem, "osoba/narozDatum")) titulPred = str(get_prop(elem, "osoba/titulPred")) titulZa = str(get_prop(elem, "osoba/titulZa")) @@ -539,6 +539,20 @@ def find_fyzicka_osoba(c, ICO, elem, conn, relationship_table_key, element, adre except: pass +def lower_names_chars(string_name): + updated_name = "" + previous_non_alpha = True + for elem in string_name: + if previous_non_alpha == True: + updated_name += elem + else: + updated_name += elem.lower() + if elem.isalpha() == True: + previous_non_alpha = False + else: + previous_non_alpha = True + return updated_name + def insert_fyzicka_osoba(c, titulPred, jmeno, prijmeni, titulZa, datum_narozeni, adresa_id): try: c.execute("INSERT into fyzicke_osoby (titul_pred, jmeno, prijmeni, titul_za, datum_naroz, adresa_id) VALUES (?,?,?,?,?,?)", (titulPred, jmeno, prijmeni, titulZa, datum_narozeni,adresa_id,)) -- cgit From 9d17c39ee4240ab1f40a8023689d53d39d95db8c Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Sun, 20 Jun 2021 16:30:44 +0200 Subject: add feature to display vacant OIs --- db_creation.py | 33 +++++++++++++++++++++++++---- justice_build.py | 9 ++++---- main.py | 2 +- models.py | 12 +++++++++++ templates/extract-actual.html | 37 ++++++++++++++++++++++++++++++++- templates/extract.html | 48 +++++++++++++++++++++++++++++++++++++++++-- update_db.py | 39 +++++++++++++++++++++++++++++------ 7 files changed, 162 insertions(+), 18 deletions(-) diff --git a/db_creation.py b/db_creation.py index cf9d504..0e6299a 100644 --- a/db_creation.py +++ b/db_creation.py @@ -197,7 +197,8 @@ def create_tables(conn): podily = """ CREATE TABLE "podily" ( "id" INTEGER NOT NULL UNIQUE, - "spolecnik_id" INTEGER NOT NULL, + "spolecnik_id" INTEGER, + "uvolneny_podil_id" INTEGER, "zapis_datum" DATE, "vymaz_datum" DATE, "druh_podilu_id" INTEGER, @@ -209,6 +210,7 @@ def create_tables(conn): "splaceni_text" TEXT, FOREIGN KEY("druh_podilu_id") REFERENCES "druhy_podilu"("id"), FOREIGN KEY("spolecnik_id") REFERENCES "spolecnici"("id"), + FOREIGN KEY("uvolneny_podil_id") REFERENCES "spolecnici_uvolneny_podil"("id"), PRIMARY KEY("id" AUTOINCREMENT) ); """ @@ -324,6 +326,17 @@ def create_tables(conn): FOREIGN KEY("company_id") REFERENCES "companies"("id") ); """ + spolecnici_uvolneny_podil = """ CREATE TABLE "spolecnici_uvolneny_podil" ( + "id" INTEGER NOT NULL UNIQUE, + "company_id" INTEGER NOT NULL, + "zapis_datum" DATE, + "vymaz_datum" DATE, + "text_uvolneny_podil" TEXT, + PRIMARY KEY("id" AUTOINCREMENT), + FOREIGN KEY("company_id") REFERENCES "companies"("id") + ) """ + + statutarni_organ_clen_relation = """ CREATE TABLE "statutarni_organ_clen_relation" ( "id" INTEGER NOT NULL UNIQUE, "statutarni_organ_id" INTEGER NOT NULL, @@ -444,7 +457,7 @@ def create_tables(conn): list_of_tables = [companies, adresy_v2, akcie, dr_relation, dr_organ_clen_relation, druhy_podilu, fyzicke_osoby, insolvency_events, jediny_akcionar, konkurz_events, nazvy, ostatni_skutecnosti, pocty_clenu_DR, pocty_clenu_organu, podily, pravni_formy, pravni_formy_relation, pravnicke_osoby, predmety_cinnosti, predmety_cinnosti_relation, prdmety_podnikani, predmety_podnikani_relation, - prokura_common_texts, prokuriste, sidlo_relation, spolecnici, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, ubo, + prokura_common_texts, prokuriste, sidlo_relation, spolecnici, spolecnici_uvolneny_podil, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, ubo, ucel, ucel_relation, zakladni_kapital, zapis_soudy, zpusoby_jednani, zpusoby_jednani_relation] for elem in list_of_tables: try: @@ -570,6 +583,10 @@ def create_indices(conn): "spolecnik_id" ); """ + podily3 = """ CREATE INDEX "index podily3" ON "podily" ( + "uvolneny_podil_id" +); """ + pravni_formy = """ CREATE INDEX "index pravni_formy" ON "pravni_formy" ( "pravni_forma" ); """ @@ -694,6 +711,14 @@ def create_indices(conn): "adresa_id" ); """ + spolecnici_uvolneny_podil1 = """ CREATE INDEX "index uvolneny_podil1" on "spolecnici_uvolneny_podil" ( + "id" +); """ + + spolecnici_uvolneny_podil2 = """ CREATE INDEX "index uvolneny_podil2" on "spolecnici_uvolneny_podil" ( + "company_id" +); """ + statutarni_organy = """ CREATE INDEX "index statutarn_organy" ON "statutarni_organy" ( "id", "statutarni_organ_text" @@ -800,11 +825,11 @@ def create_indices(conn): list_of_indices = [companies1, companies2, companies3, companies4, companies5, adresy1, adresy2, adresy3, akcie, akcie2, akcionari1, akcionari2, akcionari3, dr_clen_relation1, dr_clen_relation2, dr_relation, dr_relation2, dr_relation_3, dr_relation_4, insolvency1, insolvency2, konkurz1, konkurz2, nazvy1, nazvy2, nazvy3, ostatni_skutecnosti, ostatni_skutecnosti2, - pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, pravni_formy, pravni_formy_relation1, pravni_formy_relation2, + pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, podily3, pravni_formy, pravni_formy_relation1, pravni_formy_relation2, predmety_cinnosti_relation1, predmety_cinnosti_relation2, predmety_cinnosti_relation3, predmety_podnikani_relation1, predmety_podnikani_relation2, predmety_podnikani_relation3, predmety_cinnosti1, predmety_cinnosti2, predmety_podnikani1, predmety_podnikani2, prokuriste1, prokuriste2, prokuriste3, prokuriste4, sidlo_relation1, sidlo_relation_2, sidlo_relation_3, soudni_zapis1, soudni_zapis2, spolecnici1, - spolecnici2, spolecnici3, spolecnici4, spolecnici5, statutarni_organy, statutarni_organy_relation1, statutarni_organy_relation2, + spolecnici2, spolecnici3, spolecnici4, spolecnici5, spolecnici_uvolneny_podil1, spolecnici_uvolneny_podil2, statutarni_organy, statutarni_organy_relation1, statutarni_organy_relation2, statutarni_organy_relation_3, statutarni_organy_relation_4, zakladni_kapital1, zakladni_kapital2, zpusob_jednani, zpusob_jednani_relation1, zpusob_jednani_relation2, zpusob_jednani_relation3, pravnicke_osoby1, pravnicke_osoby2, pravnicke_osoby3, pravnicke_osoby4, statutarni_organy_relation_5, fyzicke_osoby1, ubo1, ubo2, ubo3, ucel1, ucel2, ucel_relation1, ucel_relation2, ucel_relation3] i = 0 diff --git a/justice_build.py b/justice_build.py index 5850340..4b82660 100644 --- a/justice_build.py +++ b/justice_build.py @@ -6,12 +6,13 @@ import os def main(): DB_name = "justice.db" - backup_DB() + # backup_DB() create_DB(DB_name) - valid_files = get_valid_filenames() + # valid_files = get_valid_filenames() + valid_files = ["sro-full-ceske_budejovice-2021"] os.makedirs("data", exist_ok=True) - for valid_file in valid_files: - download_data(valid_file) + # for valid_file in valid_files: + # download_data(valid_file) for valid_file in valid_files: modified_file_name = os.path.join(str(os.getcwd()), "data", valid_file + ".xml") update_DB(modified_file_name, DB_name) diff --git a/main.py b/main.py index deb9d51..80b598e 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from models import Company, Insolvency_Events, Konkurz_Events, Predmet_Podnikani from models import Zakladni_Kapital, Akcie, Nazvy, Sidlo, Sidlo_Association, Pravni_Forma_Association_v2, Pravni_Formy, Statutarni_Organ_Association, Statutarni_Organy, Pocty_Clenu_Organu from models import Zpusob_Jednani_Association, Zpusob_Jednani, Statutarni_Organ_Clen_Association, Fyzicka_Osoba, Spolecnici_Association, Podily_Association, Druhy_Podilu, Pravnicka_Osoba from models import Prokurista_Association, Dozorci_Rada_Clen_Association, Jediny_Akcionar_Association, Prokura_Common_Text_Association, Soudni_Zapisy, Ucel, Ucel_Association -from models import Adresy_v2 +from models import Adresy_v2, Uvolneny_Podil_Association from tables import Results from sqlalchemy.sql import select from sqlalchemy.sql import text diff --git a/models.py b/models.py index 6c1b84c..4b94374 100644 --- a/models.py +++ b/models.py @@ -301,6 +301,16 @@ class Spolecnici_Association(db.Model): podily = db.relationship("Podily_Association") company = db.relationship("Company") +class Uvolneny_Podil_Association(db.Model): + __tablename__ = "spolecnici_uvolneny_podil" + id = db.Column(db.Integer, primary_key=True) + company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) + zapis_datum = db.Column(MyType) + vymaz_datum = db.Column(MyType) + text_uvolneny_podil = db.Column(db.String) + podily = db.relationship("Podily_Association") + company = db.relationship("Company") + class Ubo(db.Model): __tablename__ = "ubo" id = db.Column(db.Integer, primary_key=True) @@ -356,6 +366,7 @@ class Podily_Association(db.Model): __tablename__ = "podily" id = db.Column(db.Integer, primary_key=True) spolecnik_id = db.Column(db.Integer, db.ForeignKey('spolecnici.id')) + uvolneny_podil_id = db.Column(db.Integer, db.ForeignKey('spolecnici_uvolneny_podil.id')) zapis_datum = db.Column(MyType) vymaz_datum = db.Column(MyType) druh_podilu_id = db.Column(db.Integer, db.ForeignKey('druhy_podilu.id')) @@ -409,6 +420,7 @@ class Company(db.Model): statutarni_organ_text = db.relationship("Statutarni_Organ_Association") dozorci_rada_text = db.relationship("Dozorci_Rada_Association") spolecnici = db.relationship("Spolecnici_Association") + spolecnici_uvolneny_podil = db.relationship("Uvolneny_Podil_Association") prokurista = db.relationship("Prokurista_Association") prokura_common_text = db.relationship("Prokura_Common_Text_Association") jediny_akcionar = db.relationship("Jediny_Akcionar_Association") diff --git a/templates/extract-actual.html b/templates/extract-actual.html index 6bc51fe..f24cb80 100644 --- a/templates/extract-actual.html +++ b/templates/extract-actual.html @@ -49,6 +49,14 @@ {% endif %} {% endfor %} + +{% set vacant_shares_notes = [] %} +{% for i in range (row.spolecnici_uvolneny_podil|length) %} + {% if row.spolecnici_uvolneny_podil[i].vymaz_datum == 0 %} + {% set vacant_shares_notes = vacant_shares_notes.append(row.spolecnici_uvolneny_podil[i]) %} + {% endif %} +{% endfor %} + {% set sole_shareholder_notes = [] %} {% for i in range (row.jediny_akcionar|length) %} {% if row.jediny_akcionar[i].vymaz_datum == 0 %} @@ -368,7 +376,7 @@ - {% if spolecnici_notes|length > 0 %} + {% if spolecnici_notes|length > 0 or vacant_shares_notes|length > 0 %} Společníci: @@ -398,6 +406,33 @@ {% endfor %} {% endfor %} + + + {% for i in range (vacant_shares_notes|length) %} + + Uvolněný obchodní podíl: + {% if vacant_shares_notes[i].text_uvolneny_podil != "0" %}{{ vacant_shares_notes[i].text_uvolneny_podil }}{% endif %} + + {% set vacant_shares = [] %} + {% for j in range (vacant_shares_notes[i].podily|length) %} + {% if vacant_shares_notes[i].podily[j].vymaz_datum == 0 %} + {% set vacant_shares = vacant_shares.append(vacant_shares_notes[i].podily[j]) %} + {% endif %} + {% endfor %} + + {% for k in range (vacant_shares|length) %} + + Podíl: + + {% for elem in vacant_shares[k].my_rep() %} + {{ elem }}
+ {% endfor %} + + + {% endfor %} + {% endfor %} + + {% endif %} diff --git a/templates/extract.html b/templates/extract.html index 17bdd73..2b27462 100644 --- a/templates/extract.html +++ b/templates/extract.html @@ -422,7 +422,7 @@ - {% if row.spolecnici|length > 0 %} +{% if row.spolecnici|length > 0 or row.spolecnici_uvolneny_podil|length > 0 %} Společníci: @@ -466,10 +466,54 @@ {% endfor %} {% endif %} + + {% endfor %} + + + {% for i in range (row.spolecnici_uvolneny_podil|length) %} + + Uvolněný obchodní podíl: + {% if row.spolecnici_uvolneny_podil[i].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + {{ underlne_style_open|safe }} {% if row.spolecnici_uvolneny_podil[i].text_uvolneny_podil != "0" %}{{ row.spolecnici_uvolneny_podil[i].text_uvolneny_podil }}{% endif %} + {{ underlne_style_close|safe }} + {{ underlne_style_open|safe }} Zapsáno: {{ row.spolecnici_uvolneny_podil[i].zapis_datum }} {% if row.spolecnici_uvolneny_podil[i].vymaz_datum != 0 %}
Vymazáno: {{ row.spolecnici_uvolneny_podil[i].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }} + + + {% if row.spolecnici_uvolneny_podil[i].podily|length > 0 %} + + {% for j in range (row.spolecnici_uvolneny_podil[i].podily|length) %} + + Podíl: + {% if row.spolecnici_uvolneny_podil[i].podily[j].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + {{ underlne_style_open|safe }} + {% for elem in row.spolecnici_uvolneny_podil[i].podily[j].my_rep() %} + {{ elem }}
+ {% endfor %} + {{ underlne_style_close|safe }} + + {{ underlne_style_open|safe }}Zapsáno: {{ row.spolecnici_uvolneny_podil[i].podily[j].zapis_datum }} {% if row.spolecnici_uvolneny_podil[i].podily[j].vymaz_datum != 0 %}
Vymazáno: {{ row.spolecnici_uvolneny_podil[i].podily[j].vymaz_datum }}{% endif %}{{ underlne_style_close|safe }} + + {% endfor %} + {% endif %} + {% endfor %} - {% endif %} + + +{% endif %} diff --git a/update_db.py b/update_db.py index d69f777..43dac45 100644 --- a/update_db.py +++ b/update_db.py @@ -212,12 +212,12 @@ def find_spolecnik(c, ICO, elem2, conn, primary_sql_key, element): try: my_iter = elem2.findall("podudaje/Udaj") for elem in my_iter: - spolecnik_type = str(get_prop(elem, "udajTyp/kod")) + spolecnik_kod = str(get_prop(elem, "udajTyp/kod")) zapis_datum = str(get_prop(elem, "zapisDatum")) vymaz_datum = str(get_prop(elem, "vymazDatum")) spolecnik_typ = str(get_prop(elem, "hodnotaUdaje/typ")) # TODO Chech these conditions, they sometimes cause a person not being stored (IC 27650081) - if spolecnik_type == "SPOLECNIK_OSOBA" and spolecnik_typ == "OSOBA": + if spolecnik_kod == "SPOLECNIK_OSOBA" and spolecnik_typ == "OSOBA": # TODO alternativy pro None, Spolecny podil a Uvolneny podil text_spolecnik = str(get_prop(elem, "hodnotaUdaje/textZaOsobu/value")) nazev = str(get_prop(elem, "osoba/nazev")) @@ -237,7 +237,17 @@ def find_spolecnik(c, ICO, elem2, conn, primary_sql_key, element): c.execute("INSERT INTO spolecnici (company_id, spolecnik_po_id, zapis_datum, vymaz_datum, adresa_id, text_spolecnik) VALUES (?, ?, ?, ?, ?, ?)", (primary_sql_key, spolecnik_po_id, zapis_datum, vymaz_datum, adresa_id, text_spolecnik,)) c.execute ("SELECT last_insert_rowid()") spolecnik_id = c.fetchone()[0] - insert_podily(c, elem, spolecnik_id) + insert_podily(c, elem, spolecnik_id) + elif spolecnik_kod == "SPOLECNIK_OSOBA" and spolecnik_typ == "SPOLECNY_PODIL": + pass + # text_spolecnik = str(get_prop(elem, "hodnotaUdaje/textZaOsobu/value")) + # print(text_spolecnik) + elif spolecnik_kod == "SPOLECNIK_OSOBA" and spolecnik_typ == "UVOLNENY_PODIL": + text_uvolneny_podil = str(get_prop(elem, "hodnotaUdaje/textZaOsobu/value")) + c.execute("INSERT INTO spolecnici_uvolneny_podil (company_id, zapis_datum, vymaz_datum, text_uvolneny_podil) VALUES (?, ?, ?, ?)", (primary_sql_key, zapis_datum, vymaz_datum, text_uvolneny_podil,)) + c.execute ("SELECT last_insert_rowid()") + uvolneny_op_id = c.fetchone()[0] + insert_vacant_podily(c, elem, uvolneny_op_id) except Exception as f: print(f) @@ -251,7 +261,7 @@ def find_predmet_podnikani(c, ICO, predmet_podnikani_elem, conn, primary_sql_key vymaz_datum = str(get_prop(elem2, ".//vymazDatum")) insert_instructions = [(".//hodnotaText","predmety_podnikani", "predmet_podnikani", "predmety_podnikani_relation")] for elem in insert_instructions: - inserted_figure = str(get_prop(elem2, ".//hodnotaText")) + inserted_figure = str(get_prop(elem2, ".//hodnotaText")).capitalize() insert_into_ancillary_table(c, elem, inserted_figure) ancillary_table_key = get_anciallary_table_key(c, elem, inserted_figure) insert_relation_information_v2(c, elem, primary_sql_key, ancillary_table_key, zapis_datum, vymaz_datum) @@ -268,7 +278,7 @@ def find_predmet_cinnosti(c, ICO, predmet_cinnosti_elem, conn, primary_sql_key, vymaz_datum = str(get_prop(elem2, ".//vymazDatum")) insert_instructions = [(".//hodnotaText","predmety_cinnosti", "predmet_cinnosti", "predmety_cinnosti_relation")] for elem in insert_instructions: - inserted_figure = str(get_prop(elem2, ".//hodnotaText")) + inserted_figure = str(get_prop(elem2, ".//hodnotaText")).capitalize() insert_into_ancillary_table(c, elem, inserted_figure) ancillary_table_key = get_anciallary_table_key(c, elem, inserted_figure) insert_relation_information_v2(c, elem, primary_sql_key, ancillary_table_key, zapis_datum, vymaz_datum) @@ -285,7 +295,7 @@ def find_ucel(c, ICO, ucel_elem, conn, primary_sql_key, element): vymaz_datum = str(get_prop(elem2, ".//vymazDatum")) insert_instructions = [(".//hodnotaText", "ucel", "ucel", "ucel_relation")] for elem in insert_instructions: - inserted_figure = str(get_prop(elem2, ".//hodnotaText")) + inserted_figure = str(get_prop(elem2, ".//hodnotaText")).capitalize() insert_into_ancillary_table(c, elem, inserted_figure) ancillary_table_key = get_anciallary_table_key(c, elem, inserted_figure) insert_relation_information_v2(c, elem, primary_sql_key, ancillary_table_key, zapis_datum, vymaz_datum) @@ -625,6 +635,23 @@ def insert_podily(c, elem, spolecnik_id): except Exception as f: print(f) +def insert_vacant_podily(c, elem, vacant_id): + try: + podil_iter = elem.findall("podudaje/Udaj") + for podil_elem in podil_iter: + zapisDatum = str(get_prop(podil_elem, "zapisDatum")) + vymazDatum = str(get_prop(podil_elem, "vymazDatum")) + druh_podilu_id = get_druh_podilu_id(c, podil_elem) + vklad_typ = str(get_prop(podil_elem, "hodnotaUdaje/vklad/typ")) + vklad_text = str(get_prop(podil_elem, "hodnotaUdaje/vklad/textValue")) + souhrn_typ = str(get_prop(podil_elem, "hodnotaUdaje/souhrn/typ")) + souhrn_text = str(get_prop(podil_elem, "hodnotaUdaje/souhrn/textValue")) + splaceni_typ = str(get_prop(podil_elem, "hodnotaUdaje/splaceni/typ")) + splaceni_text = str(get_prop(podil_elem, "hodnotaUdaje/splaceni/textValue")) + c.execute("INSERT INTO podily (uvolneny_podil_id, zapis_datum, vymaz_datum, druh_podilu_id, vklad_typ, vklad_text, souhrn_typ, souhrn_text, splaceni_typ, splaceni_text) VALUES (?,?,?,?,?,?,?,?,?,?)", (vacant_id, zapisDatum, vymazDatum, druh_podilu_id, vklad_typ, vklad_text, souhrn_typ, souhrn_text, splaceni_typ, splaceni_text,)) + except Exception as f: + print(f) + def get_druh_podilu_id(c, podil_elem): try: druhPodilu = str(get_prop(podil_elem, "hodnotaUdaje/druhPodilu")) -- cgit From 00fd5abb4c35f4b035b30787f5c1788290c7933a Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Sun, 20 Jun 2021 18:14:38 +0200 Subject: interim solution for common ownership interest --- db_creation.py | 32 +++++++++++++++++++++++++++----- main.py | 2 +- models.py | 13 +++++++++++++ templates/extract.html | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ update_db.py | 28 +++++++++++++++++++++++++--- 5 files changed, 114 insertions(+), 9 deletions(-) diff --git a/db_creation.py b/db_creation.py index 0e6299a..70a08df 100644 --- a/db_creation.py +++ b/db_creation.py @@ -199,6 +199,7 @@ def create_tables(conn): "id" INTEGER NOT NULL UNIQUE, "spolecnik_id" INTEGER, "uvolneny_podil_id" INTEGER, + "spolecny_podil_id" INTEGER, "zapis_datum" DATE, "vymaz_datum" DATE, "druh_podilu_id" INTEGER, @@ -336,6 +337,15 @@ def create_tables(conn): FOREIGN KEY("company_id") REFERENCES "companies"("id") ) """ + spolecnici_spolecny_podil = """ CREATE TABLE "spolecnici_spolecny_podil" ( + "id" INTEGER NOT NULL UNIQUE, + "company_id" INTEGER NOT NULL, + "zapis_datum" DATE, + "vymaz_datum" DATE, + "text_spolecny_podil" TEXT, + PRIMARY KEY("id" AUTOINCREMENT), + FOREIGN KEY("company_id") REFERENCES "companies"("id") + ) """ statutarni_organ_clen_relation = """ CREATE TABLE "statutarni_organ_clen_relation" ( "id" INTEGER NOT NULL UNIQUE, @@ -457,7 +467,7 @@ def create_tables(conn): list_of_tables = [companies, adresy_v2, akcie, dr_relation, dr_organ_clen_relation, druhy_podilu, fyzicke_osoby, insolvency_events, jediny_akcionar, konkurz_events, nazvy, ostatni_skutecnosti, pocty_clenu_DR, pocty_clenu_organu, podily, pravni_formy, pravni_formy_relation, pravnicke_osoby, predmety_cinnosti, predmety_cinnosti_relation, prdmety_podnikani, predmety_podnikani_relation, - prokura_common_texts, prokuriste, sidlo_relation, spolecnici, spolecnici_uvolneny_podil, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, ubo, + prokura_common_texts, prokuriste, sidlo_relation, spolecnici, spolecnici_uvolneny_podil, spolecnici_spolecny_podil, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, ubo, ucel, ucel_relation, zakladni_kapital, zapis_soudy, zpusoby_jednani, zpusoby_jednani_relation] for elem in list_of_tables: try: @@ -587,6 +597,10 @@ def create_indices(conn): "uvolneny_podil_id" ); """ + podily4 = """ CREATE INDEX "index podily4" ON "podily" ( + "spolecny_podil_id" +); """ + pravni_formy = """ CREATE INDEX "index pravni_formy" ON "pravni_formy" ( "pravni_forma" ); """ @@ -719,6 +733,15 @@ def create_indices(conn): "company_id" ); """ + spolecnici_spolecny_podil1 = """ CREATE INDEX "index spolecny_podil1" on "spolecnici_spolecny_podil" ( + "id" +); """ + + spolecnici_spolecny_podil2 = """ CREATE INDEX "index spolecny_podil2" on "spolecnici_spolecny_podil" ( + "company_id" +); """ + + statutarni_organy = """ CREATE INDEX "index statutarn_organy" ON "statutarni_organy" ( "id", "statutarni_organ_text" @@ -813,7 +836,6 @@ def create_indices(conn): "osoba_id" ); """ - dr_relation_4 = """ CREATE INDEX "index dr clen relation4" ON "dr_organ_clen_relation" ( "pravnicka_osoba_id" ); """ @@ -825,13 +847,13 @@ def create_indices(conn): list_of_indices = [companies1, companies2, companies3, companies4, companies5, adresy1, adresy2, adresy3, akcie, akcie2, akcionari1, akcionari2, akcionari3, dr_clen_relation1, dr_clen_relation2, dr_relation, dr_relation2, dr_relation_3, dr_relation_4, insolvency1, insolvency2, konkurz1, konkurz2, nazvy1, nazvy2, nazvy3, ostatni_skutecnosti, ostatni_skutecnosti2, - pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, podily3, pravni_formy, pravni_formy_relation1, pravni_formy_relation2, + pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, podily3, podily4, pravni_formy, pravni_formy_relation1, pravni_formy_relation2, predmety_cinnosti_relation1, predmety_cinnosti_relation2, predmety_cinnosti_relation3, predmety_podnikani_relation1, predmety_podnikani_relation2, predmety_podnikani_relation3, predmety_cinnosti1, predmety_cinnosti2, predmety_podnikani1, predmety_podnikani2, prokuriste1, prokuriste2, prokuriste3, prokuriste4, sidlo_relation1, sidlo_relation_2, sidlo_relation_3, soudni_zapis1, soudni_zapis2, spolecnici1, - spolecnici2, spolecnici3, spolecnici4, spolecnici5, spolecnici_uvolneny_podil1, spolecnici_uvolneny_podil2, statutarni_organy, statutarni_organy_relation1, statutarni_organy_relation2, + spolecnici2, spolecnici3, spolecnici4, spolecnici5, spolecnici_uvolneny_podil1, spolecnici_uvolneny_podil2, spolecnici_spolecny_podil1, spolecnici_spolecny_podil2, statutarni_organy, statutarni_organy_relation1, statutarni_organy_relation2, statutarni_organy_relation_3, statutarni_organy_relation_4, zakladni_kapital1, zakladni_kapital2, zpusob_jednani, zpusob_jednani_relation1, zpusob_jednani_relation2, - zpusob_jednani_relation3, pravnicke_osoby1, pravnicke_osoby2, pravnicke_osoby3, pravnicke_osoby4, statutarni_organy_relation_5, fyzicke_osoby1, ubo1, ubo2, ubo3, ucel1, ucel2, ucel_relation1, ucel_relation2, ucel_relation3] + zpusob_jednani_relation3, pravnicke_osoby1, pravnicke_osoby2, pravnicke_osoby3, pravnicke_osoby4, statutarni_organy_relation_5, fyzicke_osoby1, ubo1, ubo2, ubo3, ubo4, ucel1, ucel2, ucel_relation1, ucel_relation2, ucel_relation3] i = 0 for elem in list_of_indices: i += 1 diff --git a/main.py b/main.py index 80b598e..31dde42 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from models import Company, Insolvency_Events, Konkurz_Events, Predmet_Podnikani from models import Zakladni_Kapital, Akcie, Nazvy, Sidlo, Sidlo_Association, Pravni_Forma_Association_v2, Pravni_Formy, Statutarni_Organ_Association, Statutarni_Organy, Pocty_Clenu_Organu from models import Zpusob_Jednani_Association, Zpusob_Jednani, Statutarni_Organ_Clen_Association, Fyzicka_Osoba, Spolecnici_Association, Podily_Association, Druhy_Podilu, Pravnicka_Osoba from models import Prokurista_Association, Dozorci_Rada_Clen_Association, Jediny_Akcionar_Association, Prokura_Common_Text_Association, Soudni_Zapisy, Ucel, Ucel_Association -from models import Adresy_v2, Uvolneny_Podil_Association +from models import Adresy_v2, Uvolneny_Podil_Association, Spolecny_Podil_Association from tables import Results from sqlalchemy.sql import select from sqlalchemy.sql import text diff --git a/models.py b/models.py index 4b94374..a6d2eaf 100644 --- a/models.py +++ b/models.py @@ -311,6 +311,17 @@ class Uvolneny_Podil_Association(db.Model): podily = db.relationship("Podily_Association") company = db.relationship("Company") +class Spolecny_Podil_Association(db.Model): + __tablename__ = "spolecnici_spolecny_podil" + id = db.Column(db.Integer, primary_key=True) + company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) + zapis_datum = db.Column(MyType) + vymaz_datum = db.Column(MyType) + text_spolecny_podil = db.Column(db.String) + podily = db.relationship("Podily_Association") + company = db.relationship("Company") + + class Ubo(db.Model): __tablename__ = "ubo" id = db.Column(db.Integer, primary_key=True) @@ -367,6 +378,7 @@ class Podily_Association(db.Model): id = db.Column(db.Integer, primary_key=True) spolecnik_id = db.Column(db.Integer, db.ForeignKey('spolecnici.id')) uvolneny_podil_id = db.Column(db.Integer, db.ForeignKey('spolecnici_uvolneny_podil.id')) + spolecny_podil_id = db.Column(db.Integer, db.ForeignKey('spolecnici_spolecny_podil.id')) zapis_datum = db.Column(MyType) vymaz_datum = db.Column(MyType) druh_podilu_id = db.Column(db.Integer, db.ForeignKey('druhy_podilu.id')) @@ -421,6 +433,7 @@ class Company(db.Model): dozorci_rada_text = db.relationship("Dozorci_Rada_Association") spolecnici = db.relationship("Spolecnici_Association") spolecnici_uvolneny_podil = db.relationship("Uvolneny_Podil_Association") + spolecnici_spolecny_podil = db.relationship("Spolecny_Podil_Association") prokurista = db.relationship("Prokurista_Association") prokura_common_text = db.relationship("Prokura_Common_Text_Association") jediny_akcionar = db.relationship("Jediny_Akcionar_Association") diff --git a/templates/extract.html b/templates/extract.html index 2b27462..ec58487 100644 --- a/templates/extract.html +++ b/templates/extract.html @@ -513,6 +513,54 @@ {% endfor %} + + + {% for i in range (row.spolecnici_spolecny_podil|length) %} + + Společný obchodní podíl: + {% if row.spolecnici_spolecny_podil[i].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + {{ underlne_style_open|safe }} {% if row.spolecnici_spolecny_podil[i].text_uvolneny_podil != "0" %}{{ row.spolecnici_spolecny_podil[i].text_spolecny_podil }}{% endif %} + {{ underlne_style_close|safe }} + {{ underlne_style_open|safe }} Zapsáno: {{ row.spolecnici_spolecny_podil[i].zapis_datum }} {% if row.spolecnici_spolecny_podil[i].vymaz_datum != 0 %}
Vymazáno: {{ row.spolecnici_spolecny_podil[i].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }} + + + + {% if row.spolecnici_spolecny_podil[i].podily|length > 0 %} + + {% for j in range (row.spolecnici_spolecny_podil[i].podily|length) %} + + Podíl: + {% if row.spolecnici_spolecny_podil[i].podily[j].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + {{ underlne_style_open|safe }} + {% for elem in row.spolecnici_spolecny_podil[i].podily[j].my_rep() %} + {{ elem }}
+ {% endfor %} + {{ underlne_style_close|safe }} + + {{ underlne_style_open|safe }}Zapsáno: {{ row.spolecnici_spolecny_podil[i].podily[j].zapis_datum }} {% if row.spolecnici_spolecny_podil[i].podily[j].vymaz_datum != 0 %}
Vymazáno: {{ row.spolecnici_spolecny_podil[i].podily[j].vymaz_datum }}{% endif %}{{ underlne_style_close|safe }} + + {% endfor %} + {% endif %} + + {% endfor %} + + + + + + {% endif %} diff --git a/update_db.py b/update_db.py index 43dac45..df844f6 100644 --- a/update_db.py +++ b/update_db.py @@ -239,9 +239,11 @@ def find_spolecnik(c, ICO, elem2, conn, primary_sql_key, element): spolecnik_id = c.fetchone()[0] insert_podily(c, elem, spolecnik_id) elif spolecnik_kod == "SPOLECNIK_OSOBA" and spolecnik_typ == "SPOLECNY_PODIL": - pass - # text_spolecnik = str(get_prop(elem, "hodnotaUdaje/textZaOsobu/value")) - # print(text_spolecnik) + text_spolecny_podil = str(get_prop(elem, "hodnotaUdaje/textZaOsobu/value")) + c.execute("INSERT INTO spolecnici_spolecny_podil (company_id, zapis_datum, vymaz_datum, text_spolecny_podil) VALUES (?, ?, ?, ?)", (primary_sql_key, zapis_datum, vymaz_datum, text_spolecny_podil,)) + c.execute ("SELECT last_insert_rowid()") + uvolneny_op_id = c.fetchone()[0] + insert_common_podily(c, elem, uvolneny_op_id) elif spolecnik_kod == "SPOLECNIK_OSOBA" and spolecnik_typ == "UVOLNENY_PODIL": text_uvolneny_podil = str(get_prop(elem, "hodnotaUdaje/textZaOsobu/value")) c.execute("INSERT INTO spolecnici_uvolneny_podil (company_id, zapis_datum, vymaz_datum, text_uvolneny_podil) VALUES (?, ?, ?, ?)", (primary_sql_key, zapis_datum, vymaz_datum, text_uvolneny_podil,)) @@ -618,6 +620,7 @@ def find_clen_dr(c, ICO, elem, conn, relationship_table_key, element): except Exception as f: print(f) +# TODO MERGE THESE THREE FUNCTIONS INTO ONE def insert_podily(c, elem, spolecnik_id): try: podil_iter = elem.findall("podudaje/Udaj") @@ -652,6 +655,25 @@ def insert_vacant_podily(c, elem, vacant_id): except Exception as f: print(f) +def insert_common_podily(c, elem, common_id): + try: + podil_iter = elem.findall("podudaje/Udaj") + for podil_elem in podil_iter: + if str(get_prop(podil_elem, "udajTyp/kod")) == "SPOLECNIK_PODIL": + zapisDatum = str(get_prop(podil_elem, "zapisDatum")) + vymazDatum = str(get_prop(podil_elem, "vymazDatum")) + druh_podilu_id = get_druh_podilu_id(c, podil_elem) + vklad_typ = str(get_prop(podil_elem, "hodnotaUdaje/vklad/typ")) + vklad_text = str(get_prop(podil_elem, "hodnotaUdaje/vklad/textValue")) + souhrn_typ = str(get_prop(podil_elem, "hodnotaUdaje/souhrn/typ")) + souhrn_text = str(get_prop(podil_elem, "hodnotaUdaje/souhrn/textValue")) + splaceni_typ = str(get_prop(podil_elem, "hodnotaUdaje/splaceni/typ")) + splaceni_text = str(get_prop(podil_elem, "hodnotaUdaje/splaceni/textValue")) + c.execute("INSERT INTO podily (spolecny_podil_id, zapis_datum, vymaz_datum, druh_podilu_id, vklad_typ, vklad_text, souhrn_typ, souhrn_text, splaceni_typ, splaceni_text) VALUES (?,?,?,?,?,?,?,?,?,?)", (common_id, zapisDatum, vymazDatum, druh_podilu_id, vklad_typ, vklad_text, souhrn_typ, souhrn_text, splaceni_typ, splaceni_text,)) + except Exception as f: + print(f) + + def get_druh_podilu_id(c, podil_elem): try: druhPodilu = str(get_prop(podil_elem, "hodnotaUdaje/druhPodilu")) -- cgit From 9e70cd8362a097da0ebe03261ea56674b73af388 Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Sat, 26 Jun 2021 23:35:00 +0200 Subject: display common ownership interests --- db_creation.py | 40 +++++++++++++++++++++++++++-- justice_build.py | 7 +++--- main.py | 2 +- models.py | 17 ++++++++++++- templates/extract-actual.html | 58 +++++++++++++++++++++++++++++++++++++++++-- templates/extract.html | 37 ++++++++++++++++++++++----- update_db.py | 31 +++++++++++++++++++++-- 7 files changed, 174 insertions(+), 18 deletions(-) diff --git a/db_creation.py b/db_creation.py index 70a08df..c3836aa 100644 --- a/db_creation.py +++ b/db_creation.py @@ -195,6 +195,21 @@ def create_tables(conn): PRIMARY KEY("id" AUTOINCREMENT) ); """ + podilnici = """ CREATE TABLE "podilnici" ( + "id" INTEGER NOT NULL UNIQUE, + "podil_id" INTEGER, + "podilnik_fo_id" INTEGER, + "podilnik_po_id" INTEGER, + "zapis_datum" DATE, + "vymaz_datum" DATE, + "adresa_id" INTEGER, + FOREIGN KEY("adresa_id") REFERENCES "adresy_v2"("id"), + PRIMARY KEY("id" AUTOINCREMENT), + FOREIGN KEY("podilnik_fo_id") REFERENCES "fyzicke_osoby"("id"), + FOREIGN KEY("podilnik_po_id") REFERENCES "pravnicke_osoby"("id"), + FOREIGN KEY("podil_id") REFERENCES "spolecnici_spolecny_podil"("id") +); """ + podily = """ CREATE TABLE "podily" ( "id" INTEGER NOT NULL UNIQUE, "spolecnik_id" INTEGER, @@ -465,7 +480,7 @@ def create_tables(conn): ); """ list_of_tables = [companies, adresy_v2, akcie, dr_relation, dr_organ_clen_relation, druhy_podilu, fyzicke_osoby, insolvency_events, - jediny_akcionar, konkurz_events, nazvy, ostatni_skutecnosti, pocty_clenu_DR, pocty_clenu_organu, podily, pravni_formy, + jediny_akcionar, konkurz_events, nazvy, ostatni_skutecnosti, pocty_clenu_DR, pocty_clenu_organu, podily, podilnici, pravni_formy, pravni_formy_relation, pravnicke_osoby, predmety_cinnosti, predmety_cinnosti_relation, prdmety_podnikani, predmety_podnikani_relation, prokura_common_texts, prokuriste, sidlo_relation, spolecnici, spolecnici_uvolneny_podil, spolecnici_spolecny_podil, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, ubo, ucel, ucel_relation, zakladni_kapital, zapis_soudy, zpusoby_jednani, zpusoby_jednani_relation] @@ -601,6 +616,26 @@ def create_indices(conn): "spolecny_podil_id" ); """ + podilnici1 = """ CREATE INDEX "index podilnici1" ON "podilnici" ( + "id" +); """ + + podilnici2 = """ CREATE INDEX "index podilnici2" ON "podilnici" ( + "podil_id" +); """ + + podilnici3 = """ CREATE INDEX "index podilnici3" ON "podilnici" ( + "podilnik_fo_id" +); """ + + podilnici4 = """ CREATE INDEX "index podilnici4" ON "podilnici" ( + "podilnik_po_id" +); """ + + podilnici5 = """ CREATE INDEX "index podilnici5" ON "podilnici" ( + "adresa_id" +); """ + pravni_formy = """ CREATE INDEX "index pravni_formy" ON "pravni_formy" ( "pravni_forma" ); """ @@ -847,7 +882,8 @@ def create_indices(conn): list_of_indices = [companies1, companies2, companies3, companies4, companies5, adresy1, adresy2, adresy3, akcie, akcie2, akcionari1, akcionari2, akcionari3, dr_clen_relation1, dr_clen_relation2, dr_relation, dr_relation2, dr_relation_3, dr_relation_4, insolvency1, insolvency2, konkurz1, konkurz2, nazvy1, nazvy2, nazvy3, ostatni_skutecnosti, ostatni_skutecnosti2, - pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, podily3, podily4, pravni_formy, pravni_formy_relation1, pravni_formy_relation2, + pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, podily3, podily4, podilnici1, podilnici2, podilnici3, podilnici4, podilnici5, + pravni_formy, pravni_formy_relation1, pravni_formy_relation2, predmety_cinnosti_relation1, predmety_cinnosti_relation2, predmety_cinnosti_relation3, predmety_podnikani_relation1, predmety_podnikani_relation2, predmety_podnikani_relation3, predmety_cinnosti1, predmety_cinnosti2, predmety_podnikani1, predmety_podnikani2, prokuriste1, prokuriste2, prokuriste3, prokuriste4, sidlo_relation1, sidlo_relation_2, sidlo_relation_3, soudni_zapis1, soudni_zapis2, spolecnici1, diff --git a/justice_build.py b/justice_build.py index 4b82660..9acf1e7 100644 --- a/justice_build.py +++ b/justice_build.py @@ -8,11 +8,10 @@ def main(): DB_name = "justice.db" # backup_DB() create_DB(DB_name) - # valid_files = get_valid_filenames() - valid_files = ["sro-full-ceske_budejovice-2021"] + valid_files = get_valid_filenames() os.makedirs("data", exist_ok=True) - # for valid_file in valid_files: - # download_data(valid_file) + for valid_file in valid_files: + download_data(valid_file) for valid_file in valid_files: modified_file_name = os.path.join(str(os.getcwd()), "data", valid_file + ".xml") update_DB(modified_file_name, DB_name) diff --git a/main.py b/main.py index 31dde42..a4d8293 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from models import Company, Insolvency_Events, Konkurz_Events, Predmet_Podnikani from models import Zakladni_Kapital, Akcie, Nazvy, Sidlo, Sidlo_Association, Pravni_Forma_Association_v2, Pravni_Formy, Statutarni_Organ_Association, Statutarni_Organy, Pocty_Clenu_Organu from models import Zpusob_Jednani_Association, Zpusob_Jednani, Statutarni_Organ_Clen_Association, Fyzicka_Osoba, Spolecnici_Association, Podily_Association, Druhy_Podilu, Pravnicka_Osoba from models import Prokurista_Association, Dozorci_Rada_Clen_Association, Jediny_Akcionar_Association, Prokura_Common_Text_Association, Soudni_Zapisy, Ucel, Ucel_Association -from models import Adresy_v2, Uvolneny_Podil_Association, Spolecny_Podil_Association +from models import Adresy_v2, Uvolneny_Podil_Association, Spolecny_Podil_Association, Podilnici_Association from tables import Results from sqlalchemy.sql import select from sqlalchemy.sql import text diff --git a/models.py b/models.py index a6d2eaf..400e5de 100644 --- a/models.py +++ b/models.py @@ -301,6 +301,21 @@ class Spolecnici_Association(db.Model): podily = db.relationship("Podily_Association") company = db.relationship("Company") +class Podilnici_Association(db.Model): + __tablename__ = "podilnici" + id = db.Column(db.Integer, primary_key=True) + podil_id = db.Column(db.Integer, db.ForeignKey('spolecnici_spolecny_podil.id')) + podilnik_fo_id = db.Column(db.Integer, db.ForeignKey('fyzicke_osoby.id')) + podilnik_po_id = db.Column(db.Integer, db.ForeignKey('pravnicke_osoby.id')) + zapis_datum = db.Column(MyType) + vymaz_datum = db.Column(MyType) + adresa_id = db.Column(db.Integer, db.ForeignKey('adresy_v2.id')) + # text_podilnik = db.Column(db.String) + adresa = db.relationship("Adresy_v2") + jmeno = db.relationship("Fyzicka_Osoba") + oznaceni_po = db.relationship("Pravnicka_Osoba") + podily = db.relationship("Spolecny_Podil_Association") + class Uvolneny_Podil_Association(db.Model): __tablename__ = "spolecnici_uvolneny_podil" id = db.Column(db.Integer, primary_key=True) @@ -319,9 +334,9 @@ class Spolecny_Podil_Association(db.Model): vymaz_datum = db.Column(MyType) text_spolecny_podil = db.Column(db.String) podily = db.relationship("Podily_Association") + podilnici = db.relationship("Podilnici_Association") company = db.relationship("Company") - class Ubo(db.Model): __tablename__ = "ubo" id = db.Column(db.Integer, primary_key=True) diff --git a/templates/extract-actual.html b/templates/extract-actual.html index f24cb80..691dae3 100644 --- a/templates/extract-actual.html +++ b/templates/extract-actual.html @@ -49,7 +49,6 @@ {% endif %} {% endfor %} - {% set vacant_shares_notes = [] %} {% for i in range (row.spolecnici_uvolneny_podil|length) %} {% if row.spolecnici_uvolneny_podil[i].vymaz_datum == 0 %} @@ -57,6 +56,13 @@ {% endif %} {% endfor %} +{% set common_shares_notes = [] %} +{% for i in range (row.spolecnici_spolecny_podil|length) %} + {% if row.spolecnici_spolecny_podil[i].vymaz_datum == 0 %} + {% set common_shares_notes = common_shares_notes.append(row.spolecnici_spolecny_podil[i]) %} + {% endif %} +{% endfor %} + {% set sole_shareholder_notes = [] %} {% for i in range (row.jediny_akcionar|length) %} {% if row.jediny_akcionar[i].vymaz_datum == 0 %} @@ -376,7 +382,7 @@ - {% if spolecnici_notes|length > 0 or vacant_shares_notes|length > 0 %} + {% if spolecnici_notes|length > 0 or vacant_shares_notes|length > 0 or common_shares_notes|length > 0 %} Společníci: @@ -433,6 +439,54 @@ {% endfor %} + + {% for i in range (common_shares_notes|length) %} + + Společný obchodní podíl: + {% if common_shares_notes[i].text_spolecny_podil != "0" %}{{ common_shares_notes[i].text_spolecny_podil }}{% endif %} + + {% set common_shares = [] %} + {% for j in range (common_shares_notes[i].podily|length) %} + {% if common_shares_notes[i].podily[j].vymaz_datum == 0 %} + {% set common_shares = common_shares.append(common_shares_notes[i].podily[j]) %} + {% endif %} + {% endfor %} + + {% for k in range (common_shares|length) %} + + Podíl: + + {% for elem in common_shares[k].my_rep() %} + {{ elem }}
+ {% endfor %} + + + {% endfor %} + + {% set common_shares_shareholders = [] %} + {% for j in range (common_shares_notes[i].podilnici|length) %} + {% if common_shares_notes[i].podilnici[j].vymaz_datum == 0 %} + {% set common_shares_shareholders = common_shares_shareholders.append(common_shares_notes[i].podilnici[j]) %} + {% endif %} + {% endfor %} + + {% for k in range (common_shares_shareholders|length) %} + + Podílník: + + {% if common_shares_shareholders[k].podilnik_fo_id != None %} + {{ common_shares_shareholders[k].jmeno }} + {% else %} + {{ common_shares_shareholders[k].oznaceni_po.nazev }}{% if common_shares_shareholders[k].oznaceni_po.reg_cislo != 0 %}, reg č. {{ common_shares_shareholders[k].oznaceni_po.reg_cislo }}{% endif %}{% if common_shares_shareholders[k].oznaceni_po.ico != 0 %}, IČ {{ common_shares_shareholders[k].oznaceni_po.ico }}{% endif %} + {% endif %} +
{{ common_shares_shareholders[k].adresa }} + + + {% endfor %} + + {% endfor %} + + {% endif %} diff --git a/templates/extract.html b/templates/extract.html index ec58487..9eb1985 100644 --- a/templates/extract.html +++ b/templates/extract.html @@ -530,7 +530,7 @@ {{ underlne_style_open|safe }} Zapsáno: {{ row.spolecnici_spolecny_podil[i].zapis_datum }} {% if row.spolecnici_spolecny_podil[i].vymaz_datum != 0 %}
Vymazáno: {{ row.spolecnici_spolecny_podil[i].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }} - + {% if row.spolecnici_spolecny_podil[i].podily|length > 0 %} {% for j in range (row.spolecnici_spolecny_podil[i].podily|length) %} @@ -553,15 +553,40 @@ {% endfor %} {% endif %} - - {% endfor %} + + + {% if row.spolecnici_spolecny_podil[i].podilnici|length > 0 %} + + {% for j in range (row.spolecnici_spolecny_podil[i].podilnici|length) %} + + Podílník: + {% if row.spolecnici_spolecny_podil[i].podilnici[j].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + {{ underlne_style_open|safe }} + {% if row.spolecnici_spolecny_podil[i].podilnici[j].podilnik_fo_id != None %} + {{ row.spolecnici_spolecny_podil[i].podilnici[j].jmeno }} + {% else %} + {{ row.spolecnici_spolecny_podil[i].podilnici[j].oznaceni_po.nazev }}{% if row.spolecnici_spolecny_podil[i].podilnici[j].oznaceni_po.reg_cislo != 0 %}, reg č. {{ row.spolecnici_spolecny_podil[i].podilnici[j].oznaceni_po.reg_cislo }}{% endif %}{% if row.spolecnici_spolecny_podil[i].podilnici[j].oznaceni_po.ico != 0 %}, IČ {{ row.spolecnici_spolecny_podil[i].podilnici[j].oznaceni_po.ico }}{% endif %} + {% endif %} +
{{ row.spolecnici_spolecny_podil[i].podilnici[j].adresa }} + {{ underlne_style_close|safe }} + + {{ underlne_style_open|safe }}Zapsáno: {{ row.spolecnici_spolecny_podil[i].podilnici[j].zapis_datum }} {% if row.spolecnici_spolecny_podil[i].podilnici[j].vymaz_datum != 0 %}
Vymazáno: {{ row.spolecnici_spolecny_podil[i].podilnici[j].vymaz_datum }}{% endif %}{{ underlne_style_close|safe }} + + {% endfor %} +{% endif %} + + {% endfor %} - - -{% endif %} + {% endif %} diff --git a/update_db.py b/update_db.py index df844f6..8444e5b 100644 --- a/update_db.py +++ b/update_db.py @@ -238,12 +238,15 @@ def find_spolecnik(c, ICO, elem2, conn, primary_sql_key, element): c.execute ("SELECT last_insert_rowid()") spolecnik_id = c.fetchone()[0] insert_podily(c, elem, spolecnik_id) + elif spolecnik_kod == "SPOLECNIK_OSOBA" and spolecnik_typ == "SPOLECNY_PODIL": text_spolecny_podil = str(get_prop(elem, "hodnotaUdaje/textZaOsobu/value")) c.execute("INSERT INTO spolecnici_spolecny_podil (company_id, zapis_datum, vymaz_datum, text_spolecny_podil) VALUES (?, ?, ?, ?)", (primary_sql_key, zapis_datum, vymaz_datum, text_spolecny_podil,)) c.execute ("SELECT last_insert_rowid()") - uvolneny_op_id = c.fetchone()[0] - insert_common_podily(c, elem, uvolneny_op_id) + spolecny_op_id = c.fetchone()[0] + insert_common_podily(c, elem, spolecny_op_id) + insert_common_shareholders(c, elem, spolecny_op_id) + elif spolecnik_kod == "SPOLECNIK_OSOBA" and spolecnik_typ == "UVOLNENY_PODIL": text_uvolneny_podil = str(get_prop(elem, "hodnotaUdaje/textZaOsobu/value")) c.execute("INSERT INTO spolecnici_uvolneny_podil (company_id, zapis_datum, vymaz_datum, text_uvolneny_podil) VALUES (?, ?, ?, ?)", (primary_sql_key, zapis_datum, vymaz_datum, text_uvolneny_podil,)) @@ -253,6 +256,30 @@ def find_spolecnik(c, ICO, elem2, conn, primary_sql_key, element): except Exception as f: print(f) +def insert_common_shareholders(c, elem, spolecny_op_id): + try: + podil_iter = elem.findall("podudaje/Udaj") + for podil_elem in podil_iter: + if str(get_prop(podil_elem, "udajTyp/kod")) == "SPOLECNIK_PODILNIK": + zapisDatum = str(get_prop(podil_elem, "zapisDatum")) + vymazDatum = str(get_prop(podil_elem, "vymazDatum")) + typ_podilnika = str(get_prop(podil_elem, "hodnotaText")) + if typ_podilnika == "AngazmaFyzicke": + adresa_id = find_sidlo(c, podil_elem, spolecny_op_id) + spolecnik_fo_id = find_fyzicka_osoba(c, 0, podil_elem, 0, spolecny_op_id, 0, adresa_id) + c.execute("INSERT INTO podilnici (podil_id, podilnik_fo_id, zapis_datum, vymaz_datum, adresa_id) VALUES (?, ?, ?, ?, ?)", (spolecny_op_id, spolecnik_fo_id, zapisDatum, vymazDatum, adresa_id)) + if typ_podilnika == "AngazmaPravnicke": + spol_ico = str(get_prop(podil_elem, "osoba/ico")) + regCislo = str(get_prop(podil_elem, "osoba/regCislo")) + adresa_id = find_sidlo(c, podil_elem, spolecny_op_id) + spolecnik_po_id = find_pravnicka_osoba(c, podil_elem, spol_ico, regCislo, adresa_id) + c.execute("INSERT INTO podilnici (podil_id, podilnik_po_id, zapis_datum, vymaz_datum, adresa_id) VALUES (?, ?, ?, ?, ?)", (spolecny_op_id, spolecnik_po_id, zapisDatum, vymazDatum, adresa_id)) + except Exception as f: + print(f) + + + + def find_predmet_podnikani(c, ICO, predmet_podnikani_elem, conn, primary_sql_key, element): try: my_iter = predmet_podnikani_elem.findall("podudaje") -- cgit