mirror of
https://github.com/acedanger/budget-database.git
synced 2025-12-05 22:50:13 -08:00
initial commit
This commit is contained in:
16
procedures/proc_CreateTransaction.sql
Normal file
16
procedures/proc_CreateTransaction.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
use Leo
|
||||
go
|
||||
|
||||
create proc dbo.proc_CreateTransaction (
|
||||
@date date, @description varchar(200), @amount decimal(11,2)
|
||||
)
|
||||
as
|
||||
begin
|
||||
set @date = isnull(@date, getdate())
|
||||
|
||||
insert into dbo.BUDGET_DETAIL (TrxDate, TrxDescription, TrxAmount)
|
||||
select @date, @description, @amount
|
||||
|
||||
select SCOPE_IDENTITY()
|
||||
end
|
||||
go
|
||||
18
procedures/proc_GetTransactions.sql
Normal file
18
procedures/proc_GetTransactions.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
use Leo
|
||||
go
|
||||
|
||||
alter proc dbo.proc_GetTransactions (
|
||||
@yr smallint = null, @mo smallint = null
|
||||
)
|
||||
as
|
||||
begin
|
||||
set @yr = isnull(@yr, year(getdate()))
|
||||
set @mo = isnull(@mo, month(getdate()))
|
||||
|
||||
select Id, TrxDate, TrxDate_ISO8601, TrxDescription, TrxAmount, RunningBal
|
||||
from dbo.vw_BudgetRunningBalance
|
||||
where
|
||||
YEAR(TrxDate) = @yr
|
||||
and MONTH(TrxDate) = @mo
|
||||
end
|
||||
go
|
||||
54
procedures/proc_MonthlyIncomeExpense.sql
Normal file
54
procedures/proc_MonthlyIncomeExpense.sql
Normal file
@@ -0,0 +1,54 @@
|
||||
use Leo
|
||||
go
|
||||
|
||||
alter PROCEDURE dbo.proc_MonthlyIncomeExpense (
|
||||
@p_Year smallint
|
||||
)
|
||||
AS
|
||||
|
||||
with credit as (
|
||||
SELECT
|
||||
det.TrxDate
|
||||
, ctg.CtgDescription
|
||||
, det.TrxAmount
|
||||
, YR=year(det.TrxDate)
|
||||
, MO=month(det.TrxDate)
|
||||
FROM
|
||||
dbo.BUDGET_CATEGORY ctg
|
||||
JOIN BUDGET_DETAIL det ON ctg.CtgDescription = det.TrxDescription
|
||||
WHERE
|
||||
ctg.CtgCredit = 1
|
||||
and year(det.TrxDate) = @p_Year
|
||||
)
|
||||
, debit as (
|
||||
select
|
||||
det.TrxDescription
|
||||
, det.TrxDate
|
||||
, det.TrxAmount
|
||||
, YR=year(det.TrxDate)
|
||||
, MO=month(det.TrxDate)
|
||||
from
|
||||
dbo.BUDGET_DETAIL det
|
||||
left join dbo.BUDGET_CATEGORY ctg on ctg.CtgDescription = det.TrxDescription
|
||||
where
|
||||
year(det.TrxDate) = @p_Year
|
||||
and det.TrxDescription <> 'Initial Balance'
|
||||
and det.TrxAmount <> 0
|
||||
and isnull(CtgCredit, 0) = 0
|
||||
)
|
||||
|
||||
select
|
||||
crd.YR
|
||||
, crd.MO
|
||||
, EXPENSES=dbt.TTL
|
||||
, INCOME=crd.TTL
|
||||
, TTL=crd.TTL+dbt.TTL
|
||||
from (
|
||||
select YR, MO, TTL=sum(credit.TrxAmount) from credit group by YR, MO
|
||||
) crd
|
||||
join (
|
||||
select YR, MO, TTL=sum(debit.TrxAmount) from debit group by YR, MO
|
||||
) dbt on crd.YR = dbt.YR and crd.MO = dbt.MO
|
||||
|
||||
return
|
||||
go
|
||||
22
procedures/proc_UpdateHolidaysTable.sql
Normal file
22
procedures/proc_UpdateHolidaysTable.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
use Leo
|
||||
go
|
||||
|
||||
alter proc dbo.proc_UpdateHolidaysTable
|
||||
as
|
||||
if not exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'HOLIDAYS')
|
||||
create table dbo.HOLIDAYS(dt date primary key clustered, Holiday varchar(50))
|
||||
|
||||
declare @year int = 2019
|
||||
|
||||
while @year < year(getdate()) + 40
|
||||
begin
|
||||
insert into dbo.Holidays(dt, Holiday)
|
||||
select fhol.dt, fhol.Holiday
|
||||
from
|
||||
dbo.tvf_GetHolidays(@year) fhol
|
||||
left join dbo.Holidays tbh on fhol.dt = tbh.dt
|
||||
where fhol.dt is null
|
||||
|
||||
set @year = @year + 1
|
||||
end
|
||||
go
|
||||
Reference in New Issue
Block a user