public ActionResult DeleteInvoiceDetailsRow(DeleteRowViewModel deleteRowViewModel)
        {
            try
            {
                decimal ResultVAT = CalculateVat(deleteRowViewModel.VAT, deleteRowViewModel.RowTotal);

                lPOInvoiceViewModel.lPOInvoiceDetailsList = new List <LPOInvoiceDetails>();

                var LPOData = webServices.Post(new LPOInvoiceViewModel(), "Invoice/Edit/" + deleteRowViewModel.Id);
                lPOInvoiceViewModel = (new JavaScriptSerializer()).Deserialize <LPOInvoiceViewModel>(LPOData.Data.ToString());

                lPOInvoiceViewModel.Total      = lPOInvoiceViewModel.Total - deleteRowViewModel.RowTotal;
                lPOInvoiceViewModel.GrandTotal = lPOInvoiceViewModel.GrandTotal - ResultVAT;
                lPOInvoiceViewModel.GrandTotal = lPOInvoiceViewModel.GrandTotal - deleteRowViewModel.RowTotal;
                lPOInvoiceViewModel.VAT        = lPOInvoiceViewModel.VAT - ResultVAT;
                lPOInvoiceViewModel.detailId   = deleteRowViewModel.detailId;

                var result = webServices.Post(lPOInvoiceViewModel, "Invoice/DeleteDeatlsRow");

                if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    HttpContext.Cache.Remove("InvoiceData");
                    return(Json("Success", JsonRequestBehavior.AllowGet));
                }
                return(new JsonResult {
                    Data = new { Status = "Fail" }
                });
            }
            catch (Exception)
            {
                return(new JsonResult {
                    Data = new { Status = "Fail" }
                });
            }
        }
Example #2
0
        /// <summary>
        /// Function for removing a row from an order
        /// </summary>
        /// <param name="deleteRow">row that should be removed</param>
        /// <returns>Json</returns>
        public JsonResult RemoveRowFromOrder(DeleteRowViewModel deleteRow)
        {
            // fetch the order whom the row is removed from
            var orderRemove = context.Orders.Include("OrderRows").FirstOrDefault(x => x.Id == deleteRow.OrderId);
            // add some days to orderdate in order to see if the orderrow is ok to delete
            var dateInFuture = orderRemove.OrderDate.AddDays(4);

            // check if the order row is ok to remove based on how old the order is
            if (dateInFuture < DateTime.Now)
            {
                // fetch the row that should be removed
                var rowToRemove = context.OrderRows.FirstOrDefault(x => x.Id == deleteRow.RowId);
                // check so that the row isn't empty
                if (rowToRemove != null)
                {
                    // remove the row
                    context.OrderRows.Remove(rowToRemove);
                    // check if the order contains any more order rows, if not remove the actual order
                    if (orderRemove.OrderRows == null)
                    {
                        context.Orders.Remove(orderRemove);
                    }
                    // save the changes to the database
                    context.SaveChanges();
                }
                // return info to the page
                return(Json(new { status = "Success" }));
            }
            else
            {
                return(Json(new { status = "OrderToOld" }));
            }
        }
Example #3
0
        public ActionResult DeleteQuotationDetailsRow(DeleteRowViewModel deleteRowViewModel)
        {
            try
            {
                decimal ResultVAT = CalculateVat(deleteRowViewModel.VAT, deleteRowViewModel.RowTotal);

                lPOInvoiceViewModel.lPOInvoiceDetailsList = new List <LPOInvoiceDetails>();

                var LPOData = webServices.Post(new LPOInvoiceViewModel(), "Quotation/Edit/" + deleteRowViewModel.Id);
                if (LPOData.Data != "")
                {
                    lPOInvoiceViewModel = (new JavaScriptSerializer()).Deserialize <LPOInvoiceViewModel>(LPOData.Data.ToString());
                }
                lPOInvoiceViewModel.Total      = lPOInvoiceViewModel.Total - deleteRowViewModel.RowTotal;
                lPOInvoiceViewModel.GrandTotal = lPOInvoiceViewModel.GrandTotal - ResultVAT;
                lPOInvoiceViewModel.GrandTotal = lPOInvoiceViewModel.GrandTotal - deleteRowViewModel.RowTotal;
                lPOInvoiceViewModel.VAT        = lPOInvoiceViewModel.VAT - ResultVAT;
                lPOInvoiceViewModel.detailId   = deleteRowViewModel.detailId;

                var result = webServices.Post(lPOInvoiceViewModel, "Quotation/DeleteDeatlsRow");

                if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    return(Json("Success", JsonRequestBehavior.AllowGet));


                    //var deletequtation = webServices.Post(lPOInvoiceViewModel, "LPO/DeleteDeatlsRow");
                    //if (deletequtation.IsSuccess == true)
                    //{
                    //    return Json("Success", JsonRequestBehavior.AllowGet);
                    //}
                    //return new JsonResult { Data = new { Status = "Success" } };
                }
                return(new JsonResult {
                    Data = new { Status = "Fail" }
                });
            }
            catch (Exception)
            {
                return(new JsonResult {
                    Data = new { Status = "Fail" }
                });
            }
        }