Пример #1
0
        public ApplicationGroup[] Group(ApplicationListItem[] applications, OrderType[] groups, long?clientId = null,
                                        long?senderId = null, long?forwarderId = null, long?carrierId = null)
        {
            var awbIds = applications.Select(x => x.AirWaybillId ?? 0).Distinct().ToArray();

            _airWaybills   = _awbRepository.Get(awbIds).ToDictionary(x => x.Id, x => x);
            _awbAggregates = _awbRepository.GetAggregate(awbIds, clientId, senderId, forwarderId, carrierId)
                             .ToDictionary(x => x.AirWaybillId, x => x);
            _countWithouAwb     = _awbRepository.GetTotalCountWithouAwb(clientId, senderId, forwarderId, carrierId);
            _weightWithouAwb    = _awbRepository.GetTotalWeightWithouAwb(clientId, senderId, forwarderId, carrierId);
            _docWeightWithouAwb = _awbRepository.GetTotalDocWeightWithouAwb(clientId, senderId, forwarderId, carrierId);
            _valueWithouAwb     = _awbRepository.GetTotalValueWithouAwb(clientId, senderId, forwarderId, carrierId);
            _volumeWithouAwb    = _awbRepository.GetTotalVolumeWithouAwb(clientId, senderId, forwarderId, carrierId);

            return(GroupImpl(applications, groups));
        }
Пример #2
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);
        }
Пример #3
0
        public ClientCalculationListCollection List(long clientId, int take, long skip)
        {
            long total;
            var  applications = GetCalculatedApplications(clientId, take, skip, out total);

            var awbIds = applications.Select(x => x.AirWaybillId ?? 0).ToArray();

            var awbsData = _awbRepository.Get(awbIds).ToArray();

            var items = GetItems(applications);

            var groups = GetGroups(awbsData, items);

            return(new ClientCalculationListCollection
            {
                Groups = groups.ToArray(),
                Total = total
            });
        }
Пример #4
0
        public IDictionary <string, string> Get(string language, EventDataForEntity eventData)
        {
            var awb       = _awbs.Get(eventData.EntityId).Single();
            var aggregate = _awbs.GetAggregate(new[] { awb.Id }).Single();
            var culture   = CultureInfo.GetCultureInfo(language);

            return(new Dictionary <string, string>
            {
                { "DepartureAirport", awb.DepartureAirport },
                { "DateOfDeparture", LocalizationHelper.GetDate(awb.DateOfDeparture, culture) },
                { "ArrivalAirport", awb.ArrivalAirport },
                { "DateOfArrival", LocalizationHelper.GetDate(awb.DateOfArrival, culture) },
                { "TotalWeight", aggregate.TotalWeight.ToString("N2") },
                { "TotalCount", aggregate.TotalCount.ToString("N2") },
                { "TotalValue", aggregate.TotalValue.ToString("N2") },
                { "AirWaybill", awb.Bill },
                { "TotalVolume", aggregate.TotalVolume.ToString("N2") },
                { "SenderName", GetSenderName(awb) }
            });
        }
Пример #5
0
        private IEnumerable <RecipientData> GetRecipients(IEnumerable <RoleType> roles, EventDataForEntity data)
        {
            foreach (var role in roles)
            {
                switch (role)
                {
                case RoleType.Admin:
                {
                    var recipients = _admins.GetAll()
                                     .Select(user => new RecipientData(user.Email, user.Language, RoleType.Admin));
                    foreach (var recipient in recipients)
                    {
                        yield return(recipient);
                    }
                }
                break;

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

                case RoleType.Broker:
                    var brokerId = _awbs.Get(data.EntityId).Single().BrokerId;
                    if (brokerId.HasValue)
                    {
                        var broker = _brokers.Get(brokerId.Value);

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

                    break;

                case RoleType.Sender:
                    foreach (var email in _awbs.GetSenderEmails(data.EntityId))
                    {
                        yield return(new RecipientData(email.Email, email.Language, RoleType.Client));
                    }

                    break;

                case RoleType.Client:
                    foreach (var emailData in _awbs.GetClientEmails(data.EntityId))
                    {
                        foreach (var email in EmailsHelper.SplitAndTrimEmails(emailData.Email))
                        {
                            yield return(new RecipientData(email, emailData.Language, RoleType.Client));
                        }
                    }

                    break;

                case RoleType.Forwarder:
                    foreach (var email in _awbs.GetForwarderEmails(data.EntityId))
                    {
                        yield return(new RecipientData(email.Email, email.Language, RoleType.Client));
                    }

                    break;

                case RoleType.Carrier:
                    foreach (var email in _awbs.GetCarrierEmails(data.EntityId))
                    {
                        yield return(new RecipientData(email.Email, email.Language, RoleType.Client));
                    }

                    break;

                default:
                    throw new InvalidOperationException("Unknown role " + role);
                }
            }
        }
Пример #6
0
        public CalculationListCollection Row(long awbId)
        {
            var data = _awbs.Get(awbId);

            return(List(data));
        }
Пример #7
0
 private long?TryGetUserIdByAwb(long entityId, EventType type)
 {
     return(EventHelper.AwbEventTypes.Contains(type)
                         ? _awbs.Get(entityId).Select(x => x.SenderUserId).FirstOrDefault()
                         : null);
 }
Пример #8
0
        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);
                }
            }
        }