public ActionResult Create([Bind(Include = "InvoiceID,CompanyID,PartyID,UserID,Amount,AmountReceived,StatusID,Created,Modified,Remarks,InvoiceDate,InvoiceNo,PONo,AmountPending,FinYearID,CGST,CGSTAmount,SGST,SGSTAmount,IGST,IGSTAmount,IsLocal,IsActive,Casar,TotalAmount")] INV_Invoice iNV_Invoice) { if (ModelState.IsValid) { iNV_Invoice.Created = DateTime.Now; iNV_Invoice.Modified = DateTime.Now; if (Session["UserID"] != null) { iNV_Invoice.UserID = Convert.ToInt16(Session["UserID"].ToString()); } db.INV_Invoice.Add(iNV_Invoice); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "CGST"), "TaxID", "Tax", iNV_Invoice.CGST); ViewBag.IGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "IGST"), "TaxID", "Tax", iNV_Invoice.IGST); ViewBag.SGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "SGST"), "TaxID", "Tax", iNV_Invoice.SGST); ViewBag.CompanyID = new SelectList(db.SYS_Company, "CompanyID", "CompanyName", iNV_Invoice.CompanyID); ViewBag.FinYearID = new SelectList(db.SYS_FinYear, "FinYearID", "FinYear", iNV_Invoice.FinYearID); ViewBag.PartyID = new SelectList(db.MST_Party, "PartyID", "PartyName", iNV_Invoice.PartyID); ViewBag.StatusID = new SelectList(db.SYS_Status, "StatusID", "StatusName", iNV_Invoice.StatusID); ViewBag.UserID = new SelectList(db.SEC_User, "UserID", "UserName", iNV_Invoice.UserID); return(View(iNV_Invoice)); }
public ActionResult DeleteConfirmed(int id) { INV_Invoice iNV_Invoice = db.INV_Invoice.Find(id); db.INV_Invoice.Remove(iNV_Invoice); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: INV_Invoice/Create public ActionResult Create() { ViewBag.CGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "CGST"), "TaxID", "Tax"); ViewBag.IGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "IGST"), "TaxID", "Tax"); ViewBag.SGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "SGST"), "TaxID", "Tax"); ViewBag.CompanyID = new SelectList(db.SYS_Company, "CompanyID", "CompanyName"); ViewBag.FinYearID = new SelectList(db.SYS_FinYear, "FinYearID", "FinYear"); ViewBag.PartyID = new SelectList(db.MST_Party, "PartyID", "PartyName"); ViewBag.StatusID = new SelectList(db.SYS_Status, "StatusID", "StatusName"); ViewBag.UserID = new SelectList(db.SEC_User, "UserID", "UserName"); INV_Invoice _iNV_Invoice = new INV_Invoice(); return(View("Edit", _iNV_Invoice)); }
// GET: INV_Invoice/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } INV_Invoice iNV_Invoice = db.INV_Invoice.Find(id); if (iNV_Invoice == null) { return(HttpNotFound()); } return(View(iNV_Invoice)); }
public static string GetNextNumber(string _NumberFor) { var db = new DB_A157D8_AnjaliMISEntities1(); Int32 _NewIssueNo = 0; String _NewIssueReturnNo = ""; if (_NumberFor == "Issue") { Int32 TotalForMonth = db.INV_IssueReturn.Where(p => p.Created.Month == DateTime.Today.Month && p.Created.Year == DateTime.Today.Year && p.IssueReturnNo.Contains("IS")).Count(); Int32 NextCount = TotalForMonth + 1; _NewIssueNo = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + NextCount); _NewIssueReturnNo = "IS-" + _NewIssueNo; #region Check No INV_IssueReturn _INV_IssueReturnNo = db.INV_IssueReturn.Where(w => w.IssueReturnNo == _NewIssueReturnNo).FirstOrDefault(); if (_INV_IssueReturnNo != null) { NextCount = NextCount + 1; _NewIssueNo = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + NextCount); _NewIssueReturnNo = "IS-" + _NewIssueNo; } #endregion Check No } if (_NumberFor == "Return") { Int32 TotalForMonth = db.INV_IssueReturn.Where(p => p.Created.Month == DateTime.Today.Month && p.Created.Year == DateTime.Today.Year && p.IssueReturnNo.Contains("RN")).Count(); Int32 NextCount = TotalForMonth + 1; _NewIssueNo = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + NextCount); _NewIssueReturnNo = "RN-" + _NewIssueNo; #region Check No INV_IssueReturn _INV_IssueReturnNo = db.INV_IssueReturn.Where(w => w.IssueReturnNo == _NewIssueReturnNo).FirstOrDefault(); if (_INV_IssueReturnNo != null) { NextCount = NextCount + 1; _NewIssueNo = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + NextCount); _NewIssueReturnNo = "RN-" + _NewIssueNo; } #endregion Check No } if (_NumberFor == "Invoice") { Int32 TotalForMonth = db.INV_Invoice.Where(p => p.Created.Month == DateTime.Today.Month && p.Created.Year == DateTime.Today.Year).Count(); Int32 NextCount = TotalForMonth + 1; _NewIssueNo = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + NextCount); _NewIssueReturnNo = "INV-" + _NewIssueNo; #region Check No INV_Invoice _INV_IssueReturnNo = db.INV_Invoice.Where(w => w.InvoiceNo == _NewIssueReturnNo).FirstOrDefault(); if (_INV_IssueReturnNo != null) { NextCount = NextCount + 1; _NewIssueNo = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + NextCount); _NewIssueReturnNo = "INV-" + _NewIssueNo; } #endregion Check No } if (_NumberFor == "PO") { Int32 TotalForMonth = db.INV_PurchaseOrder.Where(p => p.Created.Month == DateTime.Today.Month && p.Created.Year == DateTime.Today.Year).Count(); Int32 NextCount = TotalForMonth + 1; _NewIssueNo = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + NextCount); _NewIssueReturnNo = "PO-" + _NewIssueNo; #region Check No INV_PurchaseOrder _INV_IssueReturnNo = db.INV_PurchaseOrder.Where(w => w.PONo == _NewIssueReturnNo).FirstOrDefault(); if (_INV_IssueReturnNo != null) { NextCount = NextCount + 1; _NewIssueNo = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + NextCount); _NewIssueReturnNo = "PO-" + _NewIssueNo; } #endregion Check No } return(_NewIssueReturnNo); }
public JsonResult AddInvoice(INV_InvoiceViewModal inv_InvoiceViewModal) { string validMsg = ""; try { if (inv_InvoiceViewModal == null) { //error meesage or expception handle } else if (inv_InvoiceViewModal.INV_InvoiceItems == null) { //error meesage or expception handle } else { if (inv_InvoiceViewModal.InvoiceID > 0) { int invoiceId = inv_InvoiceViewModal.InvoiceID; foreach (var item in inv_InvoiceViewModal.INV_InvoiceItems) { var checkExist = db.INV_InvoiceItem.Any(e => e.InvoiceID == invoiceId && e.ItemID == item.ItemID && e.Quantity == item.Quantity); if (checkExist == false) { var newINV_InvoiceItemAdd = new INV_InvoiceItem() { InvoiceID = invoiceId, ItemID = item.ItemID, Quantity = item.Quantity, Created = DateTime.Now, Modified = DateTime.Now, Remarks = item.Remarks, PricePerUnit = item.PricePerUnit }; db.INV_InvoiceItem.Add(newINV_InvoiceItemAdd); } } inv_InvoiceViewModal.INV_InvoiceItems.ForEach(e => { e.InvoiceID = invoiceId; e.InvoiceItemID = db.INV_InvoiceItem.Where(t => t.InvoiceID == invoiceId && t.ItemID == e.ItemID && t.Quantity == e.Quantity).FirstOrDefault().InvoiceItemID; }); List <int> getAllList = inv_InvoiceViewModal.INV_InvoiceItems.Select(e => e.InvoiceItemID).ToList(); List <INV_InvoiceItem> removeRange = db.INV_InvoiceItem.Where(t => t.InvoiceID == invoiceId && !getAllList.Contains(t.InvoiceItemID)).Select(t => t).ToList(); db.INV_InvoiceItem.RemoveRange(removeRange); INV_Invoice get_invoice = db.INV_Invoice.Where(e => e.InvoiceID == invoiceId).FirstOrDefault(); INV_InvoiceHistory Add_INV_InvoiceHistory = new INV_InvoiceHistory() { CompanyID = get_invoice.CompanyID, PartyID = get_invoice.PartyID, UserID = get_invoice.UserID, Amount = get_invoice.Amount, AmountReceived = get_invoice.AmountReceived, StatusID = get_invoice.StatusID, Created = get_invoice.Created, Remarks = get_invoice.Remarks, InvoiceDate = get_invoice.InvoiceDate, InvoiceNo = get_invoice.InvoiceNo, PONo = get_invoice.PONo, AmountPending = get_invoice.AmountPending, FinYearID = get_invoice.FinYearID, CGST = get_invoice.CGST, CGSTAmount = get_invoice.CGSTAmount, SGST = get_invoice.SGST, SGSTAmount = get_invoice.SGSTAmount, IGST = get_invoice.IGST, IGSTAmount = get_invoice.IGSTAmount, IsLocal = get_invoice.IsLocal, //IsActive = get_invoice.IsActive==null? true : get_invoice.IsActive,//ask to kamal Casar = get_invoice.Casar, TotalAmount = get_invoice.TotalAmount, Operation = "Invoice", InvoiceID = invoiceId }; db.INV_InvoiceHistory.Add(Add_INV_InvoiceHistory); if (Session["UserID"] != null) { get_invoice.UserID = Convert.ToInt16(Session["UserID"].ToString()); } get_invoice.Amount = inv_InvoiceViewModal.Amount; get_invoice.AmountReceived = inv_InvoiceViewModal.AmountReceived; get_invoice.StatusID = 1; get_invoice.Modified = DateTime.Now; get_invoice.Remarks = inv_InvoiceViewModal.Remarks; get_invoice.InvoiceDate = inv_InvoiceViewModal.InvoiceDate;//ask to kamal get_invoice.InvoiceNo = get_invoice.InvoiceNo; get_invoice.PONo = inv_InvoiceViewModal.PONo; get_invoice.AmountPending = inv_InvoiceViewModal.AmountPending; get_invoice.CGST = inv_InvoiceViewModal.CGST; get_invoice.CGSTAmount = inv_InvoiceViewModal.CGSTAmount; get_invoice.SGST = inv_InvoiceViewModal.SGST; get_invoice.SGSTAmount = inv_InvoiceViewModal.SGSTAmount; get_invoice.IGST = inv_InvoiceViewModal.IGST; get_invoice.IGSTAmount = inv_InvoiceViewModal.IGSTAmount; get_invoice.IsLocal = inv_InvoiceViewModal.IsLocal; get_invoice.Casar = inv_InvoiceViewModal.Casar; get_invoice.TotalAmount = inv_InvoiceViewModal.TotalAmount; } else { INV_Invoice new_INV_Invoice = new INV_Invoice(); new_INV_Invoice.CompanyID = CommonConfig.GetCompanyID(); new_INV_Invoice.StatusID = CommonConfig.GetStatusPending(); new_INV_Invoice.PartyID = inv_InvoiceViewModal.PartyID; if (Session["UserID"] != null) { new_INV_Invoice.UserID = Convert.ToInt16(Session["UserID"].ToString()); } new_INV_Invoice.Amount = inv_InvoiceViewModal.Amount; new_INV_Invoice.AmountReceived = inv_InvoiceViewModal.AmountReceived; new_INV_Invoice.StatusID = CommonConfig.GetStatusPending(); new_INV_Invoice.Created = DateTime.Now; new_INV_Invoice.Modified = DateTime.Now; new_INV_Invoice.Remarks = inv_InvoiceViewModal.Remarks; new_INV_Invoice.InvoiceDate = DateTime.Now; #region Generate InvoiceNo String _NewInvoiceNo = CommonConfig.GetNextNumber("Invoice"); #endregion Generate InvoiceNo new_INV_Invoice.InvoiceNo = _NewInvoiceNo.ToString(); new_INV_Invoice.PONo = inv_InvoiceViewModal.PONo; new_INV_Invoice.AmountPending = 0; new_INV_Invoice.FinYearID = CommonConfig.GetFinYearID(); new_INV_Invoice.CGST = inv_InvoiceViewModal.CGST == 0 ? null : inv_InvoiceViewModal.CGST; new_INV_Invoice.CGSTAmount = inv_InvoiceViewModal.CGST == 0 ? null : inv_InvoiceViewModal.CGSTAmount; new_INV_Invoice.SGST = inv_InvoiceViewModal.SGST == 0 ? null : inv_InvoiceViewModal.SGST; new_INV_Invoice.SGSTAmount = inv_InvoiceViewModal.SGST == 0 ? null : inv_InvoiceViewModal.SGSTAmount; new_INV_Invoice.IGST = inv_InvoiceViewModal.IGST == 0 ? null : inv_InvoiceViewModal.IGST; new_INV_Invoice.IGSTAmount = inv_InvoiceViewModal.IGST == 0 ? null : inv_InvoiceViewModal.IGSTAmount; new_INV_Invoice.IsLocal = inv_InvoiceViewModal.IsLocal; new_INV_Invoice.IsActive = true; new_INV_Invoice.Casar = inv_InvoiceViewModal.Casar; new_INV_Invoice.TotalAmount = inv_InvoiceViewModal.TotalAmount; db.INV_Invoice.Add(new_INV_Invoice); int newInvoiceId = new_INV_Invoice.InvoiceID; List <INV_InvoiceItem> newList_INV_InvoiceItem = new List <INV_InvoiceItem>(); foreach (var item in inv_InvoiceViewModal.INV_InvoiceItems) { INV_InvoiceItem new_INV_InvoiceItem = new INV_InvoiceItem(); new_INV_InvoiceItem.InvoiceItemID = item.InvoiceItemID; new_INV_InvoiceItem.InvoiceID = newInvoiceId; new_INV_InvoiceItem.ItemID = item.ItemID; new_INV_InvoiceItem.Quantity = item.Quantity; new_INV_InvoiceItem.Created = DateTime.Now; new_INV_InvoiceItem.Modified = DateTime.Now; new_INV_InvoiceItem.Remarks = item.Remarks; new_INV_InvoiceItem.PricePerUnit = item.PricePerUnit; #region INV_ItemPrice INV_ItemPrice _iNV_ItemPrice = new INV_ItemPrice(); _iNV_ItemPrice = db.INV_ItemPrice.Where(M => M.ItemID == item.ItemID && M.PurchasePrice == item.PricePerUnit).OrderByDescending(o => o.Created).FirstOrDefault(); if (_iNV_ItemPrice == null) { _iNV_ItemPrice = new INV_ItemPrice(); _iNV_ItemPrice.ItemID = item.ItemID; _iNV_ItemPrice.PurchasePrice = item.PricePerUnit; _iNV_ItemPrice.Created = DateTime.Now; _iNV_ItemPrice.Modified = DateTime.Now; _iNV_ItemPrice.FinYearID = CommonConfig.GetFinYearID(); if (Session["UserID"] != null) { _iNV_ItemPrice.UserID = Convert.ToInt16(Session["UserID"].ToString()); } db.INV_ItemPrice.Add(_iNV_ItemPrice); } #endregion INV_ItemPrice INV_Item _INV_Item = new INV_Item(); _INV_Item = db.INV_Item.Where(i => i.ItemID == item.ItemID).FirstOrDefault(); if (_INV_Item != null) { if (_INV_Item.Quantity - item.Quantity < 0) { validMsg += "<br>Insufficient Stock for " + _INV_Item.ItemName; ModelState.AddModelError("Insufficient Stock", "Insufficient Stock for " + _INV_Item.ItemName); //return Json("failure", JsonRequestBehavior.AllowGet); } _INV_Item.Quantity = _INV_Item.Quantity - item.Quantity; INV_StockHistory new_INV_StockHistory = new INV_StockHistory(); new_INV_StockHistory.ItemID = item.ItemID; new_INV_StockHistory.OperationTypeID = 8; new_INV_StockHistory.ReferenceID = _NewInvoiceNo.ToString(); new_INV_StockHistory.Quantity = item.Quantity; if (Session["UserID"] != null) { new_INV_StockHistory.UserID = Convert.ToInt16(Session["UserID"].ToString()); } new_INV_StockHistory.Created = DateTime.Now; new_INV_StockHistory.Modified = DateTime.Now; new_INV_StockHistory.Remarks = "Issue"; new_INV_StockHistory.FinYearID = CommonConfig.GetFinYearID(); new_INV_StockHistory.IssueNumber = _NewInvoiceNo; db.INV_StockHistory.Add(new_INV_StockHistory); } newList_INV_InvoiceItem.Add(new_INV_InvoiceItem); } db.INV_InvoiceItem.AddRange(newList_INV_InvoiceItem); } } if (ModelState.IsValid) { db.SaveChanges(); return(Json("Sucess", JsonRequestBehavior.AllowGet)); } else { return(Json(validMsg, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json("failure", JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit([Bind(Include = "InvoiceID,UserID,Amount,AmountReceived,StatusID,Created,Modified,Remarks,InvoiceDate,InvoiceNo,PONo,AmountPending,FinYearID,CGST,CGSTAmount,SGST,SGSTAmount,IGST,IGSTAmount,IsLocal,IsActive,Casar,TotalAmount,NewAmountPending,NewAmountReceived")] INV_Invoice iNV_Invoice) { if (iNV_Invoice.InvoiceID > 0) { if (iNV_Invoice.Remarks == null || iNV_Invoice.Remarks == "") { ViewBag.CGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "CGST"), "TaxID", "Tax", iNV_Invoice.CGST); ViewBag.IGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "IGST"), "TaxID", "Tax", iNV_Invoice.IGST); ViewBag.SGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "SGST"), "TaxID", "Tax", iNV_Invoice.SGST); ViewBag.CompanyID = new SelectList(db.SYS_Company, "CompanyID", "CompanyName", iNV_Invoice.CompanyID); ViewBag.FinYearID = new SelectList(db.SYS_FinYear, "FinYearID", "FinYear", iNV_Invoice.FinYearID); ViewBag.PartyID = new SelectList(db.MST_Party, "PartyID", "PartyName", iNV_Invoice.PartyID); ViewBag.StatusID = new SelectList(db.SYS_Status, "StatusID", "StatusName", iNV_Invoice.StatusID); ViewBag.UserID = new SelectList(db.SEC_User, "UserID", "UserName", iNV_Invoice.UserID); ModelState.AddModelError("", "Enter Remarks"); return(View(iNV_Invoice)); } } if (ModelState.IsValid) { INV_Invoice getInvoiceData = db.INV_Invoice.Where(e => e.InvoiceID == iNV_Invoice.InvoiceID).FirstOrDefault(); INV_InvoiceHistory add_INV_InvoiceHistory = new INV_InvoiceHistory(); add_INV_InvoiceHistory.CompanyID = getInvoiceData.CompanyID; add_INV_InvoiceHistory.PartyID = getInvoiceData.PartyID; add_INV_InvoiceHistory.UserID = getInvoiceData.CompanyID; add_INV_InvoiceHistory.Amount = getInvoiceData.Amount; add_INV_InvoiceHistory.AmountReceived = getInvoiceData.AmountReceived; add_INV_InvoiceHistory.StatusID = getInvoiceData.StatusID; add_INV_InvoiceHistory.Created = getInvoiceData.Created; add_INV_InvoiceHistory.Remarks = getInvoiceData.Remarks; add_INV_InvoiceHistory.InvoiceDate = getInvoiceData.InvoiceDate; add_INV_InvoiceHistory.InvoiceNo = getInvoiceData.InvoiceNo; add_INV_InvoiceHistory.PONo = getInvoiceData.PONo; add_INV_InvoiceHistory.AmountPending = getInvoiceData.AmountPending; add_INV_InvoiceHistory.FinYearID = CommonConfig.GetFinYearID(); add_INV_InvoiceHistory.CGST = getInvoiceData.CGST; add_INV_InvoiceHistory.CGSTAmount = getInvoiceData.CGSTAmount; add_INV_InvoiceHistory.SGST = getInvoiceData.SGST; add_INV_InvoiceHistory.SGSTAmount = getInvoiceData.SGSTAmount; add_INV_InvoiceHistory.IGST = getInvoiceData.IGST; add_INV_InvoiceHistory.IGSTAmount = getInvoiceData.IGSTAmount; add_INV_InvoiceHistory.IsLocal = getInvoiceData.IsLocal; add_INV_InvoiceHistory.IsActive = true; add_INV_InvoiceHistory.Casar = getInvoiceData.Casar; add_INV_InvoiceHistory.TotalAmount = getInvoiceData.TotalAmount; add_INV_InvoiceHistory.Operation = "Operation"; add_INV_InvoiceHistory.InvoiceID = getInvoiceData.InvoiceID; db.INV_InvoiceHistory.Add(add_INV_InvoiceHistory); //db.SaveChanges(); //db.Entry(iNV_Invoice).State = EntityState.Modified; if (Session["UserID"] != null) { getInvoiceData.UserID = Convert.ToInt16(Session["UserID"].ToString()); getInvoiceData.Modified = DateTime.Now; getInvoiceData.AmountReceived = iNV_Invoice.NewAmountReceived; getInvoiceData.AmountPending = getInvoiceData.AmountPending - iNV_Invoice.NewAmountReceived; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "CGST"), "TaxID", "Tax", iNV_Invoice.CGST); ViewBag.IGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "IGST"), "TaxID", "Tax", iNV_Invoice.IGST); ViewBag.SGST = new SelectList(db.ACC_Tax.Where(a => a.TaxType == "SGST"), "TaxID", "Tax", iNV_Invoice.SGST); ViewBag.CompanyID = new SelectList(db.SYS_Company, "CompanyID", "CompanyName", iNV_Invoice.CompanyID); ViewBag.FinYearID = new SelectList(db.SYS_FinYear, "FinYearID", "FinYear", iNV_Invoice.FinYearID); ViewBag.PartyID = new SelectList(db.MST_Party, "PartyID", "PartyName", iNV_Invoice.PartyID); ViewBag.StatusID = new SelectList(db.SYS_Status, "StatusID", "StatusName", iNV_Invoice.StatusID); ViewBag.UserID = new SelectList(db.SEC_User, "UserID", "UserName", iNV_Invoice.UserID); return(View(iNV_Invoice)); }