예제 #1
0
 public ActionResult GetInvNoByAmount(string InvNo, string VchrType)
 {
     if (VchrType == "Money Receipt")
     {
         var MRs = _moneyReceiptService.All().ToList().Where(x => x.MRNo == InvNo).Select(s => new
         {
             MRAmount = s.MRAmount
         }).FirstOrDefault();
         return(Json(new { MRs = MRs }, JsonRequestBehavior.AllowGet));
     }
     else if (VchrType == "Invoice")
     {
         var Sales = _SalesMainService.All().ToList().Where(x => x.SaleNo == InvNo).Select(s =>
                                                                                           new
         {
             TotSaleAmt = s.TotSaleAmt,
             NetAmount  = s.NetAmount,
             ReceiptAmt = s.ReceiptAmt
         }).FirstOrDefault();
         return(Json(new { Sales = Sales }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(Json("", JsonRequestBehavior.AllowGet));
     }
 }
예제 #2
0
        public string GenerateSaleNo(string branchCode)
        {
            branchCode = Session["BranchCode"].ToString();
            string issueNo = "";
            var    rcvNo   = _SalesMainService.All().ToList().LastOrDefault(x => x.BranchCode.Trim() == branchCode);

            if (string.IsNullOrEmpty(branchCode))
            {
                var recvNo = _SalesMainService.All().ToList().LastOrDefault(x => x.BranchCode == null);
                if (recvNo != null)
                {
                    issueNo = "00" + (Convert.ToInt64(recvNo.IssueNo.Substring(2, 6)) + 1).ToString().PadLeft(6, '0');
                }
                else
                {
                    issueNo = "00000001";
                }
            }
            else
            {
                if (rcvNo != null)
                {
                    issueNo = branchCode + (Convert.ToInt64(rcvNo.IssueNo.Substring(2, 6)) + 1).ToString().PadLeft(6, '0');
                }
                else
                {
                    issueNo = branchCode + "000001";
                }
            }

            return(issueNo);
        }
예제 #3
0
        public ActionResult GetDataByChallanNo(string ChallanNo)
        {
            var Sales       = _SalesMainService.All().Where(s => s.IssueNo == ChallanNo).FirstOrDefault();
            var SalesDetail = LoadDropDown.LoadItemByChallanNo(ChallanNo, _CommonVmService); //new SelectList(_SaleDetailService.All().Where(s => s.SalesMainID == Sales.SalesMainID).ToList(), "ItemCode", "ItemCode"); ;
            var issueMain   = _issueMainService.All().Where(s => s.IssueNo == ChallanNo).Select(x => new { x.IssDate, x.IssueNo }).FirstOrDefault();

            return(Json(new { Sales = Sales, SalesDetail = SalesDetail, issueMain = issueMain }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetAllBySaleNo(string saleNo, string CancelType)
        {
            var SaleMain = (dynamic)null;

            if (CancelType == "1")
            {
                SaleMain = _salesMainService.All().ToList().FirstOrDefault(x => x.SaleNo == saleNo);
            }
            else
            {
                SaleMain = _moneyReceiptService.All().ToList().FirstOrDefault(x => x.MRSL == saleNo);
            }
            return(Json(SaleMain, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SaveCashMR(MoneyReceiptVM MrVM, List <MoneyReceiptExt> AdjBills)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());
                    if (!rUser.HasPermission("MoneyReceiptCash_Insert"))
                    {
                        return(Json("X", JsonRequestBehavior.AllowGet));
                    }
                    //----Edit Nasir---//
                    //var cabkop = "";
                    //var sysSet = _sysSetService.All().FirstOrDefault();
                    //if (sysSet.ActualBasis == true)
                    //{
                    //var cabkop = _defACService.All().ToList().FirstOrDefault().CashAc;
                    //}
                    //else
                    //{
                    //    cabkop = _defACService.All().ToList().FirstOrDefault().CashAc;
                    //}
                    //---  ---//
                    string CRNo   = "";
                    var    IfExit = _moneyReceiptService.All().Where(x => x.MRNo == MrVM.MRNo).FirstOrDefault();
                    if (IfExit == null)
                    {
                        //var todayDate = DateTime.Now;
                        CashReceipt           CR   = new CashReceipt();
                        CashReceiptSubDetails CRSD = new CashReceiptSubDetails();
                        MoneyReceipt          MR   = new MoneyReceipt();
                        MR.MRSL        = MrVM.MRSL;
                        MR.BranchCode  = (MrVM.BranchCode == null) ? Session["BranchCode"].ToString() : MrVM.BranchCode;
                        MR.ProjCode    = (MrVM.ProjCode == null) ? Session["ProjCode"].ToString() : MrVM.ProjCode;
                        MR.MRNo        = MrVM.MRNo;
                        MR.MRDate      = MrVM.MRDate; //.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);
                        MR.MRAgainst   = MrVM.MRAgainst;
                        MR.VchrNo      = MrVM.VchrNo;
                        MR.PayMode     = "Ca";
                        MR.Posted      = MrVM.Posted;
                        MR.AdjWithBill = MrVM.AdjWithBill;
                        MR.MRAmount    = MrVM.Amount;

                        // Accode ????
                        MR.Accode = MrVM.MRAgainst; // "1.2.001";

                        MR.CustCode = MrVM.CustCode;
                        MR.FinYear  = Session["FinYear"].ToString();
                        MR.Remarks  = MrVM.Remarks;
                        MR.JobNo    = MrVM.JobNo;
                        //MR.Ca_Bk = cabkop;

                        // CR.ReceiptNo = _CashReceiptController.GenerateReceiptNo(MR.BranchCode).Substring(6, 0);//MrVM.MRNo;
                        CR.ReceiptNo = _CashReceiptController.GenerateReceiptNo(MR.BranchCode);
                        // CR.ReceiptNo = MrVM.MRNo;
                        CRNo           = CR.ReceiptNo;
                        CR.ReceiptDate = (DateTime)MrVM.MRDate;
                        CR.purAccode   = MrVM.MRAgainst;// "1.2.004";
                        CR.RefNo       = MrVM.MRSL;
                        CR.Amount      = (Double)MrVM.Amount;
                        CR.Advance     = false;
                        CR.Remarks     = MrVM.Remarks;
                        CR.GLPost      = false;
                        CR.BranchCode  = MrVM.BranchCode;
                        CR.VoucherNo   = MrVM.VchrNo;
                        CR.BranchCode  = MR.BranchCode;
                        CR.FinYear     = Session["FinYear"].ToString();

                        CRSD.SubCode       = MrVM.CustCode;
                        CRSD.Accode        = MrVM.MRAgainst;
                        CRSD.Amount        = (Double)MrVM.Amount;
                        CRSD.CashReceiptNo = CRNo;

                        //CR.purAccode = cabkop; // "1.2.004";
                        _moneyReceiptService.Add(MR);
                        _CashReceiptService.Add(CR);
                        _CashReceiptSubDetailsAppService.Add(CRSD);
                        _CashReceiptService.Save();
                        _moneyReceiptService.Save();
                        _CashReceiptSubDetailsAppService.Save();

                        //List<MoneyReceiptExt> MRExtList = new List<MoneyReceiptExt>();

                        if (AdjBills != null)
                        {
                            decimal TotAmt = MrVM.Amount;
                            foreach (var bill in AdjBills)
                            {
                                MoneyReceiptExt MRExt    = new MoneyReceiptExt();
                                var             saleMain = _salesMainService.All().Where(s => s.SaleNo == bill.SaleNo).FirstOrDefault();
                                MRExt.MRId        = _moneyReceiptService.All().OrderBy(s => s.MRId).LastOrDefault().MRId;
                                MRExt.SaleNo      = bill.SaleNo;
                                MRExt.InstallNo   = _moneyReceiptExtService.All().OrderBy(s => s.InstallNo).Where(x => x.SaleNo == bill.SaleNo).Select(s => s.InstallNo).LastOrDefault();
                                MRExt.InstallNo   = MRExt.InstallNo + 1;
                                MRExt.InstallDate = DateTime.Now;
                                if (TotAmt >= bill.Amount)
                                {
                                    MRExt.Amount = bill.Amount;
                                    TotAmt       = TotAmt - bill.Amount;

                                    saleMain.ReceiptNo  = MrVM.MRNo;
                                    saleMain.ReceiptAmt = bill.Amount;
                                    saleMain.IsPaid     = true;
                                    _salesMainService.Update(saleMain);
                                    _salesMainService.Save();

                                    _moneyReceiptExtService.Add(MRExt);
                                    _moneyReceiptExtService.Save();
                                }
                                else
                                {
                                    if (bill.IsPaid_mre)
                                    {
                                        saleMain.IsPaid = true;
                                        MRExt.Amount    = TotAmt;

                                        //TotAmt = TotAmt - bill.Amount;
                                    }
                                    else
                                    {
                                        saleMain.IsPaid = false;
                                        MRExt.Amount    = TotAmt;
                                        // MRExt.Amount = bill.Amount;
                                        //TotAmt = TotAmt - bill.Amount;
                                    }


                                    saleMain.ReceiptNo  = MrVM.MRNo;
                                    saleMain.ReceiptAmt = TotAmt;

                                    _moneyReceiptExtService.Add(MRExt);
                                    _moneyReceiptExtService.Save();

                                    string sql = string.Format("select sm.ReceiptAmt,sm.SaleNo, sm.SaleDate, (sm.NetAmount - isnull(sum(mre.Amount),0)) as Billamount from SalesMain sm left join MoneyReceiptExt mre on mre.SaleNo = sm.SaleNo where sm.CustCode = " + MrVM.CustCode + " and sm.IsPaid = 'false'  group by sm.ReceiptAmt, mre.SaleNo, sm.NetAmount, sm.SaleNo, sm.SaleDate, mre.Amount order by sm.SaleNo");
                                    IEnumerable <billShow> BillLst;
                                    using (AcclineERPContext dbContext = new AcclineERPContext())
                                    {
                                        BillLst = dbContext.Database.SqlQuery <billShow>(sql).ToList();
                                    }
                                    foreach (var Salebill in BillLst)
                                    {
                                        if (Salebill.BillAmount == 0)
                                        {
                                            saleMain.ReceiptNo  = MrVM.MRNo;
                                            saleMain.ReceiptAmt = ((Salebill.ReceiptAmt == null) ? 0 : Salebill.ReceiptAmt) + TotAmt;
                                            saleMain.IsPaid     = true;
                                            _salesMainService.Update(saleMain);
                                            _salesMainService.Save();
                                        }
                                    }
                                }
                            } //end of  foreach
                        }
                        // New Add By Nasir
                        var GCa = _AcBrService.All().Where(s => s.BranchCode == MR.BranchCode && s.Ca_Ba == "Ca").Select(x => x.Accode).FirstOrDefault();
                        if (GCa == null)
                        {
                            var gset = _gsetService.All().LastOrDefault();
                            GCa = gset.GCa;
                        }

                        //------------------
                        TransactionLogService.SaveTransactionLog(_transactionLogService, "Cash MR", "Save", MR.MRSL, Session["UserName"].ToString());
                        LoadDropDown.journalVoucherSave("CR", "I", CRNo, MrVM.VchrNo, Session["FinYear"].ToString(), Session["ProjCode"].ToString(), Session["BranchCode"].ToString(), Convert.ToDateTime(MrVM.MRDate), GCa, Session["UserName"].ToString());

                        transaction.Complete();
                        return(Json("1", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        transaction.Dispose();
                        return(Json("3", JsonRequestBehavior.AllowGet));
                    }
                }

                catch (Exception)
                {
                    transaction.Dispose();
                    return(Json("0", JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult SaveCheRec(ChequeReceipt CheRec, List <ChequeReceiptExt> AdjBills)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());
                    if (!rUser.HasPermission("ChequeReceipt_Insert"))
                    {
                        return(Json("X", JsonRequestBehavior.AllowGet));
                    }

                    string BrNo   = "";
                    var    items  = _chequeReceiptService.All().ToList().FirstOrDefault(x => x.ChqReceiptNo == CheRec.ChqReceiptNo);
                    var    chqArc = _chequeArchiveService.All().ToList().Where(x => x.ChqNo == CheRec.ChqNo).Select(s => s.ChqStatus).ToList();
                    if (chqArc.Count == 0 || chqArc.Contains("Deposit") && CheRec.ChqStatus != "Receive" || chqArc.Contains("Encash") && CheRec.ChqStatus != "Deposit" ||
                        chqArc.Contains("Dishonour") && CheRec.ChqStatus != "Encash" || chqArc.Contains("Return") && CheRec.ChqStatus != "Dishonour")
                    {
                        if (items == null)
                        {
                            ChequeReceipt cr = new ChequeReceipt();
                            cr            = CheRec;
                            cr.MRTing     = 0;
                            cr.MRTingTime = null;
                            cr.ProjCode   = Session["ProjCode"].ToString();
                            cr.FinYear    = Session["FinYear"].ToString();
                            _chequeReceiptService.Add(cr);
                            _chequeReceiptService.Save();

                            ChequeArchive CA = new ChequeArchive();
                            CA.ChqNo      = CheRec.ChqNo;
                            CA.ChqStatus  = CheRec.ChqStatus;
                            CA.UpdateBy   = CheRec.UpdateBy;
                            CA.UpdateDate = CheRec.UpdateDate;
                            CA.Reason     = CheRec.Reason;
                            CA.Remarks    = CheRec.Remarks;
                            _chequeArchiveService.Add(CA);
                            _chequeArchiveService.Save();

                            BankReceipt br = new BankReceipt();
                            br.BReceiptNo   = GenerateBankReceiptNo(CheRec.BranchCode);
                            BrNo            = br.BReceiptNo;
                            br.BReceiptDate = CheRec.ChqReceiptDate;
                            br.purAccode    = CheRec.MRAgainst.ToString();
                            br.RefNo        = CheRec.ChqReceiptNo;
                            br.bankAccode   = CheRec.DepositBank;
                            br.ChequeNo     = CheRec.ChqNo;
                            br.ChequeDate   = CheRec.ChqDate;
                            br.Amount       = (double)CheRec.Amount;
                            br.Advance      = false;
                            br.Remarks      = CheRec.Remarks;
                            br.FinYear      = Session["FinYear"].ToString();
                            br.GLPost       = CheRec.GLPost;
                            br.BranchCode   = CheRec.BranchCode;
                            br.VoucherNo    = CheRec.VchrNo;
                            br.SubCode      = CheRec.SubCode;
                            br.bankCode     = CheRec.BankCode;
                            _bankReceiptService.Add(br);
                            _bankReceiptService.Save();

                            if (AdjBills != null)
                            {
                                decimal TotAmt = CheRec.Amount;
                                foreach (var bill in AdjBills)
                                {
                                    ChequeReceiptExt chqExt = new ChequeReceiptExt();
                                    var saleMain            = _salesMainService.All().Where(s => s.SaleNo == bill.BillNo).FirstOrDefault();
                                    chqExt.ChqReceiptID = _chequeReceiptService.All().LastOrDefault().ChqReceiptId;
                                    chqExt.BillNo       = bill.BillNo;
                                    chqExt.BillDate     = saleMain.SaleDate;
                                    if (TotAmt >= bill.BillAmount)
                                    {
                                        chqExt.BillAmount = bill.BillAmount;
                                        TotAmt            = TotAmt - bill.BillAmount;

                                        saleMain.ReceiptNo  = CheRec.ChqReceiptNo;
                                        saleMain.ReceiptAmt = bill.BillAmount;
                                        saleMain.IsPaid     = true;
                                        _salesMainService.Update(saleMain);
                                        _salesMainService.Save();

                                        _chqRecExtService.Add(chqExt);
                                        _chqRecExtService.Save();
                                    }
                                    else
                                    {
                                        if (bill.IsPaid_mre)
                                        {
                                            saleMain.IsPaid  = true;
                                            chqExt.AdjAmount = TotAmt;
                                        }
                                        else
                                        {
                                            saleMain.IsPaid  = false;
                                            chqExt.AdjAmount = TotAmt;
                                        }

                                        chqExt.BillAmount = TotAmt;
                                        _chqRecExtService.Add(chqExt);
                                        _chqRecExtService.Save();

                                        string sql = string.Format("select sm.ReceiptAmt, sm.SaleNo as BillNo, sm.SaleDate as BillDate, (sm.NetAmount - isnull(sum(cre.BillAmount),0)) as Billamount from SalesMain sm left join ChequeReceiptExt cre on cre.BillNo = sm.SaleNo where sm.CustCode = " + CheRec.SubCode + " and sm.IsPaid = 'false'  group by sm.ReceiptAmt, cre.BillNo, sm.NetAmount, sm.SaleNo, sm.SaleDate, cre.BillAmount order by sm.SaleNo");
                                        IEnumerable <billShow> BillLst;
                                        using (AcclineERPContext dbContext = new AcclineERPContext())
                                        {
                                            BillLst = dbContext.Database.SqlQuery <billShow>(sql).ToList();
                                        }
                                        foreach (var Salebill in BillLst)
                                        {
                                            if (Salebill.BillAmount == 0)
                                            {
                                                saleMain.ReceiptNo  = CheRec.ChqReceiptNo;
                                                saleMain.ReceiptAmt = ((Salebill.ReceiptAmt == null) ? 0 : Salebill.ReceiptAmt) + TotAmt;
                                                saleMain.IsPaid     = true;
                                                _salesMainService.Update(saleMain);
                                                _salesMainService.Save();
                                            }
                                        }
                                    }
                                }
                            }

                            TransactionLogService.SaveTransactionLog(_transactionLogService, "ChequeReceipt", "Save", CheRec.ChqReceiptNo, Session["UserName"].ToString());
                            transaction.Complete();
                            return(Json("1", JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json("2", JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        return(Json("3", JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception)
                {
                    transaction.Dispose();
                    return(Json("0", JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult SaveMROnline(MROnlineVM MrVM, List <MoneyReceiptExt> AdjBills)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());
                    if (!rUser.HasPermission("MoneyReceiptOnline_Insert"))
                    {
                        return(Json("X", JsonRequestBehavior.AllowGet));
                    }
                    var IfExit = _moneyReceiptService.All().Where(x => x.MRSL == MrVM.MRSL && x.MRNo == MrVM.MRNo).FirstOrDefault();
                    if (IfExit == null)
                    {
                        //var todayDate = DateTime.Now;
                        //CashReceipt CR = new CashReceipt();
                        BankReceipt  br = new BankReceipt();
                        MoneyReceipt MR = new MoneyReceipt();
                        MR.MRSL       = MrVM.MRSL;
                        MR.BranchCode = (MrVM.BranchCode == null) ? Session["BranchCode"].ToString() : MrVM.BranchCode;
                        MR.ProjCode   = (MrVM.ProjCode == null) ? Session["ProjCode"].ToString() : MrVM.ProjCode;
                        MR.MRNo       = MrVM.MRNo;
                        MR.MRDate     = MrVM.MRDate; //.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond);
                        MR.MRAgainst  = MrVM.MRAgainst;
                        MR.VchrNo     = MrVM.VchrNo;
                        MR.PayMode    = "Ca";
                        //MR.Posted = MrVM.Posted;
                        //MR.AdjWithBill = MrVM.AdjWithBill;
                        MR.MRAmount = MrVM.MRAmount;
                        MR.Accode   = MrVM.MRAgainst;
                        //if (MrVM.Accode == "0")
                        //{
                        //    MR.Accode = _defACService.All().ToList().FirstOrDefault().CashAc;
                        //}
                        MR.CustCode    = MrVM.CustCode;
                        MR.FinYear     = Session["FinYear"].ToString();
                        MR.Remarks     = MrVM.Remarks;
                        MR.JobNo       = MrVM.JobNo;
                        MR.CollectedBy = MrVM.CollectedBy;
                        MR.GetwayId    = MrVM.GetwayId;
                        MR.DepositBank = MrVM.DepositBank;
                        MR.EncashDate  = MrVM.DepositDate;

                        br.BReceiptNo   = MrVM.MRSL;
                        br.BReceiptDate = (DateTime)MrVM.MRDate;
                        br.purAccode    = MrVM.MRAgainst;
                        br.RefNo        = MrVM.MRNo;
                        br.bankAccode   = MrVM.DepositBank;
                        br.ChequeNo     = "Online";
                        br.ChequeDate   = DateTime.Now;
                        br.Amount       = (double)MrVM.MRAmount;
                        br.Advance      = false;
                        br.Remarks      = MrVM.Remarks;
                        br.FinYear      = Session["FinYear"].ToString();
                        br.GLPost       = false;
                        br.BranchCode   = (MrVM.BranchCode == null) ? Session["BranchCode"].ToString() : MrVM.BranchCode;
                        br.VoucherNo    = MrVM.VchrNo;
                        br.SubCode      = MrVM.CustCode;
                        br.bankCode     = MrVM.DepositBank;


                        //CR.ReceiptNo = MrVM.MRNo;
                        //CR.ReceiptDate = (DateTime)MrVM.MRDate;
                        //CR.purAccode = MrVM.MRAgainst;
                        ////if (MrVM.Accode == "0")
                        ////{
                        ////    CR.purAccode = _defACService.All().ToList().FirstOrDefault().CashAc;
                        ////}
                        //CR.RefNo = MrVM.MRSL;
                        //CR.Amount = (Double)MrVM.MRAmount;
                        //CR.Advance = false;
                        //CR.Remarks = MrVM.Remarks;
                        //CR.GLPost = false;
                        //CR.BranchCode = MrVM.BranchCode;
                        //CR.VoucherNo = MrVM.VchrNo;
                        //CR.JobNo = MrVM.JobNo;
                        //CR.FinYear = Session["FinYear"].ToString();
                        _moneyReceiptService.Add(MR);
                        //_CashReceiptService.Add(CR);
                        //_CashReceiptService.Save();
                        _bankReceiptService.Add(br);

                        _moneyReceiptService.Save();

                        _bankReceiptService.Save();


                        //List<MoneyReceiptExt> MRExtList = new List<MoneyReceiptExt>();

                        if (AdjBills != null)
                        {
                            decimal TotAmt = MrVM.MRAmount;
                            foreach (var bill in AdjBills)
                            {
                                MoneyReceiptExt MRExt    = new MoneyReceiptExt();
                                var             saleMain = _salesMainService.All().Where(s => s.SaleNo == bill.SaleNo).FirstOrDefault();
                                MRExt.MRId        = _moneyReceiptService.All().OrderBy(x => x.MRId).LastOrDefault().MRId;
                                MRExt.SaleNo      = bill.SaleNo;
                                MRExt.InstallNo   = _moneyReceiptExtService.All().OrderBy(s => s.InstallNo).Where(x => x.SaleNo == bill.SaleNo).Select(s => s.InstallNo).LastOrDefault();
                                MRExt.InstallNo   = MRExt.InstallNo + 1;
                                MRExt.InstallDate = DateTime.Now;
                                if (TotAmt >= bill.Amount)
                                {
                                    MRExt.Amount = bill.Amount;
                                    TotAmt       = TotAmt - bill.Amount;

                                    saleMain.ReceiptNo  = MrVM.MRNo;
                                    saleMain.ReceiptAmt = bill.Amount;
                                    saleMain.IsPaid     = true;
                                    _salesMainService.Update(saleMain);
                                    _salesMainService.Save();

                                    _moneyReceiptExtService.Add(MRExt);
                                    _moneyReceiptExtService.Save();
                                }
                                else
                                {
                                    if (bill.IsPaid_mre)
                                    {
                                        saleMain.IsPaid = true;
                                        MRExt.Amount    = TotAmt;
                                    }
                                    else
                                    {
                                        saleMain.IsPaid = false;
                                        MRExt.Amount    = TotAmt;
                                    }

                                    saleMain.ReceiptNo  = MrVM.MRNo;
                                    saleMain.ReceiptAmt = bill.Amount;
                                    //MRExt.Amount = TotAmt;
                                    _moneyReceiptExtService.Add(MRExt);
                                    _moneyReceiptExtService.Save();

                                    string sql = string.Format("select sm.ReceiptAmt,sm.SaleNo, sm.SaleDate, (sm.NetAmount - isnull(sum(mre.Amount),0)) as Billamount from SalesMain sm left join MoneyReceiptExt mre on mre.SaleNo = sm.SaleNo where sm.CustCode = " + MrVM.CustCode + " and sm.IsPaid = 'false'  group by sm.ReceiptAmt, mre.SaleNo, sm.NetAmount, sm.SaleNo, sm.SaleDate, mre.Amount order by sm.SaleNo");
                                    IEnumerable <billShow> BillLst;
                                    using (AcclineERPContext dbContext = new AcclineERPContext())
                                    {
                                        BillLst = dbContext.Database.SqlQuery <billShow>(sql).ToList();
                                    }
                                    foreach (var Salebill in BillLst)
                                    {
                                        if (Salebill.BillAmount == 0)
                                        {
                                            saleMain.ReceiptNo  = MrVM.MRNo;
                                            saleMain.ReceiptAmt = ((Salebill.ReceiptAmt == null) ? 0 : Salebill.ReceiptAmt) + TotAmt;
                                            saleMain.IsPaid     = true;
                                            _salesMainService.Update(saleMain);
                                            _salesMainService.Save();
                                        }
                                    }
                                }
                            }
                        }

                        //var GCa = _AcBrService.All().Where(s => s.BranchCode == MR.BranchCode && s.Ca_Ba == "Ba").Select(x => x.Accode).FirstOrDefault();
                        //if (GCa == null)
                        //{
                        //    var gset = _gsetService.All().LastOrDefault();
                        //    GCa = gset.GCa;
                        //}

                        TransactionLogService.SaveTransactionLog(_transactionLogService, "Online MR", "Save", MR.MRSL, Session["UserName"].ToString());

                        LoadDropDown.journalVoucherSave("BR", "I", MrVM.MRSL, MrVM.VchrNo, Session["FinYear"].ToString(), Session["ProjCode"].ToString(), Session["BranchCode"].ToString(), Convert.ToDateTime(MrVM.MRDate), MrVM.DepositBank, Session["UserName"].ToString());

                        transaction.Complete();
                        return(Json("1", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        transaction.Dispose();
                        return(Json("3", JsonRequestBehavior.AllowGet));
                    }
                }

                catch (Exception)
                {
                    transaction.Dispose();
                    return(Json("0", JsonRequestBehavior.AllowGet));
                }
            }
        }