Example #1
0
        public IActionResult PostUnpostedVoucher([FromBody] UnpostedVoucherViewModel model)
        {
            IList <TransactionAccount> UpdateUALs           = new List <TransactionAccount>();
            IList <VoucherDetail>      updateVoucherDetails = new List <VoucherDetail>();

            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
            };

            PostedVou_repo.Add(PV);

            Voucher V = Vou_repo.GetFirst(a => a.VoucherId == model.VoucherId, b => b.VoucherDetails);

            V.PostedVoucherId = PV.PostedVoucherId;
            V.IsFinal         = true;

            IEnumerable <TransactionAccount> UALs = UAL_Repo.GetAll();

            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);
            }
            ;
            V.VoucherDetails = updateVoucherDetails;
            Vou_repo.Update(V);
            UAL_Repo.UpdateRange(UpdateUALs);

            UnpostedVou_repo.Delete(UnpostedVou_repo.Find(model.UnpostedVoucherId));
            return(Ok("Posted"));
        }
Example #2
0
        public IEnumerable <UnpostedVoucherViewModel> GetUnpostedVouchersByCompany([FromRoute] long companyid)
        {
            IList <UnpostedVoucherViewModel> ViewModels = new List <UnpostedVoucherViewModel>();

            foreach (UnpostedVoucher UV in UnpostedVou_repo.GetList(a => a.CompanyId != null && a.CompanyId == companyid))
            {
                UnpostedVoucherViewModel UVVM = 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)
                };
                ViewModels.Add(UVVM);
            }
            return(ViewModels);
        }