Exemplo n.º 1
0
        /// <summary>
        /// Add InvoiceLine By InvoiceLine
        /// </summary>
        /// <param name="invoiceLine"></param>
        /// <returns></returns>
        public bool AddInvoiceLine(InvoiceLine invoiceLine)
        {
            if (invoiceLine == null)
            {
                //empty item
                new LogManager().Log($"Fail to add invoice line (NULL) to invoice(Id: {InvoiceNumber})");
                return(false);
            }
            if (LineItems == null)
            {
                LineItems = new List <InvoiceLine>();
            }

            if (!LineItems.Any(i => i.InvoiceLineId == invoiceLine.InvoiceLineId))
            {
                //add
                LineItems.Add(invoiceLine);
                new LogManager().Log($"Add invoice line (Id: {invoiceLine.InvoiceLineId}) to invoice (Id: {InvoiceNumber})");
                return(true);
            }
            else
            {
                //update
                var existingItem = LineItems.Where(i => i.InvoiceLineId == invoiceLine.InvoiceLineId).First();
                LineItems.Remove(existingItem);
                LineItems.Add(invoiceLine);
                new LogManager().Log($"Update invoice line (Id: {invoiceLine.InvoiceLineId}) to invoice (Id: {InvoiceNumber})");
                return(false);
            }
        }
Exemplo n.º 2
0
 public TotalsMeta CalculateTotalsMeta()
 {
     return(new TotalsMeta
     {
         HighestDeposit = LineItems?.Where(x => x.Amount > 0)?.Max(x => x.Amount) ?? 0,
         HighestWithdrawal = LineItems?.Where(x => x.Amount < 0)?.Min(x => x.Amount) ?? 0,
         LowestDeposit = LineItems?.Where(x => x.Amount > 0)?.Min(x => x.Amount) ?? 0,
         LowestWithdrawal = LineItems?.Where(x => x.Amount < 0)?.Max(x => x.Amount) ?? 0,
         TotalsTally = LineItems?.Sum(x => x.Amount) == (EndingBalance - StartingBalance)
     });
 }
Exemplo n.º 3
0
        private void ProcessCancellation()
        {
            if (!CancelOrderRequested && !OrderRejected)
            {
                CancelOrderRequested = true;
                Send(new CancelOrderRequestMessage
                {
                    Id      = Guid.NewGuid(),
                    OrderId = OrderId
                });
            }

            foreach (var lineItem in LineItems.Where(li => li.StockConfirmed))
            {
                ReturnStock(lineItem);
            }
        }
 public bool IsAnyLineItemTotal(decimal lineItemTotal, bool isExactly, string[] excludingCategoryIds, string[] excludingProductIds, string[] excludingSkuIds)
 {
     if (isExactly)
     {
         return(LineItems.Where(x => x.CostPerEntry * x.Quantity == lineItemTotal)
                .ExcludeCategories(excludingCategoryIds)
                .ExcludeProducts(excludingProductIds)
                .ExcludeSkus(excludingSkuIds)
                .Any());
     }
     else
     {
         return(LineItems.Where(x => x.CostPerEntry * x.Quantity >= lineItemTotal)
                .ExcludeCategories(excludingCategoryIds)
                .ExcludeProducts(excludingProductIds)
                .ExcludeSkus(excludingSkuIds)
                .Any());
     }
 }
Exemplo n.º 5
0
        public double GetCampaignDiscount()
        {
            if (AppliedCampaigns.Any())
            {
                foreach (var appliedCampaign in AppliedCampaigns.OrderByDescending(a => a.AmountOfDiscount))
                {
                    var applicableLineItems = LineItems.Where(a => a.Product.Category.Equals(appliedCampaign.Category)).ToList();

                    if (applicableLineItems.Count <= appliedCampaign.MinimumItemQuantity)
                    {
                        continue;
                    }

                    var applicableLineItemsCartTotal = applicableLineItems.Sum(a => a.Product.UnitPrice * a.Quantity);

                    return(_campaignCalculator.CalculateFor(appliedCampaign, applicableLineItemsCartTotal));
                }
            }

            return(default(double));
        }
        public long?Process()
        {
            if (LineItems == null || !LineItems.Any())
            {
                throw new ArgumentNullException(nameof(LineItems));
            }

            var memberships = LineItems.Where(_ => _ is Membership);

            foreach (var membership in memberships)
            {
                var membershipDAO = _mapper.Map <MembershipDAO>(membership);
                _customerRepository.ActivateMembership(Customer.Id, membershipDAO);
            }

            var physicalProducts = LineItems.Where(_ => _ is PhysicalProduct).Cast <PhysicalProduct>().ToList();

            if (physicalProducts.Any())
            {
                return(_shippingSlipGenerator.Generate(physicalProducts));
            }

            return(null);
        }
Exemplo n.º 7
0
 public void RemoveLineItem(int id)
 {
     LineItems.Remove(LineItems.Where(li => li.Id == id).Single());
 }
 public bool IsItemCodeContains(string skuCode, string[] excludingSkuIds)
 {
     return(LineItems.Where(x => x.EntryCode.Contains(skuCode))
            .ExcludeSkus(excludingSkuIds)
            .Any());
 }
        public decimal GetItemsOfSkuQuantity(string skuId)
        {
            var retVal = LineItems.Where(x => x.EntryId == skuId).Sum(x => x.Quantity);

            return(retVal);
        }