extended
This commit is contained in:
parent
d890c1b8c2
commit
47ffeaed0f
0
schema/01-change.sql
Normal file
0
schema/01-change.sql
Normal file
@ -26,7 +26,7 @@ create table wohnung (
|
||||
create table mieter (
|
||||
id integer unsigned not null auto_increment,
|
||||
wohnung integer unsigned not null,
|
||||
anrede varchar(32),
|
||||
anrede varchar(128),
|
||||
vorname varchar(128),
|
||||
nachname varchar(128) not null,
|
||||
strasse varchar(128),
|
||||
@ -45,7 +45,8 @@ create table mieter (
|
||||
create table zahlung (
|
||||
id integer unsigned not null auto_increment,
|
||||
mieter integer unsigned not null,
|
||||
datum date not null,
|
||||
datum_ist date not null,
|
||||
datum_soll date not null,
|
||||
betrag decimal (20, 10) not null,
|
||||
constraint primary key (id),
|
||||
constraint foreign key fk_zahlung_mieter (mieter)
|
||||
|
46
schema/query-jahresabrechnung.sql
Normal file
46
schema/query-jahresabrechnung.sql
Normal file
@ -0,0 +1,46 @@
|
||||
create or replace view abrechnung1 as
|
||||
select b.jahr as jahr,
|
||||
(b.betrag / o.flaeche * w.flaeche) as anteil,
|
||||
o.shortname as objekt,
|
||||
w.shortname as wohnung,
|
||||
concat(m.vorname, ' ', m.nachname) as mieter,
|
||||
m.id as mieter_id,
|
||||
(timestampdiff(month,
|
||||
if (year(m.einzug) = b.jahr, m.einzug, makedate(b.jahr, 1)),
|
||||
if (m.auszug is not null, m.auszug, last_day(makedate(b.jahr, 365)))
|
||||
) + 1) as nutzungszeit
|
||||
from betriebskosten_abrechnung b,
|
||||
objekt o,
|
||||
wohnung w,
|
||||
mieter m
|
||||
where b.objekt = o.id and
|
||||
w.objekt = o.id and
|
||||
m.wohnung = w.id and
|
||||
(year(m.einzug) = b.jahr or year(m.auszug) = b.jahr);
|
||||
|
||||
create or replace view abrechnung2 as
|
||||
select jahr,
|
||||
anteil / 12 * nutzungszeit as anteil,
|
||||
objekt,
|
||||
wohnung,
|
||||
mieter,
|
||||
mieter_id
|
||||
from abrechnung1;
|
||||
|
||||
create or replace view abrechnung3 as
|
||||
select a.jahr as jahr,
|
||||
a.anteil as anteil,
|
||||
a.objekt as objekt,
|
||||
a.wohnung as wohnung,
|
||||
m.vorname as vorname,
|
||||
m.nachname as nachname,
|
||||
m.anrede as anrede,
|
||||
m.strasse as strasse,
|
||||
m.plz as plz,
|
||||
m.ort as ort
|
||||
from abrechnung2 a,
|
||||
mieter m
|
||||
where m.id = a.mieter_id;
|
||||
|
||||
select * from abrechnung3 where jahr = '2020';
|
||||
|
Loading…
x
Reference in New Issue
Block a user