Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save hyrmn/8be4d4f04f8c29270bed to your computer and use it in GitHub Desktop.

Select an option

Save hyrmn/8be4d4f04f8c29270bed to your computer and use it in GitHub Desktop.
public class ReservationLetterTransformer : AbstractTransformerCreationTask<Reservation>
{
public ReservationLetterTransformer()
{
TransformResults = reservations => from res in reservations
let person = LoadDocument<Person>(res.PrimaryPersonId)
let members = LoadDocument<Person>(res.Group.MemberPersonIds)
let assignments = LoadDocument<ReservationUnitAssignment>(res.UnitAssignmentIds)
let units = LoadDocument<Unit>(assignments.Select(assign => assign.UnitId).Distinct())
let invoices = LoadDocument<Invoice>(res.InvoiceIds)
let taxes = LoadDocument<Tax>(invoices.SelectMany(i => i.LineItems.SelectMany(l => l.Taxes.Select(t => t.TaxId))).Distinct())
let fees = LoadDocument<Fee>(invoices.SelectMany(i => i.LineItems.SelectMany(l => l.Fees.Select(t => t.FeeId))).Distinct())
let payments = LoadDocument<Payment>(invoices.SelectMany(i => i.Payments.Select(l => l.Key)).Distinct())
/*
let guestDefinitions =
LoadDocument<GuestDefinition>(assignments.SelectMany(assign => assign.Guests.Select(g => g.Key)).Distinct())
*/
select
new
{
Reservation = res,
Id = res.Id,
Name = res.Name,
ConfirmationNumber = res.ConfirmationNumber,
CancellationNumber = res.CancellationNumber,
StartDate = res.StartDate,
EndDate = res.EndDate,
Group = res.Group,
Length = res.Length,
SpecialRequests = res.SpecialRequests,
Units = units,
Primary = person,
Invoices = invoices.Select(inv => new LetterInvoice
{
Invoice = inv,
Id = inv.Id,
Number = inv.Number,
CreatedTime = inv.CreatedTime,
PersonId = inv.PersonId,
FirstName = person.FirstName,
LastName = person.LastName,
LineItems = inv.LineItems.Select(l => new LetterInvoice.LineItemResult
{
Id = l.Id,
Type = l.Type,
Date = l.Date,
Description = l.Description,
RetailPrice = l.RetailPrice,
ActualPrice = l.ActualPrice,
AssignmentId = AsDocument(l).Value<string>("AssignmentId"),
UnitId = AsDocument(l).Value<string>("UnitId"),
POSItemId = AsDocument(l).Value<string>("POSItemId"),
Quantity = l.Quantity,
TaxGroupId = l.TaxGroupId,
FeeGroupId = l.FeeGroupId,
RevenueAccountId = l.RevenueAccountId,
RetailPriceExtended = l.RetailPriceExtended,
EffectiveDiscount = l.EffectiveDiscount,
Taxes = l.Taxes.Select(t => new LetterInvoice.LineTaxResult
{
TaxId = t.TaxId,
ActualAmount = t.ActualAmount,
RetailAmount = t.RetailAmount,
Description =
taxes.Single(
tax => tax.Id == t.TaxId)
.Name
}),
Fees = l.Fees.Select(f => new LetterInvoice.LineFeeResult
{
FeeId = f.FeeId,
Amount = f.Amount,
Description =
fees.Single(
fee => fee.Id == f.FeeId).Name
}),
TotalTaxes = l.TotalTaxes,
TotalFees = l.TotalFees,
TotalWithTaxAndFees = l.TotalWithTaxAndFees
}),
Payments = payments.Select(p => new LetterInvoice.PaymentResult
{
Id = p.Id,
Type = p.Type,
FirstName = p.FirstName,
LastName = p.LastName,
Amount = p.Amount,
PaymentTime = p.PaymentTime,
AppliedAmount = inv.Payments.Single(ip => ip.Key == p.Id).Value,
Description = p.Description
}),
TotalUnitCharges = inv.TotalUnitCharges,
TotalPOSCharges = inv.TotalPOSCharges,
TotalCharges = inv.TotalCharges,
TotalTaxes = inv.TotalTaxes,
TotalFees = inv.TotalFees,
TotalWithTaxAndFees = inv.TotalWithTaxAndFees,
TotalPayments = inv.TotalPayments,
BalanceDue = inv.BalanceDue
}),
UnitAssignments = assignments.Select(a =>
new LetterUnitAssignment
{
PersonId = a.PersonId,
UnitId = a.UnitId,
UnitName = units.Single(u => u.Id == a.UnitId).Name,
UnitShortName = units.Single(u => u.Id == a.UnitId).ShortName,
UnitDescription = units.Single(u => u.Id == a.UnitId).Description,
ArrivalDate = a.ArrivalDate,
DepartureDate = a.DepartureDate,
TimeOfArrival = a.TimeOfArrival,
TimeOfDeparture = a.TimeOfDeparture,
RateId = a.RateId,
Guests =
a.Guests.Select(
guest =>
new LetterAssignmentGuest
{
Count = guest.Value,
//TODO: Can this be done anymore? Definitions are under Categories, so we can't really access them in this transfomer.
//Description = guestDefinitions.Single(def => def.Id == guest.Key).Description
}),
}
),
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment