Exemple #1
0
            private IList <PostingAccountCondition> GetPostingAccountsConditions()
            {
                var allLoadCarriers = LoadCarrierRepository.FindAll().Include(lc => lc.Quality)
                                      .Include(lc => lc.Type).AsNoTracking()
                                      .ToList();

                var postingAccountConditions = new List <PostingAccountCondition>();

                foreach (var postingAccount in Parent.PostingAccounts)
                {
                    var conditions = ConditionsRepository.FindByCondition(c =>
                                                                          c.AccountId == postingAccount.RefLtmsAccountId && c.ValidFrom.Date <= DateTime.Today &&
                                                                          (!c.ValidUntil.HasValue || c.ValidUntil.Value.Date >= DateTime.Today))
                                     .Include(t => t.Term)
                                     .Include(d => d.BookingDependent).AsNoTracking().ToList();

                    foreach (var condition in conditions)
                    {
                        var loadCarriers =
                            allLoadCarriers.Where(lc =>
                                                  condition.BookingDependent != null &&
                                                  lc.Type.RefLtmsArticleId == condition.BookingDependent.ArticleId);

                        if (condition.BookingDependent?.QualityId != null)
                        {
                            loadCarriers = loadCarriers.Where(flc =>
                                                              flc.Quality.RefLtmsQualityId == condition.BookingDependent.QualityId);
                        }

                        postingAccountConditions.AddRange(loadCarriers.Select(loadCarrier => new PostingAccountCondition
                        {
                            Type                 = condition.TermId.GetConditionType(),
                            Amount               = condition.BookingDependent?.Amount,
                            MaxQuantity          = condition.Term.UpperLimit,
                            MinQuantity          = condition.Term.LowerLimit,
                            LoadCarrierId        = loadCarrier.Id,
                            LoadCarrierTypeOrder = loadCarrier.Type.Order,
                            RefLtmsAccountId     = postingAccount.RefLtmsAccountId
                        }));
                    }
                }

                return(postingAccountConditions.OrderBy(c => c.LoadCarrierTypeOrder).ToList());
            }
            private Contracts.Models.ExpressCode GetExpressCodeByDigitalCode()
            {
                var avail2deli = LmsAvail2deliRepository.FindAll()
                                 .Where(ad => ad.ExpressCode == DigitalCode &&
                                        ad.State == 2 &&
                                        ad.FrachtpapiereErstellt.Value &&
                                        ad.DeletionDate == null
                                        )
                                 .Include(ad => ad.Availability)
                                 .Include(ad => ad.Delivery).AsNoTracking().FirstOrDefault();

                if (avail2deli == null)
                {
                    return(null);
                }

                var loadCarriers = LoadCarrierRepository.FindAll()
                                   .Include(lc => lc.Quality).ThenInclude(q => q.Mappings)
                                   .Include(lc => lc.Type)
                                   .FromCache().ToList();

                var loadCarrier = loadCarriers
                                  .SingleOrDefault(lc => lc.Type.RefLmsLoadCarrierTypeId == avail2deli.PalletTypeId && lc.Quality.Mappings.SingleOrDefault(qm => qm.RefLmsQualityId == avail2deli.QualityId) != null);

                Olma.LoadCarrier baseLoadCarrier = null;
                if (avail2deli.BaseQuantity != null && avail2deli.BaseQuantity != 0)
                {
                    baseLoadCarrier = loadCarriers
                                      .SingleOrDefault(lc => lc.Type.RefLmsLoadCarrierTypeId == avail2deli.BasePalletTypeId && lc.Quality.Mappings.SingleOrDefault(qm => qm.RefLmsQualityId == avail2deli.BaseQualityId) != null);
                }

                if (loadCarrier == null)
                {
                    return(null);
                }

                int?ltmsAccountId;

                switch (PrintType)
                {
                case B2b.Common.Enumerations.PrintType.LoadCarrierReceiptDelivery:
                    ltmsAccountId = avail2deli.Delivery.LtmsAccountId;
                    break;

                case B2b.Common.Enumerations.PrintType.LoadCarrierReceiptPickup:
                    ltmsAccountId = avail2deli.Availability.LtmsAccountId;
                    break;

                default:
                    return(null);
                }

                var postingAccount = PostingAccountRepository.FindAll()
                                     .Where(pa => pa.RefLtmsAccountId == ltmsAccountId)
                                     .AsNoTracking().FirstOrDefault();

                if (postingAccount == null)
                {
                    return(null);
                }

                var expressCode = new Contracts.Models.ExpressCode
                {
                    DigitalCode = DigitalCode,
                    LoadCarrierReceiptPreset = new LoadCarrierReceiptPreset
                    {
                        DeliveryNoteNumber      = avail2deli.Delivery?.DeliveryNoteNo,
                        PickupNoteNumber        = avail2deli.Availability?.ContractNo,
                        RefLmsBusinessTypeId    = avail2deli.Delivery?.BusinessTypeId,
                        LoadCarrierId           = loadCarrier.Id,
                        LoadCarrierQuantity     = avail2deli.Quantity,
                        BaseLoadCarrierId       = baseLoadCarrier?.Id,
                        BaseLoadCarrierQuantity = avail2deli.BaseQuantity,
                        PostingAccountId        = postingAccount.Id,
                        Type = PrintType == B2b.Common.Enumerations.PrintType.LoadCarrierReceiptPickup
                        ? LoadCarrierReceiptType.Pickup
                        : LoadCarrierReceiptType.Delivery,
                        PlannedFulfillmentDateTime = avail2deli.LadeterminDatum,
                        RefLtmsTransactionRowGuid  = avail2deli.RefLtmsTransactionRowGuid
                    }
                };

                return(expressCode);
            }