public bool DeleteIncome(tblIncomeSource income) { var orgSec = context.tblIncomeSources.Where(ss => ss.ID == income.ID).FirstOrDefault(); context.tblIncomeSources.Remove(orgSec); return(context.SaveChanges() > 0); }
public bool SaveIncome(tblIncomeSource income) { long maxId = context.tblIncomeSources.Select(cc => cc.ID).DefaultIfEmpty(0).Max(); income.ID = ++maxId; context.tblIncomeSources.Add(income); return(context.SaveChanges() > 0); }
public bool EditIncome(tblIncomeSource income) { var orgSec = context.tblIncomeSources.Where(ss => ss.ID == income.ID).FirstOrDefault(); orgSec.amount = income.amount; orgSec.date = income.date; orgSec.srcDescId = income.srcDescId; orgSec.sourceName = income.sourceName; orgSec.description = income.description; return(context.SaveChanges() > 0); }
public JsonResult DeleteIncome([System.Web.Http.FromBody] tblIncomeSource income) { if (Session["role"] == null) { Session["userId"] = null; Session["role"] = null; return(Json(false, JsonRequestBehavior.AllowGet)); } else if (Session["role"].ToString() == "Super Admin") { return(Json(incomeRepository.DeleteIncome(income), JsonRequestBehavior.AllowGet)); } else { Session["userId"] = null; Session["role"] = null; return(Json(false, JsonRequestBehavior.AllowGet)); } }
//[Authorize(Roles = "Admin,Super Admin")] public JsonResult Save(tblIncomeSource objDueIncomeSource) { if (Session["role"] == null) { Session["userId"] = null; Session["role"] = null; return(Json(0, JsonRequestBehavior.AllowGet)); } else if (Session["role"].ToString() == "Admin" || Session["role"].ToString() == "Super Admin") { return(Json(duePaymentRepository.Save(objDueIncomeSource), JsonRequestBehavior.AllowGet)); } else { Session["userId"] = null; Session["role"] = null; return(Json(0, JsonRequestBehavior.AllowGet)); } }
public JsonResult SaveIncome(tblIncomeSource income) { if (Session["role"] == null) { Session["userId"] = null; Session["role"] = null; return(Json(false, JsonRequestBehavior.AllowGet)); } else if (Session["role"].ToString() == "Admin" || Session["role"].ToString() == "Super Admin") { income.date = DateTime.ParseExact(income.date.ToString("dd-MM-yyyy"), "dd-MM-yyyy", CultureInfo.InvariantCulture); return(Json(incomeRepository.SaveIncome(income), JsonRequestBehavior.AllowGet)); } else { Session["userId"] = null; Session["role"] = null; return(Json(false, JsonRequestBehavior.AllowGet)); } }
public List <tblIncomeSource> GetDuePaid(DateTime date) { var results = from paid in context.tblIncomeSources join pr in context.tblParties on paid.partyId equals pr.ID where paid.isDue == 1 && paid.date == date select new { pr.name, paid.amount }; List <tblIncomeSource> objList = new List <tblIncomeSource>(); foreach (var item in results) { tblIncomeSource objIncomeSource = new tblIncomeSource(); objIncomeSource.partyName = item.name; objIncomeSource.amount = item.amount; objList.Add(objIncomeSource); } return(objList); }
public long Save(tblIncomeSource objDueIncomeSource) { try { long maxId = context.tblIncomeSources.Select(ss => ss.ID).DefaultIfEmpty(0).Max(); long maxPayId = context.tblPayables.Select(pp => pp.ID).DefaultIfEmpty(0).Max(); objDueIncomeSource.ID = ++maxId; if (objDueIncomeSource.description != null) { objDueIncomeSource.description = objDueIncomeSource.sourceName + " বকেয়া বাবদ আয়" + "," + objDueIncomeSource.description; } else { objDueIncomeSource.description = objDueIncomeSource.sourceName + " বকেয়া বাবদ আয়"; } objDueIncomeSource.isDue = 1; context.tblIncomeSources.Add(objDueIncomeSource); tblPayable payableChange = context.tblPayables.Where(ss => ss.partyId == objDueIncomeSource.partyId && ss.isActive == 1).FirstOrDefault(); payableChange.isActive = 0; tblPayable newPayable = new tblPayable(); newPayable.ID = ++maxPayId; newPayable.isActive = 1; newPayable.amount = (-1) * objDueIncomeSource.amount; newPayable.openingBalance = payableChange.openingBalance - objDueIncomeSource.amount; newPayable.date = objDueIncomeSource.date; newPayable.partyId = objDueIncomeSource.partyId.Value; newPayable.incSrcId = objDueIncomeSource.ID; context.tblPayables.Add(newPayable); return(context.SaveChanges() > 0 ? objDueIncomeSource.ID : 0); } catch (Exception exc) { throw new Exception(exc.Message); } }
public tblSell SaveHusk(tblSell huskInfo) { try { long maxId = context.tblSells.Select(p => p.ID).DefaultIfEmpty(0).Max(); huskInfo.ID = ++maxId; if (huskInfo.paidAmount > 0) { #region income source long incId = context.tblIncomeSources.Select(i => i.ID).DefaultIfEmpty(0).Max(); tblIncomeSource incomeObj = new tblIncomeSource(); incomeObj.ID = ++incId; incomeObj.partyId = huskInfo.partyId; incomeObj.sourceName = "তুষ"; // shoul be come from commonelement incomeObj.srcDescId = 21; // should be come from commonelemnt incomeObj.description = "তুষ বিক্রয় বাবদ আয়"; incomeObj.amount = huskInfo.paidAmount; incomeObj.date = huskInfo.date; context.tblIncomeSources.Add(incomeObj); #endregion huskInfo.incSrcId = incomeObj.ID; } #region save payable double?totalPr = 0; if (huskInfo.transportCostInclude) { totalPr = huskInfo.noOfBag * huskInfo.unitPrice * huskInfo.quantity + huskInfo.transportCost; } else { totalPr = huskInfo.noOfBag * huskInfo.unitPrice * huskInfo.quantity; if (huskInfo.transportCost > 0) { #region costing source tblCostingSource objTblCostingSource = new tblCostingSource(); long maxCost = context.tblCostingSources.Select(i => i.ID).DefaultIfEmpty(0).Max(); objTblCostingSource.ID = ++maxCost; objTblCostingSource.partyId = huskInfo.partyId; objTblCostingSource.amount = Convert.ToDouble(huskInfo.transportCost); objTblCostingSource.sourceName = "তুষ"; objTblCostingSource.srcDescription = "তুষ বিক্রয়ের পরিবহন খরচ"; objTblCostingSource.srcDescId = 21; objTblCostingSource.date = huskInfo.date; objTblCostingSource.sellId = huskInfo.ID; context.tblCostingSources.Add(objTblCostingSource); #endregion } } if (totalPr > 0) { long maxpayId = context.tblPayables.Select(i => i.ID).DefaultIfEmpty(0).Max(); tblPayable objTblPayable = new tblPayable(); objTblPayable.ID = ++maxpayId; objTblPayable.partyId = huskInfo.partyId; objTblPayable.date = huskInfo.date; objTblPayable.sellId = huskInfo.ID; var lastPayable = context.tblPayables.Where(p => p.partyId == huskInfo.partyId && p.isActive == 1).FirstOrDefault(); var loan = totalPr - huskInfo.paidAmount; objTblPayable.amount = loan; if (lastPayable != null) { lastPayable.isActive = 0; objTblPayable.openingBalance = objTblPayable.amount + lastPayable.openingBalance; } else { objTblPayable.openingBalance = objTblPayable.amount; } objTblPayable.isActive = 1; context.tblPayables.Add(objTblPayable); } #endregion context.tblSells.Add(huskInfo); #region substract husk from stock STK_Balance huskStk = context.STK_Balance.Where(ss => ss.stockId == huskInfo.stockId && ss.productId == huskInfo.productId).FirstOrDefault();//&& ss.sackWeight==huskInfo.quantity if (huskStk == null) { var maxStkBalId = context.STK_Balance.Select(p => p.ID).DefaultIfEmpty(0).Max(); STK_Balance stkBal = new STK_Balance(); stkBal.ID = ++maxStkBalId; stkBal.productId = huskInfo.productId; stkBal.stockId = huskInfo.stockId; stkBal.sackQuantity = -huskInfo.noOfBag; context.STK_Balance.Add(stkBal); } else { huskStk.sackQuantity -= huskInfo.noOfBag; } #endregion #region stock transaction long maxprdstkId = context.STK_Transaction.Select(p => p.ID).DefaultIfEmpty(0).Max(); //long laststkId = context.STK_Transaction.Where(s => s.stockId == huskInfo.stockId && s.prodId == huskInfo.productId).Select(l => l.ID).DefaultIfEmpty(0).Max(); STK_Transaction objStkTrans = new STK_Transaction(); objStkTrans.ID = maxprdstkId + 1; objStkTrans.date = huskInfo.date; objStkTrans.rcvQty = 0; objStkTrans.sellQty = huskInfo.noOfBag; objStkTrans.stockId = huskInfo.stockId.Value; objStkTrans.prodId = huskInfo.productId; objStkTrans.operation = 1; objStkTrans.sellId = huskInfo.ID; if (huskStk == null) { objStkTrans.openingStock = -huskInfo.noOfBag; } else { objStkTrans.openingStock = huskStk.sackQuantity.Value; } //var lastTrans = context.STK_Transaction.Where(ll => ll.ID == laststkId).FirstOrDefault(); //objStkTrans.openingStock = lastTrans == null ? 0 - huskInfo.noOfBag : lastTrans.openingStock - huskInfo.noOfBag; context.STK_Transaction.Add(objStkTrans); #endregion tblSell newSell = new tblSell(); newSell.ID = huskInfo.ID; newSell.incSrcId = huskInfo.incSrcId; return(context.SaveChanges() > 0 ? newSell : null); } catch (Exception exc) { throw new Exception(exc.Message); } }
public tblSell EditHuskInfo(tblSell huskInfo) { try { // into payable tabel column amount is 'how many amount is added with opening balance, not paidamount' var orgHuskSell = context.tblSells.Where(ss => ss.ID == huskInfo.ID).FirstOrDefault(); #region edit husk stock STK_Balance orgStk = context.STK_Balance.Where(ss => ss.stockId == orgHuskSell.stockId && ss.productId == orgHuskSell.productId).FirstOrDefault();// && ss.sackWeight == particleInfo.quantity orgStk.sackQuantity += orgHuskSell.noOfBag; STK_Balance newStk = context.STK_Balance.Where(ss => ss.stockId == huskInfo.stockId && ss.productId == huskInfo.productId).FirstOrDefault();// && ss.sackWeight == particleInfo.quantity if (newStk == null) { STK_Balance stkBal = new STK_Balance(); var maxStkBal = context.STK_Balance.Select(p => p.ID).DefaultIfEmpty(0).Max(); stkBal.ID = ++maxStkBal; stkBal.productId = huskInfo.productId; stkBal.stockId = huskInfo.stockId; stkBal.sackQuantity = -huskInfo.noOfBag; context.STK_Balance.Add(stkBal); } else { newStk.sackQuantity -= huskInfo.noOfBag; } #endregion double?totalPr = 0; if (huskInfo.transportCostInclude) { totalPr = huskInfo.noOfBag * huskInfo.unitPrice * huskInfo.quantity + huskInfo.transportCost; } else { totalPr = huskInfo.noOfBag * huskInfo.unitPrice * huskInfo.quantity; } #region costing source tblCostingSource objCostingSource = context.tblCostingSources.Where(cc => cc.sellId == huskInfo.ID).FirstOrDefault(); if (huskInfo.transportCostInclude && objCostingSource != null) { context.tblCostingSources.Remove(objCostingSource); } else if (!huskInfo.transportCostInclude && objCostingSource == null) { tblCostingSource newCost = new tblCostingSource(); long maxCost = context.tblCostingSources.Select(i => i.ID).DefaultIfEmpty(0).Max(); newCost.ID = ++maxCost; newCost.amount = Convert.ToDouble(huskInfo.transportCost); newCost.partyId = huskInfo.partyId; newCost.sourceName = "তুষ"; newCost.srcDescription = "তুষ বিক্রয়ে পরিবহন খরচ"; newCost.srcDescId = 21; newCost.date = huskInfo.date; newCost.sellId = huskInfo.ID; context.tblCostingSources.Add(newCost); } else if (!huskInfo.transportCostInclude && objCostingSource != null) { objCostingSource.amount = Convert.ToDouble(huskInfo.transportCost); objCostingSource.date = huskInfo.date; } #endregion #region edit or insert income source var orgIncomeSrc = context.tblIncomeSources.Where(ii => ii.ID == huskInfo.incSrcId).FirstOrDefault(); if (orgIncomeSrc != null) { orgIncomeSrc.amount = huskInfo.paidAmount; orgIncomeSrc.date = huskInfo.date; orgIncomeSrc.partyId = huskInfo.partyId; } else if (orgIncomeSrc == null && huskInfo.paidAmount > 0) { long incId = context.tblIncomeSources.Select(i => i.ID).DefaultIfEmpty(0).Max(); tblIncomeSource incomeObj = new tblIncomeSource(); incomeObj.ID = ++incId; incomeObj.sourceName = "তুষ"; // shoul be come from commonelement incomeObj.srcDescId = 21; // should be come from commonelemnt incomeObj.description = "তুষ বিক্রয় বাবদ আয়"; incomeObj.amount = huskInfo.paidAmount; incomeObj.date = huskInfo.date; incomeObj.partyId = huskInfo.partyId; context.tblIncomeSources.Add(incomeObj); orgHuskSell.incSrcId = incomeObj.ID; } #endregion #region edit payable var orgPayable = context.tblPayables.Where(ss => ss.sellId == huskInfo.ID).FirstOrDefault(); //long lastpayId = context.tblPayables.Where(s => s.partyId == particleInfo.partyId).Select(l => l.ID).DefaultIfEmpty(0).Max(); //var lastPayable = context.tblPayables.Where(pp => pp.ID == lastpayId).FirstOrDefault(); if (orgPayable != null) { double?difference = totalPr - huskInfo.paidAmount - orgPayable.amount; orgPayable.openingBalance = orgPayable.openingBalance + difference; orgPayable.amount = totalPr - huskInfo.paidAmount; var nextPayables = context.tblPayables.Where(pp => pp.partyId == huskInfo.partyId && pp.ID > orgPayable.ID); foreach (var item in nextPayables) { item.openingBalance = item.openingBalance + difference; } } else if (orgPayable == null && totalPr > 0) { long maxpayId = context.tblPayables.Select(i => i.ID).DefaultIfEmpty(0).Max(); tblPayable objTblPayable = new tblPayable(); objTblPayable.ID = ++maxpayId; objTblPayable.partyId = huskInfo.partyId; objTblPayable.date = huskInfo.date; objTblPayable.sellId = huskInfo.ID; var lastPayable = context.tblPayables.Where(p => p.partyId == huskInfo.partyId && p.isActive == 1).FirstOrDefault(); var loan = totalPr - huskInfo.paidAmount; objTblPayable.amount = loan; if (lastPayable != null) { lastPayable.isActive = 0; objTblPayable.openingBalance = objTblPayable.amount + lastPayable.openingBalance; } else { objTblPayable.openingBalance = objTblPayable.amount; } objTblPayable.isActive = 1; context.tblPayables.Add(objTblPayable); } #endregion #region edit stock transaction var orgStkTrans = context.STK_Transaction.Where(ss => ss.sellId == orgHuskSell.ID).FirstOrDefault(); double diff = orgStkTrans.sellQty.Value - huskInfo.noOfBag; orgStkTrans.openingStock = orgStkTrans.openingStock + orgStkTrans.sellQty.Value; orgStkTrans.date = huskInfo.date; orgStkTrans.rcvQty = 0; orgStkTrans.sellQty = huskInfo.noOfBag; orgStkTrans.stockId = huskInfo.stockId.Value; orgStkTrans.prodId = huskInfo.productId; orgStkTrans.operation = 2; orgStkTrans.openingStock = orgStkTrans.openingStock - huskInfo.noOfBag; var nextStkTrans = context.STK_Transaction.Where(ss => ss.ID > orgStkTrans.ID && ss.prodId == orgStkTrans.prodId && ss.stockId == orgStkTrans.stockId); foreach (var item in nextStkTrans) { item.openingStock += diff; } #endregion #region edit tblsell orgHuskSell.productId = huskInfo.productId; orgHuskSell.productName = huskInfo.productName; orgHuskSell.noOfBag = huskInfo.noOfBag; orgHuskSell.paidAmount = huskInfo.paidAmount; orgHuskSell.partyId = huskInfo.partyId; orgHuskSell.partyName = huskInfo.partyName; orgHuskSell.quantity = huskInfo.quantity; orgHuskSell.stockId = huskInfo.stockId; orgHuskSell.stockName = huskInfo.stockName; orgHuskSell.unit = huskInfo.unit; orgHuskSell.unitPrice = huskInfo.unitPrice; orgHuskSell.transportCost = huskInfo.transportCost; #endregion tblSell newSell = new tblSell(); newSell.ID = huskInfo.ID; newSell.incSrcId = huskInfo.incSrcId; return(context.SaveChanges() > 0 ? newSell : null); } catch (Exception ex) { throw new Exception(ex.Message); } }
public JsonResult Save(tblIncomeSource objDueIncomeSource) { //return Json(duePaymentRepository.Save(objDueIncomeSource), JsonRequestBehavior.AllowGet); return(null); }