// GET: Invoices

        public List <InvoiceItem> GetInvoices()
        {
            var container      = new TmpContainersController().GetCurrentContainer();
            var containerItems = container.ContainerItems;

            return(GetInvoices(containerItems));
        }
Exemple #2
0
        public PartialViewResult List()
        {
            var currentContainer = new TmpContainersController().GetCurrentContainer();
            var containerItems   = currentContainer.ContainerItems;



            var buyerInvoiceItems = containerItems.GroupBy(i => new { i.Buyer, i.Product })
                                    .Select(group =>
                                            new BuyerInvoiceItem
            {
                ProductContainerBuyerPrice = new Models.ProductContainerBuyerPrice
                {
                    BuyerID   = group.Key.Buyer.BuyerID,
                    Buyer     = group.Key.Buyer,
                    ProductID = group.Key.Product.ProductID,
                    Product   = group.Key.Product
                },
                Quantity = group.Sum(w => w.Quantity),
                Cartons  = group.Sum(w => w.Cartons)
            })
                                    .OrderBy(i => i.ProductContainerBuyerPrice.BuyerID).ThenBy(i => i.ProductContainerBuyerPrice.ProductID)
                                    .ToList();

            foreach (var buyerInvoiceItem in buyerInvoiceItems)
            {
                var productContainerBuyerPrice = db.ProductContainerBuyerPrices.Where(
                    pcbp => pcbp.ContainerID == CurrentContainerID &&
                    pcbp.ProductID == buyerInvoiceItem.ProductContainerBuyerPrice.ProductID &&
                    pcbp.BuyerID == buyerInvoiceItem.ProductContainerBuyerPrice.BuyerID).FirstOrDefault();

                if (productContainerBuyerPrice != null)
                {
                    buyerInvoiceItem.ProductContainerBuyerPrice = productContainerBuyerPrice;
                }
                else
                {
                    var previousProductBuyerPrice = db.ProductContainerBuyerPrices.Where(
                        pcbp => pcbp.ProductID == buyerInvoiceItem.ProductContainerBuyerPrice.ProductID &&
                        pcbp.BuyerID == buyerInvoiceItem.ProductContainerBuyerPrice.BuyerID)
                                                    .OrderByDescending(pcbp => pcbp.ContainerID)
                                                    .FirstOrDefault();
                    if (previousProductBuyerPrice != null)
                    {
                        buyerInvoiceItem.ProductContainerBuyerPrice = previousProductBuyerPrice;
                    }
                }

                switch (buyerInvoiceItem.ProductContainerBuyerPrice.Unit)
                {
                //If the pricing is in dozens, revert back the quantity to dozen because everything was turned to pieces before
                case ProductUnit.DOZ:
                    buyerInvoiceItem.Quantity /= 12;
                    break;
                }
            }

            return(PartialView(buyerInvoiceItems));
        }
        // [ValidateAntiForgeryToken]
        public PartialViewResult Edit([Bind(Include = "ContainerID,ContainerNumber,Date,ShippedPer,OnAbout,From,AirwayBillNumber,LetterOfCreditNumber,DrawnUnder, CostsIncluded, HarmonicCodes, TotalGrossWeight, TotalCartons, CountryOfOrigin, BeneficiaryBank, BeneficiarySwift, BeneficiaryUsdAccount, ImporterName, ExporterName")] Container container)
        {
            container.ContainerID = CurrentContainerID;
            if (ModelState.IsValid)
            {
                db.Entry(container).State = EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                container = new TmpContainersController().GetCurrentContainer();
            }

            ViewBag.Exporters = new SelectList(db.Containers.Select(c => c.ExporterName).Distinct());
            ViewBag.Importers = new SelectList(db.Containers.Select(c => c.ImporterName).Distinct());

            ViewBag.ImporterID = new SelectList(db.Importers, "ImporterID", "ImporterName");
            ViewBag.ExporterID = new SelectList(db.Exporters, "ExporterID", "ExporterName");
            return(PartialView("Edit", container));
        }