Пример #1
0
        public bool SaveProdStock(STK_Balance prodStk)
        {
            #region stock transaction
            long            maxprdstkId = context.STK_Transaction.Select(p => p.ID).DefaultIfEmpty(0).Max();
            long            laststkId   = context.STK_Transaction.Where(s => s.stockId == prodStk.stockId && s.prodId == prodStk.productId).Select(l => l.ID).DefaultIfEmpty(0).Max();
            STK_Transaction objStkTrans = new STK_Transaction();
            objStkTrans.ID        = maxprdstkId + 1;
            objStkTrans.date      = prodStk.date;
            objStkTrans.rcvQty    = prodStk.sackQuantity;
            objStkTrans.sellQty   = 0;
            objStkTrans.stockId   = prodStk.stockId.Value;
            objStkTrans.prodId    = prodStk.productId.Value;
            objStkTrans.operation = 1;
            var lastTrans = context.STK_Transaction.Where(ll => ll.ID == laststkId).FirstOrDefault();
            objStkTrans.openingStock = lastTrans == null ? prodStk.sackQuantity.Value : lastTrans.openingStock + prodStk.sackQuantity.Value;
            context.STK_Transaction.Add(objStkTrans);
            #endregion

            #region stock balance
            int maxId    = context.STK_Balance.Select(p => p.ID).DefaultIfEmpty(0).Max();
            var existStk = context.STK_Balance.Where(ss => ss.productId == prodStk.productId && ss.stockId == prodStk.stockId).FirstOrDefault();
            if (existStk == null)
            {
                prodStk.ID = ++maxId;
                context.STK_Balance.Add(prodStk);
            }
            else
            {
                existStk.sackQuantity += prodStk.sackQuantity;
            }
            #endregion

            return(context.SaveChanges() > 0);
        }
Пример #2
0
        public bool EditProdStock(STK_Balance prodStock)
        {
            #region stock balance
            var orgStk = context.STK_Balance.Where(ss => ss.ID == prodStock.ID).FirstOrDefault();

            #region stock transaction
            long maxprdstkId = context.STK_Transaction.Select(p => p.ID).DefaultIfEmpty(0).Max();
            long laststkId   = context.STK_Transaction.Where(s => s.stockId == prodStock.stockId && s.prodId == prodStock.productId).Select(l => l.ID).DefaultIfEmpty(0).Max();

            STK_Transaction objStkTrans = new STK_Transaction();
            objStkTrans.ID        = maxprdstkId + 1;
            objStkTrans.date      = prodStock.date;
            objStkTrans.rcvQty    = prodStock.sackQuantity;
            objStkTrans.sellQty   = 0;
            objStkTrans.stockId   = prodStock.stockId.Value;
            objStkTrans.prodId    = prodStock.productId.Value;
            objStkTrans.operation = 2;
            var lastTrans = context.STK_Transaction.Where(ll => ll.ID == laststkId).FirstOrDefault();
            objStkTrans.openingStock = lastTrans.openingStock - orgStk.sackQuantity == null?0:orgStk.sackQuantity + prodStock.sackQuantity == null?0:prodStock.sackQuantity.Value;
            context.STK_Transaction.Add(objStkTrans);
            #endregion

            orgStk.productId    = prodStock.productId;
            orgStk.sackQuantity = prodStock.sackQuantity;
            orgStk.stockId      = prodStock.stockId;
            orgStk.date         = prodStock.date;
            #endregion


            return(context.SaveChanges() > 0);
        }
Пример #3
0
 //[Authorize(Roles = "Admin,Super Admin,User")]
 public ActionResult Preview(string stockId, string productId, string from, string to)
 {
     try
     {
         string path = Path.Combine(Server.MapPath("~/Reports"), "stockInfo.rdlc");
         if (!System.IO.File.Exists(path) || string.IsNullOrEmpty(stockId) || string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(from) || string.IsNullOrEmpty(to))
         {
             return(View("rptStockInfo"));
         }
         int             sId      = Convert.ToInt32(stockId);
         int             pId      = Convert.ToInt32(productId);
         STK_Transaction stockRpt = new STK_Transaction();
         stockRpt.stockId  = sId;
         stockRpt.prodId   = pId;
         stockRpt.fromDate = Convert.ToDateTime(from);
         stockRpt.toDate   = Convert.ToDateTime(to);
         List <object> objLst          = stkRepository.GetStockInfoRpt(stockRpt);
         var           reportViewModel = stkRepository.GetRepoertViewModel(objLst, sId, 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;
     }
 }
Пример #4
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);
            }
        }
Пример #5
0
        public List <object> GetStockInfoRpt(STK_Transaction stockRpt)
        {
            var stockInfoLst = context.sp_GetStockInfo(stockRpt.stockId, stockRpt.prodId, stockRpt.fromDate, stockRpt.toDate);

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