public JsonResult GetStockQty(int pId) { int stockq; try { // Here "MyDatabaseEntities " is dbContext, which is created at time of model creation. using (PEPSIEntities dc = new PEPSIEntities()) { var wa = (from y in db.UserLogins where y.UserID.ToString() == User.Identity.Name select new { y.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(x => x.WarehouseID == wa.WorkStationID).FirstOrDefault(); var V = (from x in dc.POSMStocks where x.POSMItemID == pId && x.WarehouseId == wn.WarehouseID select x).FirstOrDefault(); stockq = Convert.ToInt32(V.OnHandQty); } return(new JsonResult { Data = stockq, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception) { return(Json(new { status = "error", message = "Product Description Not Found" })); // throw ex; } }
public string GetCustomerName(int inCustID, string inWC) { string CustName = "N/A"; try { // Here "MyDatabaseEntities " is dbContext, which is created at time of model creation. // var allOrder = db.GetDBOrderDetail(salesorderno); // IList<OrderBankDetail> d = new List<OrderBankDetail>(); using (PEPSIEntities dc = new PEPSIEntities()) { var V = (from x in dc.Customers where x.CustomerID == inCustID select x).FirstOrDefault(); var W = (from c in dc.Warehouses where c.WarehouseID == inCustID select c).FirstOrDefault(); if (inWC == "C") { CustName = V.CustomerName; } else if (inWC == "N") { CustName = W.WarehouseDescription; } } return(CustName); } catch (Exception) { return(CustName); //throw ex; } }
public JsonResult GetProductData(int idProduct) { string PName; try { // Here "MyDatabaseEntities " is dbContext, which is created at time of model creation. using (PEPSIEntities dc = new PEPSIEntities()) { var V = (from x in dc.Products where x.ProductID == idProduct select x).FirstOrDefault(); PName = V.ProductDescription; } return(new JsonResult { Data = PName, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception ex) { return(Json(new { status = "error", message = "Product ID Not Found" })); throw ex; } }
public JsonResult Rights(MenuSubVM A) { bool status = false; string mes = ""; int v = (int)A.UserID; if (ModelState.IsValid) { try { using (PEPSIEntities dc = new PEPSIEntities()) { foreach (var i in A.menudetail) { if (i.IsSelected == 1) { MenuSub ulog = new MenuSub { UserID = (int)A.UserID, SubMenu = i.SubMenu, RoleId = A.RoleId, Controller = i.Controller, Action = i.Action, MainMenuId = i.MainMenuId, WarehouseID = A.WarehouseID, MenuCode = i.MenuCode, Status = "A", CreateBy = User.Identity.Name, CreateDate = System.DateTime.Now }; dc.MenuSubs.Add(ulog); } } dc.SaveChanges(); status = true; dc.Dispose(); } } catch (Exception ex) { return(new JsonResult { Data = new { status = false, mes = mes, v = v } }); //throw ex; } } else { status = false; } return(new JsonResult { Data = new { status = true, mes = mes, v = v } }); }
public JsonResult CreateUser(UserCreateVM A) { bool status = false; string mes = ""; int v = A.UserID; if (ModelState.IsValid) { try { using (PEPSIEntities dc = new PEPSIEntities()) { UserLogin ulog = new UserLogin(); { ulog.UserID = A.UserID; ulog.UserName = A.UserName; ulog.Password = A.Password; ulog.MobileNo = A.MobileNo; ulog.WorkStationID = A.WorkStationID; ulog.RoleId = A.RoleId; ulog.MachineIP = A.MachineIP; ulog.Email = A.Email; ulog.Status = "A"; ulog.CreateBy = User.Identity.Name; ulog.CreateDate = System.DateTime.Now; } dc.UserLogins.Add(ulog); dc.SaveChanges(); status = true; dc.Dispose(); } } catch (Exception ex) { return(new JsonResult { Data = new { status = false, mes = mes, v = v } }); //throw ex; } } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
//[HttpPost] //public ActionResult Invoice(int SOrderNo) //{ // ReportViewer reportViewer = new ReportViewer // { // ProcessingMode = ProcessingMode.Local, // SizeToReportContent = true, // Width = Unit.Percentage(50), // Height = Unit.Percentage(50) // }; // //var v = (from x in db.Warehouses where x.WarehouseID == wId select x).FirstOrDefault(); // List<spRPTInvoice_Result> invoiceData = db.spRPTInvoice(SOrderNo).ToList(); // reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\Sales\Invoice.rdlc"; // //ReportParameter rp1 = new ReportParameter("wName", v.WarehouseDescription.ToString()); // //reportViewer.LocalReport.SetParameters(new ReportParameter[] { rp1 }); // ReportDataSource rdc = new ReportDataSource("InvoiceDataSet", invoiceData); // reportViewer.LocalReport.DataSources.Add(rdc); // reportViewer.LocalReport.Refresh(); // reportViewer.Visible = true; // ViewBag.ReportViewer = reportViewer; // return PartialView("DBOrderDetails"); //} //public ActionResult LoadSheet(int SOrderNo, int Trip) //{ // ReportViewer reportViewer = new ReportViewer // { // ProcessingMode = ProcessingMode.Local, // SizeToReportContent = true, // Width = Unit.Percentage(50), // Height = Unit.Percentage(50) // }; // //var v = (from x in db.Warehouses where x.WarehouseID == wId select x).FirstOrDefault(); // List<LoadSheetCR_Result> loadsheetData = db.LoadSheetCR(SOrderNo, Trip).ToList(); // reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\Order\LDSheet.rdlc"; // //ReportParameter rp1 = new ReportParameter("wName", v.WarehouseDescription.ToString()); // //reportViewer.LocalReport.SetParameters(new ReportParameter[] { rp1 }); // ReportDataSource rdc = new ReportDataSource("LoadSheetDataSet", loadsheetData); // reportViewer.LocalReport.DataSources.Add(rdc); // reportViewer.LocalReport.Refresh(); // reportViewer.Visible = true; // ViewBag.ReportViewer = reportViewer; // return PartialView("DBOrderDetails"); //} public JsonResult GetCustomerListsWareHouseWise(int wId) { using (PEPSIEntities dc = new PEPSIEntities()) { try { var custLists = db.Customers.Where(x => x.WarehouseID == wId && x.ActiveStatus == "A"); return(new JsonResult { Data = custLists, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception ex) { return(Json(new { status = "error", message = "Customer Not Found" })); // throw ex; } } }
public JsonResult GetCustomerOutstanding(int custId) { using (PEPSIEntities dc = new PEPSIEntities()) { // decimal TotalReceiveable = 0, TotalPayment = 0, TransitAmount = 0, TransitBottleAmount = 0, ActualOutstanding = 0, TotalCrLimit = 0; decimal amt = 0; try { // Here "MyDatabaseEntities " is dbContext, which is created at time of model creation. //var outstanding = db.GetCustomerCurrentOutstanding(custId); var ActualOutstanding = db.CustomerLedgerMasters.Where(x => x.CustomerID == custId).FirstOrDefault(); decimal bookamt = (decimal)ActualOutstanding.BookedAmt; if (bookamt >= 0) { amt = (decimal)ActualOutstanding.CurrentBalance + (decimal)ActualOutstanding.BookedAmt; } else { amt = (decimal)ActualOutstanding.CurrentBalance; } //foreach (var i in outstanding) //{ // TotalReceiveable = Convert.ToDecimal((i.TotalAmount) + ((i.FinishGoodsUnloadCharge + i.EmptyReturnLoadCharge) - i.ReturnFGCharge)); // TotalPayment = Convert.ToDecimal(i.PaymentReceived); // TransitAmount = Convert.ToDecimal(i.TotalTransitAmount); // TransitBottleAmount = Convert.ToDecimal(i.TransitBottleSecurityAmount); // TotalCrLimit = Math.Round(Convert.ToDecimal(TotalCrLimit) + (Convert.ToDecimal(i.RcvlAmnt)), 2); // //off TotalCrLimit = Convert.ToDecimal(TotalCrLimit+i.RcvlAmnt); // ActualOutstanding = Math.Round(Convert.ToDecimal((((TotalReceiveable + TransitAmount + TransitBottleAmount) - TotalPayment)) + (-TotalCrLimit)), 2); //} return(new JsonResult { Data = amt, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception ex) { return(Json(new { status = "error", message = "Customer Outstanding" })); // throw ex; } } }
public JsonResult GetCustomerInvoiceNumber(int cId) { using (PEPSIEntities dc = new PEPSIEntities()) { try { var invoiceLists = db.Orders.Where(x => x.CustomerID == cId).OrderByDescending(x => x.ChallanNumber); return(new JsonResult { Data = invoiceLists, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception ex) { return(Json(new { status = "error", message = "invoiceLists Not Found" })); // throw ex; } } }
public JsonResult GetCustomerActualOutstanding(int custId) { using (PEPSIEntities dc = new PEPSIEntities()) { decimal actualout = 0; try { var ActualOutstanding = db.CustomerLedgerMasters.Where(x => x.CustomerID == custId).FirstOrDefault(); actualout = ((decimal)ActualOutstanding.PaymentAmt + (decimal)ActualOutstanding.ReturnAmt) - (decimal)ActualOutstanding.InvoiceAmt; return(new JsonResult { Data = actualout, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception ex) { return(Json(new { status = "error", message = "Customer Outstanding" })); // throw ex; } } }
//public JsonResult GetCustomerCurrentOuts(int custID) //{ // try // { // var a = db.spGetCustomerCurrentOutstanding(custID).ToList(); // foreach (var v in a) // { // totalReceive = Convert.ToDecimal(v.TotalAmount); // totalUnload = Convert.ToDecimal(v.FinishGoodsUnloadCharge); // totalEmptyCharge = Convert.ToDecimal(v.EmptyReturnLoadCharge); // totalFGReturnCharge = Convert.ToDecimal(v.ReturnFGCharge); // totalPaid = Convert.ToDecimal(v.PaymentReceived); // actualOutstanding = (((totalReceive) - ((totalUnload + totalEmptyCharge) - totalFGReturnCharge)) - totalPaid); // actualOutstanding = Math.Round(actualOutstanding, 2); // } // return new JsonResult { Data = actualOutstanding, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; // } // catch (Exception ex) // { // return Json(new { status = "error", message = "Product ID Not Found" }); // } //} public JsonResult GetCustomerCurrentOuts(int custId) { using (PEPSIEntities dc = new PEPSIEntities()) { // decimal TotalReceiveable = 0, TotalPayment = 0, TransitAmount = 0, TransitBottleAmount = 0, ActualOutstanding = 0, TotalCrLimit = 0; decimal amt = 0; try { var ActualOutstanding = db.CustomerLedgerMasters.Where(x => x.CustomerID == custId).FirstOrDefault(); amt = (decimal)ActualOutstanding.CurrentBalance; return(new JsonResult { Data = amt, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception ex) { return(Json(new { status = "error", message = "Customer Outstanding" })); // throw ex; } } }
public JsonResult GetProductDesc(int idProduct) { string PName; try { using (PEPSIEntities dc = new PEPSIEntities()) { var V = (from x in dc.Products where x.ProductID == idProduct && x.Status == "A" select x).FirstOrDefault(); PName = V.ProductDescription; } return(new JsonResult { Data = PName, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception) { return(Json(new { status = "error", message = "Product Description Not Found" })); // throw ex; } }
public JsonResult GetProducExpiryDays(int idProduct) { int pexpirydays; try { using (PEPSIEntities dc = new PEPSIEntities()) { var V = (from x in dc.Products where x.ProductID == idProduct select x).FirstOrDefault(); pexpirydays = (int)V.Expirydays; // Pdate = pManudate + pexpirydays; } return(new JsonResult { Data = pexpirydays, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception ex) { return(Json(new { status = "error", message = "Product ID Not Found" })); //throw ex; } }
public ActionResult DisburseSave(ReplaceDisburseVM D) { bool status = false; string mes = ""; var w = (from y in db.UserLogins where y.UserID.ToString() == User.Identity.Name select new { y.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault(); string s1 = w.WorkStationID.ToString(); string s2 = string.Concat(s1 + "4000000"); int replaceDisNo = Convert.ToInt32(s2); var maxreplaceNO = (from n in db.ReplaceDisburseMasters where n.WarehouseID == w.WorkStationID select n.ReplaceDisburseID).DefaultIfEmpty(replaceDisNo).Max(); var maxrNo = maxreplaceNO + 1; int v = maxrNo; var maxprodtr = (from j in db.ProductTransactions where j.WarehouseID == w.WorkStationID select j.TransactionNo).Max() + 1; var customerData = (from i in db.Customers where (i.CustomerID == D.CustomerID) select i).FirstOrDefault(); if (ModelState.IsValid) { using (PEPSIEntities dc = new PEPSIEntities()) { CommonChk cm = new CommonChk(); ReplaceDisburseMaster dbo = new ReplaceDisburseMaster(); { dbo.ReplaceDisburseID = maxrNo; dbo.WarehouseID = D.WarehouseID; dbo.CustomerID = D.CustomerID; dbo.TransactionDate = DateTime.Today; dbo.DriverID = D.DriverID; dbo.VehicleID = D.VehicleID; dbo.ReplaceRefNo = D.ReplaceRefNo; dbo.TotDisburseAmt = D.TotDisburseAmt; dbo.RemainingAmt = D.RemainingAmt; dbo.LoadSheetNo = D.LoadSheetNo; dbo.TotCase = D.TotCase; dbo.TotBox = D.TotBox; dbo.VehicleID = D.VehicleID; dbo.Remarks = D.Remarks + "," + D.VehicleID; dbo.CreateDate = DateTime.Now; dbo.CreateBy = User.Identity.Name; }; dc.ReplaceDisburseMasters.Add(dbo); CustomerLedgerDetail cld = new CustomerLedgerDetail(); { cld.WarehouseID = D.WarehouseID; cld.CustomerID = D.CustomerID; cld.TransactionNo = "DIS" + maxrNo.ToString(); cld.TransactionTypeID = 19; cld.RefNumber1 = D.ReplaceDisburseID.ToString(); cld.TransactionDate = DateTime.Today; cld.CrAmount = 0; cld.DrAmount = D.TotDisburseAmt; cld.DebitCredit = "D"; cld.Narration = "ReplaceDisburse Amount#" + D.TotDisburseAmt + " to Customer" + cld.CustomerID; cld.CreateBy = User.Identity.Name; cld.CreateDate = System.DateTime.Now; } dc.CustomerLedgerDetails.Add(cld); ProductTransaction pt = new ProductTransaction(); { pt.WarehouseID = D.WarehouseID; pt.TransactionNo = maxprodtr; pt.TransactionDate = DateTime.Today; pt.TransactionTypeID = 4; pt.FromWarehouse = D.WarehouseID; pt.ReferenceNo = maxrNo.ToString(); //pt.Remarks = pt.Status = "D"; pt.CreatedBy = User.Identity.Name; pt.CreatedDate = DateTime.Now; } dc.ProductTransactions.Add(pt); foreach (var i in D.disbursedetail) { var iBatch = (from s in db.StockBatches where s.WarehouseID == D.WarehouseID && s.ProductID == i.ProductID && s.Status == "A" select s).FirstOrDefault(); int qty = cm.CasetoPcs(i.ProductID, (decimal)i.CaseQty); ReplaceDisburseDetail obd = new ReplaceDisburseDetail(); { var vr = db.ProductRateDetails.Where(x => x.ProductID == i.ProductID && x.ProductRateID == customerData.ProductRateID).FirstOrDefault(); obd.WarehouseID = D.WarehouseID; obd.ReplaceDisburseID = maxrNo; obd.CustomerID = D.CustomerID; obd.ProductID = i.ProductID; obd.CaseQty = i.CaseQty; obd.BoxQty = i.BoxQty; obd.BatchNo = i.BatchNo; obd.ManufactureDate = iBatch.ManufacturDate; obd.UnitPrice = vr.UnitPrice; obd.AlternateUnitPrice = vr.AlternateUnitPrice; obd.TotAmount = i.TotAmount; dc.ReplaceDisburseDetails.Add(obd); } StockBatchDetail sbd = new StockBatchDetail() { WarehouseID = D.WarehouseID, TransactionNo = maxprodtr, TransactionDate = System.DateTime.Today, ProductID = i.ProductID, Quantity = (int)i.CaseQty, PlasticBoxQuantity = (int)i.BoxQty, TransactionType = "Replace Disburse", BatchNo = i.BatchNo, CreateBy = User.Identity.Name, CreateDate = System.DateTime.Now, }; dc.StockBatchDetails.Add(sbd); ProductTransactionDetail ptd = new ProductTransactionDetail(); { ptd.TransactionNo = maxprodtr; ptd.WarehouseID = D.WarehouseID; ptd.ProductID = i.ProductID; ptd.Quantity = qty; ptd.PlasticBoxQuantity = (int)i.BoxQty; ptd.EmptyBottleQuantity = 0; ptd.BurstBottleQuantity = 0; ptd.BreakageBottleQuantity = 0; dc.ProductTransactionDetails.Add(ptd); }; //int allProductsQty; // var Pr = (from x in db.Products where x.ProductID == i.ProductID select x).FirstOrDefault(); // allProductsQty = (int)(i.Quantity + ((z.AlternateQuantity + z.AlternateRebateQuantity) * Pr.ConversionFactor) + z.RebateQuantity); var decreaseprodbal = db.spProductBalanceDecrease(i.ProductID, D.WarehouseID, qty, 0, 0, (int)i.BoxQty, 0); } //{ //var replace = (from r in db.ReplaceMasters where r.WarehouseID == D.WarehouseID && r.ReplaceNo == D.ReplaceRefNo select r).FirstOrDefault(); //replace.Status = "R"; //} var custReplacePayable = db.spCustomerBalanceUpdate(D.CustomerID, "A", D.TotDisburseAmt); var updatereplace = db.spRelaceDataUpdate(D.ReplaceRefNo, D.WarehouseID, "C", D.CustomerID, "M", User.Identity.Name, DateTime.Now); dc.SaveChanges(); status = true; dc.Dispose(); } ModelState.Clear(); } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
public ActionResult SaveReturn(ReturnmentVM R) { var w = (from y in db.UserLogins where y.UserID.ToString() == User.Identity.Name select new { y.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault(); string s1 = w.WorkStationID.ToString(); string s2 = string.Concat(s1 + "3000000"); string s3 = string.Concat(s1 + "5000000"); int vRID = Convert.ToInt32(s2); int MaxCashID = Convert.ToInt32(s3); bool status = false; string mes = ""; //int = db.Returnments.Max(p=>p.ReturnmentID)+1; var V = (from x in db.Customers where x.CustomerID == R.CustomerID select x).FirstOrDefault(); var MvrID = (from n in db.Returnments where n.WarehouseID == w.WorkStationID select n.ReturnmentID).DefaultIfEmpty(vRID).Max(); int vrID = MvrID + 1; int v = vrID; var PTID = (from x in db.ProductTransactions where x.WarehouseID == w.WorkStationID select x.TransactionNo).Max(); int TrID = (PTID + 1); var maxCasettleId = (from n in db.CashSettlements where n.WarehouseID == w.WorkStationID select n.CashSettlementID).DefaultIfEmpty(MaxCashID).Max(); csID = Convert.ToInt32(maxCasettleId + 1); decimal securityAmt = 0; decimal securitywithRebate = 0; decimal diffamt = 0; decimal negload = 0; if (ModelState.IsValid) { using (PEPSIEntities dc = new PEPSIEntities()) { CommonChk cm = new CommonChk(); Returnment dbr = new Returnment { WarehouseID = R.WarehouseID, ReturnmentID = vrID, CustomerID = R.CustomerID, Reasons = R.Reasons, RefNumber = R.RefNumber, ReturnDate = DateTime.Today,//R.ReturnDate, ReturnTypeID = R.ReturnTypeID, ReturnGoodsQty = R.ReturnGoodsQty, InAmount = R.InAmount, AdjustedAmt = R.AdjustedAmt, CreateDate = DateTime.Now, CreateBy = User.Identity.Name }; dc.Returnments.Add(dbr); if (R.FareAmt > 0) { var CustName = (from x in db.Customers where x.CustomerID == R.CustomerID select x).FirstOrDefault(); TransportAgencyandFareSetup tf = new TransportAgencyandFareSetup(); { tf.WarehouseID = R.WarehouseID; tf.CustomerName = CustName.CustomerName.ToString(); tf.Address = CustName.CustomerAddress1; tf.TAID = (int)R.TAID; tf.ChallanNumber = vrID; tf.FareAmnt = (decimal)R.FareAmt; tf.VechileNo = R.VechileNo; tf.EnteredBy = User.Identity.Name; tf.EnteredDate = DateTime.Now; tf.ChallanDate = DateTime.Today; tf.TotalCases = R.ReturnGoodsQty; tf.Status = "No"; tf.Remarks = "Returned Hired Truck"; tf.EmptyReturn = "Yes"; } dc.TransportAgencyandFareSetups.Add(tf); } if (R.ReturnTypeID == 14) { foreach (var i in R.listreturndetail) { decimal countQtywithRebate = 0; int countQtywithRebatePlastic = 0; countQtywithRebate = (decimal)i.ReturnQty + (decimal)i.RebateQty; countQtywithRebatePlastic = (int)i.Packsize + (int)i.RebatePlastic; decimal xxx = cm.GetSecurityAmount((int)i.ProductID, (decimal)i.ReturnQty, (int)i.Packsize); decimal xx = cm.GetSecurityAmount((int)i.ProductID, countQtywithRebate, countQtywithRebatePlastic); securityAmt = securityAmt + xxx; securitywithRebate = securitywithRebate + xx; diffamt = securitywithRebate - securityAmt; } } decimal cramt = 0; decimal drinksamount = (decimal)R.InAmount - securityAmt; decimal cramtsub = (decimal)R.InAmount - (decimal)R.AdjustedAmt; // Unloadcharge is negetive decimal cramtadd = (decimal)R.InAmount + (decimal)R.AdjustedAmt; decimal totsecurityamount = securityAmt + diffamt; if (R.ReturnTypeID == 13) { cramt = cramtadd; securityAmt = (decimal)R.InAmount; } else { cramt = cramtsub; } if (R.ReturnTypeID != 13) // Not Empty Return { ProductTransaction dm = new ProductTransaction(); { dm.TransactionTypeID = R.ReturnTypeID; dm.TransactionNo = TrID;// dm.WarehouseID = R.WarehouseID; dm.FromWarehouse = R.WarehouseID; //dm.ToWarehouse = S.ToWarehouse; dm.TransactionDate = DateTime.Today; dm.ReferenceNo = vrID.ToString(); if (R.ReturnTypeID != 13) { dm.Status = "R"; } //else //{ // dm.Status = "A"; //} //cuser = User.Identity.Name dm.CreatedBy = User.Identity.Name; dm.CreatedDate = DateTime.Now; } dc.ProductTransactions.Add(dm); } // Customer Ledger if (R.ReturnTypeID != 12) { CustomerLedgerDetail cld = new CustomerLedgerDetail(); { cld.WarehouseID = R.WarehouseID; cld.CustomerID = (int)R.CustomerID; cld.TransactionNo = "RTN" + vrID.ToString(); cld.TransactionTypeID = R.ReturnTypeID; cld.RefNumber1 = R.RefNumber.ToString(); cld.TransactionDate = DateTime.Today; cld.CrAmount = cramt;//R.InAmount; cld.DrAmount = 0; cld.DebitCredit = "C"; cld.Narration = "Returnment Amount#" + cramt /*R.InAmount*/ + " to Customer" + cld.CustomerID; cld.CreateBy = User.Identity.Name; cld.CreateDate = System.DateTime.Now; } dc.CustomerLedgerDetails.Add(cld); var m = (from x in db.Customers where x.CustomerID == R.CustomerID select x).FirstOrDefault(); CashSettlement cs = new CashSettlement(); cs.WarehouseID = R.WarehouseID; cs.CustomerID = (int)R.CustomerID; cs.CashSettlementID = csID; cs.CashSettlementDate = DateTime.Today; cs.DeliveryChallanDate = DateTime.Today; cs.OrderID = vrID;// R.ReturnmentID; cs.DeliveryChallanNumbers = 0; cs.TransactionNo = vrID; cs.TotalAmount = cramt; cs.ReceivedAmount = cramt; cs.CustomerExecutiveID = m.CustomerExecutiveID; if (R.ReturnTypeID == 13) { cs.EmptyReturnLoadCharge = R.AdjustedAmt; cs.SecurityAmount = -R.InAmount; } else { // cs.FinishGoodsUnloadCharge = R.AdjustedAmt; cs.ReturnFGCharge = R.AdjustedAmt; cs.SecurityAmount = -totsecurityamount; } cs.CreateBy = User.Identity.Name; cs.CraeteDate = DateTime.Now; dc.CashSettlements.Add(cs); // var cb = db.spCustomerBalanceUpdate(R.CustomerID, "R", cramt/*R.InAmount*/); decimal vInvAmt = cramt - securityAmt; decimal vBookAmt = 0; decimal vCurBal = cramt + diffamt; if (R.ReturnTypeID == 14) { negload = -(decimal)R.AdjustedAmt; } else { negload = (decimal)R.AdjustedAmt; } decimal vChargeAmount = negload; decimal vSecurityAmt = securityAmt + diffamt;// securitywithRebate; decimal vRebate = 0; decimal vFare = (decimal)R.FareAmt; decimal VactuaInvAmount = vInvAmt - negload;// (decimal)R.AdjustedAmt; // without loaduloadcharge db.spUpdateDBsInvoiceValue( R.CustomerID, "S", vCurBal, vCurBal, VactuaInvAmount, vBookAmt, vSecurityAmt, vChargeAmount, vFare, vRebate, vrID ); } foreach (var i in R.listreturndetail) { var q = (from x in db.Products where x.ProductID == i.ProductID select x).FirstOrDefault(); int conf = q.ConversionFactor; decimal totpcqty = (decimal)i.ReturnQty * conf; int csqty = (Convert.ToInt32(Math.Round(totpcqty)) / conf); int pcqty = (Convert.ToInt32(Math.Round(totpcqty)) % conf); decimal totrebpcqty = (decimal)i.RebateQty * conf; int rebcsqty = (Convert.ToInt32(Math.Round(totrebpcqty)) / conf); int rebpcqty = (Convert.ToInt32(Math.Round(totrebpcqty)) % conf); if (R.ReturnTypeID != 13) { ProductTransactionDetail ptd = new ProductTransactionDetail(); decimal qty = (decimal)i.ReturnQty + (decimal)i.RebateQty; int s = q.ConversionFactor; // decimal qt = Math.Round((decimal)(i.ReturnQty) * s, 2); decimal qt = Math.Round((decimal)(qty) * s, 2); int pcquantity = (Convert.ToInt32(Math.Round(qt)) % s); int casesqty = (Convert.ToInt32(Math.Round(qt)) / s); ptd.WarehouseID = R.WarehouseID; ptd.TransactionNo = TrID; ptd.ProductID = (int)i.ProductID; ptd.Quantity = (int)qt;// (int)i.ReturnQty; ptd.PlasticBoxQuantity = (int)i.Packsize; ptd.BatchNo = i.BatchNo; dc.ProductTransactionDetails.Add(ptd); StockBatchDetail sbd = new StockBatchDetail(); sbd.WarehouseID = R.WarehouseID; sbd.TransactionNo = vrID; sbd.TransactionDate = System.DateTime.Today; sbd.ProductID = (int)i.ProductID; sbd.Quantity = (int)qt;// (int)i.ReturnQty; sbd.PlasticBoxQuantity = i.Packsize; sbd.TransactionType = "Return Product"; sbd.BatchNo = (int)i.BatchNo; sbd.CreateBy = User.Identity.Name; sbd.CreateDate = System.DateTime.Now; dc.StockBatchDetails.Add(sbd); if (R.ReturnTypeID == 14) { var peb = db.spProductBalanceUpdate(i.ProductID, R.WarehouseID, (int)qt, 0, 0, 0, 0);// (int)i.ReturnQty); } ; } ; ReturnmentDetail rd = new ReturnmentDetail(); rd.WarehouseID = R.WarehouseID; rd.ReturnmentID = vrID;// R.ReturnmentID; rd.ProductID = i.ProductID; rd.ReturnQty = i.ReturnQty; rd.Amount = i.Amount; rd.Packsize = i.Packsize; rd.BatchNo = i.BatchNo; rd.RebateQty = i.RebateQty; rd.RebatePlastic = i.RebatePlastic; rd.SchemeID = i.SchemeID; dc.ReturnmentDetails.Add(rd); if (R.ReturnTypeID != 12) { CashSettlementDetail cd = new CashSettlementDetail(); var ratedata = db.ProductRateDetails.Where(x => x.ProductRateID == V.ProductRateID && x.ProductID == i.ProductID).FirstOrDefault(); // double xva = .2; cd.WarehouseID = R.WarehouseID; cd.CashSettlementID = csID; cd.AlternateReturnedFilledQuantity = (int)i.RebateQty; cd.ProductID = (int)i.ProductID; cd.UnitPrice = ratedata.UnitPrice; cd.AlternateAgencyCommission = ratedata.AlternateAgencyCommission; cd.AlternateUnitPrice = ratedata.AlternateUnitPrice; cd.MRPRate = ratedata.MRPRate; cd.AlternateRebateAmount = 0; cd.AlternateGrossSalesAmount = 0; cd.VATAmount = 0; cd.SchemeID = (int)i.SchemeID; cd.ReturnedPlasticBoxSecurity = 0;// (decimal)i.Amount* (decimal)xva; //cd.UnitPrice = if (R.ReturnTypeID == 13) { //cd.ReturnedAlternateSecurityDeposit = (decimal)i.Amount; cd.ReturnedQuantity = pcqty; cd.AlternateReturnedQuantity = csqty; cd.ReturnedPlasticBoxQuantity = (int)i.Packsize; cd.ReturnedSecurityDeposit = q.SecurityDeposit; cd.ReturnedAlternateSecurityDeposit = q.AlternateSecurityDeposit; cd.ReturnedPlasticBoxSecurity = q.PlasticBoxSecurity; } else { cd.AlternateReturnedFilledQuantity = csqty; // (int)i.ReturnQty; cd.ReturnedFilledQuantity = pcqty; cd.AlternateReturnedRebateQuantity = rebcsqty; // (int)i.RebateQty; cd.ReturnedRebateQuantity = rebpcqty; cd.ReturnedPlasticBoxQuantity = (int)i.Packsize + (int)i.RebatePlastic; cd.ReturnedSecurityDeposit = q.SecurityDeposit; cd.ReturnedAlternateSecurityDeposit = q.AlternateSecurityDeposit; cd.ReturnedPlasticBoxSecurity = q.PlasticBoxSecurity; } dc.CashSettlementDetails.Add(cd); } //if (R.ReturnTypeID == 14) //{ // var pb = db.spProductBalanceUpdate(i.ProductID, R.WarehouseID, (int)i.ReturnQty, 0, 0, 0, 0); //} } ; dc.SaveChanges(); status = true; dc.Dispose(); } ModelState.Clear(); } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
public JsonResult AddInvoiceData(InvoiceVM Inv) { var w = (from yt in db.UserLogins where yt.UserID.ToString() == User.Identity.Name select new { yt.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(t => t.WarehouseID == w.WorkStationID).FirstOrDefault(); bool status = false; string mes = ""; string s1 = w.WorkStationID.ToString(); string s2 = string.Concat(s1 + "6000000"); string s3 = string.Concat(s1 + "5000000"); int MaxChallanNo = Convert.ToInt32(s2); int MaxCashID = Convert.ToInt32(s3); var maxchno = (from n in db.Orders where n.WarehouseID == w.WorkStationID select n.ChallanNumber).DefaultIfEmpty(MaxChallanNo).Max(); var maxCasettleId = (from n in db.CashSettlements where n.WarehouseID == w.WorkStationID select n.CashSettlementID).DefaultIfEmpty(MaxCashID).Max(); var maxprodtr = (from j in db.ProductTransactions where j.WarehouseID == w.WorkStationID select j.TransactionNo).Max() + 1; chNumber = Convert.ToInt32(maxchno + 1); csID = Convert.ToInt32(maxCasettleId + 1); int v = chNumber; if (ModelState.IsValid) { try { using (PEPSIEntities dc = new PEPSIEntities()) { // var V = db.Orders.Max(p => p.ChallanNumber); CommonChk cm = new CommonChk(); { if (cm.chkDuplicateChallan(Inv.OrderID) == true) { //status = false; var vr = db.Orders.SingleOrDefault(x => x.OrderID == Inv.OrderID); CashSettlement cs = new CashSettlement(); { // var vr = db.Orders.SingleOrDefault(x => x.OrderID == Inv.OrderID); cs.CashSettlementID = csID; cs.SalesPersonID = vr.SalesPersonID; cs.DeliveryChallanDate = DateTime.Today; //vr.DeliveryChallanDate; cs.CustomerID = vr.CustomerID; cs.DeliveryChallanNumbers = chNumber; // Convert.ToInt32(vr.ChallanNumber)+1; cs.WarehouseID = vr.WarehouseID; cs.VehicleID = vr.VehicleID; cs.CashSettlementDate = DateTime.Today; cs.RebateWillBeGivenWithOrder = vr.RebateWillBeGivenWithOrder; cs.SpecialNoteFromOrder = vr.SpecialNote; cs.SpecialInstruction = Inv.SpecialNote; cs.OrderID = vr.OrderID; cs.ProductRateID = vr.ProductRateID; cs.DayendFinished = "N"; cs.DayendDay = DateTime.Now; cs.OrderTypeID = vr.OrderTypeID; cs.CustomerExecutiveID = vr.CustomerExecutiveID; cs.DriverID = vr.DriverID; cs.Promotional = vr.Promotional; cs.CheckedByShipping = "Y"; cs.AgencyCommission = Inv.AgencyCommission; // vr.AgencyCommission; cs.TotalSpecialCharges = vr.SpecialCharge1Amount; cs.SecurityAmount = Inv.SecurityAmount; //vr cs.DrinksAmount = (Inv.SalesAmount - Inv.AgencyCommission); //(vr.SalesAmount - vr.AgencyCommission); cs.FinishGoodsUnloadCharge = Inv.FinishGoodsUnloadCharge; //vr cs.CreateBy = User.Identity.Name; cs.CraeteDate = DateTime.Now; // dc.CashSettlements.Add(cs); } dc.CashSettlements.Add(cs); // Product Transaction ProductTransaction pt = new ProductTransaction(); { pt.WarehouseID = Inv.WarehouseID; pt.TransactionNo = maxprodtr; pt.TransactionDate = DateTime.Today; pt.TransactionTypeID = 7; pt.FromWarehouse = Inv.WarehouseID; pt.ReferenceNo = csID.ToString(); pt.Remarks = Inv.SpecialNote; pt.Status = "I"; pt.CreatedBy = User.Identity.Name; pt.CreatedDate = DateTime.Now; } dc.ProductTransactions.Add(pt); // Helper InvoiceHelper pm = new InvoiceHelper(); { pm.OrderID = Inv.OrderID; pm.HelperID1 = Inv.Helper1; pm.HelperID2 = Inv.Helper2; pm.HelperID3 = Inv.Helper2; dc.InvoiceHelpers.Add(pm); } // Customer Ledger CustomerLedgerDetail cld = new CustomerLedgerDetail(); { cld.WarehouseID = vr.WarehouseID; cld.CustomerID = vr.CustomerID; cld.TransactionNo = "INV" + csID.ToString(); cld.CrAmount = 0; cld.TransactionTypeID = 15; cld.TransactionDate = DateTime.Today; cld.RefNumber1 = csID.ToString(); cld.DrAmount = (Inv.SalesAmount + Inv.SecurityAmount) - (Inv.AgencyCommission + (decimal)Inv.FinishGoodsUnloadCharge);// (Inv.SalesAmount - Inv.AgencyCommission); //(vr.SalesAmount - vr.AgencyCommission); cld.DebitCredit = "D"; cld.Narration = "Invoice Value#" + cld.DrAmount + " for Customer" + cld.CustomerID; cld.CreateBy = User.Identity.Name; cld.CreateDate = System.DateTime.Now; } dc.CustomerLedgerDetails.Add(cld); // update Customer Ledgermaster // Farid Correction 03dec2018 //decimal amountofdr = (Inv.SalesAmount - Inv.AgencyCommission); //decimal bokamt = amountofdr + Inv.SecurityAmount; //var clmbf = db.spCustomerBalanceUpdate(vr.CustomerID, "F", bokamt); //var clm = db.spCustomerBalanceUpdate(vr.CustomerID, "I", amountofdr); //var security = db.spCustomerBalanceUpdate(vr.CustomerID, "S", Inv.SecurityAmount); //decimal vInvAmt = (Inv.SalesAmount - Inv.AgencyCommission)- (decimal)Inv.FinishGoodsUnloadCharge; decimal vInvAmt = Inv.SalesAmount - (Inv.AgencyCommission); //(decimal)Inv.FinishGoodsUnloadCharge decimal vBookAmt = Inv.SalesAmount + Inv.SecurityAmount - Inv.AgencyCommission; decimal vCurBal = (Inv.SalesAmount + Inv.SecurityAmount) - (Inv.AgencyCommission + (decimal)Inv.FinishGoodsUnloadCharge); decimal vChargeAmount = (decimal)Inv.FinishGoodsUnloadCharge; decimal vSecurityAmt = Inv.SecurityAmount; decimal vRebateAmt = 0; if (Inv.RebateAmount > 0) { decimal vRebate = (Inv.RebateAmount); vRebateAmt = vRebate; } else { decimal vRebate = Inv.RebateAmount; vRebateAmt = vRebate; } decimal vFare = Inv.FareAmnt; db.spUpdateDBsInvoiceValue( vr.CustomerID, "I", vCurBal, vCurBal, vInvAmt, vBookAmt, vSecurityAmt, vChargeAmount, vFare, vRebateAmt, chNumber ); // Farid Correction // var clm = db.spCustomerBalanceUpdate(vr.CustomerID, "I", bokamt);// with sequirity amount // Add Fare Amount if (Inv.VehicleID == 1) { //need to adjust without var cus = cm.GetCustomerName(vr.CustomerID, "C"); var cusAdd = db.Customers.Where(x => x.CustomerID == vr.CustomerID).FirstOrDefault(); var c = db.spInsertHireTruckFare(Inv.WarehouseID, chNumber, Inv.TAID, DateTime.Today, cus, cusAdd.CustomerAddress1, Inv.VechileNo, Inv.FareAmnt, 0, Inv.TotalCases, "No", User.Identity.Name, DateTime.Now, "Hired Truck"); } var ODetails = db.OrderDetails.Where(x => x.WarehouseID == Inv.WarehouseID && x.OrderID == Inv.OrderID); foreach (var z in ODetails.ToList()) { CashSettlementDetail csd = new CashSettlementDetail() { WarehouseID = Inv.WarehouseID, CashSettlementID = csID, ProductID = z.ProductID, SchemeID = (int)z.SchemeID, UnitPrice = (decimal)z.UnitPrice, AlternateUnitPrice = (decimal)z.AlternateUnitPrice, Quantity = (int)z.Quantity, AlternateQuantity = (int)z.AlternateQuantity, PlasticBoxQuantity = (int)z.PlasticBoxQuantity, RebateQuantity = (int)z.RebateQuantity, AlternateRebateQuantity = (int)z.AlternateRebateQuantity, AgencyCommission = (decimal)z.AgencyCommission, AlternateAgencyCommission = (decimal)z.AlternateAgencyCommission, SecurityDeposit = (decimal)z.SecurityDeposit, AlternateSecurityDeposit = (decimal)z.AlternateSecurityDeposit, PlasticBoxSecurity = (decimal)z.PlasticBoxSecurity, MRPRate = z.MRPRate }; dc.CashSettlementDetails.Add(csd); var totpc = (from x in db.Products where x.ProductID == z.ProductID select x).FirstOrDefault(); int TotQty = (int)(z.Quantity + ((z.AlternateQuantity + z.AlternateRebateQuantity) * totpc.ConversionFactor) + z.RebateQuantity); StockBatchDetail sbd = new StockBatchDetail() { WarehouseID = Inv.WarehouseID, TransactionNo = csID, TransactionDate = System.DateTime.Today, ProductID = z.ProductID, Quantity = TotQty,//(int)z.AlternateQuantity for rebate and case to pcs, PlasticBoxQuantity = z.PlasticBoxQuantity, TransactionType = "Invoice Creation", BatchNo = (int)z.BatchNo, CreateBy = User.Identity.Name, CreateDate = System.DateTime.Now, }; dc.StockBatchDetails.Add(sbd); //var cc = (int)z.Quantity; //var xxx = (int)z.PlasticBoxQuantity; //var cc = CommonChk // CommonChk cm = new CommonChk(); //int qty = cm.CasetoPcs(z.ProductID, (int)z.AlternateQuantity); // off for rebate int qty = TotQty; //int qty = cm.CasetoPcs(z.ProductID, TotQty); Farid Correction ProductTransactionDetail ptd = new ProductTransactionDetail(); { ptd.TransactionNo = maxprodtr; ptd.WarehouseID = Inv.WarehouseID; ptd.ProductID = z.ProductID; ptd.Quantity = qty;// (int)z.AlternateQuantity; ptd.PlasticBoxQuantity = (int)z.PlasticBoxQuantity; //BatchNo = z.BatchNo, //ExpiryDate = z.ExpDate, //ManufactureDate = z.MfgDate, ptd.EmptyBottleQuantity = 0; ptd.BurstBottleQuantity = 0; ptd.BreakageBottleQuantity = 0; dc.ProductTransactionDetails.Add(ptd); }; // Product Stock Maintaince // int allProductsQty; //var Pr = (from x in db.Products where x.ProductID == z.ProductID select x).FirstOrDefault(); // allProductsQty = (int)(z.Quantity + ((z.AlternateQuantity + z.AlternateRebateQuantity) * Pr.ConversionFactor) + z.RebateQuantity); // SqlCommand com = new SqlCommand("spProductBalanceDecrease", con); // off for holding stock against loadsheet //var decreaseprodbal = db.spProductBalanceDecrease(z.ProductID, // vr.WarehouseID, // qty, // 0, // 0, // 0, // 0); var decreaseprodbal = db.spStockBookedandBookedFree(z.ProductID, vr.WarehouseID, qty, "D"); } // Update Order var upby = User.Identity.Name; var orderdata = db.spOrderUpdateAfterInvoice( Inv.WarehouseID, Inv.OrderID, "Y", DateTime.Today, Inv.SalesAmount, Inv.SecurityAmount, Inv.RebateAmount, Inv.AgencyCommission, chNumber, upby, csID, "Y", Inv.FinishGoodsUnloadCharge, upby, DateTime.Now, Inv.AdvanceOrder ); // con.Close(); //Transport QR Data Tauhid //salesOrderNo will be OrderDate try { var getSONo = (from x in db.Orders where x.OrderID == Inv.OrderID select x).FirstOrDefault(); SalesOrdNo = Convert.ToInt32(getSONo.OrderID); TransportQRData qd = db.TransportQRDatas.SingleOrDefault(x => x.SalesOrderNo == SalesOrdNo); qd.InvoiceDateTime = System.DateTime.Now; qd.DeliveryChallanNumber = chNumber; dc.Entry(qd).State = EntityState.Modified; } catch (Exception ex) { } dc.SaveChanges(); //Invoice Print var getSNo = (from x in db.Orders where x.ChallanNumber == chNumber select x).FirstOrDefault(); SalesOrdNo = Convert.ToInt32(getSNo.SalesOrderNo); // SalesOrdNo = (int)Inv.SalesOrderNo; //if (SalesOrdNo!=null) //{ // return RedirectToAction("Invoce", "OrderReport"); //} status = true; //int v = chNumber; Dispose(); // status = true; //return new JsonResult { Data = new { status = status, mes = mes } }; } else { status = false; v = 0; } } } } catch (Exception ex) { throw ex; } } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v, SNo = SalesOrdNo } }); //return RedirectToAction("Invoice", "ReprintController", new { @InvNo = v }); }
public ActionResult UserLogin(LoginViewModel model, string returnUrl) { try { // Verification. if (ModelState.IsValid) { // Initialization. var loginInfo = this.databaseManager.spLoginUser(model.UserID, model.Password).ToList(); // var loginInfo = this.databaseManager.LoginUserPassword(model.UserCode, model.Password).ToList(); // Verification. if (loginInfo != null && loginInfo.Count() > 0) { // Initialization. var logindetails = loginInfo.First(); // Login In. // var sid = logindetails.UserName; var sid = logindetails.userId; this.SignInUser(sid.ToString(), false); // Info. // return this.RedirectToLocal(returnUrl); // for menu bool isExist = false; using (PEPSIEntities dc = new PEPSIEntities()) { isExist = dc.UserLogins.Where(x => x.UserID == model.UserID).Any(); if (isExist) { LoginModels loginCredentials = dc.UserLogins.Where(x => x.UserID == model.UserID).Select(x => new LoginModels { UserName = x.UserName, UserRoleId = x.RoleId, UserID = x.UserID }).FirstOrDefault(); List <MenuModels> menus = dc.MenuSubs.Where(x => x.RoleId == loginCredentials.UserRoleId && x.UserID == loginCredentials.UserID).Select(x => new MenuModels { MainMenuId = x.MenuMain.Id, MainMenuName = x.MenuMain.MainMenu, SubMenuId = x.MenuCode, SubMenuName = x.SubMenu, ControllerName = x.Controller, ActionName = x.Action, RoleId = x.RoleId, UserID = x.UserID, RoleName = x.MenuRole.Roles }).ToList(); FormsAuthentication.SetAuthCookie(loginCredentials.UserID.ToString(), false); Session["LoginCredentials"] = loginCredentials; Session["MenuMaster"] = menus; Session["Name"] = loginCredentials.UserID; return(this.RedirectToLocal(returnUrl)); } else { ViewBag.ErrorMsg = "Please enter the valid credentials!..."; return(View("Index")); } } } else { // Setting. ModelState.AddModelError(string.Empty, "Invalid UserName or Password..Please check"); } } } catch (Exception ex) { // Info Console.Write(ex); } return(this.View(model)); }
public ActionResult OrderEntrySave(OrderEntryVM D) { bool status = false; string mes = ""; var w = (from y in db.UserLogins where y.UserID.ToString() == User.Identity.Name select new { y.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault(); // var PTID = (from x in db.OrderBankSummaries select x.SalesOrderNO).DefaultIfEmpty(610000000).Max(); // PIDMax = (PTID + 1); string s1 = w.WorkStationID.ToString(); string s2 = string.Concat(s1 + "9000000"); int OrderNo = Convert.ToInt32(s2); var maxSalesOrderNO = (from n in db.OrderBankSummaries where n.WarehouseID == w.WorkStationID select n.SalesOrderNO).DefaultIfEmpty(OrderNo).Max(); // var batch = (from x in dc.StockBatches where x.ProductID == i.ProductID && x.WarehouseID == S.WarehouseID select x.BatchNo).DefaultIfEmpty(100).Max() + 1; //Max(x => x.SalesOrderNO)) var maxsalno = maxSalesOrderNO + 1; int v = maxsalno; DateTime date2 = Convert.ToDateTime(D.ExpectDeliverDate); if (ModelState.IsValid) { using (PEPSIEntities dc = new PEPSIEntities()) { OrderBankSummary dbo = new OrderBankSummary { SalesOrderNO = maxsalno, WarehouseID = D.WarehouseID, CustomerID = D.CustomerID, OrderCase = D.TotOrderCase, OrderBox = D.TotOrderBox, SalesOrderDate = DateTime.Today, PartialDelivered = "N", RefOrderNO = D.Remarks, Status = "A", Remarks = D.Remarks, Delivered = "N", ExpectDeliverDate = date2,// DateTime.Today.AddDays(1), TotalOrderAmount = D.TotalOrderAmount, EmptyBottleCase = D.EmptyBottleCase, CreateDate = DateTime.Now, CreateBy = User.Identity.Name }; dc.OrderBankSummaries.Add(dbo); foreach (var i in D.oderCustomer) { OrderBankDetail obd = new OrderBankDetail(); obd.WarehouseID = D.WarehouseID; obd.SalesOrderNO = maxsalno; obd.CustomerID = D.CustomerID; obd.ProductID = i.ProductID; obd.OrderCase = i.OrderCase; obd.PlasticBox = i.PlasticBox; obd.Amount = i.Amount; //obd. = DateTime.Now.Date; obd.CreateBy = User.Identity.Name; obd.CreateDate = DateTime.Now; dc.OrderBankDetails.Add(obd); } dc.SaveChanges(); status = true; dc.Dispose(); } ModelState.Clear(); } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
public ActionResult CreateLoadSheet(LoadSheetVM A) { var w = (from yt in db.UserLogins where yt.UserID.ToString() == User.Identity.Name select new { yt.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(t => t.WarehouseID == w.WorkStationID).FirstOrDefault(); bool status = true; string mes = ""; // int maxsl = 0; decimal unitprice = 0; string pstatus = ""; string s1 = w.WorkStationID.ToString(); string s2 = string.Concat(s1 + "8000000"); int OrderNo = Convert.ToInt32(s2); var orderID = (from n in db.Orders where n.WarehouseID == w.WorkStationID select n.OrderID).DefaultIfEmpty(OrderNo).Max(); //var maxorderid = (from n in db.Orders // where n.OrderID == (db.Orders.Max(xo => xo.OrderID)) // select new { n.OrderID }).FirstOrDefault(); var customerData = (from i in db.Customers where (i.CustomerID == A.CustomerID) select i).FirstOrDefault(); var mindeliverychallan = db.Orders .Where(p => p.WarehouseID == A.WarehouseID) // not consider salesorderno p.SalesOrderNo == A.SalesOrderNo && .Min(p => p.ChallanNumber); //var maxsl = db.Orders // .Where(p => p.WarehouseID == A.WarehouseID) // .Max(p => p.OrderID); int orderno = orderID + 1; int v = orderno; // Checking challan negetive if (mindeliverychallan >= 0) { mindeliverychallan = -1; } else { mindeliverychallan = mindeliverychallan - 1; } if (A.VehicleID == 1) { A.DriverID = 0; } if (ModelState.IsValid) { // try // { using (PEPSIEntities dc = new PEPSIEntities()) { var getorderdate = dc.OrderBankSummaries.Where(x => x.WarehouseID == A.WarehouseID && x.SalesOrderNO == A.SalesOrderNo).FirstOrDefault(); Order dbo = new Order { //Add orders table //Here Id Primary Key of DB table auto increase // SLNo = maxsl, SalesOrderNo = A.SalesOrderNo, //CustomerExecutive = (A.CustomerExecutiveID), OrderID = orderno,//A.OrderID, //OrderDate = A.OrderDate,//DateTime.Today, OrderDate = getorderdate.SalesOrderDate, WarehouseID = A.WarehouseID, DriverID = (int)A.DriverID, CustomerID = A.CustomerID, VehicleID = A.VehicleID, SalesPersonID = customerData.SalesPersonID, //Trip = 0, //SalesAmount = 0, //SecurityAmount = 0, //RebateAmount = 0, //AgencyCommission = 0, Trip = 1, OrderTypeID = A.OrderTypeID, ProductRateID = customerData.ProductRateID, CustomerExecutiveID = customerData.CustomerExecutiveID,// A.CustomerExecutiveID, LoadSheetRemarks = A.LoadSheetRemarks, Delivered = "N", Cash = "N", IsCashSettlementPrepared = "N", Transit = "N", Promotional = "N", InvoiceFromVATInvoiceNumber = "N", VATChallanRequired = "Y", ReadyForDelivery = "Y", AdvanceOrder = "N", //RebateWillBeGivenWithOrder = A.RebateWillBeGivenWithOrder, //SSMA_TimeStamp =Convert.ToByte(DateTime.Now), // SSMA_TimeStamp = null, CreateBy = User.Identity.Name, CreateDate = System.DateTime.Now }; dc.Orders.Add(dbo); // status = true; CommonChk c = new CommonChk(); foreach (var j in A.orderdetail) { //checking stock balace if (c.stockchk(j.ProductID, A.WarehouseID, (int)j.AlternateQuantity) == true) { //status = false; } else { status = false; }; } ; if (status == true) { foreach (var i in A.orderdetail) { // Add order detail OrderDetail dod = new OrderDetail(); // var d = (from x in db.spGetSalesOrder(A.SalesOrderNo) where x.ProductID == i.ProductID select x).FirstOrDefault(); var d = (from n in db.spGetSalesOrderNewProduct(A.SalesOrderNo, i.ProductID) where n.CustomerID == A.CustomerID select n).FirstOrDefault(); var batch = (from x in db.StockBatches where x.ProductID == i.ProductID && x.WarehouseID == A.WarehouseID && x.Status == "A" select x).FirstOrDefault(); // Id Primary key Auto generate var q = (from x in db.Products where x.ProductID == i.ProductID select x).FirstOrDefault(); // unitprice = q.UnitPrice; int s = q.ConversionFactor; decimal qt = Math.Round((decimal)(i.AlternateQuantity) * s, 2); decimal rqty = Math.Round((decimal)(i.AlternateRebateQuantity) * s, 2); int quantity = (Convert.ToInt32(Math.Round(qt)) % s); int casesqty = (Convert.ToInt32(Math.Round(qt)) / s); int rebateqty = (Convert.ToInt32(Math.Round(rqty)) % s); int rebatecase = (Convert.ToInt32(Math.Round(rqty)) / s); int totbookedqty = (int)qt + (int)rqty; dod.WarehouseID = A.WarehouseID; dod.OrderID = orderno;// A.OrderID; dod.ProductID = i.ProductID; //dod.Quantity = i.Quantity; dod.SchemeID = (int)i.SchemeID; dod.Quantity = quantity; dod.AlternateQuantity = casesqty; dod.RebateQuantity = rebateqty; dod.AlternateRebateQuantity = rebatecase; dod.AgencyCommission = d.AgencyCommission; dod.AlternateAgencyCommission = d.AlternateAgencyCommission; dod.UnitPrice = d.UnitPrice; dod.AlternateUnitPrice = d.AlternateUnitPrice; dod.SecurityDeposit = d.SecurityDeposit; dod.AlternateSecurityDeposit = d.AlternateSecurityDeposit; dod.PlasticBoxQuantity = (int)i.PlasticBoxQuantity; dod.PlasticBoxSecurity = d.PlasticBoxSecurity; dod.BatchNo = batch.BatchNo; dod.MfgDate = batch.ManufacturDate; dod.ExpDate = batch.ExpiryDate; dod.MRPRate = d.MRPRate; dc.OrderDetails.Add(dod); //Add scheme infomation OrderSchemeDetail os = new OrderSchemeDetail(); os.OrderID = orderno;// A.OrderID; os.ProductID = i.ProductID; os.SchemeID = (int)i.SchemeID; os.WarehouseID = A.WarehouseID; dc.OrderSchemeDetails.Add(os); // Booked Product var bookedproduct = db.spStockBookedandBookedFree( i.ProductID, A.WarehouseID, totbookedqty, "B"); } } //db.SaveChanges(); // status = true; if (status == true) { //update if (A.OrderTypeID == 1) { pstatus = "C"; } else { pstatus = "P"; } var ob = db.spOrderBankSumUpdate(A.SalesOrderNo, A.WarehouseID, pstatus); //Where(x => x.SalesOrderNO == A.SalesOrderNo && x.WarehouseID == A.WarehouseID && x.CustomerID == A.CustomerID).FirstOrDefault(); var bookamtupdate = db.spCustomerBalanceUpdate(A.CustomerID, "B", A.SalesAmount); // db.Entry(ob).State = EntityState.Modified; //Transport QR Data //Ad QR LoadSheet Timing //Add scheme infomation try { TransportQRData qd = db.TransportQRDatas.SingleOrDefault(x => x.SLNO == A.QRSL); qd.LoadingDateTime = System.DateTime.Now; qd.SalesOrderNo = orderno; dc.Entry(qd).State = EntityState.Modified; } catch (Exception ex) { } dc.SaveChanges(); status = true; dc.Dispose(); } else { status = false; v = 0000; } } } // catch (Exception ex) // { // return new JsonResult { Data = new { status = false, mes = "NO Save", v = v } }; // return JsonResult { Data = new { status = "error", message = "Not Found" }}; //} return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
public JsonResult SaveBGData(CustomerBGInfoVM A) { bool status = false; string mes = ""; string v = A.BGRefNo; int bgNo; bgNo = (from x in db.CustomerBGInfoes select x).Max(p => p.BankGuaranteeNo) + 1; var c = db.Customers.Where(t => t.CustomerID == A.CustomerID).FirstOrDefault(); if (ModelState.IsValid) { try { using (PEPSIEntities dc = new PEPSIEntities()) { CustomerBGInfo bg = new CustomerBGInfo(); { bg.CustomerID = A.CustomerID; bg.BankGuaranteeNo = bgNo; bg.BankName = A.BankName; bg.BGRefNo = A.BGRefNo; bg.ActualBGAmt = A.ActualBGAmt; bg.BGAmount = A.BGAmount; bg.IssueDate = A.IssueDate; bg.ExpiryDate = A.ExpiryDate; bg.BankBrName = A.BankBrName; bg.Status = "A"; bg.CreateBy = User.Identity.Name; bg.CreateDate = System.DateTime.Now; } dc.CustomerBGInfoes.Add(bg); CustomerLedgerDetail cl = new CustomerLedgerDetail(); { cl.WarehouseID = (int)c.WarehouseID; cl.TransactionNo = "BG" + bgNo; cl.TransactionTypeID = 18; cl.CustomerID = A.CustomerID; cl.DebitCredit = "C"; cl.CrAmount = A.BGAmount; cl.DrAmount = 0; cl.Narration = "Customer BG amount#" + A.BGAmount + "Against BG NO#" + A.BGRefNo; cl.RefNumber1 = A.BGRefNo; cl.TransactionDate = System.DateTime.Today; cl.CreateBy = User.Identity.Name; cl.CreateDate = System.DateTime.Now; } dc.CustomerLedgerDetails.Add(cl); // Update Customer Curr balance var d = db.spCustomerBalanceUpdate(A.CustomerID, "G", A.BGAmount); // Save All Data dc.SaveChanges(); status = true; dc.Dispose(); } } catch (Exception ex) { return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); //throw ex; } } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
public ActionResult SaveProductReceived(StockReceivedVM S) { var w = (from y in db.UserLogins where y.UserID.ToString() == User.Identity.Name select new { y.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault(); string s1 = w.WorkStationID.ToString(); string s2 = string.Concat(s1 + "0000000"); int Trno = Convert.ToInt32(s2); bool status = false; string mes = ""; int v; int PIDMax; // var PTID = db.ProductTransactions.Max(p => p.TransactionNo); var PTID = (from x in db.ProductTransactions where x.WarehouseID == wn.WarehouseID select x.TransactionNo).DefaultIfEmpty(Trno).Max(); PIDMax = (PTID + 1); v = PIDMax; try { if (ModelState.IsValid) { using (PEPSIEntities dc = new PEPSIEntities()) { ProductTransaction dm = new ProductTransaction(); { // Here Id Primary Key of DB table auto increase dm.TransactionTypeID = 3; dm.TransactionNo = PIDMax; dm.WarehouseID = S.WarehouseID; dm.FromWarehouse = S.FromWarehouse; //dm.ToWarehouse = S.WarehouseID; dm.TransactionDate = DateTime.Today; dm.ReferenceNo = S.ReferenceNo; dm.Status = "A"; //cuser = User.Identity.Name dm.CreatedBy = User.Identity.Name; dm.CreatedDate = DateTime.Now; dm.StoreLocation = S.StoreLocation; } dc.ProductTransactions.Add(dm); foreach (var i in S.ProdTrDtl) { ProductTransactionDetail dmd = new ProductTransactionDetail(); dmd.ProductID = i.ProductID; // Not Null dmd.WarehouseID = S.WarehouseID; //dmd.WarehouseID = (int)S.FromWarehouse; dmd.TransactionNo = PIDMax; // dmd.PlantNo = dmd.LineNoPlant = i.LineNoPlant; dmd.BatchNo = i.BatchNo; dmd.ExpiryDate = i.ExpiryDate; dmd.ManufactureDate = i.ManufactureDate; dmd.Quantity = (i.Quantity); dmd.EmptyBottleQuantity = (i.EmptyBottleQuantity); dmd.PlasticBoxQuantity = i.PlasticBoxQuantity; dmd.BurstBottleQuantity = (i.BurstBottleQuantity); dmd.BreakageBottleQuantity = (i.BreakageBottleQuantity); //TCases = TCases + i.Quantity; dc.ProductTransactionDetails.Add(dmd); // For Batch StockBatch sb = new StockBatch(); sb.ProductID = i.ProductID; sb.WarehouseID = (int)S.WarehouseID; sb.BatchNo = (int)i.BatchNo; sb.ManufacturDate = (DateTime)i.ManufactureDate; sb.ExpiryDate = (DateTime)i.ExpiryDate; sb.PlantLineNo = (int)i.LineNoPlant; sb.PlantNo = i.PlantNo; sb.IssueQuantity = i.Quantity; sb.ReceivedQty = i.Quantity; sb.Status = "A"; sb.WarehouseLocationCode = S.StoreLocation; dc.StockBatches.Add(sb); // Add stock batch detail for transaction history StockBatchDetail sbd = new StockBatchDetail(); sbd.WarehouseID = S.WarehouseID; sbd.BatchNo = (int)i.BatchNo; sbd.ProductID = i.ProductID; sbd.TransactionNo = PIDMax; sbd.Quantity = i.Quantity; sbd.BurstBottleQuantity = i.BurstBottleQuantity; sbd.BreakageBottleQuantity = i.BreakageBottleQuantity; sbd.PlasticBoxQuantity = (int)i.PlasticBoxQuantity; sbd.TransactionDate = DateTime.Today; sbd.TransactionType = "Transfer Received"; sbd.CreateBy = User.Identity.Name; sbd.CreateDate = DateTime.Now; dc.StockBatchDetails.Add(sbd); } foreach (var i in S.ProdTrDtl) { var CF = (from x in dc.Products where x.ProductID == i.ProductID select x).FirstOrDefault(); try { var V = (from x in db.ProductBalances where x.ProductID == i.ProductID && x.WarehouseID == S.ToWarehouse select x).FirstOrDefault(); //Add Stock var productupdate = dc.spProductBalanceUpdate(i.ProductID, S.WarehouseID, (int)i.Quantity, //change i.BurstBottleQuantity, i.BreakageBottleQuantity, (int)i.PlasticBoxQuantity, i.EmptyBottleQuantity); } catch (Exception ex) { throw ex; } } var pt = dc.ProductTransactions.Where(x => x.WarehouseID == S.FromWarehouse && x.TransactionNo == S.TransactionNo && x.TransactionTypeID == S.TransactionTypeID).FirstOrDefault(); pt.UpdatedBy = User.Identity.Name; pt.UpdatedDate = DateTime.Now; dc.SaveChanges(); status = true; dc.Dispose(); } } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); } catch (Exception ex) { return(Json(new { status = "error", message = "Transaction No Not Found" })); // throw ex; } }
public ActionResult SaveData(StockVM S) { var w = (from y in db.UserLogins where y.UserID.ToString() == User.Identity.Name select new { y.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault(); // var PTID = (from x in db.OrderBankSummaries select x.SalesOrderNO).DefaultIfEmpty(610000000).Max(); // PIDMax = (PTID + 1); string s1 = w.WorkStationID.ToString(); string s2 = string.Concat(s1 + "0000000"); string s3 = string.Concat(s1 + Convert.ToString(DateTime.Now.Year) + "000"); string plantfl = wn.PlantFlag; int batchno = Convert.ToInt32(s3); int Trno = Convert.ToInt32(s2); bool status = true; string mes = ""; int PIDMax; var PTID = (from x in db.ProductTransactions where x.WarehouseID == wn.WarehouseID select x.TransactionNo).DefaultIfEmpty(Trno).Max(); PIDMax = (PTID + 1); int v = PIDMax; if (ModelState.IsValid) { try { using (PEPSIEntities dc = new PEPSIEntities()) { CommonChk ck = new CommonChk(); ProductTransaction dm = new ProductTransaction(); { // Here Id Primary Key of DB table auto increase //var PTID = db.ProductTransactions.DefaultIfEmpty(100).Max(p => p.TransactionNo); dm.TransactionTypeID = S.TransactionTypeID; dm.TransactionNo = PIDMax;// dm.WarehouseID = S.WarehouseID; dm.FromWarehouse = S.WarehouseID; dm.ToWarehouse = S.ToWarehouse; dm.TransactionDate = DateTime.Today; dm.ReferenceNo = S.ReferenceNo; dm.Remarks = S.Remarks; if (S.TransactionTypeID != 1) { if (S.TransactionTypeID == 1) { dm.Status = "T"; } if (S.TransactionTypeID == 6) { dm.Status = "D"; } if (S.TransactionTypeID == 10) { dm.Status = "B"; } if (S.TransactionTypeID == 11) { dm.Status = "W"; } } else { dm.Status = "A"; } //cuser = User.Identity.Name dm.CreatedBy = User.Identity.Name; dm.CreatedDate = DateTime.Now; dm.StoreLocation = S.StoreLocation; } dc.ProductTransactions.Add(dm); // Transfer Note if (S.TransactionTypeID == 2) { ProductTransferNote ptn = new ProductTransferNote(); { var PTNoteID = (from x in db.ProductTransferNotes where x.WarehouseID == w.WorkStationID select x.SLNo).DefaultIfEmpty(1).Max(); int TrNoteId = Convert.ToInt32((PTNoteID)) + 1; ptn.WarehouseID = S.WarehouseID; ptn.TransactionNo = PIDMax; ptn.VehicleID = S.VehicleID; if (S.VehicleID == 1) { ptn.DriverID = 0; } else { ptn.DriverID = S.DriverID; } ptn.Remarks = S.Remarks; ptn.SLNo = TrNoteId; ptn.CreateBy = User.Identity.Name; ptn.CreateDate = DateTime.Now; } dc.ProductTransferNotes.Add(ptn); } // Agency Fare Amount if (S.VehicleID == 1 && S.TransactionTypeID == 2) { TransportAgencyandFareSetup tf = new TransportAgencyandFareSetup(); { tf.WarehouseID = S.WarehouseID; tf.TAID = (int)S.TAID; tf.ChallanNumber = PIDMax; tf.ChallanDate = DateTime.Today; tf.CustomerName = ck.GetCustomerName((int)S.ToWarehouse, "N"); tf.Address = ck.GetCustomerName((int)S.ToWarehouse, "N"); tf.VechileNo = S.VehicleID.ToString(); tf.FareAmnt = (decimal)S.FareAmnt; tf.Remarks = "Hired Truck"; tf.TotalCases = S.TotCase; tf.Status = "No"; tf.EnteredBy = User.Identity.Name; tf.EnteredDate = System.DateTime.Now; } dc.TransportAgencyandFareSetups.Add(tf); } if (S.TransactionTypeID == 2) { foreach (var j in S.ProdTrDtl) { //checking stock balace if (ck.stockchkcs(j.ProductID, S.WarehouseID, (int)j.Quantity) == true) { //status = false; } else { status = false; }; } ; } if (status == true) { foreach (var i in S.ProdTrDtl) { var CF = (from x in dc.Products where x.ProductID == i.ProductID select x).FirstOrDefault(); var batch = (from x in dc.StockBatches where x.ProductID == i.ProductID && x.WarehouseID == S.WarehouseID select x.BatchNo).DefaultIfEmpty(batchno).Max() + 1; ProductTransactionDetail dmd = new ProductTransactionDetail(); dmd.ProductID = i.ProductID; // Not Null dmd.WarehouseID = S.WarehouseID; dmd.TransactionNo = PIDMax; dmd.LineNoPlant = i.LineNoPlant; if (S.TransactionTypeID != 1) { dmd.BatchNo = i.BatchNo; } else { dmd.BatchNo = batch; } if (plantfl == "Y") { int plant = (int)wn.PlantNo; dmd.PlantNo = plant; } dmd.ManufactureDate = i.ManufactureDate; //DateTime d = Convert.ToDateTime(i.ManufactureDate); if (CF.Expirydays == null) { dmd.ExpiryDate = i.ManufactureDate; } else { dmd.ExpiryDate = Convert.ToDateTime(i.ManufactureDate).AddDays((int)CF.Expirydays);// + 10;// (int)CF.Expirydays; //i.ExpiryDate; } dmd.Quantity = (i.Quantity); dmd.EmptyBottleQuantity = (i.EmptyBottleQuantity); dmd.PlasticBoxQuantity = i.PlasticBoxQuantity; dmd.BurstBottleQuantity = (i.BurstBottleQuantity); dmd.BreakageBottleQuantity = (i.BreakageBottleQuantity); //TCases = TCases + i.Quantity; dc.ProductTransactionDetails.Add(dmd); // For Batch StockBatch sb = new StockBatch(); sb.ProductID = i.ProductID; sb.WarehouseID = S.WarehouseID; //sb.BatchNo = batch; if (S.TransactionTypeID != 1) { var t = db.StockBatches.Where(x => x.WarehouseID == S.WarehouseID && x.ProductID == i.ProductID && x.BatchNo == i.BatchNo).FirstOrDefault(); sb.BatchRefNo = t.BatchRefNo; sb.ManufacturDate = t.ManufacturDate; sb.ExpiryDate = t.ExpiryDate; sb.PlantLineNo = t.PlantLineNo; sb.BatchNo = (int)i.BatchNo; // Add sb.PlantNo = t.PlantNo; if (S.TransactionTypeID == 2) { sb.Status = "T"; } if (S.TransactionTypeID == 6) { sb.Status = "D"; } if (S.TransactionTypeID == 10) { sb.Status = "B"; } if (S.TransactionTypeID == 11) { sb.Status = "W"; } } else { sb.ManufacturDate = (DateTime)i.ManufactureDate; sb.ExpiryDate = Convert.ToDateTime(i.ManufactureDate).AddDays((int)CF.Expirydays); //(DateTime)i.ExpiryDate; sb.PlantLineNo = (int)i.LineNoPlant; sb.PlantNo = i.PlantNo; sb.BatchRefNo = i.BatchNo; sb.BatchNo = batch; // Add sb.WarehouseLocationCode = S.StoreLocation; sb.Status = "A"; } sb.IssueQuantity = (decimal)i.Quantity; sb.ReceivedQty = i.Quantity; dc.StockBatches.Add(sb); // Add stock batch detail for transaction history StockBatchDetail sbd = new StockBatchDetail(); sbd.WarehouseID = S.WarehouseID; sbd.ProductID = i.ProductID; sbd.TransactionNo = PIDMax; sbd.Quantity = i.Quantity; sbd.BurstBottleQuantity = i.BurstBottleQuantity; sbd.BreakageBottleQuantity = i.BreakageBottleQuantity; sbd.PlasticBoxQuantity = (int)i.PlasticBoxQuantity; sbd.TransactionDate = DateTime.Today; sbd.CreateBy = User.Identity.Name; sbd.CreateDate = DateTime.Now; if (S.TransactionTypeID == 2) { sbd.BatchNo = i.BatchNo; sbd.TransactionType = "Product Transfer"; } else if (S.TransactionTypeID == 10) { sbd.BatchNo = i.BatchNo; sbd.TransactionType = "Warehouse Burst"; } else if (S.TransactionTypeID == 11) { sbd.BatchNo = i.BatchNo; sbd.TransactionType = "Write Off"; } else if (S.TransactionTypeID == 6) { sbd.BatchNo = i.BatchNo; sbd.TransactionType = "Adjustment"; } else { sbd.TransactionType = "Product Received"; sbd.BatchNo = batch; } dc.StockBatchDetails.Add(sbd); } } //db.SaveChanges(); // dc.SaveChanges(); foreach (var i in S.ProdTrDtl) { var CF = (from x in dc.Products where x.ProductID == i.ProductID select x).FirstOrDefault(); try { if (S.TransactionTypeID == 1) { var productupdate = dc.spProductBalanceUpdate(i.ProductID, S.WarehouseID, (int)i.Quantity, // change i.BurstBottleQuantity, i.BreakageBottleQuantity, (int)i.PlasticBoxQuantity, //change i.EmptyBottleQuantity); } if (S.TransactionTypeID != 1 && status == true) { //Deduct Stock var productupdate = dc.spProductBalanceDecrease(i.ProductID, S.WarehouseID, (int)i.Quantity, //change i.BurstBottleQuantity, i.BreakageBottleQuantity, (int)i.PlasticBoxQuantity, i.EmptyBottleQuantity); } } catch (Exception ex) { throw ex; } } if (status == true) { dc.SaveChanges(); status = true; dc.Dispose(); } } // return new JsonResult { Data = new { status = status, mes = mes } }; } catch (Exception ex) { throw ex; } } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); //, v = v } }; }
public JsonResult SaveCLData(CustomerCreditLimitVM A) { bool status = false; string mes = ""; string v = A.CLNo; int clNo; clNo = (from x in db.CustomerCreditLimits select x).Max(p => p.CLRefNo) + 1; var c = db.Customers.Where(t => t.CustomerID == A.CustomerID).FirstOrDefault(); if (ModelState.IsValid) { try { using (PEPSIEntities dc = new PEPSIEntities()) { CustomerCreditLimit clm = new CustomerCreditLimit(); { clm.CustomerID = A.CustomerID; clm.CLRefNo = clNo; clm.CLNo = A.CLNo; clm.ApproveBy = A.ApproveBy; clm.ApproveDate = A.ApproveDate; clm.ActivateDate = A.ActivateDate; clm.IssueDate = A.IssueDate; clm.ExpiryDate = A.ExpiryDate; clm.CLAmount = A.CLAmount; clm.Status = "A"; clm.CreateBy = User.Identity.Name; clm.CreateDate = System.DateTime.Now; } dc.CustomerCreditLimits.Add(clm); CustomerLedgerDetail cl = new CustomerLedgerDetail(); { cl.WarehouseID = (int)c.WarehouseID; cl.TransactionNo = "CL" + clNo; cl.TransactionTypeID = 17; cl.CustomerID = A.CustomerID; cl.DebitCredit = "C"; cl.CrAmount = A.CLAmount; cl.DrAmount = 0; cl.Narration = "Credit limit amount#" + A.CLAmount + "Against CLRef#" + A.CLNo; cl.RefNumber1 = A.CLNo; cl.TransactionDate = System.DateTime.Today; cl.CreateBy = User.Identity.Name; cl.CreateDate = System.DateTime.Now; } dc.CustomerLedgerDetails.Add(cl); // Update Customer Curr balance var d = db.spCustomerBalanceUpdate(A.CustomerID, "L", A.CLAmount); // Save All Data dc.SaveChanges(); status = true; dc.Dispose(); } } catch (Exception ex) { return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); //throw ex; } } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
public JsonResult SaveCustomer(CustomerVM A) { bool status = false; string mes = ""; int maxCus; maxCus = (from x in db.Customers where x.WarehouseID == A.WarehouseID select x).Max(p => p.CustomerID) + 1; //var c = db.Customers.Where(t => t.CustomerID == A.CustomerID).FirstOrDefault(); int v = maxCus; if (ModelState.IsValid) { try { using (PEPSIEntities dc = new PEPSIEntities()) { Customer c = new Customer(); { c.CustomerID = maxCus; c.CustomerName = A.CustomerName; c.ProprietorsName = A.ProprietorsName; //c.CustomerShortName = A.ProprietorsName; c.ContactPersonsName = A.ProprietorsName; c.WarehouseID = A.WarehouseID; c.CustomerTypeID = A.CustomerTypeID; c.CustomerAddress1 = A.CustomerAddress1; c.CustomerAddress2 = A.CustomerAddress1; c.CustomerPhone = A.CustomerPhone; c.CustomerMobilePhone = A.CustomerPhone; c.CustomerExecutiveID = A.CustomerExecutiveID; c.SalesPersonID = A.SalesPersonID; c.RegionID = A.RegionID; c.ClusterName = A.ClusterName; c.ProductRateID = A.ProductRateID; c.CustomerStartingDate = DateTime.Today; c.VATRegistrationNumber = A.VATRegistrationNumber; c.ActiveStatus = "A"; c.CreateBy = User.Identity.Name; c.CreateDate = System.DateTime.Now; } dc.Customers.Add(c); CustomerLedgerMaster cl = new CustomerLedgerMaster(); { cl.CustomerID = maxCus; cl.CurrentBalance = 0; cl.BankGuranteeAmt = 0; cl.BlockedAmt = 0; cl.BookedAmt = 0; cl.CheckingFlag = "Y"; cl.CreditAmt = 0; cl.OpeningBalance = 0; cl.PaymentAmt = 0; cl.ReplacementPayable = 0; cl.ReturnAmt = 0; cl.TotalSequrityAmt = 0; cl.CustomerStatus = "A"; cl.SequrityReceive = 0; cl.SequrityRefund = 0; cl.TotalSequrityAmt = 0; cl.LoadUnloadCharge = 0; cl.OutstandingAmt = 0; cl.InvoiceAmt = 0; cl.CreateBy = User.Identity.Name; cl.WarehouseID = A.WarehouseID; cl.CreateDate = System.DateTime.Now; } dc.CustomerLedgerMasters.Add(cl); TransportFareSetup tf = new TransportFareSetup(); tf.CustomerID = maxCus; tf.CustomerName = A.CustomerName; tf.WarehouseID = A.WarehouseID; tf.Address = A.CustomerAddress1; tf.IsActive = 1; tf.Rate1 = 3000; tf.Rate2 = 4000; tf.Rate3 = 6000; tf.Date = DateTime.Today; dc.TransportFareSetups.Add(tf); // Save All Data dc.SaveChanges(); status = true; dc.Dispose(); } } catch (Exception ex) { return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); //throw ex; } } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
public ActionResult ReplaceSave(ReplacementMasterVM D) { bool status = false; string mes = ""; var w = (from y in db.UserLogins where y.UserID.ToString() == User.Identity.Name select new { y.WorkStationID }).FirstOrDefault(); var wn = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault(); string s1 = w.WorkStationID.ToString(); string s2 = string.Concat(s1 + "2000000"); int returnNo = Convert.ToInt32(s2); var maxreturnNO = (from n in db.ReplaceMasters where n.WarehouseID == w.WorkStationID select n.ReplaceNo).DefaultIfEmpty(returnNo).Max(); var maxrNo = maxreturnNO + 1; int v = maxrNo; if (ModelState.IsValid) { using (PEPSIEntities dc = new PEPSIEntities()) { ReplaceMaster dbo = new ReplaceMaster(); { dbo.ReplaceNo = maxrNo; dbo.WarehouseID = D.WarehouseID; dbo.CustomerID = D.CustomerID; dbo.TransactionDate = DateTime.Today; dbo.ProcessfromDate = D.ProcessfromDate; dbo.ProcessToDate = D.ProcessToDate; dbo.ReferenceNo = D.ReferenceNo; dbo.TotReturnAmt = D.TotReturnAmt; dbo.TotSalesAmt = D.TotSalesAmt; dbo.TotPayableAmt = D.TotPayableAmt; dbo.CalculationID = D.CalculationID; dbo.Remarks = D.Remarks; dbo.Status = "P"; dbo.CreateDate = DateTime.Now; dbo.CreateBy = User.Identity.Name; }; dc.ReplaceMasters.Add(dbo); CustomerLedgerDetail cld = new CustomerLedgerDetail(); { cld.WarehouseID = D.WarehouseID; cld.CustomerID = D.CustomerID; cld.TransactionNo = "PAY" + maxrNo.ToString(); cld.TransactionTypeID = 12; cld.RefNumber1 = D.ReferenceNo.ToString(); cld.TransactionDate = DateTime.Today; cld.CrAmount = D.TotPayableAmt; cld.DrAmount = 0; cld.DebitCredit = "C"; cld.Narration = "ReplacePayable Creation Amount#" + D.TotPayableAmt + " to Customer" + cld.CustomerID; cld.CreateBy = User.Identity.Name; cld.CreateDate = System.DateTime.Now; } dc.CustomerLedgerDetails.Add(cld); foreach (var i in D.replacedetail) { ReplaceDetail obd = new ReplaceDetail(); obd.WarehouseID = D.WarehouseID; obd.ReplacementNo = maxrNo; obd.ReturnID = i.ReturnID; obd.ProductID = i.ProductID; obd.AlternateQuantity = i.AlternateQuantity; obd.PlasticBoxQuantity = i.PlasticBoxQuantity; obd.SubTotAmount = i.SubTotAmount; dc.ReplaceDetails.Add(obd); var updatereturn = db.spRelaceDataUpdate(i.ReturnID, D.WarehouseID, "", D.CustomerID, "R", User.Identity.Name, DateTime.Now); } var custReplacePayable = db.spCustomerBalanceUpdate(D.CustomerID, "T", D.TotPayableAmt); dc.SaveChanges(); status = true; dc.Dispose(); } ModelState.Clear(); } else { status = false; } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }