Skip to content

Commit

Permalink
minor formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TONYRYANWORLDWIDE committed Jun 26, 2019
1 parent 9f44f65 commit 3d573ed
Show file tree
Hide file tree
Showing 54 changed files with 8,568 additions and 483 deletions.
6,608 changes: 6,608 additions & 0 deletions Bills.dtsx

Large diffs are not rendered by default.

185 changes: 185 additions & 0 deletions Date of Each Bill.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
USE TRBILLS
Declare @today as date = cast(getdate() as date)

Declare @adjustments as int = 668 --sophie daycare and car damage +CC paid(18)


Declare @FundsInKeyToday as numeric(18,2) = (Select KeyBalance - @adjustments from keybalance)
Declare @days as int = 365

--Select @FundsInKeyToday, @adjustments

;If object_id('tempdb..#dateofeachbill') is not null drop table #dateofeachbill
;with base as
(
select *
,row_number() over(partition by [DATE] order by [DATE]) OnePayDayPerDate
from monthlybill mb
)



Select *
,case when [day] % 14 = 1 and (OnePayDayPerDate = 1 or onepaydayperdate is null) then 'TonyPayDay'
when [day] % 14 = 8 and (OnePayDayPerDate = 1 or onepaydayperdate is null) then 'CrystalPayDay'
end as [PayDay]
into #dateofeachbill
from base b
--order by cast(date as int)
full outer join dbo.dates dod
on datepart(d, dod.thedate) = b.Date



;If object_id('tempdb..#final') is not null drop table #final
Select
theDate
,Bill
,Cost
,Amount as BringHome
,[DayOfWeek]
into #final
from #dateofeachbill doeb
left join dbo.bringhomepay bhp on bhp.name = doeb.payday and thedate > @today

--Select * from #final
--Select * from dbo.BringHomePay


Declare @start as date = (Select max(thedate)from #final where thedate <= @today and [dayofweek] = 'Friday')
Declare @end as date = dateadd(d, @days, @start)



;If object_id('tempdb..#reportstart') is not null drop table #reportstart
Select * into #reportstart from #final where thedate between @today and @end


;If object_id('tempdb..#Mondays') is not null drop table #Mondays
;with base as
(
Select distinct thedate
from #reportstart where dayofweek = 'Monday'
)


Select thedate,row_number() over(order by thedate) ord
into #Mondays
from base --where dayofweek = 'Monday'



Declare @i as int = 1
Declare @weeks as int =(Select count(*) from #reportstart
where [dayofweek] = 'Monday')
while @i <= @weeks
begin
--Select * from WeeklyBill
Insert into #reportstart
(TheDate,Bill, Cost,[DayOfWeek])
Select thedate, bill, cost,'Monday'
from dbo.WeeklyBill wb left join #Mondays m on m.ord = @i
where thedate is not null

set @i = @i + 1
end


Delete from #reportstart
where (thedate = '06/25/2019' and bill in ('Subscribe and save'))

Update #reportstart
set cost = 0 where thedate = '06/24/2019' and bill = 'grocery'



Declare @oneoffbill as varchar(max)
Declare @oneoffdate as date
Declare @oneoffcost as int


--Declare @MyTableVar table
-- (thedate date ,
-- oneoffbill varchar(15),
-- oneoffcost int
-- )

--Insert @MyTableVar values ('05/30/2019','EmmasBday' ,250)

--insert into #reportstart
--(thedate, bill,cost,dayofweek)

--Select mt.*,d.DayOfWeek From @MyTableVar mt
--left join dbo.dates d on mt.thedate = d.thedate


--Select * from #reportstart
--order by thedate


--Select *,case when thedate >= '09/02/2019' and bill = 'Sophie Daycare' then 35
--when thedate >= '09/02/2019' and bill = 'Emma Daycare' then 75 -- includes 40$ a week for tuition (360/ month for 10 months)
--else cost end as cost2 from #reportstart
--where bill like '%care%'
--order by thedate

update #reportstart
set cost = case when thedate >= '09/02/2019' and bill = 'Sophie Daycare' then 35
when thedate >= '09/02/2019' and bill = 'Emma Daycare' then 75 -- includes 40$ a week for tuition (360/ month for 10 months)
else cost end




;If object_id('tempdb..##report') is not null drop table ##report
;with base as
(
Select *,
cast(SUM (Cost) OVER (ORDER BY THEDATE) as numeric(13,2)) AS RUNNINGTOTALBILLS
,cast(SUM (Bringhome) OVER (ORDER BY THEDATE) as numeric(13,2)) AS RUNNINGTOTALINCOME
,row_number() over(order by thedate) Increm
from #reportstart
)

,base2 as
(
Select *
,coalesce(runningtotalbills,0) runningtotalbills2
,coalesce(runningtotalincome,0) as RunningTotalIncomeFinal
, case when increm = 1 then @FundsInKeyToday else 0 end as StartingBalance
from base
)
,base3 as
(
Select *
,cast(SUM (StartingBalance) OVER (ORDER BY THEDATE) as numeric(13,2)) AS StartingBalanceFinal
from base2
)
select
TheDate, Bill, Cost, runningtotalbills2,coalesce(Bringhome, 0) bringhome, RunningtotalincomeFinal, StartingBalanceFinal
,(StartingBalanceFinal + RunningTotalIncomeFinal) - RunningTotalBills2 NET, DayOfWeek
into ##report
from base3

--Declare @today as date = cast(getdate() as date)
select *--TheDate, Bill, Cost, NET, DayOFWeek
from ##report
where 1 = 1
and (not (bill is null) or dayofweek = 'Thursday')
and thedate <=
(
Select max(thedate)
from ##report
where thedate <= dateadd(d,367,@today)
and dayofweek = 'Thursday'
)
order by thedate

--Select min(net) from ##report
--where [thedate] >= '01/23/2020'



--Select * from ##Report where net = '25.69'


Binary file modified WindowsFormsApplinq/.vs/WindowsFormsApplinq/v16/.suo
Binary file not shown.
1 change: 1 addition & 0 deletions WindowsFormsApplinq/WindowsFormsApplinq/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<add name="WindowsFormsApplinq.Properties.Settings.BillsConnectionString" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Bills;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient" />
<add name="WindowsFormsApplinq.Properties.Settings.TRBillsConnectionString" connectionString="Data Source=trbillsapp.database.windows.net;Initial Catalog=TRBills;User ID=tonyryan;Password=AzureWebApp#1;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False" providerName="System.Data.SqlClient" />
<add name="TRBillsEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:trbillsapp.database.windows.net,1433;initial catalog=TRBills;persist security info=True;user id=tonyryan;password=AzureWebApp#1;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
<add name="TRBillsEntities1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:trbillsapp.database.windows.net,1433;initial catalog=TRBills;persist security info=True;user id=tonyryan;password=AzureWebApp#1;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
Expand Down
20 changes: 20 additions & 0 deletions WindowsFormsApplinq/WindowsFormsApplinq/BringHomePay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace WindowsFormsApplinq
{
using System;
using System.Collections.Generic;

public partial class BringHomePays
{
public string Name { get; set; }
public Nullable<decimal> Amount { get; set; }
}
}
3 changes: 3 additions & 0 deletions WindowsFormsApplinq/WindowsFormsApplinq/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ private void formload()
}
public void BtnSubmit_Click(object sender, EventArgs e)
{

MonthlyBills v = new MonthlyBills();

string TheBill = "";
DataClasses1DataContext DC = new DataClasses1DataContext();
int newmonthlyrows = DC.MonthlyBills.Count() + 1;
Expand Down
21 changes: 21 additions & 0 deletions WindowsFormsApplinq/WindowsFormsApplinq/KeyBalance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace WindowsFormsApplinq
{
using System;
using System.Collections.Generic;

public partial class KeyBalances
{
public Nullable<float> KeyBalance1 { get; set; }
public Nullable<System.DateTime> DateTime { get; set; }
public string Placeholder { get; set; }
}
}
33 changes: 33 additions & 0 deletions WindowsFormsApplinq/WindowsFormsApplinq/Model1.Context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace WindowsFormsApplinq
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

public partial class TRBillsEntities1 : DbContext
{
public TRBillsEntities1()
: base("name=TRBillsEntities1")
{
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}

public virtual DbSet<BringHomePay> BringHomePays { get; set; }
public virtual DbSet<KeyBalance> KeyBalances { get; set; }
public virtual DbSet<MonthlyBill> MonthlyBills { get; set; }
public virtual DbSet<WeeklyBill> WeeklyBills { get; set; }
}
}
Loading

0 comments on commit 3d573ed

Please sign in to comment.