コード例 #1
0
        public ActionResult GetAdjBills(string CustCode, string MRAgainst, decimal Amount, string isEdit)
        {
            var    Bills = default(dynamic);
            string sql   = "";
            string MrAg  = LoadDropDown.GetMrAgainstType(MRAgainst);

            if (MrAg == null)
            {
                MrAg = MRAgainst;              //temporary Ashik
            }
            if (MrAg == "Sales")
            {
                if (isEdit == "1")
                {
                    Bills = (from mr in _moneyReceiptService.All().ToList()
                             join mre in _moneyReceiptExtService.All().ToList() on mr.MRId equals mre.MRId
                             where mr.CustCode == CustCode
                             select new
                    {
                        SaleNo = mre.SaleNo,
                        SaleDate = mr.MRDate,
                        BillAmount = mre.Amount,
                        IsPaid = true
                    }).ToList();
                }
                else if (isEdit == "ChqEdit")
                {
                    sql = string.Format("select sm.IsPaid, sm.NetAmount as Billamount,  sm.SaleNo, sm.SaleDate , (sm.NetAmount - isnull(sum(cre.BillAmount),0)) as Billamt from SalesMain sm left join ChequeReceiptExt cre on cre.BillNo = sm.SaleNo  where sm.CustCode = " + CustCode + "   group by sm.IsPaid, cre.BillNo, sm.NetAmount, sm.SaleNo, sm.SaleDate order by sm.SaleNo ");
                    //sql = string.Format("select sm.IsPaid, sm.NetAmount as Billamount,  sm.SaleNo, sm.SaleDate , (sm.NetAmount - isnull(sum(cre.BillAmount),0)) as Billamt from SalesMain sm left join ChequeReceiptExt cre on cre.BillNo = sm.SaleNo  where sm.CustCode = " + CustCode + " and sm.Ispaid = 'true' and Billamt = 0 group by sm.IsPaid, 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();
                        Bills   = BillLst;
                    }
                }
                else
                {
                    //decimal MrExtAmt = 0;
                    //Bills = (from sm in _salesMainService.All().ToList()
                    //         join mre in _moneyReceiptExtService.All().ToList() on sm.SaleNo equals mre.SaleNo into SmMre
                    //         from leftJ in SmMre.DefaultIfEmpty()
                    //         where sm.CustCode == CustCode && sm.IsPaid == false
                    //         //group leftJ by leftJ.SaleNo into G
                    //         select new
                    //         {
                    //             SaleNo = sm.SaleNo,
                    //             SaleDate = sm.SaleDate,
                    //             BillAmount = sm.NetAmount - (MrExtAmt = (leftJ == null) ? 0 : leftJ.Amount)
                    //         }).GroupBy(x => x.SaleNo).ToList();

                    sql = string.Format("select sm.SaleNo, sm.SaleDate, (sm.NetAmount - (select isnull(sum(mre.Amount),0) as Billamount from MoneyReceiptExt mre where SaleNo = sm.SaleNo)) as Billamount from SalesMain sm  where sm.CustCode = " + CustCode + " and sm.IsPaid = 'false'  group by sm.NetAmount, sm.SaleNo, sm.SaleDate order by sm.SaleNo  ");
                    IEnumerable <billShow> BillLst;
                    using (AcclineERPContext dbContext = new AcclineERPContext())
                    {
                        BillLst = dbContext.Database.SqlQuery <billShow>(sql).ToList();
                        Bills   = BillLst;
                    }
                }
            }
            //else if (true)
            //{

            //}

            return(Json(new { data = Bills }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        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));
                }
            }
        }