Ejemplo n.º 1
0
        public ActionResult DeleteReceiptLineItem(Models.ViewModels.Sales.AddSalesReceipt model)
        {
            var request     = HttpContext.Request;
            var deletedItem = request.Form["DeletedLineItem"];

            model.AddSalesReceiptLines.Remove(model.AddSalesReceiptLines.Where(i => i.ItemId.ToString() == deletedItem.ToString()).FirstOrDefault());
            return(View(model));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add new receipt with no invoice
        /// </summary>
        /// <returns></returns>
        public ActionResult AddReceipt()
        {
            var model = new Models.ViewModels.Sales.AddSalesReceipt();

            //TODO: get the default customer advances account from GL setting if there is.
            model.AccountToCreditId = _financialService.GetAccounts().Where(a => a.AccountName == "Customer Advances").FirstOrDefault() != null
                ? _financialService.GetAccounts().Where(a => a.AccountName == "Customer Advances").FirstOrDefault().Id
                : -1;

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult AddReceiptItem(Models.ViewModels.Sales.AddSalesReceipt model)
        {
            var rowId = Guid.NewGuid();

            if (model.ItemId.Value != -1 && model.Quantity > 0)
            {
                var item = _inventoryService.GetItemById(model.ItemId.Value);
                if (!item.Price.HasValue)
                {
                    ModelState.AddModelError("Amount", "Selling price is not set.");
                    return(View(model));
                }
                Models.ViewModels.Sales.AddSalesReceiptLine itemModel = new Models.ViewModels.Sales.AddSalesReceiptLine()
                {
                    RowId         = rowId.ToString(),
                    ItemId        = model.ItemId.Value,
                    MeasurementId = model.MeasurementId.Value,
                    Quantity      = model.Quantity,
                    Discount      = model.Discount,
                    Amount        = item.Price.Value * model.Quantity,
                    AmountToPay   = model.AmountToPay
                };
                if (model.AddSalesReceiptLines.FirstOrDefault(i => i.ItemId == model.ItemId) == null)
                {
                    model.AddSalesReceiptLines.Add(itemModel);
                }
            }
            else if (!string.IsNullOrEmpty(model.AccountCode) && model.Amount != 0)
            {
                var account = _financialService.GetAccounts().Where(a => a.AccountCode == model.AccountCode).FirstOrDefault();
                if (account != null)
                {
                    Models.ViewModels.Sales.AddSalesReceiptLine accountItemModel = new Models.ViewModels.Sales.AddSalesReceiptLine()
                    {
                        RowId             = rowId.ToString(),
                        AccountToCreditId = account.Id,
                        Amount            = model.AmountToPay,
                        AmountToPay       = model.AmountToPay,
                    };
                    model.AddSalesReceiptLines.Add(accountItemModel);
                }
            }
            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult SaveSalesReceipt(Models.ViewModels.Sales.AddSalesReceipt model)
        {
            var receipt = new SalesReceiptHeader()
            {
                AccountToDebitId = model.AccountToDebitId,
                //SalesInvoiceHeaderId = model.SalesInvoiceId,
                CustomerId = model.CustomerId.Value,
                Date       = model.Date,
                CreatedBy  = User.Identity.Name,
                CreatedOn  = DateTime.Now,
                ModifiedBy = User.Identity.Name,
                ModifiedOn = DateTime.Now,
            };

            foreach (var line in model.AddSalesReceiptLines)
            {
                if (line.AmountToPay > line.Amount)
                {
                    return(RedirectToAction("SalesInvoices"));
                }

                receipt.SalesReceiptLines.Add(new SalesReceiptLine()
                {
                    SalesInvoiceLineId = line.SalesInvoiceLineId,
                    ItemId             = line.ItemId,
                    MeasurementId      = line.MeasurementId,
                    Quantity           = line.Quantity,
                    Discount           = line.Discount,
                    Amount             = line.Amount,
                    AmountPaid         = line.AmountToPay,
                    CreatedBy          = User.Identity.Name,
                    CreatedOn          = DateTime.Now,
                    ModifiedBy         = User.Identity.Name,
                    ModifiedOn         = DateTime.Now,
                });
            }
            _salesService.AddSalesReceipt(receipt);
            return(RedirectToAction("SalesInvoices"));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Add new receipt with no invoice
 /// </summary>
 /// <returns></returns>
 public ActionResult AddReceipt()
 {
     var model = new Models.ViewModels.Sales.AddSalesReceipt();
     model.AccountToCreditId = _financialService.GetAccounts().Where(a => a.AccountName == "Accounts Receivable").FirstOrDefault().Id;
     return View(model);
 }
Ejemplo n.º 6
0
        public ActionResult AddSalesReceipt(int? salesInvoiceId = null)
        {
            var model = new Models.ViewModels.Sales.AddSalesReceipt();
            if (salesInvoiceId.HasValue)
            {
                var salesInvoice = _salesService.GetSalesInvoiceById(salesInvoiceId.Value);
                model.SalesInvoiceId = salesInvoice.Id;
                model.SalesInvoiceNo = salesInvoice.No;
                model.InvoiceDate = salesInvoice.Date;
                model.Date = DateTime.Now;
                model.CustomerId = salesInvoice.CustomerId;

                foreach (var line in salesInvoice.SalesInvoiceLines)
                {
                    model.AddSalesReceiptLines.Add(new Models.ViewModels.Sales.AddSalesReceiptLine()
                    {
                        SalesInvoiceLineId = line.Id,
                        ItemId = line.ItemId,
                        MeasurementId = line.MeasurementId,
                        Quantity = line.Quantity,
                        Discount = line.Discount,
                        Amount = line.Amount
                    });
                }
            }
            return View(model);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add new receipt with no invoice
        /// </summary>
        /// <returns></returns>
        public ActionResult AddReceipt()
        {
            var model = new Models.ViewModels.Sales.AddSalesReceipt();
            //TODO: get the default customer advances account from GL setting if there is.
            model.AccountToCreditId = _financialService.GetAccounts().Where(a => a.AccountName == "Customer Advances").FirstOrDefault() != null
                ? _financialService.GetAccounts().Where(a => a.AccountName == "Customer Advances").FirstOrDefault().Id
                : -1;

            return View(model);
        }