@using System.Collections.Generic @using System.Linq @using Resto.Front.PrintTemplates.Cheques.Razor @using Resto.Front.PrintTemplates.Cheques.Razor.TemplateModels @inherits TemplateBase @{ var order = Model.Order; var chequeInfo = Model.ChequeInfo; var session = chequeInfo.Session; var paymentsSum = 0m; bool useAggregatedDiscount; if (order.Items.Count() < 2) { useAggregatedDiscount = true; } else { const decimal MaxGeneralDiscountDeviation = 0.01m; var discounts = order.Items.Select(x => x.SumWithoutDiscounts == 0 ? 0 : x.SumWithDiscounts / x.SumWithoutDiscounts).ToList(); useAggregatedDiscount = discounts.Max() - discounts.Min() < MaxGeneralDiscountDeviation; } var resultSum = order.Items.Sum(item => item.SumWithDiscounts); var subTotal = order.Items.Sum(item => item.SumWithoutDiscounts); } @* header *@
Eleni's Pizza Works
6711 15th St E, Sarasota, FL 34243
Check #@order.Number
@* body *@ @Products(order.Items, useAggregatedDiscount) @if (useAggregatedDiscount && subTotal != resultSum) { var percent = decimal.Round((resultSum / subTotal - 1) * 100, 2); var sum = resultSum - subTotal; @(percent < 0m ? string.Format(Resources.AggregatedDiscountNameFormat, -percent) : string.Format(Resources.AggregatedIncreaseNameFormat, percent)) @FormatPercent(percent) $@FormatMoney(sum)
} @* payments *@ @foreach (var prepay in order.Payments.Where(p => p.IsPrepay)) { paymentsSum += prepay.Sum; } @foreach (var payment in order.Payments.Where(p => !p.IsPrepay)) { paymentsSum += payment.Sum; }
@helper Products(IEnumerable orderItems, bool useAggregatedDiscount) { if (orderItems.IsEmpty()) { @Resources.ZeroChequeBody } else { Item @Resources.AmountShort @Resources.ResultSum @foreach (var orderItem in orderItems) { @Product(orderItem, useAggregatedDiscount) }
} } @helper Product(IPastOrderItem orderItem, bool useAggregatedDiscount) { @(orderItem.ProductSize == null ? orderItem.Product.Name : string.Format(Resources.ProductNameWithSizeFormat, orderItem.Product.Name, orderItem.ProductSize.Name)) @FormatAmount(orderItem.Amount) @FormatMoney(orderItem.SumWithoutDiscounts) }