public ActionResult DeleteTransfer(int id)
        {
            try
            {
                AccountListVsAmountTransfer TransferDetails = db.AccountListVsAmountTransfer.Where(s => s.AccountListVsAmountTransferID == id).FirstOrDefault();

                var FromAccountForAmountChange = db.AccountList.Where(s => s.AccountListID == TransferDetails.FromAccountID).FirstOrDefault();
                var ToAccountForAmountChange   = db.AccountList.Where(s => s.AccountListID == TransferDetails.ToAccountID).FirstOrDefault();
                if (ToAccountForAmountChange.InitialBalance < TransferDetails.Amount)
                {
                    return(Json(new { success = false, message = "Sorry Balance is not avialable for transfer." }, JsonRequestBehavior.AllowGet));
                }

                TransferDetails.DeleteBy   = AppUtils.LoginUserID;
                TransferDetails.DeleteDate = AppUtils.GetDateNow();
                TransferDetails.Status     = AppUtils.TableStatusIsDelete;
                FromAccountForAmountChange.InitialBalance = FromAccountForAmountChange.InitialBalance + TransferDetails.Amount;
                ToAccountForAmountChange.InitialBalance   = ToAccountForAmountChange.InitialBalance - TransferDetails.Amount;


                db.Entry(TransferDetails).State            = System.Data.Entity.EntityState.Modified;
                db.Entry(FromAccountForAmountChange).State = System.Data.Entity.EntityState.Modified;
                db.Entry(ToAccountForAmountChange).State   = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                TempData["message"] = "Information Removed Successfully";
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = "Error occourd. Please contact with adminstrator." }, JsonRequestBehavior.AllowGet));
            }
        }
        private void SetTransferInformationDuringUpdate(ref AccountListVsAmountTransfer dbTransferDetails, ref AccountList fromAccountForAmountChange, ref AccountList toAccountForAmountChange, AccountListVsAmountTransfer accountlistvsamounttransferdetails)
        {
            //dbTransferDetails.AccountListID = accountlistvsamounttransferdetails.AccountListID;
            //dbTransferDetails.ToAccountID = accountlistvsamounttransferdetails.ToAccountID;
            dbTransferDetails.TransferDate = accountlistvsamounttransferdetails.TransferDate;
            dbTransferDetails.Description  = accountlistvsamounttransferdetails.Description;
            dbTransferDetails.PaymentByID  = accountlistvsamounttransferdetails.PaymentByID;
            dbTransferDetails.References   = accountlistvsamounttransferdetails.References;
            dbTransferDetails.UpdateBy     = AppUtils.GetLoginUserID();
            dbTransferDetails.UpdateDate   = AppUtils.GetDateNow();
            //if (dbTransferDetails.Amount > accountlistvsamounttransferdetails.Amount)
            //{
            //    var ReducedAmount = dbTransferDetails.Amount - accountlistvsamounttransferdetails.Amount;
            //    FromAccountForAmountChange.InitialBalance = FromAccountForAmountChange.InitialBalance + ReducedAmount;
            //    ToAccountForAmountChange.InitialBalance = ToAccountForAmountChange.InitialBalance - ReducedAmount;
            //}
            //else if (dbTransferDetails.Amount < accountlistvsamounttransferdetails.Amount)
            //{
            //    var AdditionalAmount = dbTransferDetails.Amount - accountlistvsamounttransferdetails.Amount;
            //    FromAccountForAmountChange.InitialBalance = FromAccountForAmountChange.InitialBalance - AdditionalAmount;
            //    ToAccountForAmountChange.InitialBalance = ToAccountForAmountChange.InitialBalance + AdditionalAmount;
            //}

            //dbTransferDetails.Amount = accountlistvsamounttransferdetails.Amount;
        }
        private void SetInOutDateDuringCreate(ref AccountListVsAmountTransfer accountListVsAmountTransferIn, ref AccountListVsAmountTransfer accountListVsAmountTransferOut, AccountListVsAmountTransfer cl)
        {
            accountListVsAmountTransferIn.BreakDownAccountListID = cl.AccountListVsAmountTransferID;
            accountListVsAmountTransferIn.TransferType           = "In";
            accountListVsAmountTransferIn.Amount       = cl.Amount;
            accountListVsAmountTransferIn.CreateBy     = cl.CreateBy;
            accountListVsAmountTransferIn.CreateDate   = cl.CreateDate;
            accountListVsAmountTransferIn.CurrencyID   = cl.CurrencyID;
            accountListVsAmountTransferIn.Description  = cl.Description;
            accountListVsAmountTransferIn.ToAccountID  = cl.ToAccountID;
            accountListVsAmountTransferIn.PaymentByID  = cl.PaymentByID;
            accountListVsAmountTransferIn.References   = cl.References;
            accountListVsAmountTransferIn.Status       = cl.Status;
            accountListVsAmountTransferIn.Tags         = cl.Tags;
            accountListVsAmountTransferIn.TransferDate = cl.TransferDate;


            accountListVsAmountTransferOut.BreakDownAccountListID = cl.AccountListVsAmountTransferID;
            accountListVsAmountTransferOut.TransferType           = "Out";
            accountListVsAmountTransferOut.Amount        = cl.Amount;
            accountListVsAmountTransferOut.CreateBy      = cl.CreateBy;
            accountListVsAmountTransferOut.CreateDate    = cl.CreateDate;
            accountListVsAmountTransferOut.CurrencyID    = cl.CurrencyID;
            accountListVsAmountTransferOut.Description   = cl.Description;
            accountListVsAmountTransferOut.FromAccountID = cl.FromAccountID;
            accountListVsAmountTransferOut.PaymentByID   = cl.PaymentByID;
            accountListVsAmountTransferOut.References    = cl.References;
            accountListVsAmountTransferOut.Status        = cl.Status;
            accountListVsAmountTransferOut.Tags          = cl.Tags;
            accountListVsAmountTransferOut.TransferDate  = cl.TransferDate;
        }
Beispiel #4
0
        private string GetButtonForTransfer(AccountListVsAmountTransfer transfer)
        {
            AccountListVsAmountTransfer accountListVsAmount = new AccountListVsAmountTransfer();


            if (transfer.FromAccountID != 0)
            {
                accountListVsAmount = db.AccountListVsAmountTransfer.Where(x => x.Description == transfer.Description && x.TransferDate == transfer.TransferDate && x.Amount == transfer.Amount && x.References == transfer.References && x.FromAccountID == transfer.FromAccountID).FirstOrDefault();
            }
            if (transfer.ToAccountID != 0)
            {
                accountListVsAmount = db.AccountListVsAmountTransfer.Where(x => x.Description == transfer.Description && x.TransferDate == transfer.TransferDate && x.Amount == transfer.Amount && x.References == transfer.References && x.ToAccountID == transfer.ToAccountID).FirstOrDefault();
            }

            string s = "<a class='glyphicon glyphicon-edit btn-circle btn-default' href='/AccountListVsAmountTransfer/Manage?id=" + accountListVsAmount.AccountListVsAmountTransferID + "'></a>";

            return(s);
        }
        public ActionResult UpdateAccountListVsAmountTransfer(AccountListVsAmountTransfer accountlistvsamounttransferdetails)
        {
            try
            {
                AccountListVsAmountTransfer dbTransferDetails = db.AccountListVsAmountTransfer.Where(s => s.AccountListVsAmountTransferID == accountlistvsamounttransferdetails.AccountListVsAmountTransferID).FirstOrDefault();

                var FromAccountForAmountChange = db.AccountList.Where(s => s.AccountListID == accountlistvsamounttransferdetails.FromAccountID).FirstOrDefault();
                var ToAccountForAmountChange   = db.AccountList.Where(s => s.AccountListID == accountlistvsamounttransferdetails.ToAccountID).FirstOrDefault();

                SetTransferInformationDuringUpdate(ref dbTransferDetails, ref FromAccountForAmountChange, ref ToAccountForAmountChange, accountlistvsamounttransferdetails);

                db.Entry(dbTransferDetails).State = System.Data.Entity.EntityState.Modified;
                //db.Entry(FromAccountForAmountChange).State = System.Data.Entity.EntityState.Modified;
                //db.Entry(ToAccountForAmountChange).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult InsertAccountListVsAmountTransfer(AccountListVsAmountTransfer AccountListVsAmountTransferDetails)
        {
            try
            {
                AccountListVsAmountTransferDetails.CreateBy   = AppUtils.GetLoginUserID();
                AccountListVsAmountTransferDetails.CreateDate = AppUtils.GetDateTimeNow();
                AccountListVsAmountTransferDetails.Status     = AppUtils.TableStatusIsActive;
                AccountListVsAmountTransferDetails.CurrencyID = 1;

                var FromAccountForAmountChange = db.AccountList.Where(s => s.AccountListID == AccountListVsAmountTransferDetails.FromAccountID).FirstOrDefault();
                var ToAccountForAmountChange   = db.AccountList.Where(s => s.AccountListID == AccountListVsAmountTransferDetails.ToAccountID).FirstOrDefault();

                FromAccountForAmountChange.InitialBalance = (FromAccountForAmountChange.InitialBalance - AccountListVsAmountTransferDetails.Amount);
                ToAccountForAmountChange.InitialBalance   = (ToAccountForAmountChange.InitialBalance + AccountListVsAmountTransferDetails.Amount);

                db.Entry(FromAccountForAmountChange).State = System.Data.Entity.EntityState.Modified;
                db.Entry(ToAccountForAmountChange).State   = System.Data.Entity.EntityState.Modified;
                db.AccountListVsAmountTransfer.Add(AccountListVsAmountTransferDetails);
                db.SaveChanges();

                if (AccountListVsAmountTransferDetails.AccountListVsAmountTransferID > 0)
                {
                    AccountListVsAmountTransfer AccountListVsAmountTransferIn  = new AccountListVsAmountTransfer();
                    AccountListVsAmountTransfer AccountListVsAmountTransferOut = new AccountListVsAmountTransfer();
                    SetInOutDateDuringCreate(ref AccountListVsAmountTransferIn, ref AccountListVsAmountTransferOut, AccountListVsAmountTransferDetails);
                    db.AccountListVsAmountTransfer.Add(AccountListVsAmountTransferIn);
                    db.AccountListVsAmountTransfer.Add(AccountListVsAmountTransferOut);
                    db.SaveChanges();
                }

                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }