Example #1
0
		public string GetText(string template, string language, EventType type, ApplicationData application,
			byte[] bytes)
		{
			var data = GetTextLocalizedData(type, application, language, bytes);

			return _bulder.GetText(template, language, data);
		}
		private IEnumerable<CalculationItem> GetItems(
			ApplicationData[] applications,
			IReadOnlyDictionary<long, decimal> tariffs)
		{
			var appIds = applications.Select(x => x.Id).ToArray();
			var calculations = _applications.GetCalculations(appIds);

			return applications.Select(a => new CalculationItem
			{
				ApplicationId = a.Id,
				Value = a.Value,
				Count = a.Count,
				ClientNic = a.ClientNic,
				Factory = a.FactoryName,
				FactureCost = a.FactureCostEdited ?? a.FactureCost,
				FactureCostEx = a.FactureCostExEdited ?? a.FactureCostEx,
				Invoice = a.Invoice,
				Mark = a.MarkName,
				ScotchCost = (a.ScotchCostEdited ?? CalculationHelper.GetSenderTapeTariff(tariffs, a.SenderId)) * a.Count,
				TariffPerKg = a.TariffPerKg,
				SenderRate = a.SenderRate,
				TransitCost = a.TransitCostEdited ?? a.TransitCost,
				ValueCurrencyId = a.CurrencyId,
				Weight = a.Weight,
				PickupCost = a.PickupCostEdited ?? a.PickupCost,
				AirWaybillId = a.AirWaybillId.Value,
				DisplayNumber = a.GetApplicationDisplay(),
				InsuranceCost = CalculationHelper.GetInsuranceCost(a.Value, a.InsuranceRate),
				TotalSenderRate = CalculationHelper.GetTotalSenderRate(a.SenderRate, a.Weight),
				IsCalculated = calculations.ContainsKey(a.Id),
				ClassId = a.Class,
				TotalTariffCost = CalculationHelper.GetTotalTariffCost(a.CalculationTotalTariffCost, a.TariffPerKg, a.Weight),
				Profit = CalculationHelper.GetProfit(a, tariffs)
			}).OrderBy(x => x.ClientNic).ThenByDescending(x => x.ApplicationId).ToArray();
		}
Example #3
0
		public void TestInitialize()
		{
			_context = new MockContainer();

			_service = _context.Create<ApplicationPresenter>();

			_applicationData = _context.Create<ApplicationData>();
		}
Example #4
0
		private IDictionary<string, string> GetTextLocalizedData(EventType type,
			ApplicationData application, string language, byte[] bytes)
		{
			var culture = CultureInfo.GetCultureInfo(language);

			var localizedData = GetTextLocalizedData(application, language, culture);

			switch(type)
			{
				case EventType.ApplicationSetState:
					OnSetState(bytes, language, localizedData);
					break;

				case EventType.SetTransitReference:
				case EventType.ApplicationCreated:
				case EventType.SetSender:
				case EventType.SetForwarder:
				case EventType.SetCarrier:
					break;

				case EventType.Calculate:
				case EventType.CalculationCanceled:
					OnCalculation(bytes, culture, localizedData);
					break;

				case EventType.CPFileUploaded:
				case EventType.InvoiceFileUploaded:
				case EventType.PackingFileUploaded:
				case EventType.SwiftFileUploaded:
				case EventType.DeliveryBillFileUploaded:
				case EventType.Torg12FileUploaded:
				case EventType.T1FileUploaded:
				case EventType.Ex1FileUploaded:
				case EventType.OtherApplFileUploaded:
					OnFileUpload(bytes, localizedData);
					break;

				case EventType.SetDateOfCargoReceipt:
					OnSetDateOfCargoReceipt(bytes, culture, localizedData);
					break;

				case EventType.SetAwb:
					OnSetAwb(bytes, culture, localizedData);
					break;

				default:
					throw new ArgumentOutOfRangeException("type");
			}

			return localizedData;
		}
Example #5
0
		private IDictionary<string, string> GetTextLocalizedData(ApplicationData application, string language,
			CultureInfo culture)
		{
			var state = _states.Get(language, application.StateId).Select(x => x.Value).FirstOrDefault();
			var countryName = _countries.All(language).First(x => x.Id == application.CountryId).Name;
			var cityName = _cities.All(language).First(x => x.Id == application.TransitCityId).Name;
			var value = LocalizationHelper.GetValueString(application.Value, application.CurrencyId, culture);
			var deliveryBill = _files.GetNames(application.Id, ApplicationFileType.DeliveryBill).Select(x => x.Name).ToArray();
			var invoice = _files.GetNames(application.Id, ApplicationFileType.Invoice).Select(x => x.Name).ToArray();
			var packing = _files.GetNames(application.Id, ApplicationFileType.Packing).Select(x => x.Name).ToArray();
			var swift = _files.GetNames(application.Id, ApplicationFileType.Swift).Select(x => x.Name).ToArray();
			var torg12 = _files.GetNames(application.Id, ApplicationFileType.Torg12).Select(x => x.Name).ToArray();
			var t1 = _files.GetNames(application.Id, ApplicationFileType.T1).Select(x => x.Name).ToArray();
			var ex1 = _files.GetNames(application.Id, ApplicationFileType.Ex1).Select(x => x.Name).ToArray();

			var localizedData = new Dictionary<string, string>();
			Add(localizedData, "AddressLoad", application.AddressLoad);
			Add(localizedData, "FactoryName", application.FactoryName);
			Add(localizedData, "Id", application.Id.ToString(culture));
			Add(localizedData, "Count", application.Count.HasValue ? application.Count.Value.ToString(culture) : null);
			Add(localizedData, "MarkName", application.MarkName);
			Add(localizedData, "Invoice", application.Invoice);
			Add(localizedData, "CountryName", countryName);
			Add(localizedData, "CreationTimestamp", LocalizationHelper.GetDate(application.CreationTimestamp, culture));
			Add(localizedData, "Value", value);
			Add(localizedData, "Weight", application.Weight.HasValue ? application.Weight.Value.ToString(culture) : null);
			Add(localizedData, "AirWaybill", application.AirWaybill);
			Add(localizedData, "AirWaybillDateOfArrival",
				LocalizationHelper.GetDate(application.AirWaybillDateOfArrival, culture));
			Add(localizedData, "AirWaybillDateOfDeparture",
				LocalizationHelper.GetDate(application.AirWaybillDateOfDeparture, culture));
			Add(localizedData, "AirWaybillGTD", application.AirWaybillGTD);
			Add(localizedData, "Characteristic", application.Characteristic);
			Add(localizedData, "ClientNic", application.ClientNic);
			Add(localizedData, "DateOfCargoReceipt", LocalizationHelper.GetDate(application.DateOfCargoReceipt, culture));
			Add(localizedData, "DaysInWork", application.GetDaysInWork().ToString(culture));
			Add(localizedData, "DeliveryBillFiles", string.Join(", ", deliveryBill));
			Add(localizedData, "DeliveryType", LocalizationHelper.GetDeliveryType(application.TransitDeliveryType, culture));
			Add(localizedData, "DisplayNumber", application.GetApplicationDisplay());
			Add(localizedData, "FactoryContact", application.FactoryContact);
			Add(localizedData, "FactoryEmail", application.FactoryEmail);
			Add(localizedData, "FactoryPhone", application.FactoryPhone);
			Add(localizedData, "InvoiceFiles", string.Join(", ", invoice));
			Add(localizedData, "LegalEntity", application.ClientLegalEntity);
			Add(localizedData, "Pickup",
				application.IsPickup
						? Alicargo.Core.Resources.Entities.ResourceManager.GetString("Pickup", culture)
						: "");
			Add(localizedData, "MethodOfDelivery", LocalizationHelper.GetMethodOfDelivery(application.MethodOfDelivery, culture));
			Add(localizedData, "MethodOfTransit",
					LocalizationHelper.GetMethodOfTransit(application.TransitMethodOfTransit, culture));
			Add(localizedData, "PackingFiles", string.Join(", ", packing));
			Add(localizedData, "StateChangeTimestamp", LocalizationHelper.GetDate(application.StateChangeTimestamp, culture));
			Add(localizedData, "StateName", state != null ? state.LocalizedName : null);
			Add(localizedData, "SwiftFiles", string.Join(", ", swift));
			Add(localizedData, "TermsOfDelivery", application.TermsOfDelivery);
			Add(localizedData, "Torg12Files", string.Join(", ", torg12));
			Add(localizedData, "T1Files", string.Join(", ", t1));
			Add(localizedData, "Ex1Files", string.Join(", ", ex1));
			Add(localizedData, "TransitAddress", application.TransitAddress);
			Add(localizedData, "CarrierName", application.CarrierName);
			Add(localizedData, "CarrierContact", application.CarrierContact);
			Add(localizedData, "CarrierAddress", application.CarrierAddress);
			Add(localizedData, "CarrierPhone", application.CarrierPhone);
			Add(localizedData, "CarrierEmail", application.CarrierEmail);
			Add(localizedData, "TransitCity", cityName);
			Add(localizedData, "TransitPhone", application.TransitPhone);
			Add(localizedData, "TransitRecipientName", application.TransitRecipientName);
			Add(localizedData, "TransitReference", application.TransitReference);
			Add(localizedData, "TransitWarehouseWorkingTime", application.TransitWarehouseWorkingTime);
			Add(localizedData, "Volume", application.Volume.ToString("N2", culture));
			Add(localizedData, "WarehouseWorkingTime", application.WarehouseWorkingTime);
			Add(localizedData, "SenderName", application.SenderName);
			Add(localizedData, "SenderContact", application.SenderContact);
			Add(localizedData, "SenderPhone", application.SenderPhone);
			Add(localizedData, "SenderAddress", application.SenderAddress);
			Add(localizedData, "SenderEmail", application.SenderEmail);
			Add(localizedData, "ForwarderName", application.ForwarderName);
			Add(localizedData, "CountInInvoce", application.CountInInvoce.ToString());
			Add(localizedData, "DocumentWeight", application.DocumentWeight.ToString());
			Add(localizedData, "MRN", application.MRN);

			return localizedData;
		}
		private static decimal GetProfit(ApplicationData application)
		{
			return application.CalculationProfit
				   ?? CalculationHelper.GetTotalTariffCost(application.CalculationTotalTariffCost,
					   application.TariffPerKg,
					   application.Weight)
				   + (application.GetAdjustedScotchCost() ?? 0)
				   + CalculationHelper.GetInsuranceCost(application.Value, application.InsuranceRate)
				   + (application.GetAdjustedFactureCost() ?? 0)
				   + (application.GetAdjustedFactureCostEx() ?? 0)
				   + (application.GetAdjustedPickupCost() ?? 0)
				   + (application.GetAdjustedTransitCost() ?? 0);
		}
		private static void Validate(
			ClientData clientData, ApplicationAdminModel model, TransitEditModel transitModel,
			ApplicationData data)
		{
			data.ShouldBeEquivalentTo(model,
				options => options.ExcludingMissingProperties()
					.Excluding(x => x.PickupCost)
					.Excluding(x => x.CarrierId)
					.Excluding(x => x.CarrierName)
					.Excluding(x => x.InsuranceRate));
			data.InsuranceRate.ShouldBeEquivalentTo(model.InsuranceRate / 100);
			data.GetAdjustedFactureCost().ShouldBeEquivalentTo(model.FactureCostEdited);
			data.GetAdjustedFactureCostEx().ShouldBeEquivalentTo(model.FactureCostExEdited);
			data.GetAdjustedTransitCost().ShouldBeEquivalentTo(model.TransitCostEdited);
			data.GetAdjustedPickupCost().ShouldBeEquivalentTo(model.PickupCostEdited);
			data.GetAdjustedScotchCost().ShouldBeEquivalentTo(model.ScotchCostEdited);
			data.CurrencyId.ShouldBeEquivalentTo(model.Currency.CurrencyId);
			data.ClientLegalEntity.ShouldBeEquivalentTo(clientData.LegalEntity);
			data.ClientNic.ShouldBeEquivalentTo(clientData.Nic);
			data.TransitAddress.ShouldBeEquivalentTo(transitModel.Address);
			data.TransitCityId.ShouldBeEquivalentTo(TestConstants.TestCityId1);
			data.CarrierId.ShouldBeEquivalentTo(TestConstants.TestCarrierId1);
			data.TransitDeliveryType.ShouldBeEquivalentTo(transitModel.DeliveryType);
			data.TransitMethodOfTransit.ShouldBeEquivalentTo(transitModel.MethodOfTransit);
			data.TransitPhone.ShouldBeEquivalentTo(transitModel.Phone);
			data.TransitRecipientName.ShouldBeEquivalentTo(transitModel.RecipientName);
			data.TransitWarehouseWorkingTime.ShouldBeEquivalentTo(transitModel.WarehouseWorkingTime);
		}
		private IEnumerable<RecipientData> GetRecipients(ApplicationData application, IEnumerable<RoleType> roles)
		{
			foreach(var role in roles)
			{
				switch(role)
				{
					case RoleType.Admin:
						foreach(
							var recipient in _admins.GetAll().Select(user => new RecipientData(user.Email, user.Language, RoleType.Admin)))
						{
							yield return recipient;
						}
						break;

					case RoleType.Manager:
						foreach(
							var recipient in
								_managers.GetAll().Select(user => new RecipientData(user.Email, user.Language, RoleType.Manager)))
						{
							yield return recipient;
						}
						break;

					case RoleType.Sender:
						if(application.SenderId.HasValue)
						{
							var sender = _senders.Get(application.SenderId.Value);
							yield return new RecipientData(sender.Email, sender.Language, role);
						}
						break;

					case RoleType.Broker:
						if(application.AirWaybillId.HasValue)
						{
							var awb = _awbs.Get(application.AirWaybillId.Value).Single();
							if(awb.BrokerId.HasValue)
							{
								var broker = _brokers.Get(awb.BrokerId.Value);

								yield return new RecipientData(broker.Email, broker.Language, role);
							}
						}

						break;

					case RoleType.Forwarder:
						var forwarder = _forwarders.Get(application.ForwarderId);
						yield return new RecipientData(forwarder.Email, forwarder.Language, role);
						break;

					case RoleType.Carrier:
						var carrier = _carriers.Get(application.CarrierId);
						yield return new RecipientData(carrier.Email, carrier.Language, role);
						break;

					case RoleType.Client:
						var client = _clients.Get(application.ClientId);
						foreach(var email in EmailsHelper.SplitAndTrimEmails(client.Emails))
						{
							yield return new RecipientData(email, client.Language, role);
						}
						break;

					default:
						throw new InvalidOperationException("Unknown role " + role);
				}
			}
		}
		public ApplicationListItem[] Map(ApplicationData[] data, string language)
		{
			var appIds = data.Select(x => x.Id).ToArray();
			var stateIds = data.Select(x => x.StateId).ToArray();

			var countries = _countries.All(language).ToDictionary(x => x.Id, x => x.Name);
			var states = _states.Get(language, stateIds);
			var stateAvailability = _stateFilter.GetStateAvailabilityToSet();
			var calculations = _applications.GetCalculations(appIds);
			var cps = _files.GetInfo(appIds, ApplicationFileType.CP);
			var deliveryBills = _files.GetInfo(appIds, ApplicationFileType.DeliveryBill);
			var invoices = _files.GetInfo(appIds, ApplicationFileType.Invoice);
			var packings = _files.GetInfo(appIds, ApplicationFileType.Packing);
			var otherFiles = _files.GetInfo(appIds, ApplicationFileType.Other);
			var swifts = _files.GetInfo(appIds, ApplicationFileType.Swift);
			var torg12 = _files.GetInfo(appIds, ApplicationFileType.Torg12);
			var t1 = _files.GetInfo(appIds, ApplicationFileType.T1);
			var ex1 = _files.GetInfo(appIds, ApplicationFileType.Ex1);
			var cities = _cities.All(language).ToDictionary(x => x.Id, x => x.Name);

			return data.Select(x => new ApplicationListItem
			{
				CountryName = countries[x.CountryId],
				State = new ApplicationStateModel
				{
					StateId = x.StateId,
					StateName = states[x.StateId].LocalizedName
				},
				CanClose = x.StateId == _stateConfig.CargoOnTransitStateId,
				CanSetState = stateAvailability.Contains(x.StateId),
				AddressLoad = x.AddressLoad,
				Id = x.Id,
				FactoryName = x.FactoryName,
				Invoice = x.Invoice,
				MarkName = x.MarkName,
				Volume = x.Volume,
				Count = x.Count,
				AirWaybill = x.AirWaybill,
				Characteristic = x.Characteristic,
				ClientLegalEntity = x.ClientLegalEntity,
				ClientNic = x.ClientNic,
				ClientId = x.ClientId,
				CreationTimestamp = x.CreationTimestamp,
				DateInStock = x.DateInStock,
				DateOfCargoReceipt = x.DateOfCargoReceipt,
				FactoryContact = x.FactoryContact,
				FactoryEmail = x.FactoryEmail,
				FactoryPhone = x.FactoryPhone,
				StateChangeTimestamp = x.StateChangeTimestamp,
				StateId = x.StateId,
				TermsOfDelivery = x.TermsOfDelivery,
				TransitAddress = x.TransitAddress,
				CarrierName = x.CarrierName,
				CarrierContact = x.CarrierContact,
				CarrierAddress = x.CarrierAddress,
				CarrierPhone = x.CarrierPhone,
				TransitId = x.TransitId,
				TransitCity = cities[x.TransitCityId],
				TransitDeliveryTypeString = x.TransitDeliveryType.ToLocalString(),
				TransitMethodOfTransitString = x.TransitMethodOfTransit.ToLocalString(),
				TransitPhone = x.TransitPhone,
				TransitRecipientName = x.TransitRecipientName,
				TransitReference = x.TransitReference,
				TransitWarehouseWorkingTime = x.TransitWarehouseWorkingTime,
				WarehouseWorkingTime = x.WarehouseWorkingTime,
				Weight = x.Weight,
				MethodOfDeliveryId = (int)x.MethodOfDelivery,
				IsPickup = x.IsPickup,
				TransitMethodOfTransitId = (int)x.TransitMethodOfTransit,
				Value = x.Value,
				CurrencyId = (int)x.CurrencyId,
				AirWaybillId = x.AirWaybillId,
				PickupCost = x.GetAdjustedPickupCost(),
				FactureCost = x.GetAdjustedFactureCost(),
				FactureCostEx = x.GetAdjustedFactureCostEx(),
				ScotchCost = x.GetAdjustedScotchCost(),
				SenderName = x.SenderName,
				ForwarderName = x.ForwarderName,
				SenderScotchCost = x.SenderScotchCost,
				TariffPerKg = x.TariffPerKg,
				TransitCost = x.GetAdjustedTransitCost(),
				ForwarderTransitCost = x.TransitCost,
				CanSetTransitCost = !calculations.ContainsKey(x.Id),
				CPFiles = cps.ContainsKey(x.Id) ? cps[x.Id].ToArray() : null,
				DeliveryBillFiles = deliveryBills.ContainsKey(x.Id) ? deliveryBills[x.Id].ToArray() : null,
				InvoiceFiles = invoices.ContainsKey(x.Id) ? invoices[x.Id].ToArray() : null,
				PackingFiles = packings.ContainsKey(x.Id) ? packings[x.Id].ToArray() : null,
				OtherFiles = otherFiles.ContainsKey(x.Id) ? otherFiles[x.Id].ToArray() : null,
				SwiftFiles = swifts.ContainsKey(x.Id) ? swifts[x.Id].ToArray() : null,
				Torg12Files = torg12.ContainsKey(x.Id) ? torg12[x.Id].ToArray() : null,
				T1Files = t1.ContainsKey(x.Id) ? t1[x.Id].ToArray() : null,
				Ex1Files = ex1.ContainsKey(x.Id) ? ex1[x.Id].ToArray() : null,
				DisplayNumber = x.GetApplicationDisplay(),
				DaysInWork = x.GetDaysInWork(),
				CreationTimestampLocalString = LocalizationHelper.GetDate(x.CreationTimestamp, CultureProvider.GetCultureInfo()),
				StateChangeTimestampLocalString =
					LocalizationHelper.GetDate(x.StateChangeTimestamp, CultureProvider.GetCultureInfo()),
				DateOfCargoReceiptLocalString =
					x.DateOfCargoReceipt.HasValue
						? LocalizationHelper.GetDate(x.DateOfCargoReceipt.Value, CultureProvider.GetCultureInfo())
						: null,
				DateInStockLocalString =
					x.DateInStock.HasValue ? LocalizationHelper.GetDate(x.DateInStock.Value, CultureProvider.GetCultureInfo()) : null,
				MethodOfDeliveryLocalString = x.MethodOfDelivery.ToLocalString(),
				ValueString = GetValueString(x.Value, x.CurrencyId),
				MRN = x.MRN,
				CountInInvoce = x.CountInInvoce,
				DocumentWeight = x.DocumentWeight
			}).ToArray();
		}
		private static decimal GetProfit(ApplicationData data)
		{
			return (data.SenderScotchCost ?? 0)
			       + (data.FactureCost ?? 0)
			       + (data.FactureCostEx ?? 0)
			       + (data.PickupCost ?? 0)
			       + CalculationHelper.GetTotalSenderRate(data.SenderRate, data.Weight);
		}
Example #11
0
		private EmailMessage GetEmailMessage(
			string email,
			string culture,
			EmailTemplateLocalizationData localization,
			ApplicationData application,
			byte[] data,
			EventType type,
			FileHolder[] files,
			long? emailSenderUserId)
		{
			var subject = _textBuilder.GetText(localization.Subject, culture, type, application, data);
			var body = _textBuilder.GetText(localization.Body, culture, type, application, data);

			return new EmailMessage(subject, body, _defaultFrom, email, emailSenderUserId)
			{
				IsBodyHtml = localization.IsBodyHtml,
				Files = files
			};
		}