コード例 #1
0
 // [Authorize(Roles = "Admin,Super Admin,User")]
 public ActionResult PaddyStock(string stockId, string productId, string from, string to)
 {
     try
     {
         string path = Path.Combine(Server.MapPath("~/Reports"), "paddyStockInfo.rdlc");
         if (!System.IO.File.Exists(path) || string.IsNullOrEmpty(stockId) || string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(from) || string.IsNullOrEmpty(to))
         {
             return(View("rptStockInfo"));
         }
         int pId   = Convert.ToInt32(productId);
         int stkId = Convert.ToInt32(stockId);
         PaddyTransaction stockRpt = new PaddyTransaction();
         stockRpt.prodId   = pId;
         stockRpt.stockId  = stkId;
         stockRpt.fromDate = Convert.ToDateTime(from);
         stockRpt.toDate   = Convert.ToDateTime(to);
         List <object> objLst          = reportRepository.GetPaddyStockRpt(stockRpt);
         var           reportViewModel = reportRepository.GetPaddyStockViewModel(objLst, stkId, pId, from, to);
         reportViewModel.FileName = path;
         var renderedBytes = reportViewModel.RenderReport();
         if (reportViewModel.ViewAsAttachment)
         {
             Response.AddHeader("content-disposition", reportViewModel.ReporExportFileName);
         }
         return(File(renderedBytes, reportViewModel.LastmimeType));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
        public long SavePaddyTransfer(STK_Balance objStkBalance)
        {
            var transferFrom =
                context.STK_Balance.Where(
                    ss => ss.stockId == objStkBalance.stockId && ss.productId == objStkBalance.productId && ss.sackWeight == objStkBalance.sackWeight).FirstOrDefault();

            transferFrom.sackQuantity = transferFrom.sackQuantity - objStkBalance.sackQuantity;
            if (transferFrom.sackQuantity < 0)
            {
                return(0);
            }
            var transferTo = context.STK_Balance.Where(
                ss => ss.stockId == objStkBalance.targetStockId && ss.productId == objStkBalance.productId && ss.sackWeight == objStkBalance.sackWeight).FirstOrDefault();

            if (transferTo != null)
            {
                transferTo.sackQuantity += objStkBalance.sackQuantity;
            }
            else
            {
                var         maxId   = context.STK_Balance.Select(ss => ss.ID).DefaultIfEmpty(0).Max();
                STK_Balance stockTo = new STK_Balance();
                stockTo.ID         = ++maxId;
                stockTo.stockId    = objStkBalance.targetStockId;
                stockTo.sackWeight = objStkBalance.sackWeight;
                context.STK_Balance.Add(stockTo);
            }
            #region paddy transaction
            var maxTransId = context.PaddyTransactions.Select(ss => ss.ID).DefaultIfEmpty(0).Max();
            PaddyTransaction exstRlsStk  = context.PaddyTransactions.Where(pp => pp.prodId == objStkBalance.productId && pp.stockId == objStkBalance.stockId && pp.bagWeight == objStkBalance.sackWeight).FirstOrDefault();
            PaddyTransaction objTransRls = new PaddyTransaction();
            objTransRls.ID           = ++maxTransId;
            objTransRls.date         = objStkBalance.date;
            objTransRls.bagWeight    = objStkBalance.sackWeight;
            objTransRls.stockId      = objStkBalance.stockId.Value;
            objTransRls.prodId       = objStkBalance.productId.Value;
            objTransRls.releaseQty   = objStkBalance.sackQuantity;
            objTransRls.openingStock = exstRlsStk == null ? 0 : exstRlsStk.openingStock - objStkBalance.sackQuantity.Value;
            context.PaddyTransactions.Add(objTransRls);

            PaddyTransaction exstRcvStk  = context.PaddyTransactions.Where(pp => pp.prodId == objStkBalance.productId && pp.stockId == objStkBalance.targetStockId && pp.bagWeight == objStkBalance.sackWeight).FirstOrDefault();
            PaddyTransaction objTransRcv = new PaddyTransaction();
            objTransRcv.ID           = ++maxTransId;
            objTransRcv.date         = objStkBalance.date;
            objTransRcv.bagWeight    = objStkBalance.sackWeight;
            objTransRcv.stockId      = objStkBalance.targetStockId;
            objTransRcv.prodId       = objStkBalance.productId.Value;
            objTransRcv.rcvQty       = objStkBalance.sackQuantity;
            objTransRcv.openingStock = exstRcvStk == null ? 0 : exstRcvStk.openingStock + objStkBalance.sackQuantity.Value;
            objTransRcv.serial       = objStkBalance.serial;
            objTransRcv.millCost     = objStkBalance.millCost;
            objTransRcv.fromStock    = objStkBalance.stockId;
            context.PaddyTransactions.Add(objTransRcv);
            #endregion
            return(context.SaveChanges() > 0 ? objTransRcv.ID : 0);
        }
コード例 #3
0
        // 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);
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public List <object> GetPaddyStockRpt(PaddyTransaction stockRpt)
        {
            var stockInfoLst = context.sp_RptPaddyStockInfo(stockRpt.stockId, stockRpt.prodId, stockRpt.fromDate, stockRpt.toDate);

            return(stockInfoLst.ToList <object>());
        }