コード例 #1
0
        private void btnPaySundry_Click(object sender, EventArgs e)
        {
            epSundryAmount.SetError(txtSundry, "");

            if (!Functions.IsPosDbl(txtSundry.Text))
            {
                epSundryAmount.SetError(txtSundry, "Must be a positive number");
                return;
            }

            float payment = float.Parse(txtSundry.Text);

            if (payment > _selectedAccount.Outstanding)
            {
                epSundryAmount.SetError(txtSundry, "This account only owes £" + _selectedAccount.Outstanding.ToString("0.00"));
                return;
            }

            _db.Payments.Add(
                new Payment
            {
                Account_Id      = _selectedAccount.Id,
                Amount          = payment,
                IsSundry        = true,
                Note            = "",
                PaidByAccountId = 0,
                Timestamp       = dtPayment.Value
            });
            _db.SaveChanges();
            if (_selectedAccount.Outstanding <= 0)
            {
                AccountStatus accountStatus = (from s in _db.AccountStatus where s.Status == "Completed" select s).FirstOrDefault();
                if (accountStatus == null)
                {
                    return;
                }

                _db.AccountStatusChanges.Add(new AccountStatusChange
                {
                    Account_Id       = _selectedAccount.Id,
                    AccountStatus_Id = accountStatus.Id,
                    Timestamp        = DateTime.Now
                });
                _db.SaveChanges();
                MessageBox.Show("This account is now Completed.");
            }

            //Summary
            txtSummaryCustomer.Text = _selectedCustomer.FullName;
            txtSummaryAccount.Text  = _selectedAccount.InvoiceCode;
            txtSummaryDate.Text     = dtPayment.Value.ToString("dd/MMM/yyyy");
            txtSummaryPayment.Text  = payment.ToString("C2");
            pnlSummary.Visible      = true;

            Clear();
        }
コード例 #2
0
        public void ShowCustomer(int customerID)
        {
            var db       = new LA_Entities();
            var customer = db.Customers.Find(customerID);

            //Is this customer locked by someone else?
            if (!String.IsNullOrEmpty(customer.LockedByUser) && customer.LockedByUser != Properties.Settings.Default.User)
            {
                //Is it to be unlocked?
                if (MessageBox.Show("This customer is currently locked by " + customer.LockedByUser + ".  Do you want to unlock it?", "Customer Locked", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    customer.LockedByUser = "";
                    db.SaveChanges();
                }
                else
                {
                    if (EvBackToMain != null)
                    {
                        EvBackToMain();
                    }
                    return;
                }
            }

            _currentCustomerID             = customer.Id;
            txtSurname.Text                = customer.Surname;
            txtStartDate.Text              = customer.StartDate.ToString("dd MMMM yyyy");
            txtPostCode.Text               = customer.PostCode;
            txtPhoneNumber.Text            = customer.PhoneNumber;
            txtNotes.Text                  = customer.Notes;
            txtMaxLoan.Text                = customer.Maxloan.ToString(CultureInfo.InvariantCulture);
            txtForename.Text               = customer.Forename;
            txtAddress.Text                = customer.Address;
            cmbCollectionDay.SelectedIndex = customer.PreferredDay;
            cmbCollector.SelectedValue     = customer.Collector.Id;
            customer.LockedByUser          = Properties.Settings.Default.User;
            db.SaveChanges();

            dgAccounts.AutoGenerateColumns = false;
            var accountsToShow = customer.Accounts.ToList().Where(account => !account.CurrentStatus.IsDeleted).ToList();

            dgAccounts.DataSource = accountsToShow;

            btnDelete.Enabled     = true;
            btnNewAccount.Enabled = true;
            BtnSave.Enabled       = true;
            btnSearch.Enabled     = false;
        }
コード例 #3
0
        private void ClearFields()
        {
            var db = new LA_Entities();

            if (_currentCustomerID > 0)
            {
                Customer c = db.Customers.Find(_currentCustomerID);
                c.LockedByUser = "";
                db.SaveChanges();
            }
            _currentCustomerID  = 0;
            txtAddress.Text     = "";
            txtForename.Text    = "";
            txtMaxLoan.Text     = "";
            txtNotes.Text       = "";
            txtPhoneNumber.Text = "";
            txtPostCode.Text    = "";
            txtStartDate.Text   = "";
            txtSurname.Text     = "";

            cmbCollectionDay.SelectedIndex = -1;
            cmbCollector.SelectedIndex     = -1;

            dgAccounts.DataSource = null;
            btnSearch.Enabled     = true;

            ClearErrors();

            btnDelete.Enabled     = false;
            btnNewAccount.Enabled = false;
            BtnSave.Enabled       = false;
            btnSearch.Enabled     = true;

            txtSurname.Focus();
        }
コード例 #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!IsValid())
            {
                return;
            }

            var c = new Collector();

            if (lstCollectors.SelectedItem != null)
            {
                c = (Collector)lstCollectors.SelectedItem;
            }
            c.CollectorName = txtCollectorName.Text.Trim();
            c.Notes         = txtNotes.Text.Trim();
            _db.SaveChanges();
            if (EvShowStatusText != null)
            {
                EvShowStatusText("Collector: " + c.CollectorName + ". Saved");
            }
            PopulateList();
        }
コード例 #5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var db   = new LA_Entities();
            var name = txtForename.Text.Trim() + " " + txtSurname.Text.Trim();

            if (MessageBox.Show("Delete " + name, "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            //Get the customer
            Customer cust = db.Customers.Find(_currentCustomerID);

            //Check Accounts
            bool canDelete = true;

            foreach (Account a in cust.Accounts)
            {
                if (a.CurrentStatus.IsCreated && a.Outstanding > 0)
                {
                    canDelete = false;
                }
            }

            if (!canDelete)
            {
                MessageBox.Show("This customer has outstanding accounts and, therefore, cannot be deleted.", "No Deletion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //Delete
            cust.IsDeleted = true;
            db.SaveChanges();

            if (EvShowStatusText != null)
            {
                EvShowStatusText(cust.FullName + " deleted.");
            }
            ClearFields();
        }
コード例 #6
0
        private void SaveCustomer()
        {
            var      db = new LA_Entities();
            Customer customer;

            if (_currentCustomerID == 0)
            {
                customer = new Customer();
                db.Customers.Add(customer);
            }
            else
            {
                customer = db.Customers.Find(_currentCustomerID);
            }

            if (txtMaxLoan.Text.Trim().Length == 0)
            {
                txtMaxLoan.Text = "0";
            }

            customer.Address      = txtAddress.Text.Trim();
            customer.Collector_Id = ((Collector)cmbCollector.SelectedItem).Id;
            customer.Forename     = txtForename.Text.Trim();
            customer.Maxloan      = int.Parse(txtMaxLoan.Text);
            customer.Notes        = txtNotes.Text.Trim();
            customer.PhoneNumber  = txtPhoneNumber.Text.Trim();
            customer.PostCode     = txtPostCode.Text.Trim();
            customer.PreferredDay = cmbCollectionDay.SelectedIndex;
            customer.Surname      = txtSurname.Text.Trim();
            db.SaveChanges();
            _currentCustomerID = customer.Id;

            if (EvShowStatusText != null)
            {
                EvShowStatusText("Customer: '" + customer.Surname + "' Saved");
            }
        }
コード例 #7
0
        private void SaveValues()
        {
            var isNewAccount = (_currentAccount.Id == 0);

            var interest = float.Parse(txtInterest.Text);
            var netValue = float.Parse(txtNetValue.Text);

            _currentAccount.Customer.Notes  = txtCustomerNotes.Text;
            _currentAccount.GrossValue      = netValue + interest;
            _currentAccount.LastChecked     = DateTime.Now;
            _currentAccount.NetValue        = netValue;
            _currentAccount.Notes           = txtNotes.Text.Trim();
            _currentAccount.Payment         = float.Parse(txtPayment.Text);
            _currentAccount.PaymentPeriod   = (int)udPaymentPeriod.Value;
            _currentAccount.PayMonthly      = (cmbPeriod.SelectedIndex == 1);
            _currentAccount.NextPaymentDate = dtNextPayment.Value;
            if (isNewAccount)
            {
                _db.Accounts.Add(_currentAccount);
            }
            _db.SaveChanges();

            if (isNewAccount)
            {
                var canBePaidOff = _currentAccount.Customer.Accounts.Where(account => account.Id != _currentAccount.Id).Where(account => account.CurrentStatus.IsCreated && account.Outstanding > 0).ToList();

                //Can other accounts be paid off?

                if (canBePaidOff.Count > 0)
                {
                    new FrmPayOffAccounts(_currentAccount.Id, canBePaidOff);
                }
            }

            if (EvShowStatusText != null)
            {
                EvShowStatusText("Account: '" + _currentAccount.InvoiceCode + "' Saved");
            }
        }
コード例 #8
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            foreach (Account acc in lstAccounts.SelectedItems)
            {
                var period        = acc.PayMonthly ? "month" : "week";
                var numOfPayments = acc.PlannedNumberOfPayments * acc.PaymentPeriod;
                var durationText  =
                    $"The agreement will have a minimum duration of {numOfPayments.ToString(CultureInfo.InvariantCulture)} {period}s";

                //Loans paid off
                double paidOffAmount             = 0;
                var    lpoText                   = "";
                var    paymentsPaidByThisAccount = (from p in _db.Payments where p.PaidByAccountId == acc.Id select p).ToList();
                if (paymentsPaidByThisAccount.Count > 0)
                {
                    lpoText += "(";
                    foreach (var p in paymentsPaidByThisAccount)
                    {
                        paidOffAmount += p.Amount;
                        lpoText       += p.Account.InvoiceCode + ", ";
                    }
                    lpoText = lpoText.Substring(0, lpoText.Length - 2) + ")";
                }

                var repayablePeriod = "The loan will be repayable in " + acc.PlannedNumberOfPayments.ToString(CultureInfo.InvariantCulture) + " installments and each subsequent " + period + "ly payment will be due on the same day each succeeding " + period;
                var repaymentText   = "Your " + period + "ly repayment will be";

                //Generate PDF
                var headerFont = FontFactory.GetFont("Arial", 10);
                var normalFont = FontFactory.GetFont("Arial", 8);
                var smallFont  = FontFactory.GetFont("Arial", 7);
                var document   = new Document(PageSize.A4, 25, 25, 30, 30);
                var pdfPath    = ReportHelper.CreateDoc(ref document);
                document.Open();

                //.HorizontalAlignment = ?; 0=Left, 1=Centre, 2=Right
                var tHeader = new PdfPTable(1);
                tHeader.AddCell(new PdfPCell(new Phrase("Pre Contract Fixed Sum Loan Agreement regulated by the Consumer Credit Act 1974", headerFont))
                {
                    HorizontalAlignment = 1
                });
                document.Add(tHeader);

                var widths     = new[] { 1f, 2f, 1f, 2f };
                var tAddresses = new PdfPTable(4);
                tAddresses.SetWidths(widths);
                var phLenders  = new Phrase("R & M Donaldson" + Environment.NewLine + "P.O. Box 11, Heaton, NE7 7YW" + Environment.NewLine + "Telephone 0191 2811112", normalFont);
                var phBorrower = new Phrase(acc.Customer.FullName + Environment.NewLine +
                                            acc.Customer.Address + Environment.NewLine +
                                            "Tel. " + acc.Customer.PhoneNumber, normalFont);
                tAddresses.AddCell(new Phrase("The Lenders", normalFont));
                tAddresses.AddCell(phLenders);
                tAddresses.AddCell(new Phrase("The Borrowers", normalFont));
                tAddresses.AddCell(phBorrower);
                document.Add(tAddresses);

                widths = new[] { 1f, 1f, 2f };
                var tMain = new PdfPTable(3);
                tMain.SetWidths(widths);
                tMain.AddCell(new PdfPCell(new Phrase("Key Financial Information", headerFont))
                {
                    Colspan = 2
                });
                tMain.AddCell(new Phrase("Terms and Conditions", headerFont));

                var tDetails = new PdfPTable(2);
                tDetails.AddCell(new Phrase("Amount of Loan", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase(acc.NetValue.ToString("C0"), normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new Phrase("Duration", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase(durationText, normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new Phrase("Total amount now payable (loan + interest)", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase(acc.GrossValue.ToString("C0"), normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new Phrase("Repayments are to commence", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase(acc.FirstPayment.ToString("dd/MMM/yyyy"), normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new PdfPCell(new Phrase(repayablePeriod, normalFont))
                {
                    Colspan = 2
                });
                tDetails.AddCell(new Phrase(repaymentText, normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase(acc.Payment.ToString("C0"), normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new Phrase("Personal APR", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase(acc.PersonalApr.ToString("0.0") + "%", normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new Phrase("Typical APR", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase(acc.TypicalApr.ToString("0.0") + "%", normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new PdfPCell(new Phrase("Other Financial Infomation", normalFont))
                {
                    Colspan = 2
                });
                tDetails.AddCell(new Phrase("Total amount interest charged on this loan", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase((acc.GrossValue - acc.NetValue).ToString("C0"), normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new Phrase("Amount required to settle existing loan(s)", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase(paidOffAmount.ToString("C0"), normalFont))
                {
                    HorizontalAlignment = 2
                });
                tDetails.AddCell(new PdfPCell(new Phrase(lpoText, normalFont))
                {
                    Colspan = 2
                });
                tDetails.AddCell(new Phrase("Cash now required", normalFont));
                tDetails.AddCell(new PdfPCell(new Phrase((acc.NetValue - paidOffAmount).ToString("C0"), normalFont))
                {
                    HorizontalAlignment = 2
                });

                tDetails.AddCell(new PdfPCell(new Phrase(Resources.Agreement_Comment01, smallFont))
                {
                    Colspan = 2
                });
                tDetails.AddCell(new PdfPCell(new Phrase("Key Information", headerFont))
                {
                    Colspan = 2
                });
                tDetails.AddCell(new PdfPCell(new Phrase(Resources.Agreement_Comment02, smallFont))
                {
                    Colspan = 2
                });
                tMain.AddCell(new PdfPCell(tDetails)
                {
                    Colspan = 2
                });

                tMain.AddCell(new Paragraph(Resources.Agreement_Terms_and_Conditions, smallFont));
                document.Add(tMain);
                document.Close();

                ////todo: replace this with auto printing code
                //var copies = Settings.Default.AgreementsToPrint;
                //Process.Start(pdfPath);

                var onScreen = Settings.Default.AgreementsToScreen;
                if (onScreen)
                {
                    Process.Start(pdfPath);
                }
                else
                {
                    Pdf.PrintPdf(pdfPath);
                }
            }

            if (MessageBox.Show(@"Did the Agreements print correctly?", @"Confirm Printing", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                foreach (Account acc in lstAccounts.SelectedItems)
                {
                    acc.PrintedForm = true;
                }
                _db.SaveChanges();
            }

            PopulateFields();
        }
コード例 #9
0
        private void btnPayment_Click(object sender, EventArgs e)
        {
            //Validate Payments
            var isValid = true;

            foreach (DataGridViewRow r in dgAccounts.Rows)
            {
                var paymentCell = r.Cells["Payment"];
                var payment     = (paymentCell.Value == null) ? 0F : float.Parse(paymentCell.Value.ToString());
                if (payment < 0)
                {
                    isValid = false;
                    paymentCell.Style.BackColor = Color.Red;
                }
                else if (payment > 0)
                {
                    //Is this account being overpaid?
                    var outstanding = float.Parse(r.Cells["Outstanding"].Value.ToString().TrimStart('£'));
                    if (outstanding < payment)
                    {
                        isValid = false;
                        paymentCell.Style.BackColor = Color.Red;
                    }
                    else
                    {
                        paymentCell.Style.BackColor = Color.White;
                    }
                }
            }
            if (!isValid)
            {
                return;
            }

            float totalPayments = 0;

            foreach (DataGridViewRow r in dgAccounts.Rows)
            {
                var paymentCell  = r.Cells["Payment"];
                var payeeIdValue = int.Parse(r.Cells[0].Value.ToString());
                var paymentValue = float.Parse(paymentCell.Value.ToString());
                if (paymentValue <= 0)
                {
                    continue;
                }

                var newPayment = new Payment
                {
                    Account_Id      = payeeIdValue,
                    Amount          = paymentValue,
                    Timestamp       = DateTime.Now,
                    PaidByAccountId = _parentAccount.Id,
                    IsSundry        = true,
                    Note            = ""
                };
                _db.Payments.Add(newPayment);
                totalPayments += paymentValue;
            }
            _db.SaveChanges();

            toolStripStatusLabel1.Text = @"Payments made: " + totalPayments.ToString("£0.00");

            var accounts = _accountIDs.Select(id => _db.Accounts.Find(id)).ToList();

            ShowAccounts(_parentAccount.Id, accounts);
        }
コード例 #10
0
        private void btnAccept_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgPayments.Rows)
            {
                var paymentCell = row.Cells["Payment"];
                if (paymentCell.Style.BackColor == Color.Red)
                {
                    MessageBox.Show("Fix invalid Payment data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            //Validate Amount Taken
            epAmountProvided.Clear();
            if (String.IsNullOrEmpty(txtAmountCollected.Text))
            {
                epAmountProvided.SetError(txtAmountCollected, "Enter a value");
                return;
            }
            if (!Functions.IsPosDbl(txtAmountCollected.Text))
            {
                epAmountProvided.SetError(txtAmountCollected, "Enter a positive numeric value");
                return;
            }

            //Validate Payments
            bool isValid = true;

            foreach (DataGridViewRow r in dgPayments.Rows)
            {
                DataGridViewCell paymentCell = r.Cells["Payment"];
                if (!paymentCell.ReadOnly)
                {
                    bool cellOk = true;
                    if (paymentCell.Value.ToString() == "")
                    {
                        paymentCell.Value = "0";
                    }
                    if (!Functions.IsDbl(paymentCell.Value.ToString()))
                    {
                        cellOk = false;
                    }
                    else
                    {
                        double val = Convert.ToDouble(paymentCell.Value);
                        if (val < 0)
                        {
                            cellOk = false;
                        }
                    }
                    if (!cellOk)
                    {
                        isValid = false;
                        paymentCell.Style.BackColor = Color.LightPink;
                        continue;
                    }

                    //Is this account being overpaid?
                    var payment     = float.Parse(paymentCell.Value.ToString());
                    var outstanding = float.Parse(r.Cells["Outstanding"].Value.ToString());
                    if ((outstanding < payment) && payment > 0)
                    {
                        isValid = false;
                        paymentCell.Style.BackColor = Color.LightPink;
                    }
                    else
                    {
                        paymentCell.Style.BackColor = Color.Khaki;
                    }
                }
            }
            if (!isValid)
            {
                MessageBox.Show("Check entered values", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            foreach (DataGridViewRow r in dgPayments.Rows)
            {
                DataGridViewCell paymentCell = r.Cells["Payment"];
                if (!paymentCell.ReadOnly)
                {
                    int   accountID = int.Parse(r.Cells[0].Value.ToString());
                    float payment   = float.Parse(paymentCell.Value.ToString());
                    if (payment > 0)
                    {
                        Account a = _db.Accounts.Find(accountID);
                        var     p = new Payment
                        {
                            Amount    = payment,
                            IsSundry  = false,
                            Note      = "",
                            Timestamp = dtCollection.Value
                        };
                        a.Payments.Add(p);
                        _db.SaveChanges();
                    }
                }
            }
            ShowPayments();

            //Print Report
            var collectorID = ((Collector)(cmbCollector.SelectedValue)).Id;
            var reports     = new Reports.Reports();
            var file        = reports.PaymentsTaken(collectorID, dtCollection.Value, Convert.ToDouble(txtAmountCollected.Text));

            Process.Start(file);

            Cursor.Current = Cursors.Default;
        }