Esempio n. 1
0
        public IActionResult PostUnpostedVouchers([FromBody] IEnumerable <UnpostedVoucherViewModel> models)
        {
            IList <Voucher>         Vs  = new List <Voucher>();
            IList <UnpostedVoucher> UVs = new List <UnpostedVoucher>();

            IList <TransactionAccount> UpdateUALs           = new List <TransactionAccount>();
            IList <VoucherDetail>      updateVoucherDetails = new List <VoucherDetail>();

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

            foreach (UnpostedVoucherViewModel model in models)
            {
                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);
                V.PostedVoucherId = PV.PostedVoucherId;
                V.IsFinal         = true;

                foreach (VoucherDetail VD in model.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;
                Vs.Add(V);
                UVs.Add(UnpostedVou_repo.Find(model.UnpostedVoucherId));
            }

            Vou_repo.UpdateRange(Vs);
            UAL_Repo.UpdateRange(UpdateUALs);

            UnpostedVou_repo.DeleteRange(UVs);
            return(Ok("Posted"));
        }
Esempio n. 2
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"));
        }
Esempio n. 3
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 }));
        }