Beispiel #1
0
        private Result PostCashOnHand()
        {
            // post cash on hand credit side
            var member      = Nfmb.FindByCode(_accountDetail.MemberCode);
            var accountCode = GlobalSettings.CodeOfCashOnHand;

            if (string.IsNullOrWhiteSpace(accountCode))
            {
                return(new Result(false, GenerateCodeOfAccountNotSetMessage("Cash on Hand")));
            }
            var account = Account.FindByCode(accountCode);
            var amount  = _accountDetail.EndingBalance +
                          _accountDetail.TimeDepositDetails.CalculateInterestEarned(_voucherDocument.VoucherDate) -
                          _accountDetail.TimeDepositDetails.CalculateServiceFee(_voucherDocument.VoucherDate);
            var cv = new CashVoucher
            {
                MemberCode    = member.MemberCode,
                MemberName    = member.MemberName,
                AccountCode   = account.AccountCode,
                AccountTitle  = account.AccountTitle,
                Credit        = amount,
                VoucherDate   = _voucherDocument.VoucherDate,
                VoucherNo     = _voucherDocument.VoucherNo,
                Explanation   = "Withdrawal of Time Deposit",
                AmountInWords = Converter.AmountToWords(amount),
            };

            var postResult = cv.Create();

            if (!postResult.Success)
            {
                Rollback();
            }
            return(postResult);
        }
Beispiel #2
0
        private void btnAmountInWords_Click(object sender, RoutedEventArgs e)
        {
            if (_currentItems.Count <= 0)
            {
                return;
            }

            if (!CanModify)
            {
                MessageWindow.AlertRecordIsLocked();
                return;
            }

            foreach (CashVoucher currentItem in _currentItems)
            {
                currentItem.Amount        = 0;
                currentItem.AmountInWords = string.Empty;
            }

            var currentRecord = (CashVoucher)dgTransactionDetails.SelectedItem;

            if (currentRecord == null)
            {
                return;
            }

            currentRecord.Amount        = currentRecord.Debit + currentRecord.Credit;
            currentRecord.AmountInWords = Converter.AmountToWords(currentRecord.Amount);
        }
Beispiel #3
0
        private void UpdateTotalAmount()
        {
            TotalAmount = CreditAmount01 +
                          CreditAmount02 +
                          CreditAmount03 +
                          CreditAmount04 +
                          CreditAmount05 +
                          CreditAmount06 +
                          CreditAmount07 +
                          CreditAmount08 +
                          CreditAmount09 +
                          CreditAmount10 +
                          CreditAmount11 +
                          CreditAmount12;

            AmountInWords = Converter.AmountToWords(TotalAmount);
        }
        private void btnPost_Click(object sender, EventArgs e)
        {
            var collection = OfficialReceipt.WhereDocumentNumberIs(_officialReceipt.VoucherNo);

            if (collection.Count > 0)
            {
                MessageWindow.ShowAlertMessage("OR No. already in use.");
                return;
            }
            try
            {
                _officialReceipt.Collector = MainController.LoggedUser.CollectorName;
                _officialReceipt.IsPosted  = true;
                _officialReceipt.Create();

                // cash on hand
                var or = new OfficialReceipt
                {
                    MemberCode = _officialReceipt.MemberCode, MemberName = _officialReceipt.MemberName
                };

                var coh = Account.FindByCode(GlobalSettings.CodeOfCashOnHand);
                or.AccountCode  = coh.AccountCode;
                or.AccountTitle = coh.AccountTitle;

                // insert denomination details
                or.Debit = _officialReceipt.Credit;

                if (_denomonation != null)
                {
                    #region --- Cash CashAndCheckBreakDown ---

                    //JEA: Since deno09 is not available (0.50), I use it as lieu to 200
                    or.Deno01 = _denomonation.Deno01; //1000
                    or.Deno02 = _denomonation.Deno02; //500
                    or.Deno03 = _denomonation.Deno03; //100
                    or.Deno04 = _denomonation.Deno04; //50
                    or.Deno05 = _denomonation.Deno05; //20
                    or.Deno06 = _denomonation.Deno06; //10
                    or.Deno07 = _denomonation.Deno07; //5
                    or.Deno08 = _denomonation.Deno08; //1
                    or.Deno09 = _denomonation.Deno09; //.5 -> 200
                    or.Deno10 = _denomonation.Deno10; //.25

                    #endregion --- Cash CashAndCheckBreakDown ---

                    #region --- Check CashAndCheckBreakDown ---

                    or.BankName1   = _denomonation.BankName1;
                    or.BankDate1   = _denomonation.BankDate1;
                    or.BankCheck1  = _denomonation.BankCheck1;
                    or.BankAmount1 = _denomonation.BankAmount1;

                    or.BankName2   = _denomonation.BankName2;
                    or.BankDate2   = _denomonation.BankDate2;
                    or.BankCheck2  = _denomonation.BankCheck2;
                    or.BankAmount2 = _denomonation.BankAmount2;

                    or.BankName3   = _denomonation.BankName3;
                    or.BankDate3   = _denomonation.BankDate3;
                    or.BankCheck3  = _denomonation.BankCheck3;
                    or.BankAmount3 = _denomonation.BankAmount3;

                    or.BankName4   = _denomonation.BankName4;
                    or.BankDate4   = _denomonation.BankDate4;
                    or.BankCheck4  = _denomonation.BankCheck4;
                    or.BankAmount4 = _denomonation.BankAmount4;

                    or.BankName5   = _denomonation.BankName5;
                    or.BankDate5   = _denomonation.BankDate5;
                    or.BankCheck5  = _denomonation.BankCheck5;
                    or.BankAmount5 = _denomonation.BankAmount5;

                    #endregion
                }

                or.AmountInWords = Converter.AmountToWords(_officialReceipt.Credit);
                or.Amount        = _officialReceipt.Credit;

                or.VoucherDate = _officialReceipt.VoucherDate;
                or.VoucherNo   = _officialReceipt.VoucherNo;
                or.VoucherType = VoucherTypes.OR;

                or.Collector = MainController.LoggedUser.CollectorName;
                or.IsPosted  = true;

                or.Create();

                #region --- Voucher Log ---

                var voucherLog = new VoucherLog();
                voucherLog.Find("OR", _officialReceipt.VoucherNo);
                voucherLog.Date     = _officialReceipt.VoucherDate;
                voucherLog.Initials = MainController.LoggedUser.Initials;
                if (_denomonation != null && _denomonation.HasCheckDeposit)
                {
                    voucherLog.Remarks = "CHK";
                }

                voucherLog.Save();

                #endregion

                MessageWindow.ShowNotifyMessage("Transaction posted! Printing validation...");
                DialogResult = true;
                Close();
            }
            catch (Exception exception)
            {
                MessageWindow.ShowAlertMessage(exception.Message);
            }
        }
Beispiel #5
0
        private Result PostToVoucher()
        {
            var postingDetails = new LoanPostingDetails
            {
                VoucherType = VoucherTypes.CV,
                VoucherDate = GlobalSettings.DateOfOpenTransaction
            };

            postingDetails.VoucherNumber = Voucher.LastDocumentNo(postingDetails.VoucherType) + 1;

            postingDetails.ReleaseNumber = ModelController.Releases.MaxReleaseNumber() + 1;
            postingDetails.ReleaseDate   = postingDetails.VoucherDate;

            // 1. ask user to enter voucher information
            var postingWindow = new LoanPostingWindow(postingDetails);

            if (postingWindow.ShowDialog() != true)
            {
                return(new Result(false, "Posting was cancelled by user."));
            }

            // 1.1 Must be open transaction
            if (postingDetails.VoucherDate != GlobalSettings.DateOfOpenTransaction)
            {
                return(new Result(false, "Voucher date is locked!"));
            }
            if (postingDetails.VoucherDate != MainController.LoggedUser.TransactionDate)
            {
                return(new Result(false, "Transaction Date is not valid or not set!"));
            }

            // 2. inform user if voucher information already exist, ask if to overwrite

            if (postingDetails.VoucherType == VoucherTypes.CV)
            {
                ObservableCollection <CashVoucher> cvEntries =
                    CashVoucher.WhereDocumentNumberIs(postingDetails.VoucherNumber);
                if (cvEntries.Count > 0)
                {
                    return(new Result(false, string.Format("{0} #{1} already exist!", postingDetails.VoucherType,
                                                           postingDetails.VoucherNumber)));
                }
            }

            if (postingDetails.VoucherType == VoucherTypes.JV)
            {
                ObservableCollection <JournalVoucher> jvEntries =
                    JournalVoucher.WhereDocumentNumberIs(postingDetails.VoucherNumber);
                if (jvEntries.Count > 0)
                {
                    return(new Result(false, string.Format("{0} #{1} already exist!", postingDetails.VoucherType,
                                                           postingDetails.VoucherNumber)));
                }
            }

            // 3. post transaction details

            _loanDetails.ReleaseNo    = postingDetails.ReleaseNumber;
            _loanDetails.DateReleased = postingDetails.ReleaseDate;

            //TODO: Loan Application Information
            //loanDetails.ThisMonth
            //loanDetails.DateApplied = _loanDetail.DateGranted;
            //loanDetails.DateApproved
            //loanDetails.DateCancelled;
            //loanDetails.DateReleased


            // net proceeds
            var netProceeds = new ComputationDetail
            {
                AccountCode  = _loanComputation.NetProceedsCode,
                AccountTitle = _loanComputation.NetProceedsTitle,
                Amount       = _loanComputation.NetProceedsAmount
            };

            if (postingDetails.VoucherType == VoucherTypes.JV)
            {
                #region --- Add entry for Cash On Hand ---

                var net = new JournalVoucher
                {
                    MemberCode   = _loanDetails.MemberCode,
                    MemberName   = _loanDetails.MemberName,
                    AccountCode  = netProceeds.AccountCode,
                    AccountTitle = netProceeds.AccountTitle,
                    Credit       = netProceeds.Amount,
                    VoucherDate  = postingDetails.VoucherDate,
                    VoucherNo    = postingDetails.VoucherNumber,
                };
                net.Amount        = net.Credit;
                net.AmountInWords = Converter.AmountToWords(net.Amount);
                Result postResult = net.Create();
                if (!postResult.Success)
                {
                    JournalVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Add entries for Charges ---

                foreach (ComputationDetail computationDetail in _loanComputation.Charges)
                {
                    if (string.IsNullOrEmpty(computationDetail.AccountCode) || computationDetail.Amount == 0)
                    {
                        continue;
                    }
                    var charges = new JournalVoucher
                    {
                        MemberCode   = _loanDetails.MemberCode,
                        MemberName   = _loanDetails.MemberName,
                        AccountCode  = computationDetail.AccountCode,
                        AccountTitle = computationDetail.AccountTitle,
                        Credit       = computationDetail.Amount,
                        VoucherDate  = postingDetails.VoucherDate,
                        VoucherNo    = postingDetails.VoucherNumber
                    };
                    postResult = charges.Create();
                    if (postResult.Success)
                    {
                        continue;
                    }
                    JournalVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Add entries for Deductions ---

                foreach (ComputationDetail computationDetail in _loanComputation.Deductions)
                {
                    if (string.IsNullOrEmpty(computationDetail.AccountCode) || computationDetail.Amount == 0)
                    {
                        continue;
                    }
                    var deductions = new JournalVoucher
                    {
                        MemberCode   = _loanDetails.MemberCode,
                        MemberName   = _loanDetails.MemberName,
                        AccountCode  = computationDetail.AccountCode,
                        AccountTitle = computationDetail.AccountTitle,
                        Credit       = computationDetail.Amount,
                        VoucherDate  = postingDetails.VoucherDate,
                        VoucherNo    = postingDetails.VoucherNumber
                    };
                    postResult = deductions.Create();
                    if (postResult.Success)
                    {
                        continue;
                    }
                    JournalVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Add entry for Unearned Income ---

                Account ui             = Account.FindByCode(GlobalSettings.CodeOfUnearnedIncome);
                var     unearnedIncome = new JournalVoucher
                {
                    MemberCode   = _loanDetails.MemberCode,
                    MemberName   = _loanDetails.MemberName,
                    AccountCode  = ui.AccountCode,
                    AccountTitle = ui.AccountTitle,
                    Credit       = _loanAmortizationHeader.PaymentSchedules.Sum(sched => sched.Interest),
                    VoucherDate  = postingDetails.VoucherDate,
                    VoucherNo    = postingDetails.VoucherNumber
                };

                postResult = unearnedIncome.Create();
                if (!postResult.Success)
                {
                    JournalVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Add entry for Capital Build-Up ---

                Account cbu            = Account.FindByCode(GlobalSettings.CodeOfCapitalBuildUp);
                var     capitalBuildUp = new JournalVoucher
                {
                    MemberCode   = _loanDetails.MemberCode,
                    MemberName   = _loanDetails.MemberName,
                    AccountCode  = cbu.AccountCode,
                    AccountTitle = cbu.AccountTitle,
                    Credit       = _loanAmortizationHeader.PaymentSchedules.Sum(sched => sched.CapitalBuildUp),
                    VoucherDate  = postingDetails.VoucherDate,
                    VoucherNo    = postingDetails.VoucherNumber
                };

                postResult = capitalBuildUp.Create();
                if (!postResult.Success)
                {
                    JournalVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Finally add entry for the loan applied ---

                var loanVoucherEntry = new JournalVoucher
                {
                    MemberCode   = _loanDetails.MemberCode,
                    MemberName   = _loanDetails.MemberName,
                    AccountCode  = _loanDetails.AccountCode,
                    AccountTitle = _loanDetails.AccountTitle,
                    Debit        = _loanDetails.LoanAmount + unearnedIncome.Credit + capitalBuildUp.Credit,
                    VoucherDate  = postingDetails.VoucherDate,
                    VoucherNo    = postingDetails.VoucherNumber,
                    LoanDetails  = _loanDetails,
                    Explanation  = _loanDetails.GenerateExplanation()
                };

                postResult = loanVoucherEntry.Create();
                if (!postResult.Success)
                {
                    JournalVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion
            }
            else
            {
                #region --- Add entry for Cash On Hand ---

                var net = new CashVoucher
                {
                    MemberCode   = _loanDetails.MemberCode,
                    MemberName   = _loanDetails.MemberName,
                    AccountCode  = netProceeds.AccountCode,
                    AccountTitle = netProceeds.AccountTitle,
                    Credit       = netProceeds.Amount,
                    VoucherDate  = postingDetails.VoucherDate,
                    VoucherNo    = postingDetails.VoucherNumber,
                };
                net.Amount        = net.Credit;
                net.AmountInWords = Converter.AmountToWords(net.Amount);
                Result postResult = net.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Add entries for Charges ---

                foreach (ComputationDetail computationDetail in _loanComputation.Charges)
                {
                    if (string.IsNullOrEmpty(computationDetail.AccountCode) || computationDetail.Amount == 0)
                    {
                        continue;
                    }
                    var charges = new CashVoucher
                    {
                        MemberCode   = _loanDetails.MemberCode,
                        MemberName   = _loanDetails.MemberName,
                        AccountCode  = computationDetail.AccountCode,
                        AccountTitle = computationDetail.AccountTitle,
                        Credit       = computationDetail.Amount,
                        VoucherDate  = postingDetails.VoucherDate,
                        VoucherNo    = postingDetails.VoucherNumber
                    };
                    postResult = charges.Create();
                    if (postResult.Success)
                    {
                        continue;
                    }
                    CashVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Add entries for Deductions ---

                foreach (ComputationDetail computationDetail in _loanComputation.Deductions)
                {
                    if (string.IsNullOrEmpty(computationDetail.AccountCode) || computationDetail.Amount == 0)
                    {
                        continue;
                    }
                    var deductions = new CashVoucher
                    {
                        MemberCode   = _loanDetails.MemberCode,
                        MemberName   = _loanDetails.MemberName,
                        AccountCode  = computationDetail.AccountCode,
                        AccountTitle = computationDetail.AccountTitle,
                        Credit       = computationDetail.Amount,
                        VoucherDate  = postingDetails.VoucherDate,
                        VoucherNo    = postingDetails.VoucherNumber
                    };
                    postResult = deductions.Create();
                    if (postResult.Success)
                    {
                        continue;
                    }
                    CashVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Add entry for Unearned Income ---

                Account ui             = Account.FindByCode(GlobalSettings.CodeOfUnearnedIncome);
                var     unearnedIncome = new CashVoucher
                {
                    MemberCode   = _loanDetails.MemberCode,
                    MemberName   = _loanDetails.MemberName,
                    AccountCode  = ui.AccountCode,
                    AccountTitle = ui.AccountTitle,
                    Credit       = _loanAmortizationHeader.PaymentSchedules.Sum(sched => sched.Interest),
                    VoucherDate  = postingDetails.VoucherDate,
                    VoucherNo    = postingDetails.VoucherNumber
                };

                postResult = unearnedIncome.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Add entry for Capital Build-Up ---

                Account cbu            = Account.FindByCode(GlobalSettings.CodeOfCapitalBuildUp);
                var     capitalBuildUp = new CashVoucher
                {
                    MemberCode   = _loanDetails.MemberCode,
                    MemberName   = _loanDetails.MemberName,
                    AccountCode  = cbu.AccountCode,
                    AccountTitle = cbu.AccountTitle,
                    Credit       = _loanAmortizationHeader.PaymentSchedules.Sum(sched => sched.CapitalBuildUp),
                    VoucherDate  = postingDetails.VoucherDate,
                    VoucherNo    = postingDetails.VoucherNumber
                };

                postResult = capitalBuildUp.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion

                #region --- Finally add entry for the loan applied ---

                var loanVoucherEntry = new CashVoucher
                {
                    MemberCode   = _loanDetails.MemberCode,
                    MemberName   = _loanDetails.MemberName,
                    AccountCode  = _loanDetails.AccountCode,
                    AccountTitle = _loanDetails.AccountTitle,
                    Debit        = _loanDetails.LoanAmount + unearnedIncome.Credit + capitalBuildUp.Credit,
                    VoucherDate  = postingDetails.VoucherDate,
                    VoucherNo    = postingDetails.VoucherNumber,
                    LoanDetails  = _loanDetails,
                    Explanation  = _loanDetails.GenerateExplanation()
                };

                postResult = loanVoucherEntry.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(postingDetails.VoucherNumber);
                    return(postResult);
                }

                #endregion
            }

            #region --- Voucher Log ---

            var voucherLog = new VoucherLog();
            voucherLog.Find(postingDetails.VoucherType.ToString(), postingDetails.VoucherNumber);
            voucherLog.Date     = postingDetails.VoucherDate;
            voucherLog.Initials = MainController.LoggedUser.Initials;

            voucherLog.Save();

            #endregion

            return(new Result(true, string.Format("A loan has been created! Please check {0} #{1}.",
                                                  postingDetails.VoucherType, postingDetails.VoucherNumber)));
        }
Beispiel #6
0
        private void btnPost_Click(object sender, EventArgs e)
        {
            var loanAmount  = _cashVoucher.Debit;
            var voucherNo   = _cashVoucher.VoucherNo;
            var voucherDate = MainController.LoggedUser.TransactionDate;
            var document    = new VoucherDocument(VoucherTypes.CV, voucherNo, voucherDate);

            // is there already a loan product for salary advance?
            if (_loanProduct == null)
            {
                MessageWindow.ShowAlertMessage("No Loan Products found for Salary Advance.");
                return;
            }

            // does user enter a valid amount?
            if (loanAmount <= 0)
            {
                MessageWindow.ShowAlertMessage("Invalid amount!");
                return;
            }

            // does the voucher number been used?
            var collection = CashVoucher.WhereDocumentNumberIs(voucherNo);

            if (collection.Count > 0)
            {
                MessageWindow.ShowAlertMessage("CV No. already in use.");
                return;
            }

            try
            {
                // what is the account for salary advance?
                var salaryAdvance = Account.FindByCode(GlobalSettings.CodeOfSalaryAdvance);

                var cashOnHandReceived = loanAmount;

                #region --- Finally add entry for the loan applied ---

                // what will be the loan details?
                var loanDetails = GenerateLoanDetails();

                _cashVoucher.SetMember(_member);
                _cashVoucher.SetAccount(salaryAdvance);
                _cashVoucher.SetDocument(document);
                _cashVoucher.Explanation = loanDetails.GenerateExplanation();
                _cashVoucher.LoanDetails = loanDetails;

                Result postResult = _cashVoucher.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(document.Number);
                    MessageWindow.ShowAlertMessage(postResult.Message);
                    return;
                }

                #endregion

                #region --- Interest Charge ---

                var interest = new CashVoucher();
                interest.SetMember(_member);
                interest.SetAccount(Account.FindByCode(GlobalSettings.CodeOfMiscellaneousIncome));
                interest.SetDocument(document);
                interest.Credit = loanDetails.InterestAmount;
                postResult      = interest.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(document.Number);
                    MessageWindow.ShowAlertMessage(postResult.Message);
                    return;
                }
                cashOnHandReceived -= interest.Credit;

                #endregion

                #region --- Add entries for Charges ---

                foreach (var charge in _loanProduct.LoanCharges)
                {
                    var entry = new CashVoucher();
                    entry.SetMember(_member);
                    entry.SetAccount(Account.FindByCode(charge.AccountCode));
                    entry.SetDocument(document);
                    entry.Credit = loanAmount * charge.Rate;

                    postResult = entry.Create();
                    if (postResult.Success)
                    {
                        cashOnHandReceived -= entry.Credit;
                        continue;
                    }

                    CashVoucher.DeleteAll(document.Number);
                    MessageWindow.ShowAlertMessage(postResult.Message);
                    return;
                }

                #endregion

                #region --- Add entry for Cash On Hand ---

                var net = new CashVoucher();
                net.SetMember(_member);
                net.SetAccount(Account.FindByCode(GlobalSettings.CodeOfCashOnHand));
                net.SetDocument(document);
                net.Credit        = cashOnHandReceived;
                net.Amount        = cashOnHandReceived;
                net.AmountInWords = Converter.AmountToWords(cashOnHandReceived);
                postResult        = net.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(document.Number);
                    MessageWindow.ShowAlertMessage(postResult.Message);
                    return;
                }

                #endregion

                #region --- Voucher Log ---

                var voucherLog = new VoucherLog();
                voucherLog.Find("CV", _cashVoucher.VoucherNo);
                voucherLog.Date     = _cashVoucher.VoucherDate;
                voucherLog.Initials = MainController.LoggedUser.Initials;
                voucherLog.Save();

                #endregion

                MessageWindow.ShowNotifyMessage("Salary Advance created. Please check CV# " + voucherNo);
                DialogResult = true;
                Close();
            }
            catch (Exception exception)
            {
                MessageWindow.ShowAlertMessage(exception.Message);
            }
        }
Beispiel #7
0
        private void Post()
        {
            var loanAmount  = _cashVoucher.Debit;
            var voucherNo   = _cashVoucher.VoucherNo;
            var voucherDate = MainController.LoggedUser.TransactionDate;
            var document    = new VoucherDocument(VoucherTypes.CV, voucherNo, voucherDate);

            // is there already a loan product for Go Negosyo?
            if (_loanProduct == null)
            {
                MessageWindow.ShowAlertMessage("No Loan Products found for Go Negosyo.");
                return;
            }

            // does user enter a valid amount?
            if (loanAmount <= 0)
            {
                MessageWindow.ShowAlertMessage("Invalid amount!");
                return;
            }

            // does the voucher number been used?
            var collection = CashVoucher.WhereDocumentNumberIs(voucherNo);

            if (collection.Count > 0)
            {
                MessageWindow.ShowAlertMessage("CV No. already in use.");
                return;
            }

            try
            {
                // what is the account for Go Negosyo?
                var goNegosyo = Account.FindByCode(GlobalSettings.CodeOfGoNegosyo);

                #region --- Finally add entry for the loan applied ---

                // what will be the loan details?
                var loanDetails = GenerateLoanDetails();

                _cashVoucher.SetMember(_member);
                _cashVoucher.SetAccount(goNegosyo);
                _cashVoucher.SetDocument(document);
                _cashVoucher.Explanation = loanDetails.GenerateExplanation();
                _cashVoucher.LoanDetails = loanDetails;

                Result postResult = _cashVoucher.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(document.Number);
                    MessageWindow.ShowAlertMessage(postResult.Message);
                    return;
                }

                #endregion

                // NO CHARGES

                #region --- Add entry for Accounts Payable Merchandise ---

                var net = new CashVoucher();
                net.SetMember(_member);
                net.SetAccount(Account.FindByCode(GlobalSettings.CodeOfAccountsPayableMerchandise));
                net.SetDocument(document);
                net.Credit        = loanAmount;
                net.Amount        = loanAmount;
                net.AmountInWords = Converter.AmountToWords(loanAmount);
                postResult        = net.Create();
                if (!postResult.Success)
                {
                    CashVoucher.DeleteAll(document.Number);
                    MessageWindow.ShowAlertMessage(postResult.Message);
                    return;
                }

                #endregion

                #region --- Voucher Log ---

                var voucherLog = new VoucherLog();
                voucherLog.Find("CV", _cashVoucher.VoucherNo);
                voucherLog.Date     = _cashVoucher.VoucherDate;
                voucherLog.Initials = MainController.LoggedUser.Initials;
                voucherLog.Save();

                #endregion

                MessageWindow.ShowNotifyMessage("Go Negosyo created. Please check CV# " + voucherNo);
                DialogResult = true;
                Close();
            }
            catch (Exception exception)
            {
                MessageWindow.ShowAlertMessage(exception.Message);
            }
        }