Files
linqpad/Understanding UNC PayPeriods.linq
T

193 lines
7.1 KiB
C#

<Query Kind="Program">
<Connection>
<ID>40766b24-ff74-431b-b387-6c221ede77cf</ID>
<Persist>true</Persist>
<Server>p3121-sql-02.sdt.local</Server>
<Database>jazz prd UNC 20180206.1</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
</Query>
void Main()
{
var validPayPeriods = PayPeriodCycles
.GroupBy(g => new { g.PayCycleID, g.PayCycleName }, (g, pp) =>
new
{
g.PayCycleID,
g.PayCycleName,
PayPeriods = pp.Select(p =>
new payperiodtiming
{
PayPeriodID = p.PayPeriodID,
PeriodEndCalendarDate = p.PeriodEndCalendarDate,
PeriodStartCalendarDate = p.PeriodStartCalendarDate
}).OrderByDescending(p => p.PeriodEndCalendarDate).Take(6)
})
.SelectMany(g => g.PayPeriods);
DeptPayPeriods
.ToList()
// .OrderBy(dpp => dpp.DepartmentID)
// .ThenByDescending(dpp => dpp.PayPeriodID)
.GroupBy(dpp => new { dpp.DepartmentID, dpp.Department }, (g, dpp) => new deptpayperiodtiming
{
DepartmentID = g.DepartmentID,
Department = g.Department,
PayPeriodTimings = dpp.Select(d => d.PayPeriodID).Distinct()
.Join(validPayPeriods, x => x, vpp => vpp.PayPeriodID, (x, vpp) => vpp)
.OrderByDescending(d => d.PayPeriodID)
})
.Where(dpp => dpp.PayPeriodTimings.Any())
.Dump("Department PayPeriods");
}
public void ShowCycles()
{
PayPeriodCycles
.GroupBy(g => new { g.PayCycleID, g.PayCycleName }, (g, pp) =>
new
{
g.PayCycleID,
g.PayCycleName,
PayPeriods = pp.Select(p =>
new payperiodtiming
{
PayPeriodID = p.PayPeriodID,
PeriodEndCalendarDate = p.PeriodEndCalendarDate,
PeriodStartCalendarDate = p.PeriodStartCalendarDate
}).OrderByDescending(p => p.PeriodEndCalendarDate).Take(6)
})
.Dump("Pay Period Cycles");
}
public IEnumerable<deptpayperiod> DeptPayPeriods => (from fact in FactPayrollSampledPayPeriods
join dept in DimDepartments on fact.DepartmentID equals dept.DepartmentID
select new deptpayperiod
{
PayPeriodID = fact.PayPeriodID,
DepartmentID = fact.DepartmentID,
Department = dept.Name
}).Union((from fact in ViewPrimaryStatisticsStaffingByPayPeriod
join dept in DimDepartments on fact.DepartmentID equals dept.DepartmentID
select new deptpayperiod
{
PayPeriodID = fact.PayPeriodID,
DepartmentID = fact.DepartmentID,
Department = dept.Name
})).Distinct();
public IEnumerable<payperiodcycle> PayPeriodCycles => from pp in DimPayPeriods
where pp.PeriodEndCalendarDate < DateTime.Now
select new payperiodcycle
{
PayPeriodID = pp.PayPeriodID,
PayCycleID = pp.PayCycleID,
PayCycleName = pp.PayCycleName,
PeriodEndCalendarDate = pp.PeriodEndCalendarDate,
PeriodStartCalendarDate = pp.PeriodStartCalendarDate
};
// Define other methods and classes here
public class deptpayperiod
{
public short PayPeriodID { get; set; }
public int DepartmentID { get; set; }
public string Department { get; set; }
}
public class deptpayperiodtiming
{
public int DepartmentID { get; set; }
public string Department { get; set; }
internal IEnumerable<payperiodtiming> PayPeriodTimings { get; set; }
public IDictionary<short, payperioddate> PayPeriods =>
PayPeriodTimings.ToDictionary(ppt => ppt.PayPeriodID,
ppt => new payperioddate
{
PeriodStartCalendarDate = ppt.PeriodStartCalendarDate,
PeriodEndCalendarDate = ppt.PeriodEndCalendarDate
});
public DateTime? PeriodStartDate => PayPeriodTimings.OrderByDescending(ppt => ppt.PayPeriodID).First().PeriodStartCalendarDate;
public DateTime? PeriodEndDate => PayPeriodTimings.OrderByDescending(ppt => ppt.PayPeriodID).First().PeriodEndCalendarDate;
}
public class payperioddate
{
public DateTime PeriodEndCalendarDate { get; set; }
public DateTime? PeriodStartCalendarDate { get; set; }
object ToDump() => new
{
PeriodStartDate = $"{PeriodStartCalendarDate:yyyy MM dd}",
PeriodEndDate = $"{PeriodEndCalendarDate:yyyy MM dd}"
};
}
public class payperiodtiming : payperioddate
{
public short PayPeriodID { get; set; }
object ToDump() => new
{
PayPeriodID = $"{PayPeriodID}",
PeriodStartDate = $"{PeriodStartCalendarDate:yyyy MM dd}",
PeriodEndDate = $"{PeriodEndCalendarDate:yyyy MM dd}"
};
}
public class payperiodcycle : payperiodtiming
{
public int PayCycleID { get; set; }
public string PayCycleName { get; set; }
}