private static SenderCalculationAwbInfo[] GetInfo(
            IEnumerable <SenderCalculationGroup> groups,
            IEnumerable <ApplicationData> items,
            IReadOnlyDictionary <long, decimal> tariffs)
        {
            return(groups.Select(g =>
            {
                var rows = items.Where(a => a.AirWaybillId == g.AirWaybillId).ToArray();

                var info = new SenderCalculationAwbInfo
                {
                    AirWaybillId = g.AirWaybillId,
                    TotalCostOfSenderForWeight = g.TotalCostOfSenderForWeight,
                    FlightCost = g.FlightCost,
                    TotalSenderRate = rows.Sum(x => CalculationHelper.GetTotalSenderRate(x.SenderRate, x.Weight)),
                    TotalScotchCost = rows.Sum(x => CalculationHelper.GetSenderTapeTariff(tariffs, x.SenderId) * x.Count) ?? 0,
                    TotalFactureCost = rows.Sum(x => x.FactureCost ?? 0),
                    TotalFactureCostEx = rows.Sum(x => x.FactureCostEx ?? 0),
                    TotalPickupCost = rows.Sum(x => x.PickupCost ?? 0),
                    CostPerKgOfSender = null,
                    FlightCostPerKg = null
                };

                var totalWeight = (decimal)rows.Sum(x => x.Weight ?? 0);

                if (totalWeight != 0)
                {
                    info.CostPerKgOfSender = info.TotalSenderRate / totalWeight;
                    info.FlightCostPerKg = info.FlightCost / totalWeight;
                }

                return info;
            }).ToArray());
        }
Exemple #2
0
        private static int DrawInfo(ExcelWorksheet ws, SenderCalculationAwbInfo info, int iRow, int count)
        {
            var range = ws.Cells[iRow, 1, iRow, count];

            range.Merge = true;
            range.Style.Fill.PatternType = ExcelFillStyle.Solid;
            range.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
            ws.Row(iRow).Height = ExcelConstants.DefaultRowHeight;
            iRow++;

            ws.Cells[iRow, 1].Value  = "sender";
            ws.Cells[iRow, 2].Value  = info.CostPerKgOfSender;
            ws.Cells[iRow, 10].Value = info.TotalSenderRate;
            ws.Cells[iRow, 11].Value = info.TotalScotchCost;
            ws.Cells[iRow, 12].Value = info.TotalFactureCost;
            ws.Cells[iRow, 13].Value = info.TotalFactureCostEx;
            ws.Cells[iRow, 14].Value = info.TotalPickupCost;
            ws.Cells[iRow, 15].Value = info.TotalOfSender;
            ws.Row(iRow).Height      = ExcelConstants.DefaultRowHeight;
            ws.Cells[iRow, 1, iRow, 14].Style.Font.Bold = true;
            iRow++;

            ws.Cells[iRow, 1].Value  = "flight";
            ws.Cells[iRow, 2].Value  = info.FlightCostPerKg;
            ws.Cells[iRow, 15].Value = info.FlightCost;
            ws.Row(iRow).Height      = ExcelConstants.DefaultRowHeight;
            ws.Cells[iRow, 1, iRow, 14].Style.Font.Bold = true;
            iRow++;

            ws.Cells[iRow, 1].Value  = "cost total";
            ws.Cells[iRow, 15].Value = info.Total;
            var rangeCost = ws.Cells[iRow, 1, iRow, count];

            rangeCost.Style.Fill.PatternType = ExcelFillStyle.Solid;
            rangeCost.Style.Fill.BackgroundColor.SetColor(Color.HotPink);
            ws.Row(iRow).Height = ExcelConstants.DefaultRowHeight;
            ws.Cells[iRow, 1, iRow, 15].Style.Font.Bold = true;
            iRow++;

            return(iRow);
        }