public long Save(tblCostingSource objCostSource) { try { //int maxId = context.tblCostingSources.Select(ss => ss.ID).DefaultIfEmpty(0).Max(); //long maxDueId = context.tblDues.Select(pp => pp.ID).DefaultIfEmpty(0).Max(); //objCostSource.ID = ++maxId; //objCostSource.description = objCostSource.sourceName + " বকেয়া বাবদ আয়"; //objCostSource.isDue = 1; //context.tblCostingSources.Add(objCostSource); //tblDue payableChange = // context.tblDues.Where(ss => ss.partyId == objCostSource.partyId && ss.isActive==1).FirstOrDefault(); //payableChange.isActive = 0; //tblDue newdue = new tblDue(); //newdue.ID = ++maxDueId; //newdue.isActive = 1; //newdue.amount = (-1)*objCostSource.amount; //newdue.openingBalance = payableChange.openingBalance - objCostSource.amount; //newdue.date = objCostSource.date; //newdue.partyId = objCostSource.partyId.Value; //newdue.incSrcId = objCostSource.ID; //context.tblDues.Add(newdue); return(context.SaveChanges() > 0 ? objCostSource.ID : 0); } catch (Exception exc) { throw new Exception(exc.Message); } }
public bool DeleteConsumption(tblCostingSource consumption) { var orgSec = context.tblCostingSources.Where(ss => ss.ID == consumption.ID).FirstOrDefault(); context.tblCostingSources.Remove(orgSec); return(context.SaveChanges() > 0); }
//[Authorize(Roles = "Admin,Super Admin")] public JsonResult Save(tblCostingSource objLoanCostingSource) { if (Session["role"] == null) { Session["userId"] = null; Session["role"] = null; objLoanCostingSource.date = DateTime.ParseExact(objLoanCostingSource.date.ToString("dd-MM-yyyy"), "dd-MM-yyyy", CultureInfo.InvariantCulture); return Json(0, JsonRequestBehavior.AllowGet); } else if (Session["role"].ToString() == "Admin" || Session["role"].ToString() == "Super Admin") { objLoanCostingSource.date = DateTime.ParseExact(objLoanCostingSource.date.ToString("dd-MM-yyyy"), "dd-MM-yyyy", CultureInfo.InvariantCulture); return Json(loanPaymentRepository.Save(objLoanCostingSource), JsonRequestBehavior.AllowGet); } else { Session["userId"] = null; Session["role"] = null; return Json(0, JsonRequestBehavior.AllowGet); } }
public bool SaveConsumption(tblCostingSource consumption) { long maxId = context.tblCostingSources.Select(cc => cc.ID).DefaultIfEmpty(0).Max(); consumption.ID = ++maxId; context.tblCostingSources.Add(consumption); return(context.SaveChanges() > 0); }
public bool EditConsumption(tblCostingSource consumption) { var orgSec = context.tblCostingSources.Where(ss => ss.ID == consumption.ID).FirstOrDefault(); orgSec.amount = consumption.amount; orgSec.date = consumption.date; orgSec.srcDescId = consumption.srcDescId; orgSec.sourceName = consumption.sourceName; orgSec.srcDescription = consumption.srcDescription; return(context.SaveChanges() > 0); }
public long Save(tblCostingSource objLoanCostingSource) { try { long maxId = context.tblCostingSources.Select(ss => ss.ID).DefaultIfEmpty(0).Max(); long maxDueId = context.tblDues.Select(pp => pp.ID).DefaultIfEmpty(0).Max(); objLoanCostingSource.ID = ++maxId; objLoanCostingSource.srcDescription = "ধান ক্রয় বাবদ ব্যায় পরিশোধ"; objLoanCostingSource.sourceName = "ধান"; objLoanCostingSource.srcDescId = 23; objLoanCostingSource.isDue = 1; context.tblCostingSources.Add(objLoanCostingSource); tblDue latestDue = context.tblDues.Where(ss => ss.partyId == objLoanCostingSource.partyId && ss.date <= objLoanCostingSource.date).OrderByDescending(ss => ss.date).ThenByDescending(ss => ss.ID).FirstOrDefault(); List <tblDue> nextDues = context.tblDues.Where(dd => dd.partyId == objLoanCostingSource.partyId && dd.date > objLoanCostingSource.date).ToList(); //dueChange.isActive = 0; tblDue newDue = new tblDue(); newDue.ID = ++maxDueId; //newDue.isActive = 1; newDue.costingId = objLoanCostingSource.ID; newDue.amount = (-1) * objLoanCostingSource.amount; if (latestDue == null) { newDue.openingBalance = newDue.amount; } else { newDue.openingBalance = latestDue.openingBalance + newDue.amount; } newDue.date = objLoanCostingSource.date; newDue.partyId = objLoanCostingSource.partyId.Value; if (nextDues != null) { foreach (var item in nextDues) { item.openingBalance += newDue.amount; } } context.tblDues.Add(newDue); return(context.SaveChanges() > 0 ? objLoanCostingSource.ID : 0); } catch (Exception exc) { throw new Exception(exc.Message); } }
public tblCostingSource Save(tblCostingSource withdraw) { try { long maxId = context.tblCostingSources.Select(p => p.ID).DefaultIfEmpty(0).Max(); withdraw.ID = ++maxId; context.tblCostingSources.Add(withdraw); return(context.SaveChanges() > 0 ? withdraw : null); } catch (Exception exc) { throw new Exception(exc.Message); } }
public JsonResult SaveConsumption(tblCostingSource consumption) { 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") { return(Json(consumptionRepository.SaveConsumption(consumption), JsonRequestBehavior.AllowGet)); } else { Session["userId"] = null; Session["role"] = null; return(Json(false, JsonRequestBehavior.AllowGet)); } }
public JsonResult EditConsumption([System.Web.Http.FromBody] tblCostingSource consumption) { if (Session["role"] == null) { Session["userId"] = null; Session["role"] = null; return(Json(false, JsonRequestBehavior.AllowGet)); } else if (Session["role"].ToString() == "Super Admin") { return(Json(consumptionRepository.EditConsumption(consumption), JsonRequestBehavior.AllowGet)); } else { Session["userId"] = null; Session["role"] = null; return(Json(false, JsonRequestBehavior.AllowGet)); } }
public List <tblCostingSource> GetLoanPaid(DateTime date) { var results = from loan in context.tblCostingSources join pr in context.tblParties on loan.partyId equals pr.ID where loan.isDue == 1 && loan.date == date select new { pr.name, loan.amount }; List <tblCostingSource> objList = new List <tblCostingSource>(); foreach (var item in results) { tblCostingSource objCostingSource = new tblCostingSource(); objCostingSource.partyName = item.name; objCostingSource.amount = item.amount; objList.Add(objCostingSource); } return(objList); }
// just try to avoid opening values public long SavePaddy(tblBuy paddyInfo) { try { long maxId = context.tblBuys.Select(p => p.ID).DefaultIfEmpty(0).Max(); paddyInfo.ID = ++maxId; if (paddyInfo.amount > 0 || paddyInfo.labourCostPerBag > 0 || paddyInfo.transportCost > 0) { #region costing source long cstId = context.tblCostingSources.Select(i => i.ID).DefaultIfEmpty(0).Max(); tblCostingSource costObj = new tblCostingSource(); costObj.ID = ++cstId; costObj.sourceName = "ধান"; // shoul be come from commonelement costObj.srcDescId = 23; // should be come from commonelemnt costObj.srcDescription = "ধান ক্রয় বাবদ খরচ"; // costObj.amount = paddyInfo.amount + labCost* paddyInfo.noOfBag+ paddyInfo.transportCost ?? 0; costObj.labourCostPerBag = paddyInfo.labourCostPerBag ?? 0; if (paddyInfo.transportCostInclude) { costObj.transportCost = paddyInfo.transportCost ?? 0; } else { costObj.transportCost = 0; } costObj.amount = paddyInfo.amount; costObj.date = paddyInfo.date; costObj.partyId = paddyInfo.partyId; costObj.buyId = paddyInfo.ID; context.tblCostingSources.Add(costObj); #endregion } #region save dues long maxdueId = context.tblDues.Select(i => i.ID).DefaultIfEmpty(0).Max(); tblDue objDue = new tblDue(); objDue.ID = ++maxdueId; objDue.partyId = paddyInfo.partyId; objDue.buyId = paddyInfo.ID; objDue.date = paddyInfo.date; //tblDue dueItem = context.tblDues.Where(bb => bb.date <= paddyInfo.date && bb.partyId == paddyInfo.partyId).OrderByDescending(oo => oo.date).ThenByDescending(ii => ii.ID).FirstOrDefault(); //List<tblDue> dueItems = context.tblDues.Where(bb => bb.date > paddyInfo.date && bb.partyId == paddyInfo.partyId).ToList(); double?totalPr = paddyInfo.price * paddyInfo.quantityPerBag / 40 * paddyInfo.noOfBag; var due = totalPr - paddyInfo.amount; objDue.amount = due; //if (dueItem == null) //{ // objDue.openingBalance = objDue.amount; //} //else //{ // objDue.openingBalance = dueItem.openingBalance + objDue.amount; //} //if (dueItems != null) //{ // foreach (var item in dueItems) // { // item.openingBalance += objDue.amount; // } //} context.tblDues.Add(objDue); #endregion context.tblBuys.Add(paddyInfo); #region stock balance STK_Balance padStk = context.STK_Balance.Where(ss => ss.stockId == paddyInfo.stockId && ss.productId == paddyInfo.productId && ss.sackWeight == paddyInfo.quantityPerBag).FirstOrDefault(); if (padStk != null) { padStk.sackQuantity += paddyInfo.noOfBag; } else { STK_Balance newStk = new STK_Balance(); int maxbalId = context.STK_Balance.Select(p => p.ID).DefaultIfEmpty(0).Max(); newStk.ID = ++maxbalId; newStk.productId = paddyInfo.productId; newStk.stockId = paddyInfo.stockId; newStk.sackWeight = paddyInfo.quantityPerBag; newStk.sackQuantity = paddyInfo.noOfBag; context.STK_Balance.Add(newStk); } #endregion #region stock transaction long maxprdstkId = context.PaddyTransactions.Select(p => p.ID).DefaultIfEmpty(0).Max(); long laststkId = context.PaddyTransactions.Where(s => s.stockId == paddyInfo.stockId && s.prodId == paddyInfo.productId && s.bagWeight == paddyInfo.quantityPerBag).Select(l => l.ID).DefaultIfEmpty(0).Max(); var lastTrans = context.PaddyTransactions.Where(ll => ll.ID == laststkId).FirstOrDefault(); PaddyTransaction objStkTrans = new PaddyTransaction(); objStkTrans.ID = maxprdstkId + 1; objStkTrans.date = paddyInfo.date; objStkTrans.rcvQty = paddyInfo.noOfBag; objStkTrans.releaseQty = 0; objStkTrans.stockId = paddyInfo.stockId; objStkTrans.prodId = paddyInfo.productId; objStkTrans.buyId = paddyInfo.ID; objStkTrans.bagWeight = paddyInfo.quantityPerBag; objStkTrans.openingStock = lastTrans == null ? paddyInfo.noOfBag : lastTrans.openingStock + paddyInfo.noOfBag; context.PaddyTransactions.Add(objStkTrans); #endregion #region BagTransactions long maxBagId = context.BagTransactions.Select(b => b.ID).DefaultIfEmpty(0).Max(); if (paddyInfo.bagPrice > 0) { BagTransaction prevItem = context.BagTransactions.Where(bb => bb.date <= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice > 0 || bb.sentPrice > 0)).OrderByDescending(oo => oo.date).ThenByDescending(ii => ii.ID).FirstOrDefault(); List <BagTransaction> nextItems = context.BagTransactions.Where(bb => bb.date > paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice > 0 || bb.sentPrice > 0)).ToList(); //int bagCnt = paddyInfo.noOfBag > 0 ? paddyInfo.noOfBag : 1; double?curPriceDue = prevItem == null ? paddyInfo.noOfBag * paddyInfo.bagPrice : prevItem.priceDues + paddyInfo.noOfBag * paddyInfo.bagPrice; BagTransaction bagTrans = new BagTransaction(); bagTrans.ID = ++maxBagId; bagTrans.partyId = paddyInfo.partyId; bagTrans.rcvId = paddyInfo.ID; bagTrans.comRcvBag = paddyInfo.noOfBag; bagTrans.rcvPrice = paddyInfo.bagPrice; bagTrans.comSentBag = 0; bagTrans.sentPrice = 0; bagTrans.priceDues = curPriceDue; bagTrans.bagDues = 0; bagTrans.date = paddyInfo.date; context.BagTransactions.Add(bagTrans); if (nextItems != null) { foreach (var item in nextItems) { item.priceDues += curPriceDue; } } } else { BagTransaction prevItem = context.BagTransactions.Where(bb => bb.date <= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice == 0 || bb.rcvPrice == null) && (bb.sentPrice == 0 || bb.sentPrice == null)).OrderByDescending(oo => oo.date).ThenByDescending(ii => ii.ID).FirstOrDefault(); List <BagTransaction> nextItems = context.BagTransactions.Where(bb => bb.date > paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice == 0 || bb.rcvPrice == null) && (bb.sentPrice == 0 || bb.sentPrice == null)).ToList(); int?curBagDue = prevItem == null ? paddyInfo.noOfBag : prevItem.bagDues + paddyInfo.noOfBag; BagTransaction bagTrans = new BagTransaction(); bagTrans.ID = ++maxBagId; bagTrans.partyId = paddyInfo.partyId; bagTrans.rcvId = paddyInfo.ID; bagTrans.comRcvBag = paddyInfo.noOfBag; bagTrans.rcvPrice = 0; bagTrans.comSentBag = 0; bagTrans.sentPrice = 0; bagTrans.priceDues = 0; bagTrans.bagDues = curBagDue; bagTrans.date = paddyInfo.date; context.BagTransactions.Add(bagTrans); if (nextItems != null) { foreach (var item in nextItems) { item.bagDues += curBagDue; } } } #endregion return(context.SaveChanges() > 0 ? paddyInfo.ID : 0); } catch (Exception exc) { throw new Exception(exc.Message); } }
public long EditPaddyInfo(tblBuy paddyInfo) { var orgPaddy = context.tblBuys.Where(ss => ss.ID == paddyInfo.ID).FirstOrDefault(); #region edit paddy stock STK_Balance padStk = context.STK_Balance.Where(ss => ss.stockId == orgPaddy.stockId && ss.productId == orgPaddy.productId && ss.sackWeight == orgPaddy.quantityPerBag).FirstOrDefault(); if (padStk != null) { padStk.sackQuantity -= orgPaddy.noOfBag; } STK_Balance curStk = context.STK_Balance.Where(ss => ss.stockId == paddyInfo.stockId && ss.productId == paddyInfo.productId && ss.sackWeight == paddyInfo.quantityPerBag).FirstOrDefault(); if (curStk != null) { curStk.sackQuantity += paddyInfo.noOfBag; } else { STK_Balance newStk = new STK_Balance(); int maxbalId = context.STK_Balance.Select(p => p.ID).DefaultIfEmpty(0).Max(); newStk.ID = ++maxbalId; newStk.productId = paddyInfo.productId; newStk.stockId = paddyInfo.stockId; newStk.sackWeight = paddyInfo.quantityPerBag; newStk.sackQuantity = paddyInfo.noOfBag; context.STK_Balance.Add(newStk); } #endregion #region edit costing source var orgCostSrc = context.tblCostingSources.Where(ii => ii.buyId == paddyInfo.ID).FirstOrDefault(); if (orgCostSrc != null) { orgCostSrc.amount = paddyInfo.amount; orgCostSrc.date = paddyInfo.date; if (paddyInfo.transportCostInclude) { orgCostSrc.transportCost = paddyInfo.transportCost; } else { orgCostSrc.transportCost = 0; } orgCostSrc.labourCostPerBag = paddyInfo.labourCostPerBag; orgCostSrc.partyId = paddyInfo.partyId; } else if (orgCostSrc == null && (paddyInfo.amount > 0 || paddyInfo.transportCost > 0)) { long cstId = context.tblCostingSources.Select(i => i.ID).DefaultIfEmpty(0).Max(); tblCostingSource cstObj = new tblCostingSource(); cstObj.ID = ++cstId; cstObj.sourceName = "ধান"; // shoul be come from commonelement cstObj.srcDescId = 23; // should be come from commonelemnt cstObj.srcDescription = "ধান ক্রয় বাবদ খরচ"; cstObj.amount = paddyInfo.amount; cstObj.date = paddyInfo.date; cstObj.buyId = paddyInfo.ID; cstObj.partyId = paddyInfo.partyId; cstObj.labourCostPerBag = paddyInfo.labourCostPerBag ?? 0; if (paddyInfo.transportCostInclude) { cstObj.transportCost = paddyInfo.transportCost ?? 0; } else { cstObj.transportCost = 0; } context.tblCostingSources.Add(cstObj); } #endregion #region edit stock transaction var orgStkTrans = context.PaddyTransactions.Where(ss => ss.buyId == orgPaddy.ID).FirstOrDefault(); if (orgStkTrans.stockId == paddyInfo.stockId) { double diff = orgStkTrans.rcvQty.Value - paddyInfo.noOfBag; orgStkTrans.openingStock = orgStkTrans.openingStock - orgStkTrans.rcvQty.Value; orgStkTrans.date = paddyInfo.date; orgStkTrans.rcvQty = paddyInfo.noOfBag; orgStkTrans.releaseQty = 0; orgStkTrans.stockId = paddyInfo.stockId; orgStkTrans.prodId = paddyInfo.productId; orgStkTrans.openingStock = orgStkTrans.openingStock + paddyInfo.noOfBag; // here may be change for different stock var nextStkTrans = context.PaddyTransactions.Where(ss => ss.ID > orgStkTrans.ID && ss.prodId == orgStkTrans.prodId && ss.stockId == orgStkTrans.stockId && ss.bagWeight == orgStkTrans.bagWeight);// && ss.date>=orgStkTrans.date foreach (var item in nextStkTrans) { item.openingStock -= diff; } } else { var nextStkTrans = context.PaddyTransactions.Where(ss => ss.ID > orgStkTrans.ID && ss.prodId == orgStkTrans.prodId && ss.stockId == orgStkTrans.stockId && ss.bagWeight == orgStkTrans.bagWeight);// && ss.date >= orgStkTrans.date foreach (var item in nextStkTrans) { item.openingStock -= orgStkTrans.rcvQty.Value; } context.PaddyTransactions.Remove(orgStkTrans); long maxprdstkId = context.PaddyTransactions.Select(p => p.ID).DefaultIfEmpty(0).Max(); long laststkId = context.PaddyTransactions.Where(s => s.stockId == paddyInfo.stockId && s.prodId == paddyInfo.productId && s.bagWeight == paddyInfo.quantityPerBag).Select(l => l.ID).DefaultIfEmpty(0).Max(); var lastTrans = context.PaddyTransactions.Where(ll => ll.ID == laststkId).FirstOrDefault(); PaddyTransaction objStkTrans = new PaddyTransaction(); objStkTrans.ID = maxprdstkId + 1; objStkTrans.date = paddyInfo.date; objStkTrans.rcvQty = paddyInfo.noOfBag; objStkTrans.releaseQty = 0; objStkTrans.stockId = paddyInfo.stockId; objStkTrans.prodId = paddyInfo.productId; objStkTrans.buyId = paddyInfo.ID; objStkTrans.bagWeight = paddyInfo.quantityPerBag; objStkTrans.openingStock = lastTrans == null ? paddyInfo.noOfBag : lastTrans.openingStock + paddyInfo.noOfBag; context.PaddyTransactions.Add(objStkTrans); } #endregion #region edit tblbuy orgPaddy.productId = paddyInfo.productId; orgPaddy.noOfBag = paddyInfo.noOfBag; orgPaddy.truckNumber = paddyInfo.truckNumber; //orgPaddy.tra nsportCost = paddyInfo.transportCost; //orgPaddy.labourCostPerBag = paddyInfo.labourCostPerBag; //orgPaddy.amount = paddyInfo.amount; orgPaddy.partyId = paddyInfo.partyId; orgPaddy.quantityPerBag = paddyInfo.quantityPerBag; orgPaddy.stockId = paddyInfo.stockId; orgPaddy.unit = paddyInfo.unit; orgPaddy.price = paddyInfo.price; #endregion #region edit dues tblDue orgDue = context.tblDues.Where(d => d.buyId == orgPaddy.ID).FirstOrDefault(); double?totalPr = paddyInfo.price * paddyInfo.quantityPerBag / 40 * paddyInfo.noOfBag; var due = totalPr - paddyInfo.amount; orgDue.amount = due; //tblDue dueItem = context.tblDues.Where(bb => bb.date <= paddyInfo.date && bb.partyId == paddyInfo.partyId && bb.ID < orgDue.ID).OrderByDescending(oo => oo.date).ThenByDescending(ii => ii.ID).FirstOrDefault(); //List<tblDue> dueItems = context.tblDues.Where(bb => bb.date > paddyInfo.date && bb.partyId == paddyInfo.partyId).ToList(); //if (dueItem == null) //{ // orgDue.openingBalance = orgDue.amount; //} //else //{ // orgDue.openingBalance = dueItem.openingBalance + orgDue.amount; //} //if (dueItems != null) //{ // foreach (var item in dueItems) // { // item.openingBalance += orgDue.amount; // } //} #endregion #region edit sackinfo BagTransaction orgItem = context.BagTransactions.Where(bb => bb.rcvId == orgPaddy.ID).FirstOrDefault(); //remove if section when all price of previous paddy has been applied if (orgItem == null) { #region BagTransactions long maxBagId = context.BagTransactions.Select(b => b.ID).DefaultIfEmpty(0).Max(); if (paddyInfo.bagPrice > 0) { BagTransaction prevItem = context.BagTransactions.Where(bb => bb.date <= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice > 0 || bb.sentPrice > 0)).OrderByDescending(oo => oo.date).ThenByDescending(ii => ii.ID).FirstOrDefault(); List <BagTransaction> nextItems = context.BagTransactions.Where(bb => bb.date > paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice > 0 || bb.sentPrice > 0)).ToList(); //int bagCnt = paddyInfo.noOfBag > 0 ? paddyInfo.noOfBag : 1; double?curPriceDue = prevItem == null ? paddyInfo.noOfBag * paddyInfo.bagPrice : prevItem.priceDues + paddyInfo.noOfBag * paddyInfo.bagPrice; BagTransaction bagTrans = new BagTransaction(); bagTrans.ID = ++maxBagId; bagTrans.partyId = paddyInfo.partyId; bagTrans.rcvId = paddyInfo.ID; bagTrans.comRcvBag = paddyInfo.noOfBag; bagTrans.rcvPrice = paddyInfo.bagPrice; bagTrans.comSentBag = 0; bagTrans.sentPrice = 0; bagTrans.priceDues = curPriceDue; bagTrans.bagDues = 0; bagTrans.date = paddyInfo.date; context.BagTransactions.Add(bagTrans); if (nextItems != null) { foreach (var item in nextItems) { item.priceDues += curPriceDue; } } } else { BagTransaction prevItem = context.BagTransactions.Where(bb => bb.date <= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice == 0 || bb.rcvPrice == null) && (bb.sentPrice == 0 || bb.sentPrice == null)).OrderByDescending(oo => oo.date).ThenByDescending(ii => ii.ID).FirstOrDefault(); List <BagTransaction> nextItems = context.BagTransactions.Where(bb => bb.date > paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice == 0 || bb.rcvPrice == null) && (bb.sentPrice == 0 || bb.sentPrice == null)).ToList(); int?curBagDue = prevItem == null ? paddyInfo.noOfBag : prevItem.bagDues + paddyInfo.noOfBag; BagTransaction bagTrans = new BagTransaction(); bagTrans.ID = ++maxBagId; bagTrans.partyId = paddyInfo.partyId; bagTrans.rcvId = paddyInfo.ID; bagTrans.comRcvBag = paddyInfo.noOfBag; bagTrans.rcvPrice = 0; bagTrans.comSentBag = 0; bagTrans.sentPrice = 0; bagTrans.priceDues = 0; bagTrans.bagDues = curBagDue; bagTrans.date = paddyInfo.date; context.BagTransactions.Add(bagTrans); if (nextItems != null) { foreach (var item in nextItems) { item.bagDues += curBagDue; } } } #endregion } else { orgItem.rcvPrice = orgItem.rcvPrice ?? 0; paddyInfo.bagPrice = paddyInfo.bagPrice ?? 0; if (orgItem.rcvPrice > 0 && paddyInfo.bagPrice > 0) { List <BagTransaction> nextItems = context.BagTransactions.Where(bb => bb.date >= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice > 0 || bb.sentPrice > 0)).ToList(); // && bb.ID>orgItem.ID double?prevPriceDue = orgItem.priceDues - orgItem.rcvPrice * orgItem.comRcvBag; double?curPriceDue = prevPriceDue + paddyInfo.noOfBag * paddyInfo.bagPrice; if (nextItems != null) { foreach (var item in nextItems) { item.priceDues = item.priceDues - orgItem.priceDues + curPriceDue; } } orgItem.partyId = paddyInfo.partyId; orgItem.comRcvBag = paddyInfo.noOfBag; orgItem.rcvPrice = paddyInfo.bagPrice; orgItem.priceDues = curPriceDue; orgItem.date = paddyInfo.date; } else if ((orgItem.rcvPrice == 0 || orgItem.rcvPrice == null) && (paddyInfo.bagPrice == 0 || paddyInfo.bagPrice == null)) { List <BagTransaction> nextItems = context.BagTransactions.Where(bb => bb.date >= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice == 0 || bb.rcvPrice == null) && (bb.sentPrice == 0 || bb.sentPrice == null)).ToList(); //&& bb.ID > orgItem.ID int?prevBagDue = orgItem.bagDues - orgItem.comRcvBag; int?curBagDue = prevBagDue + paddyInfo.noOfBag; if (nextItems != null) { foreach (var item in nextItems) { item.bagDues = item.bagDues - orgItem.bagDues + curBagDue; } } orgItem.partyId = paddyInfo.partyId; orgItem.comRcvBag = paddyInfo.noOfBag; orgItem.bagDues = curBagDue; orgItem.date = paddyInfo.date; } else if (orgItem.rcvPrice > 0 && (paddyInfo.bagPrice == 0 || paddyInfo.bagPrice == null)) { List <BagTransaction> nextItemsWithPric = context.BagTransactions.Where(bb => bb.date >= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice > 0 || bb.sentPrice > 0)).ToList(); //&& bb.ID > orgItem.ID List <BagTransaction> nextItemsWithoutPric = context.BagTransactions.Where(bb => bb.date >= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice == 0 || bb.rcvPrice == null) && (bb.sentPrice == 0 || bb.sentPrice == null)).ToList(); //&& bb.ID > orgItem.ID int?prevBagDue = orgItem.bagDues - orgItem.comRcvBag; int?curBagDue = prevBagDue + paddyInfo.noOfBag; if (nextItemsWithPric != null) { foreach (var item in nextItemsWithPric) { item.priceDues = item.priceDues - orgItem.priceDues; } } if (nextItemsWithoutPric != null) { foreach (var item in nextItemsWithoutPric) { item.bagDues = item.bagDues + paddyInfo.noOfBag; } } orgItem.partyId = paddyInfo.partyId; orgItem.comRcvBag = paddyInfo.noOfBag; orgItem.rcvPrice = 0; orgItem.priceDues = 0; orgItem.bagDues = curBagDue; orgItem.date = paddyInfo.date; } else if ((orgItem.rcvPrice == 0 || orgItem.rcvPrice == null) && paddyInfo.bagPrice > 0) { List <BagTransaction> nextItemsWithPric = context.BagTransactions.Where(bb => bb.date >= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice > 0 || bb.sentPrice > 0)).ToList(); // && bb.ID > orgItem.ID List <BagTransaction> nextItemsWithoutPric = context.BagTransactions.Where(bb => bb.date >= paddyInfo.date && bb.partyId == paddyInfo.partyId && (bb.rcvPrice == 0 || bb.rcvPrice == null) && (bb.sentPrice == 0 || bb.sentPrice == null)).ToList(); // && bb.ID > orgItem.ID double?prevPriceDue = orgItem.priceDues - orgItem.rcvPrice * orgItem.comRcvBag; double?curPriceDue = prevPriceDue + paddyInfo.noOfBag * paddyInfo.bagPrice; if (nextItemsWithPric != null) { foreach (var item in nextItemsWithPric) { item.priceDues = item.priceDues + paddyInfo.noOfBag * paddyInfo.bagPrice; } } if (nextItemsWithoutPric != null) { foreach (var item in nextItemsWithoutPric) { item.bagDues = item.bagDues - orgItem.comRcvBag; } } orgItem.partyId = paddyInfo.partyId; orgItem.comRcvBag = paddyInfo.noOfBag; orgItem.rcvPrice = paddyInfo.bagPrice; orgItem.priceDues = curPriceDue; orgItem.bagDues = 0; orgItem.date = paddyInfo.date; } } #endregion return(context.SaveChanges() > 0 ? paddyInfo.ID : 0); }
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(tblCostingSource objCosting) { return(Json(withdrawRepo.Save(objCosting), JsonRequestBehavior.AllowGet)); }