Пример #1
0
        public ActionResult GetSearchItem(string itemCode)
        {
            string            sql            = "";
            List <vuItemInfo> vuItemInfoList = new List <vuItemInfo>();

            if (itemCode != "")
            {
                if (Convert.ToBoolean(Session["MaintLot"]) == true)
                {
                    sql            = string.Format("SELECT dbo.CurrentStock.ItemCode,dbo.ItemInfo.ItemName, dbo.Location.LocName, dbo.Branch.BranchName,");
                    sql           += string.Format("dbo.CurrentStock.CurrQty  FROM  dbo.CurrentStock INNER JOIN dbo.ItemInfo ON dbo.CurrentStock.ItemCode = dbo.ItemInfo.ItemCode ");
                    sql           += string.Format("INNER JOIN dbo.Location ON dbo.CurrentStock.LocCode = dbo.Location.LocCode INNER JOIN dbo.BranchLocMap ");
                    sql           += string.Format("ON dbo.Location.LocCode = dbo.BranchLocMap.LocCode INNER JOIN dbo.Branch ON dbo.BranchLocMap.BranchCode = dbo.Branch.BranchCode where dbo.CurrentStock.ItemCode='" + itemCode + "' and CurrQty <> 0");
                    vuItemInfoList = _vuItemInfoAppService.SqlQueary(sql).ToList();
                }
                else
                {
                    var existCurrStoc = CostLedgerAppService.All().Where(x => x.ItemCode == itemCode).ToList();
                    if (existCurrStoc.Count != 0)
                    {
                        var result = (from r in existCurrStoc group r by r.LocNo into g
                                      select new { LocNo = g.Key, TrDate = g.Max(a => a.TrDate) }).ToList();
                        foreach (var item in result)
                        {
                            var        existCurrStock = CostLedgerAppService.All().Where(x => x.ItemCode == itemCode && x.TrDate == item.TrDate && x.LocNo == item.LocNo).FirstOrDefault();
                            vuItemInfo vuItemInfo     = new vuItemInfo();
                            vuItemInfo.ItemCode = existCurrStock.ItemCode;
                            vuItemInfo.ItemName = (_ItemInfoService.All().Where(s => s.ItemCode == itemCode)
                                                   .Select(c => c.ItemName)).FirstOrDefault();
                            vuItemInfo.LocName = (_locationService.All().Where(s => s.LocCode == item.LocNo)
                                                  .Select(c => c.LocName)).FirstOrDefault();
                            vuItemInfo.BranchName = "";
                            vuItemInfo.CurrQty    = existCurrStock.BalQty;
                            vuItemInfoList.Add(vuItemInfo);
                        }
                    }
                }
            }
            return(Json(new { data = vuItemInfoList }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult SaveUpdatePurRet(PurRetMain PurRet, List <PurRetDetail> PurRetDetail, string IsSave)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());

                    #region for Purs Return transection
                    string trnType = "Save";
                    string Msg     = "1";


                    //Firstly deleted the saved For Update
                    if (IsSave == "1")
                    {
                        if (!rUser.HasPermission("PurchaseReturn_Update"))
                        {
                            return(Json("U", JsonRequestBehavior.AllowGet));
                        }
                        trnType = "Update";
                        Msg     = "2";

                        #region For AVP OR LOT

                        if (Session["MaintLot"].ToString() == "True")
                        {
                            var sRetMain   = _PurRetMainService.All().Where(s => s.PurRetNo == PurRet.PurRetNo).FirstOrDefault();
                            var sRetDetail = _PurRetDetailService.All().Where(s => s.PurRetId == sRetMain.PurRetId).ToList();
                            foreach (var currentItem in sRetDetail)
                            {
                                var currentStocks = _currentStockService.All().ToList().FirstOrDefault(m => m.ItemCode == currentItem.ItemCode &&
                                                                                                       m.LocCode == PurRet.LocNo &&
                                                                                                       m.LotNo == currentItem.LotNo);
                                if (currentStocks != null)
                                {
                                    currentStocks.CurrQty   = currentStocks.CurrQty + currentItem.ReturnQty;
                                    currentStocks.UnitPrice = Convert.ToDouble(currentItem.UnitPrice);
                                    _currentStockService.Update(currentStocks);
                                }
                            }
                        }
                        else
                        {
                            // For Costledger Code
                        }
                        #endregion

                        var saleRetDel = _PurRetMainService.All().ToList().Where(y => y.PurRetNo == PurRet.PurRetNo).FirstOrDefault();
                        _PurRetDetailService.All().ToList().Where(y => y.PurRetId == saleRetDel.PurRetId).ToList().ForEach(x => _PurRetDetailService.Delete(x));
                        _PurRetDetailService.Save();
                        _PurRetMainService.Delete(saleRetDel);
                        _PurRetMainService.Save();

                        var rcvDel = _issueMainService.All().ToList().Where(y => y.RefNo == PurRet.PurRetNo && y.VchrNo == PurRet.VchrNo).FirstOrDefault();
                        _issueDetailService.All().ToList().Where(y => y.IssueNo == PurRet.ChallanNo).ToList().ForEach(x => _issueDetailService.Delete(x));
                        _receiveDetailService.Save();
                        _issueMainService.Delete(rcvDel);
                        _issueMainService.Save();
                    }

                    if (!rUser.HasPermission("PurchaseReturn_Insert"))
                    {
                        return(Json("X", JsonRequestBehavior.AllowGet));
                    }

                    var IfExist = _PurRetMainService.All().Where(x => x.PurRetNo == PurRet.PurRetNo).FirstOrDefault();
                    if (IfExist == null)
                    {
                        PurRet.FinYear       = Session["FinYear"].ToString();
                        PurRet.BranchCode    = Session["BranchCode"].ToString();
                        PurRet.ProjCode      = Session["ProjCode"].ToString();
                        PurRet.EntryDateTime = DateTime.Now;
                        _PurRetMainService.Add(PurRet);
                        _PurRetMainService.Save();

                        if (PurRetDetail != null)
                        {
                            foreach (var sRetDExtItem in PurRetDetail)
                            {
                                PurRetDetail sRetDetail = new PurRetDetail();
                                var          srID       = _PurRetMainService.All().Select(s => s.PurRetId).LastOrDefault();
                                if (srID == 0)
                                {
                                    sRetDExtItem.PurRetId = 1;
                                }
                                else
                                {
                                    sRetDExtItem.PurRetId = srID;
                                }
                                sRetDetail = sRetDExtItem;
                                _PurRetDetailService.Add(sRetDetail);
                            }
                        }
                        _PurRetDetailService.Save();

                        #region  For Issue
                        var IssueNo = _issueMainService.All().Select(s => Convert.ToInt32(s.IssueNo)).LastOrDefault() + 1;
                        if (IssueNo != 0)
                        {
                            var       todayDate = DateTime.Now;
                            IssueMain issueInfo = new IssueMain();
                            issueInfo.IssueNo     = "0" + IssueNo.ToString(); //PurRet.PurRetNo;
                            issueInfo.BranchCode  = Session["BranchCode"].ToString();
                            issueInfo.IssueDate   = PurRet.PurRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);
                            issueInfo.FromLocCode = PurRet.LocNo;
                            //issueInfo.StoreLocCode = PurRet.StoreLocCode;
                            issueInfo.IssueToSubCode = PurRet.CustCode;
                            //issueInfo.DesLocCode = PurRet.DesLocCode;
                            //issueInfo.Accode = PurRet.Accode;
                            issueInfo.RefNo   = PurRet.PurRetNo;
                            issueInfo.RefDate = PurRet.PurRetDate;
                            issueInfo.Remarks = PurRet.Remarks;
                            //issueInfo.IssueByCode = PurRet.IssueByCode;
                            issueInfo.AppByCode         = PurRet.ApprBy;
                            issueInfo.IssTime           = DateTime.Now;
                            issueInfo.FinYear           = Session["FinYear"].ToString();
                            issueInfo.GLPost            = false;
                            issueInfo.IssDate           = PurRet.PurRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);
                            issueInfo.cashReceiptStatus = false;
                            issueInfo.IsReceived        = false;
                            issueInfo.VchrNo            = PurRet.VchrNo;
                            double amount = 0.0;
                            issueInfo.EntrySrc   = "PR";
                            issueInfo.EntrySrcNo = issueInfo.IssueNo;
                            List <IssueDetails> issuDetailsList = new List <IssueDetails>();
                            #region For LOT OR AVP
                            if (Session["MaintLot"].ToString() == "True")
                            {
                                #region Not AutoLot by issueDetail

                                foreach (var currentItem in PurRetDetail)
                                {
                                    var currentStocks = _currentStockService.All().ToList().FirstOrDefault(m => m.ItemCode == currentItem.ItemCode &&
                                                                                                           m.LocCode == PurRet.LocNo &&
                                                                                                           m.LotNo == currentItem.LotNo);
                                    if (currentStocks != null)
                                    {
                                        currentStocks.CurrQty   = currentStocks.CurrQty - currentItem.ReturnQty;
                                        currentStocks.UnitPrice = (double)currentItem.UnitPrice;
                                        _currentStockService.Update(currentStocks);
                                    }
                                    else
                                    {
                                        CurrentStock currStock = new CurrentStock();
                                        currStock.LocCode   = PurRet.LocNo;
                                        currStock.LotNo     = currentItem.LotNo;
                                        currStock.ItemCode  = currentItem.ItemCode;
                                        currStock.CurrQty   = 0 - currentItem.ReturnQty;
                                        currStock.UnitPrice = (double)currentItem.UnitPrice;
                                        _currentStockService.Add(currStock);
                                    }
                                }
                                #endregion
                            }
                            else
                            {
                                #region for Cost ledger
                                foreach (var costLedger in PurRetDetail)
                                {
                                    CostLedger cLedger = new CostLedger();
                                    cLedger.IssQty   = costLedger.ReturnQty;
                                    cLedger.IssRate  = (double)costLedger.UnitPrice;
                                    cLedger.IssTotal = cLedger.IssQty * cLedger.IssRate;

                                    cLedger.RecQty   = 0;
                                    cLedger.RecRate  = 0;
                                    cLedger.RecTotal = 0;

                                    var existCurrStoc = CostLedgerAppService.All().Where(x => x.ItemCode == costLedger.ItemCode && x.LocNo == PurRet.LocNo.Trim()).ToList();
                                    if (existCurrStoc.Count != 0)
                                    {
                                        var date           = existCurrStoc.Max(x => x.TrDate);
                                        var existCurrStock = CostLedgerAppService.All().OrderByDescending(s => s.RecId).Where(x => x.ItemCode == costLedger.ItemCode && x.LocNo == PurRet.LocNo.Trim() && x.TrDate == date).FirstOrDefault();

                                        cLedger.BalQty   = existCurrStock.BalQty - cLedger.IssQty;
                                        cLedger.BalRate  = System.Math.Round(existCurrStock.BalRate, 2);
                                        cLedger.BalTotal = System.Math.Round(cLedger.BalQty * cLedger.BalRate, 2);

                                        cLedger.LocNo    = PurRet.LocNo;
                                        cLedger.ItemCode = costLedger.ItemCode;
                                        cLedger.TrDate   = PurRet.PurRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);

                                        cLedger.UpdSrcNo = PurRet.PurRetNo;
                                        cLedger.UpdSrc   = "PR";
                                        CostLedgerAppService.Add(cLedger);
                                    }
                                    else if (existCurrStoc.Count == 0)
                                    {
                                        cLedger.CurrQty   = 0;
                                        cLedger.UnitPrice = 0;
                                        cLedger.BalTotal  = 0;

                                        cLedger.BalQty   = cLedger.BalQty - cLedger.IssQty;
                                        cLedger.BalRate  = cLedger.IssRate;
                                        cLedger.BalRate  = System.Math.Round(cLedger.BalRate, 2);
                                        cLedger.BalTotal = System.Math.Round(cLedger.BalQty * cLedger.BalRate, 2);

                                        cLedger.LocNo    = PurRet.LocNo;
                                        cLedger.ItemCode = costLedger.ItemCode;
                                        cLedger.TrDate   = PurRet.PurRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);

                                        cLedger.UpdSrcNo = PurRet.PurRetNo;
                                        cLedger.UpdSrc   = "PR";
                                        CostLedgerAppService.Add(cLedger);
                                    }
                                    CostLedgerAppService.Save();
                                }
                                #endregion
                            }
                            #endregion


                            foreach (var issuDetailsItem in PurRetDetail)
                            {
                                IssueDetails issueDetailsInfo = new IssueDetails();
                                issueDetailsInfo.IssueNo     = "0" + IssueNo.ToString();
                                issueDetailsInfo.ItemCode    = issuDetailsItem.ItemCode;
                                issueDetailsInfo.SubCode     = PurRet.CustCode;
                                issueDetailsInfo.Description = issuDetailsItem.Description;
                                issueDetailsInfo.Qty         = issuDetailsItem.ReturnQty;
                                issueDetailsInfo.Price       = (double)issuDetailsItem.UnitPrice;
                                //issueDetailsInfo.ExQty = issuDetailsItem.ExQty;
                                issueDetailsInfo.LotNo = "01";
                                amount = amount + (issuDetailsItem.ReturnQty * (double)issuDetailsItem.UnitPrice);
                                issuDetailsList.Add(issueDetailsInfo);
                            }

                            issueInfo.Amount       = amount;
                            issueInfo.IssueDetails = issuDetailsList;
                            _issueMainService.Add(issueInfo);
                            _issueMainService.Save();
                        }
                        #endregion
                        TransactionLogService.SaveTransactionLog(_transactionLogService, "Purchase Return", trnType, PurRet.VchrNo, Session["UserName"].ToString());
                        //LoadDropDown.ProvitionInvRSave("IR", "I", recvInfo.RcvNo, recvInfo.VchrNo, Session["FinYear"].ToString(), Session["ProjCode"].ToString(), Session["BranchCode"].ToString(), recvMain.RcvDate.ToString("yyyy-MM-dd"), Session["UserName"].ToString());
                        transaction.Complete();
                        return(Json(new { Msg = Msg }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        transaction.Dispose();
                        return(Json("3", JsonRequestBehavior.AllowGet));
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    transaction.Dispose();
                    return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet));
                }
            }
        }
Пример #3
0
        public ActionResult SaveUpdateSaleRet(SaleRetMain SaleRet, List <SaleRetDetail> SaleRetDetail, string IsSave)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());

                    #region for Sales Return transection
                    string trnType = "Save";
                    string Msg     = "1";

                    //Firstly deleted the saved For Update
                    if (IsSave == "1")
                    {
                        if (!rUser.HasPermission("SalesReturn_Update"))
                        {
                            return(Json("U", JsonRequestBehavior.AllowGet));
                        }
                        trnType = "Update";
                        Msg     = "2";

                        #region For AVP OR LOT

                        if (Session["MaintLot"].ToString() == "True")
                        {
                            var sRetMain   = _saleRetMainService.All().Where(s => s.SaleRetNo == SaleRet.SaleRetNo).FirstOrDefault();
                            var sRetDetail = _saleRetDetailService.All().Where(s => s.SaleRetId == sRetMain.SaleRetId).ToList();
                            foreach (var currentItem in sRetDetail)
                            {
                                var currentStocks = _currentStockService.All().ToList().FirstOrDefault(m => m.ItemCode == currentItem.ItemCode &&
                                                                                                       m.LocCode == SaleRet.LocNo &&
                                                                                                       m.LotNo == currentItem.LotNo);
                                if (currentStocks != null)
                                {
                                    currentStocks.CurrQty   = currentStocks.CurrQty - currentItem.ReturnQty;
                                    currentStocks.UnitPrice = Convert.ToDouble(currentItem.UnitPrice);
                                    _currentStockService.Update(currentStocks);
                                }
                            }
                        }
                        else
                        {
                            // For Costledger Code
                        }
                        #endregion

                        var saleRetDel = _saleRetMainService.All().ToList().Where(y => y.SaleRetNo == SaleRet.SaleRetNo).FirstOrDefault();
                        _saleRetDetailService.All().ToList().Where(y => y.SaleRetId == saleRetDel.SaleRetId).ToList().ForEach(x => _saleRetDetailService.Delete(x));
                        _saleRetDetailService.Save();
                        _saleRetMainService.Delete(saleRetDel);
                        _saleRetMainService.Save();

                        var rcvDel = _receiveMainService.All().ToList().Where(y => y.ChallanNo == SaleRet.ChallanNo && y.RefNo == SaleRet.SaleRetNo && y.VchrNo == SaleRet.VchrNo).FirstOrDefault();
                        _receiveDetailService.All().ToList().Where(y => y.RcvNo == rcvDel.RcvNo).ToList().ForEach(x => _receiveDetailService.Delete(x));
                        _receiveDetailService.Save();
                        _receiveMainService.Delete(rcvDel);
                        _receiveMainService.Save();
                    }

                    if (!rUser.HasPermission("SalesReturn_Insert"))
                    {
                        return(Json("X", JsonRequestBehavior.AllowGet));
                    }

                    var IfExist = _saleRetMainService.All().Where(x => x.SaleRetNo == SaleRet.SaleRetNo).FirstOrDefault();
                    if (IfExist == null)
                    {
                        SaleRet.FinYear       = Session["FinYear"].ToString();
                        SaleRet.BranchCode    = Session["BranchCode"].ToString();
                        SaleRet.ProjCode      = Session["ProjCode"].ToString();
                        SaleRet.EntryDateTime = DateTime.Now;
                        _saleRetMainService.Add(SaleRet);
                        _saleRetMainService.Save();

                        if (SaleRetDetail != null)
                        {
                            foreach (var sRetDExtItem in SaleRetDetail)
                            {
                                SaleRetDetail sRetDetail = new SaleRetDetail();
                                var           srID       = _saleRetMainService.All().Select(s => s.SaleRetId).LastOrDefault();
                                if (srID == null)
                                {
                                    sRetDExtItem.SaleRetId = 1;
                                }
                                else
                                {
                                    sRetDExtItem.SaleRetId = srID;
                                }
                                sRetDetail = sRetDExtItem;
                                _saleRetDetailService.Add(sRetDetail);
                            }
                        }
                        _saleRetDetailService.Save();

                        #region for Receive transection

                        //var ExistRcv = _receiveMainService.All().Where(x => x.RcvNo == SaleRet.SaleRetNo).FirstOrDefault();
                        var rcvNo = _receiveMainService.All().Select(s => Convert.ToInt32(s.RcvNo)).LastOrDefault() + 1;
                        //if (ExistRcv == null)
                        //{
                        var         todayDate = DateTime.Now;
                        ReceiveMain recvMain  = new ReceiveMain();
                        recvMain.RcvNo           = "0" + rcvNo.ToString();
                        recvMain.BranchCode      = Session["BranchCode"].ToString();
                        recvMain.RcvDate         = SaleRet.SaleRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);
                        recvMain.Source          = SaleRet.CustCode;
                        recvMain.ChallanNo       = SaleRet.ChallanNo;
                        recvMain.RefNo           = SaleRet.SaleRetNo;
                        recvMain.RefDate         = (DateTime)SaleRet.SaleRetDate;
                        recvMain.Remarks         = SaleRet.Remarks;
                        recvMain.AppByCode       = SaleRet.ApprBy;
                        recvMain.RcvdTime        = DateTime.Now;
                        recvMain.StoreLocCode    = SaleRet.LocNo;
                        recvMain.RecvFromSubCode = SaleRet.CustCode;
                        recvMain.VchrNo          = SaleRet.VchrNo;
                        recvMain.FinYear         = Session["FinYear"].ToString();
                        recvMain.GLPost          = false;
                        recvMain.RcvdDate        = SaleRet.SaleRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);
                        recvMain.expenseStatus   = false;
                        recvMain.CreditPur       = false;

                        double amount = 0.0;

                        List <ReceiveDetails> receveDetailsList = new List <ReceiveDetails>();
                        foreach (var recvDetailsItem in SaleRetDetail)
                        {
                            ReceiveDetails receivDetails = new ReceiveDetails();
                            receivDetails.RcvNo       = "0" + rcvNo.ToString();
                            receivDetails.ItemCode    = recvDetailsItem.ItemCode;
                            receivDetails.SubCode     = SaleRet.CustCode;
                            receivDetails.Description = recvDetailsItem.Description;
                            receivDetails.Qty         = recvDetailsItem.ReturnQty;
                            receivDetails.Price       = Convert.ToDouble(recvDetailsItem.UnitPrice);
                            receivDetails.ExQty       = recvDetailsItem.ReturnQty;
                            receivDetails.LotNo       = recvDetailsItem.LotNo;

                            amount = amount + Convert.ToDouble((recvDetailsItem.ReturnQty * recvDetailsItem.UnitPrice));
                            receveDetailsList.Add(receivDetails);
                        }

                        recvMain.Amount = amount;

                        #region For AVP OR LOT

                        if (Session["MaintLot"].ToString() == "True")
                        {
                            foreach (var currentItem in SaleRetDetail)
                            {
                                var currentStocks = _currentStockService.All().ToList().FirstOrDefault(m => m.ItemCode == currentItem.ItemCode &&
                                                                                                       m.LocCode == recvMain.StoreLocCode &&
                                                                                                       m.LotNo == currentItem.LotNo);
                                if (currentStocks != null)
                                {
                                    currentStocks.CurrQty   = currentItem.ReturnQty + currentStocks.CurrQty;
                                    currentStocks.UnitPrice = Convert.ToDouble(currentItem.UnitPrice);
                                    _currentStockService.Update(currentStocks);
                                }
                                else
                                {
                                    CurrentStock currStock = new CurrentStock();
                                    currStock.LocCode   = SaleRet.LocNo;
                                    currStock.LotNo     = currentItem.LotNo;
                                    currStock.ItemCode  = currentItem.ItemCode;
                                    currStock.CurrQty   = currentItem.ReturnQty;
                                    currStock.UnitPrice = Convert.ToDouble(currentItem.UnitPrice);
                                    _currentStockService.Add(currStock);
                                }

                                var lotNO = _lotDtService.All().ToList().Where(m => m.LotNo == currentItem.LotNo).FirstOrDefault();
                                if (lotNO == null)
                                {
                                    LotDT lotDt = new LotDT();
                                    lotDt.LotNo     = currentItem.LotNo;
                                    lotDt.LotDate   = SaleRet.SaleRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);
                                    lotDt.RefNo     = SaleRet.SaleRetNo;
                                    lotDt.RefSource = "Sales Return Receive";
                                    _lotDtService.Add(lotDt);
                                }
                            }
                        }
                        else
                        {
                            #region AVP
                            foreach (var cItem in SaleRetDetail)
                            {
                                CostLedger cLedger = new CostLedger();
                                cLedger.RecQty   = cItem.ReturnQty;
                                cLedger.RecRate  = Convert.ToDouble(cItem.UnitPrice);
                                cLedger.RecTotal = System.Math.Round(cLedger.RecQty * cLedger.RecRate, 2);

                                double CurrQty = 0, BalTotal = 0;
                                var    existCurrStoc = CostLedgerAppService.All().Where(x => x.ItemCode == cItem.ItemCode && x.LocNo == recvMain.StoreLocCode.Trim()).ToList();
                                if (existCurrStoc.Count != 0)
                                {
                                    var date           = existCurrStoc.Max(x => x.TrDate);
                                    var existCurrStock = CostLedgerAppService.All().OrderByDescending(s => s.RecId).Where(x => x.ItemCode == cItem.ItemCode && x.LocNo == recvMain.StoreLocCode.Trim() && x.TrDate == date).ToList();
                                    foreach (var item in existCurrStock)
                                    {
                                        CurrQty  = item.BalQty;
                                        BalTotal = item.BalTotal;
                                    }
                                }
                                cLedger.IssQty   = 0;
                                cLedger.IssRate  = 0;
                                cLedger.IssTotal = 0;
                                cLedger.BalQty   = CurrQty + cLedger.RecQty;

                                if (cLedger.BalQty != 0)
                                {
                                    cLedger.BalRate = (BalTotal + cLedger.RecTotal) / cLedger.BalQty;
                                }
                                else
                                {
                                    cLedger.BalRate = 0;
                                }
                                cLedger.BalRate = System.Math.Round(cLedger.BalRate, 2);

                                cLedger.BalTotal = System.Math.Round(cLedger.BalQty * cLedger.BalRate, 2);

                                cLedger.LocNo    = recvMain.StoreLocCode;
                                cLedger.ItemCode = cItem.ItemCode;
                                cLedger.TrDate   = (DateTime)SaleRet.SaleRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);

                                cLedger.UpdSrcNo = SaleRet.SaleRetNo;
                                cLedger.UpdSrc   = "SR";
                                CostLedgerAppService.Add(cLedger);
                            }
                            CostLedgerAppService.Save();

                            #endregion
                        }
                        #endregion

                        recvMain.RcvDetails = receveDetailsList;
                        _receiveMainService.Add(recvMain);
                        _currentStockService.Save();
                        _receiveMainService.Save();
                        //}

                        #endregion


                        TransactionLogService.SaveTransactionLog(_transactionLogService, "Sales Return", trnType, rcvNo.ToString(), Session["UserName"].ToString());
                        //LoadDropDown.ProvitionInvRSave("IR", "I", recvInfo.RcvNo, recvInfo.VchrNo, Session["FinYear"].ToString(), Session["ProjCode"].ToString(), Session["BranchCode"].ToString(), recvMain.RcvDate.ToString("yyyy-MM-dd"), Session["UserName"].ToString());
                        transaction.Complete();
                        return(Json(new { Msg = Msg }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        transaction.Dispose();
                        return(Json("3", JsonRequestBehavior.AllowGet));
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    transaction.Dispose();
                    return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet));
                }
            }
        }