Example #1
0
 public IActionResult DeleteUnpostedVoucher([FromRoute] long id)
 {
     try
     {
         UnpostedVoucher UV = UnpostedVou_repo.GetFirst(a => a.UnpostedVoucherId == id);
         Voucher         V  = Vou_repo.GetFirst(a => a.VoucherId == UV.VoucherId);
         if (V.IsFinal == true)
         {
             return(BadRequest("Posted Vouchers can't be deleted"));
         }
         UnpostedVou_repo.Delete(UV);
         VouDetail_repo.DeleteRange(VouDetail_repo.GetList(a => a.VoucherId == V.VoucherId));
         Vou_repo.Delete(V);
         return(Ok("Deleted"));
     }
     catch (NullReferenceException)
     {
         return(BadRequest("Invalid Voucher"));
     }
 }
Example #2
0
 public IActionResult GetUnpostedVoucher([FromRoute] long id)
 {
     try
     {
         UnpostedVoucher UV = UnpostedVou_repo.Find(id);
         return(Json(new UnpostedVoucherViewModel()
         {
             UnpostedVoucherId = UV.UnpostedVoucherId,
             VoucherId = UV.VoucherId,
             Date = UV.Date,
             Description = UV.Description,
             TotalCreditAmount = UV.TotalCreditAmount,
             TotalDebitAmount = UV.TotalDebitAmount,
             FinancialYear = FinancialYear_Repo.GetFirst(a => a.FinancialYearId == UV.FinancialYearId),
             VoucherType = VoucherType_Repo.GetFirst(a => a.VoucherTypeId == UV.VoucherTypeId),
             VoucherDetails = VouDetail_repo.GetList(a => a.VoucherId == UV.VoucherId, b => b.Account)
         }
                     ));
     }
     catch (NullReferenceException)
     {
         return(BadRequest("Invalid Id"));
     }
 }
Example #3
0
        public IActionResult UpdateUnpostedVoucher([FromBody] UnpostedVoucherViewModel model)
        {
            Voucher V = Vou_repo.GetFirst(a => a.VoucherId == model.VoucherId);

            V.Date              = model.Date;
            V.Description       = model.Description;
            V.TotalCreditAmount = model.TotalCreditAmount;
            V.TotalDebitAmount  = model.TotalDebitAmount;
            V.IsFinal           = model.Posted;
            V.FinancialYearId   = model.FinancialYearId;
            V.VoucherType       = model.VoucherType;
            VouDetail_repo.DeleteRange(VouDetail_repo.GetList(a => a.VoucherId == V.VoucherId));
            V.VoucherDetails = model.VoucherDetails;

            UnpostedVoucher UV = UnpostedVou_repo.GetFirst(a => a.VoucherId == model.VoucherId && a.UnpostedVoucherId == model.UnpostedVoucherId);

            V.UnpostedVoucherId = UV.UnpostedVoucherId;

            if (model.Posted == true)
            {
                PostedVoucher PV = new PostedVoucher()
                {
                    VoucherId         = UV.VoucherId,
                    VoucherCode       = UV.VoucherCode,
                    Date              = model.Date,
                    Description       = model.Description,
                    TotalCreditAmount = model.TotalCreditAmount,
                    TotalDebitAmount  = model.TotalDebitAmount,
                    FinancialYearId   = model.FinancialYearId,
                    VoucherTypeId     = model.VoucherTypeId,
                    CreatedAt         = DateTime.Now
                };

                PostedVou_repo.Add(PV);
                V.IsFinal         = true;
                V.PostedVoucherId = PV.PostedVoucherId;

                IEnumerable <TransactionAccount> UALs                 = UAL_Repo.GetAll();
                IList <TransactionAccount>       UpdateUALs           = new List <TransactionAccount>();
                IList <VoucherDetail>            updateVoucherDetails = new List <VoucherDetail>();

                foreach (VoucherDetail VD in V.VoucherDetails)
                {
                    TransactionAccount UL = UALs.FirstOrDefault(a => a.AccountId == VD.AccountId);
                    VD.AccountBalanceAmountBeforePosting    = UL.CurrentBalance;
                    UL.TotalTransactionsAgainstThisAccount += 1;
                    UL.TotalDebit    += VD.DebitAmount;
                    UL.TotalCredit   += VD.CreditAmount;
                    UL.CurrentBalance = UL.CurrentBalance - VD.DebitAmount + VD.CreditAmount;
                    VD.AccountBalanceAmountAfterPosting = UL.CurrentBalance;

                    UpdateUALs.Add(UL);
                    updateVoucherDetails.Add(VD);
                }
                ;
                UAL_Repo.UpdateRange(UpdateUALs);
                UnpostedVou_repo.Delete(UV);

                V.VoucherDetails = updateVoucherDetails;
            }
            else if (model.Posted == false)
            {
                UV.Date              = model.Date;
                UV.Description       = model.Description;
                UV.TotalDebitAmount  = model.TotalDebitAmount;
                UV.TotalCreditAmount = model.TotalCreditAmount;
                UV.FinancialYearId   = model.FinancialYearId;
                UV.VoucherTypeId     = model.VoucherTypeId;

                UnpostedVou_repo.Update(UV);
                V.UnpostedVoucherId = UV.UnpostedVoucherId;
                V.IsFinal           = false;
            }

            Vou_repo.Update(V);
            return(Ok("Updated"));
        }
Example #4
0
        public IActionResult AddVoucher([FromBody] Voucher model)
        {
            Vou_repo.Add(model);
            if (model.IsFinal == true)
            {
                PostedVoucher PV = new PostedVoucher()
                {
                    CompanyId         = model.CompanyId,
                    VoucherId         = model.VoucherId,
                    VoucherCode       = model.VoucherCode,
                    Date              = model.Date,
                    Description       = model.Description,
                    TotalCreditAmount = model.TotalCreditAmount,
                    TotalDebitAmount  = model.TotalDebitAmount,
                    FinancialYearId   = model.FinancialYearId,
                    VoucherTypeId     = model.VoucherTypeId,
                    CreatedAt         = DateTime.Now
                };

                IEnumerable <TransactionAccount> UALs                 = UAL_Repo.GetAll();
                IList <TransactionAccount>       UpdateUALs           = new List <TransactionAccount>();
                IList <VoucherDetail>            UpdateVoucherDetails = new List <VoucherDetail>();

                foreach (VoucherDetail VD in model.VoucherDetails)
                {
                    TransactionAccount UL = UALs.FirstOrDefault(a => a.AccountId == VD.AccountId);
                    VD.AccountBalanceAmountBeforePosting = UL.CurrentBalance;
                    UL.TotalDebit    += VD.DebitAmount;
                    UL.TotalCredit   += VD.CreditAmount;
                    UL.CurrentBalance = UL.CurrentBalance - VD.DebitAmount + VD.CreditAmount;
                    VD.AccountBalanceAmountAfterPosting = UL.CurrentBalance;

                    UpdateUALs.Add(UL);
                    UpdateVoucherDetails.Add(VD);
                }

                UAL_Repo.UpdateRange(UpdateUALs);

                PostedVou_repo.Add(PV);
                model.PostedVoucherId = PV.PostedVoucherId;
                model.VoucherDetails  = UpdateVoucherDetails;
            }
            else if (model.IsFinal == false || model.IsFinal == null)
            {
                UnpostedVoucher UV = new UnpostedVoucher()
                {
                    CompanyId         = model.CompanyId,
                    VoucherId         = model.VoucherId,
                    VoucherCode       = model.VoucherCode,
                    Date              = model.Date,
                    Description       = model.Description,
                    TotalCreditAmount = model.TotalCreditAmount,
                    TotalDebitAmount  = model.TotalDebitAmount,
                    FinancialYearId   = model.FinancialYearId,
                    VoucherTypeId     = model.VoucherTypeId
                };

                UnpostedVou_repo.Add(UV);
                model.UnpostedVoucherId = UV.UnpostedVoucherId;
            }
            Vou_repo.Update(model);
            return(new OkObjectResult(new { VoucherID = model.VoucherId }));
        }