public void Add(CalculationData data, long applicationId)
		{
			_executor.Execute("[dbo].[Calculation_Add]", new
			{
				data.ClientId,
				ApplicationHistoryId = applicationId,
				data.AirWaybillDisplay,
				data.ApplicationDisplay,
				data.MarkName,
				data.Weight,
				data.TariffPerKg,
				data.ScotchCost,
				data.InsuranceRate,
				data.FactureCost,
				data.FactureCostEx,
				data.TransitCost,
				data.PickupCost,
				data.FactoryName,
				data.CreationTimestamp,
				ClassId = data.Class,
				data.Count,
				data.Invoice,
				data.Value,
				data.Profit,
				data.TotalTariffCost
			});
		}
		private static string GetComment(string type, CalculationData calculation)
		{
			if(calculation.Profit.HasValue)
				return type
				       + Environment.NewLine
				       + Entities.AWB + ": " + calculation.AirWaybillDisplay
				       + Environment.NewLine
				       + Entities.Application + ": " + calculation.ApplicationDisplay
				       + Environment.NewLine
				       + Entities.Sum + ": " + calculation.Profit;

			var profit = calculation.TotalTariffCost ?? 0
			             + calculation.ScotchCost
			             + (decimal)calculation.Weight * calculation.TariffPerKg
			             + (decimal)calculation.InsuranceRate * calculation.Value
			             + calculation.FactureCost
			             + calculation.FactureCostEx
			             + calculation.PickupCost
			             + calculation.TransitCost;

			return string.Format(
				"#{0} | {1:N2} kg * {2:N2}€ = {3:N2}€ | скотч - {4:N2}€ | страховка - {5:N2}€ |" +
				" фактура - {6:N2}€ | доставка - {7:N2}€ | забор с фабрики - {8:N2}€ | Итого - {9:N2}€",
				calculation.ApplicationDisplay,
				calculation.Weight,
				calculation.TariffPerKg,
				calculation.Weight * (double)calculation.TariffPerKg,
				calculation.ScotchCost,
				calculation.InsuranceRate * (double)calculation.Value,
				calculation.FactureCost + calculation.FactureCostEx,
				calculation.TransitCost,
				calculation.PickupCost,
				profit);
		}
		public CalculationDataDrawable(CalculationData data, string clientNick, int columnCount, ExcelWorksheet excel)
		{
			_data = data;
			_clientNick = clientNick;
			_excel = excel;
			_columnCount = columnCount;
		}
Exemple #4
0
		public CalculationData Calculate(long applicationId)
		{
			var application = _applications.Get(applicationId);

			if(application.AirWaybillId == null)
				throw new InvalidOperationException(
					"For calculation an air waybill should be presented. Applicaiton id: "
					+ application.Id);

			var awb = _awbs.Get(application.AirWaybillId.Value).First();

			var weight = application.Weight ?? 0;
			var tariffPerKg = application.TariffPerKg ?? 0;
			var scotch = GetTapeCost(application);
			var transitCost = application.TransitCostEdited ?? application.TransitCost ?? 0;
			var pickupCost = application.PickupCostEdited ?? application.PickupCost ?? 0;

			var calculation = new CalculationData
			{
				AirWaybillDisplay = AwbHelper.GetAirWaybillDisplay(awb),
				ApplicationDisplay = application.GetApplicationDisplay(),
				ClientId = application.ClientId,
				FactureCost = application.FactureCostEdited ?? application.FactureCost ?? 0,
				FactureCostEx = application.FactureCostExEdited ?? application.FactureCostEx ?? 0,
				MarkName = application.MarkName,
				FactoryName = application.FactoryName,
				ScotchCost = scotch,
				TariffPerKg = tariffPerKg,
				Weight = weight,
				TransitCost = transitCost,
				PickupCost = pickupCost,
				CreationTimestamp = DateTimeProvider.Now,
				Count = application.Count ?? 0,
				Invoice = application.Invoice,
				Value = application.Value,
				Class = application.Class,
				InsuranceRate = application.InsuranceRate,
				Profit = application.CalculationProfit,
				TotalTariffCost = application.CalculationTotalTariffCost
			};

			_calculations.Add(calculation, applicationId);

			return calculation;
		}
		public static decimal GetMoney(CalculationData calculation, float insuranceRate)
		{
			if(calculation.Profit.HasValue)
			{
				return calculation.Profit.Value;
			}

			return CalculationHelper.GetTotalTariffCost(
				calculation.TotalTariffCost,
				calculation.TariffPerKg,
				calculation.Weight)
			       + calculation.ScotchCost
			       + calculation.Value * (decimal)insuranceRate
			       + calculation.FactureCost
			       + calculation.FactureCostEx
			       + calculation.TransitCost
			       + calculation.PickupCost;
		}
		private static MemoryStream Get(ClientData client, decimal balance, CalculationData[] calculations,
			ClientBalanceHistoryItem[] history)
		{
			var stream = new MemoryStream();

			using(var pck = new ExcelPackage())
			{
				var excel = pck.Workbook.Worksheets.Add(Entities.Application);
				excel.Cells.Style.Font.Name = ExcelConstants.DefaultFontName;
				excel.Cells.Style.Font.Size = ExcelConstants.DefaultFontSize;
				excel.Cells.Style.Numberformat.Format = "0.00";

				var columnCount = DrawHeader(excel, balance);

				var iRow = DrawRows(client, calculations, history, columnCount, 3, excel);

				AdjustExcel(columnCount, excel, iRow);

				pck.SaveAs(stream);
			}

			stream.Position = 0;

			return stream;
		}
		private static int DrawRows(ClientData client, CalculationData[] calculations,
			ClientBalanceHistoryItem[] history, int columnCount, int iRow, ExcelWorksheet excel)
		{
			var drawables = DrawableMapper.Get(history, excel, client, columnCount)
				.Union(DrawableMapper.Get(calculations, excel, client, columnCount))
				.OrderByDescending(x => x.Position)
				.ToArray();

			foreach(var drawable in drawables)
			{
				iRow = drawable.Draw(iRow);
			}

			return iRow;
		}
		private CalculationData AddNew(CalculationData data, long applicationId)
		{
			_calculation.Add(data, applicationId);

			return _calculation.GetByApplication(applicationId);
		}
Exemple #9
0
		public static IDrawable[] Get(CalculationData[] calculations, ExcelWorksheet excel, ClientData client, int columnCount)
		{
			return calculations.Select(x => (IDrawable)new CalculationDataDrawable(
				x, client.Nic, columnCount, excel)).ToArray();
		}
Exemple #10
0
		public static decimal GetMoney(CalculationData calculation)
		{
			return GetMoney(calculation, calculation.InsuranceRate);
		}