Exemplo n.º 1
0
        public async Task <IActionResult> ConfirmAccount(FinancialAccountModel financialAccount)
        {
            var team = await _context.Teams.SingleOrDefaultAsync(m => m.Slug == TeamSlug && m.IsActive);

            if (team == null)
            {
                return(NotFound());
            }

            financialAccount.Chart      = financialAccount.Chart.SafeToUpper();
            financialAccount.Account    = financialAccount.Account.SafeToUpper();
            financialAccount.SubAccount = financialAccount.SubAccount.SafeToUpper();
            financialAccount.Project    = financialAccount.Project.SafeToUpper();

            if (!await _financialService.IsAccountValid(financialAccount.Chart, financialAccount.Account, financialAccount.SubAccount))
            {
                ModelState.AddModelError("Account", "Valid Account Not Found.");
            }

            if (!string.IsNullOrWhiteSpace(financialAccount.Project) && !await _financialService.IsProjectValid(financialAccount.Project))
            {
                ModelState.AddModelError("Project", "Project Not Valid.");
            }

            var accountLookup = new KfsAccount();

            if (ModelState.IsValid)
            {
                accountLookup = await _financialService.GetAccount(financialAccount.Chart, financialAccount.Account);

                if (!accountLookup.IsValidIncomeAccount)
                {
                    ModelState.AddModelError("Account", "Not An Income Account.");
                }
            }


            if (ModelState.IsValid)
            {
                //OK, it is valid, so lookup display values
                financialAccount.KfsAccount = accountLookup;
                if (!string.IsNullOrWhiteSpace(financialAccount.Project))
                {
                    financialAccount.KfsAccount.ProjectName = await _financialService.GetProjectName(financialAccount.Project);
                }

                if (!string.IsNullOrWhiteSpace(financialAccount.SubAccount))
                {
                    financialAccount.KfsAccount.SubAccountName = await _financialService.GetSubAccountName(financialAccount.Chart, financialAccount.Account, financialAccount.SubAccount);
                }

                financialAccount.Team = team;
                return(View(financialAccount));
            }

            financialAccount.Team = team;
            return(View("CreateAccount", financialAccount));
        }
Exemplo n.º 2
0
        public void SavePayment(int invoiceId, int vendorId, int accountId, decimal amount, DateTime date)
        {
            var payment = new VendorPayment()
            {
                VendorId = vendorId,
                PurchaseInvoiceHeaderId = invoiceId,
                Date   = date,
                Amount = amount,
            };
            var vendor   = GetVendorById(vendorId);
            var debit    = _financialService.CreateGeneralLedgerLine(DrOrCrSide.Dr, vendor.AccountsPayableAccountId.Value, amount);
            var credit   = _financialService.CreateGeneralLedgerLine(DrOrCrSide.Cr, accountId, amount);
            var glHeader = _financialService.CreateGeneralLedgerHeader(DocumentTypes.PurchaseInvoicePayment, date, string.Empty);

            glHeader.GeneralLedgerLines.Add(debit);
            glHeader.GeneralLedgerLines.Add(credit);

            if (_financialService.GetAccount(accountId).Balance < amount)
            {
                throw new Exception("Not enough balance.");
            }

            if (_financialService.ValidateGeneralLedgerEntry(glHeader))
            {
                payment.GeneralLedgerHeader = glHeader;
                payment.No = GetNextNumber(SequenceNumberTypes.VendorPayment).ToString();
                _vendorPaymentRepo.Insert(payment);
            }
        }
Exemplo n.º 3
0
        public IActionResult Account(int?id)
        {
            var o = _service.GetAccount(id ?? 0);

            if (o == null)
            {
                return(NotFound());
            }
            var model = o.ToModel2();

            return(Ok(model));
        }
Exemplo n.º 4
0
        public IActionResult Account(int id)
        {
            var account = _financialService.GetAccount(id);

            var accountDto = new Dto.Financial.Account()
            {
                Id              = account.Id,
                AccountClassId  = account.AccountClassId,
                ParentAccountId = account.ParentAccountId,
                CompanyId       = account.CompanyId,
                AccountCode     = account.AccountCode,
                AccountName     = account.AccountName,
                Description     = account.Description,
                IsCash          = account.IsCash,
                IsContraAccount = account.IsContraAccount,
                Balance         = account.Balance,
                DebitBalance    = account.DebitBalance,
                CreditBalance   = account.CreditBalance
            };

            return(new ObjectResult(accountDto));
        }