initial commit

This commit is contained in:
Peter Wood
2022-07-15 15:37:20 -04:00
parent 70a85b6024
commit 27e7c7829c
13 changed files with 249 additions and 0 deletions

View 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

View 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

View 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

View 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