Пример #1
0
        public ActionResult UpdateBankReceipt(BankReceipt bankReceipt)
        {
            RBACUser rUser = new RBACUser(Session["UserName"].ToString());

            if (!rUser.HasPermission("BankReceipt_Update"))
            {
                return(Json("U", JsonRequestBehavior.AllowGet));
            }
            List <BankOperationVModel> CashOPVM = new List <BankOperationVModel>();
            var gset = _gsetService.All().LastOrDefault();

            try
            {
                bankReceipt.BranchCode   = Session["BranchCode"].ToString();
                bankReceipt.FinYear      = Session["FinYear"].ToString();
                bankReceipt.bankAccode   = Session["BankAccode"].ToString();
                bankReceipt.NewChart     = _NewChartService.All().ToList().FirstOrDefault(x => x.Accode == bankReceipt.purAccode.Trim());
                bankReceipt.bankNewChart = _NewChartService.All().ToList().FirstOrDefault(x => x.Accode == bankReceipt.bankAccode.Trim());

                using (var transaction = new TransactionScope())
                {
                    try
                    {
                        _BankReceiptAppService.Update(bankReceipt);
                        _BankReceiptAppService.Save();
                        //delete to provision
                        //var entryNo = Convert.ToInt64(bankReceipt.VoucherNo.Substring(2, 8)).ToString().PadLeft(8, '0');
                        var entryNo = bankReceipt.BReceiptNo;
                        LoadDropDown.journalVoucherRemoval("BR", entryNo, bankReceipt.VoucherNo, bankReceipt.FinYear);
                        var sysSet = _sysSetService.All().FirstOrDefault();
                        if (sysSet.CashRule == "O")
                        {
                            LoadDropDown.journalVoucherSave("BR", "I", bankReceipt.BReceiptNo, bankReceipt.VoucherNo, bankReceipt.FinYear, "01", bankReceipt.BranchCode, bankReceipt.BReceiptDate, bankReceipt.bankAccode, Session["UserName"].ToString());
                        }
                        //insert to provision
                        LoadDropDown.journalVoucherSave("BR", "I", bankReceipt.BReceiptNo, bankReceipt.VoucherNo, bankReceipt.FinYear, "01", bankReceipt.BranchCode, bankReceipt.BReceiptDate, bankReceipt.bankAccode, Session["UserName"].ToString());
                        TransactionLogService.SaveTransactionLog(_transactionLogService, "Bank Receipt", "Update", bankReceipt.BReceiptNo, User.Identity.Name);

                        CashOPVM = GetAllRemittances(bankReceipt.BReceiptDate, bankReceipt.BranchCode, bankReceipt.bankAccode);
                        transaction.Complete();
                    }
                    catch (Exception)
                    {
                        transaction.Dispose();
                    }
                }

                return(Json(CashOPVM, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json("0", JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult UpdateCheRec(ChequeReceipt CheRec)
        {
            RBACUser rUser = new RBACUser(Session["UserName"].ToString());

            if (!rUser.HasPermission("ChequeReceipt_Update"))
            {
                return(Json("U", JsonRequestBehavior.AllowGet));
            }
            using (var transaction = new TransactionScope())
            {
                try
                {
                    var VchrExist   = _vchrMainService.All().FirstOrDefault(s => s.VchrNo == CheRec.VchrNo);
                    var chqArcExist = _chequeArchiveService.All().ToList().Where(x => x.ChqNo == CheRec.oldChqNo).Select(s => s.ChqStatus).ToList();
                    if (chqArcExist.Contains("Receive") && CheRec.ChqStatus == "Receive" || chqArcExist.Contains("Receive") && CheRec.ChqStatus == "Deposit" || chqArcExist.Contains("Deposit") && CheRec.ChqStatus == "Encash" ||
                        chqArcExist.Contains("Encash") && CheRec.ChqStatus != "Dishonour" && CheRec.ChqStatus != "Return")
                    {
                        if (VchrExist == null)
                        {
                            ChequeReceipt cr = new ChequeReceipt();
                            cr            = CheRec;
                            cr.MRTing     = 0;
                            cr.MRTingTime = null;
                            cr.ProjCode   = Session["ProjCode"].ToString();
                            cr.FinYear    = Session["FinYear"].ToString();

                            _chequeReceiptService.Update(cr);
                            _chequeReceiptService.Save();

                            var chqArc = _chequeArchiveService.All().FirstOrDefault(s => s.ChqNo == CheRec.oldChqNo && s.ChqStatus == CheRec.ChqStatus);
                            if (chqArc != null && chqArc.ChqStatus == CheRec.ChqStatus)
                            {
                                chqArc.ChqNo      = CheRec.ChqNo;
                                chqArc.UpdateBy   = CheRec.UpdateBy;
                                chqArc.UpdateDate = CheRec.UpdateDate;
                                chqArc.Reason     = CheRec.Reason;
                                chqArc.Remarks    = CheRec.Remarks;
                                _chequeArchiveService.Update(chqArc);
                                _chequeArchiveService.Save();
                            }
                            else
                            {
                                ChequeArchive ca = new ChequeArchive();
                                ca.ChqStatus  = CheRec.ChqStatus;
                                ca.ChqNo      = CheRec.ChqNo;
                                ca.UpdateBy   = CheRec.UpdateBy;
                                ca.UpdateDate = CheRec.UpdateDate;
                                ca.Reason     = CheRec.Reason;
                                ca.Remarks    = CheRec.Remarks;
                                _chequeArchiveService.Add(ca);
                                _chequeArchiveService.Save();
                            }

                            BankReceipt br = _bankReceiptService.All().Where(s => s.RefNo == CheRec.ChqReceiptNo && s.ChequeNo == CheRec.ChqNo).FirstOrDefault();
                            if (CheRec.ChqStatus == "Deposit")
                            {
                                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.Update(br);
                                _bankReceiptService.Save();
                            }

                            var MoneyR = _moneyReceiptService.All().Where(s => s.MRNo == CheRec.ChqReceiptNo).FirstOrDefault();
                            //insert to provision and money receipt table
                            if (CheRec.ChqStatus == "Encash" && (MoneyR == null ? "000000" : MoneyR.MRNo) != CheRec.ChqReceiptNo)
                            {
                                MoneyReceipt MR = new MoneyReceipt();
                                MR.MRSL        = LoadDropDown.GenerateRecvSlNo(_moneyReceiptService, CheRec.BranchCode, Session["BranchCode"].ToString(), CheRec.ProjCode, Session["VchrConv"].ToString());
                                MR.BranchCode  = (CheRec.BranchCode == null) ? Session["BranchCode"].ToString() : CheRec.BranchCode;
                                MR.ProjCode    = (CheRec.ProjCode == null) ? Session["ProjCode"].ToString() : CheRec.ProjCode;
                                MR.MRNo        = CheRec.ChqReceiptNo;
                                MR.MRDate      = CheRec.ChqReceiptDate;
                                MR.MRAgainst   = CheRec.MRAgainst;
                                MR.VchrNo      = CheRec.VchrNo;
                                MR.PayMode     = "Cq";
                                MR.Posted      = CheRec.PostDated;
                                MR.AdjWithBill = CheRec.AdjWithBill;
                                MR.MRAmount    = CheRec.Amount;
                                MR.Accode      = CheRec.MRAgainst;
                                MR.CustCode    = CheRec.SubCode;
                                MR.FinYear     = Session["FinYear"].ToString();
                                MR.Remarks     = CheRec.Remarks;
                                MR.JobNo       = CheRec.JobNo;
                                MR.Ca_Bk       = CheRec.DepositBank;
                                MR.ChqNo       = CheRec.ChqNo;
                                MR.ChqDate     = CheRec.ChqDate;
                                MR.EncashDate  = CheRec.EncashDate;
                                MR.DepositBank = CheRec.DepositBank;
                                _moneyReceiptService.Add(MR);
                                _moneyReceiptService.Save();

                                var chqExt = _chqRecExtService.All().ToList().Where(s => s.ChqReceiptID == CheRec.ChqReceiptId);
                                foreach (var chqExtitem in chqExt)
                                {
                                    MoneyReceiptExt MRExt = new MoneyReceiptExt();
                                    MRExt.MRId   = _moneyReceiptService.All().OrderBy(s => s.MRId).LastOrDefault().MRId;
                                    MRExt.SaleNo = chqExtitem.BillNo;
                                    MRExt.Amount = chqExtitem.BillAmount;
                                    _moneyReceiptExtService.Add(MRExt);
                                    _moneyReceiptExtService.Save();
                                }
                                LoadDropDown.journalVoucherSave("BR", "I", br.BReceiptNo, CheRec.VchrNo, Session["FinYear"].ToString(), Session["ProjCode"].ToString(), CheRec.BranchCode, CheRec.ChqReceiptDate, CheRec.DepositBank, Session["UserName"].ToString());
                            }
                            ////update to provision
                            //LoadDropDown.journalVoucherRemoval("BR", CheRec.ChqReceiptNo, CheRec.VchrNo, Session["FinYear"].ToString());
                            //LoadDropDown.journalVoucherSave("BR", "I", CheRec.ChqReceiptNo, CheRec.VchrNo, Session["FinYear"].ToString(), Session["ProjCode"].ToString(), CheRec.BranchCode, CheRec.ChqReceiptDate, CheRec.DepositBank, Session["UserName"].ToString());
                            TransactionLogService.SaveTransactionLog(_transactionLogService, "ChequeReceipt", "Update", 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));
                }
            }
        }