protected void AddLineItem(Models.ViewModels.Purchases.PurchaseHeaderViewModel model)
        {
            var item    = _inventoryService.GetItemByNo(model.PurchaseLine.ItemNo);
            var newLine = new Models.ViewModels.Purchases.PurchaseLineItemViewModel()
            {
                ItemId          = item.Id,
                ItemNo          = item.No,
                ItemDescription = item.Description,
                Measurement     = item.SellMeasurement.Description,
                Quantity        = model.PurchaseLine.Quantity,
                Price           = model.PurchaseLine.Price,
            };

            model.PurchaseLine.PurchaseLineItems.Add(newLine);

            foreach (var line in model.PurchaseLine.PurchaseLineItems)
            {
                var taxes = _financialService.ComputeInputTax(model.VendorId.Value, line.ItemId, line.Quantity, line.Price, decimal.Zero);
                var taxVM = new Models.ViewModels.Purchases.PurchaseLineItemTaxViewModel();
                //foreach (var tax in taxes)
                //{
                //    var t = _financialService.GetTaxes().Where(tx => tx.Id == int.Parse(tax.Key.ToString())).FirstOrDefault();
                //    taxVM.TaxId = int.Parse(tax.Key.ToString());
                //    taxVM.Amount = tax.Value;
                //    taxVM.TaxRate = t.Rate;
                //    taxVM.TaxName = t.TaxName;
                //    model.PurchaseLine.PurchaseLineItemsTaxes.Add(taxVM);
                //}
            }
        }
        public ActionResult PurchaseInvoice(int id = 0, int deliveryId = 0)
        {
            var model = new Models.ViewModels.Purchases.PurchaseHeaderViewModel();

            model.DocumentType = Core.Domain.DocumentTypes.PurchaseInvoice;
            model.IsDirect     = deliveryId == 0;
            model.Id           = id;
            if (id == 0)
            {
                return(View(model));
            }
            else
            {
                var invoice = _purchasingService.GetPurchaseInvoiceById(id);
                model.Id          = invoice.Id;
                model.VendorId    = invoice.VendorId;
                model.Date        = invoice.Date;
                model.ReferenceNo = string.Empty;
                foreach (var line in invoice.PurchaseInvoiceLines)
                {
                    var lineItem = new Models.ViewModels.Purchases.PurchaseLineItemViewModel();
                    lineItem.Id              = line.Id;
                    lineItem.ItemId          = line.ItemId;
                    lineItem.ItemNo          = line.Item.No;
                    lineItem.ItemDescription = line.Item.Description;
                    lineItem.Measurement     = line.Measurement.Description;
                    lineItem.Quantity        = line.Quantity;
                    lineItem.Price           = line.Amount;
                    model.PurchaseLine.PurchaseLineItems.Add(lineItem);
                }
                return(View(model));
            }
        }
        public ActionResult PurchaseDelivery(int id = 0, int orderid = 0)
        {
            var model = new Models.ViewModels.Purchases.PurchaseHeaderViewModel();

            model.DocumentType = Core.Domain.DocumentTypes.PurchaseReceipt;
            if (id == 0)
            {
                model.Id = id;
                if (orderid != 0)
                {
                    var order = _purchasingService.GetPurchaseOrderById(orderid);
                    model.Id          = order.Id;
                    model.VendorId    = order.VendorId;
                    model.Date        = order.Date;
                    model.ReferenceNo = string.Empty;
                    foreach (var line in order.PurchaseOrderLines)
                    {
                        var lineItem = new Models.ViewModels.Purchases.PurchaseLineItemViewModel();
                        lineItem.Id              = line.Id;
                        lineItem.ItemId          = line.ItemId;
                        lineItem.ItemNo          = line.Item.No;
                        lineItem.ItemDescription = line.Item.Description;
                        lineItem.Measurement     = line.Measurement.Description;
                        lineItem.Quantity        = line.Quantity;
                        lineItem.Price           = line.Amount;
                        model.PurchaseLine.PurchaseLineItems.Add(lineItem);
                    }
                }
                return(View(model));
            }
            else
            {
                var delivery = _purchasingService.GetPurchaseReceiptById(id);
                model.Id          = delivery.Id;
                model.VendorId    = delivery.VendorId;
                model.Date        = delivery.Date;
                model.ReferenceNo = string.Empty;
                foreach (var line in delivery.PurchaseReceiptLines)
                {
                    var lineItem = new Models.ViewModels.Purchases.PurchaseLineItemViewModel();
                    lineItem.Id              = line.Id;
                    lineItem.ItemId          = line.ItemId;
                    lineItem.ItemNo          = line.Item.No;
                    lineItem.ItemDescription = line.Item.Description;
                    lineItem.Measurement     = line.Measurement.Description;
                    lineItem.Quantity        = line.Quantity;
                    lineItem.Price           = line.Amount;
                    model.PurchaseLine.PurchaseLineItems.Add(lineItem);
                }
                return(View(model));
            }
        }
        protected void AddLineItem(Models.ViewModels.Purchases.PurchaseHeaderViewModel model)
        {
            var item = _inventoryService.GetItemByNo(model.PurchaseLine.ItemNo);
            var newLine = new Models.ViewModels.Purchases.PurchaseLineItemViewModel()
            {
                ItemId = item.Id,
                ItemNo = item.No,
                ItemDescription = item.Description,
                Measurement = item.SellMeasurement.Description,
                Quantity = model.PurchaseLine.Quantity,
                Price = model.PurchaseLine.Price,
            };
            model.PurchaseLine.PurchaseLineItems.Add(newLine);

            foreach (var line in model.PurchaseLine.PurchaseLineItems)
            {
                var taxes = _financialService.ComputeInputTax(model.VendorId.Value, line.ItemId, line.Quantity, line.Price, decimal.Zero);
                var taxVM = new Models.ViewModels.Purchases.PurchaseLineItemTaxViewModel();
                foreach (var tax in taxes)
                {
                    var t = _financialService.GetTaxes().Where(tx => tx.Id == int.Parse(tax.Key.ToString())).FirstOrDefault();
                    taxVM.TaxId = int.Parse(tax.Key.ToString());
                    taxVM.Amount = tax.Value;
                    taxVM.TaxRate = t.Rate;
                    taxVM.TaxName = t.TaxName;
                    model.PurchaseLine.PurchaseLineItemsTaxes.Add(taxVM);
                }
            }
        }
 public ActionResult PurchaseInvoice(int id = 0, int deliveryId = 0)
 {
     var model = new Models.ViewModels.Purchases.PurchaseHeaderViewModel();
     model.DocumentType = Core.Domain.DocumentTypes.PurchaseInvoice;
     model.IsDirect = deliveryId == 0;
     model.Id = id;
     if (id == 0)
     {
         return View(model);
     }
     else
     {
         var invoice = _purchasingService.GetPurchaseInvoiceById(id);
         model.Id = invoice.Id;
         model.VendorId = invoice.VendorId;
         model.Date = invoice.Date;
         model.ReferenceNo = string.Empty;
         foreach (var line in invoice.PurchaseInvoiceLines)
         {
             var lineItem = new Models.ViewModels.Purchases.PurchaseLineItemViewModel();
             lineItem.Id = line.Id;
             lineItem.ItemId = line.ItemId;
             lineItem.ItemNo = line.Item.No;
             lineItem.ItemDescription = line.Item.Description;
             lineItem.Measurement = line.Measurement.Description;
             lineItem.Quantity = line.Quantity;
             lineItem.Price = line.Amount;
             model.PurchaseLine.PurchaseLineItems.Add(lineItem);
         }
         return View(model);
     }
 }
 public ActionResult PurchaseDelivery(int id = 0, int orderid = 0)
 {
     var model = new Models.ViewModels.Purchases.PurchaseHeaderViewModel();
     model.DocumentType = Core.Domain.DocumentTypes.PurchaseReceipt;
     if (id == 0)
     {
         model.Id = id;
         if (orderid != 0)
         {
             var order = _purchasingService.GetPurchaseOrderById(orderid);
             model.Id = order.Id;
             model.VendorId = order.VendorId;
             model.Date = order.Date;
             model.ReferenceNo = string.Empty;
             foreach (var line in order.PurchaseOrderLines)
             {
                 var lineItem = new Models.ViewModels.Purchases.PurchaseLineItemViewModel();
                 lineItem.Id = line.Id;
                 lineItem.ItemId = line.ItemId;
                 lineItem.ItemNo = line.Item.No;
                 lineItem.ItemDescription = line.Item.Description;
                 lineItem.Measurement = line.Measurement.Description;
                 lineItem.Quantity = line.Quantity;
                 lineItem.Price = line.Amount;
                 model.PurchaseLine.PurchaseLineItems.Add(lineItem);
             }
         }
         return View(model);
     }
     else
     {
         var delivery = _purchasingService.GetPurchaseReceiptById(id);
         model.Id = delivery.Id;
         model.VendorId = delivery.VendorId;
         model.Date = delivery.Date;
         model.ReferenceNo = string.Empty;
         foreach (var line in delivery.PurchaseReceiptLines)
         {
             var lineItem = new Models.ViewModels.Purchases.PurchaseLineItemViewModel();
             lineItem.Id = line.Id;
             lineItem.ItemId = line.ItemId;
             lineItem.ItemNo = line.Item.No;
             lineItem.ItemDescription = line.Item.Description;
             lineItem.Measurement = line.Measurement.Description;
             lineItem.Quantity = line.Quantity;
             lineItem.Price = line.Amount;
             model.PurchaseLine.PurchaseLineItems.Add(lineItem);
         }
         return View(model);
     }
 }