private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                ImusCityGovernmentSystem.Model.FundBank  account   = db.FundBanks.Find(FundBankID);
                ImusCityGovernmentSystem.Model.BankTrail banktrail = new BankTrail();

                if (String.IsNullOrEmpty(amounttb.Text))
                {
                    MessageBox.Show("Please enter the amount to be adjusted");
                }
                else
                {
                    switch (adjustmenttypecb.Text.Substring(0, 1))
                    {
                    case "D":
                        if (Convert.ToDecimal(amounttb.Text) > account.CurrentBalance)
                        {
                            MessageBox.Show("Cannot be debited, you will have an insufficients funds");
                            return;
                        }
                        account.CurrentBalance -= Convert.ToDecimal(amounttb.Text);
                        banktrail.DebitCredit   = "D";
                        break;

                    case "C":
                        account.CurrentBalance += Convert.ToDecimal(amounttb.Text);
                        banktrail.DebitCredit   = "C";
                        break;
                    }
                    banktrail.FundBankID  = FundBankID;
                    banktrail.Amount      = Convert.ToDecimal(amounttb.Text);
                    banktrail.EntryName   = nameof(BankTrailEntry.Adjustment);
                    banktrail.CheckID     = null;
                    banktrail.EntryNameID = (int)BankTrailEntry.Adjustment;
                    banktrail.EmployeeID  = App.EmployeeID;
                    banktrail.DateCreated = DateTime.Now;
                    db.BankTrails.Add(banktrail);

                    db.SaveChanges();


                    var audit = new AuditTrailModel
                    {
                        Activity   = "Adjusted current amount of FUNDBANK ID: " + FundBankID.ToString(),
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                    MessageBox.Show("Adjustment added succesfully");
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                if (SystemClass.CheckConnection())
                {
                    if (fundcb.SelectedValue == null)
                    {
                        Mouse.OverrideCursor = null;
                        MessageBox.Show("Please select fund");
                    }
                    else
                    {
                        ImusCityHallEntities db = new ImusCityHallEntities();
                        int fundBankId          = (int)fundcb.SelectedValue;
                        var fundBank            = db.FundBanks.Find(fundBankId);
                        ImusCityGovernmentSystem.Model.Disbursement disbursement = db.Disbursements.Find(DisbursementID);

                        var controlNumber = db.ControlNumbers.OrderByDescending(m => m.ControlNoID).FirstOrDefault(m => m.FundBankID == fundBankId && m.Active == true);

                        if (String.IsNullOrEmpty(checknotb.Text))
                        {
                            MessageBox.Show("Please provide the check number");
                            this.Close();
                        }
                        else if (String.IsNullOrEmpty(checkdesctb.Text))
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Please provide check description");
                        }
                        else if (checkamounttb.Text.Equals("0.00"))
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Please enter check amount");
                        }
                        else if (db.Checks.Any(m => m.CheckNo == checknotb.Text && m.Status != (int)CheckStatus.Deleted && m.Disbursement.FundBankID == fundBankId))
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Check number is already been used");
                        }
                        else if (db.FundBanks.Find(fundBankId).CurrentBalance < Convert.ToDecimal(checkamounttb.Text))
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Check cannot be created, you have insufficients funds");
                        }
                        else if (controlNumber == null)
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Selected fund have no available check number");
                        }
                        else if (db.DamageChecks.Where(m => m.FundBankID == fundBankId && m.CheckNumber == checknotb.Text).Count() >= 1)
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("The current check number is in the list of damage checks");
                        }
                        else
                        {
                            Check check = new Check();
                            check.DisbursementID   = DisbursementID;
                            check.CheckNo          = checknotb.Text;
                            check.CheckDescription = checkdesctb.Text;
                            check.Amount           = Convert.ToDecimal(checkamounttb.Text);
                            check.EmployeeID       = App.EmployeeID;
                            check.DateCreated      = DateTime.Now;
                            check.Status           = (int)CheckStatus.Created;

                            //Increment of the Check Number.
                            if (controlNumber.EndingControlNo == controlNumber.NextControlNo)
                            {
                                controlNumber.Active = false;
                            }
                            else
                            {
                                controlNumber.NextControlNo++;
                            }

                            check.ControlNo = checknotb.Text;
                            var savedCheck = db.Checks.Add(check);


                            ImusCityGovernmentSystem.Model.BankTrail banktrail = new BankTrail();
                            banktrail.DebitCredit = "D";
                            banktrail.FundBankID  = fundBankId;
                            banktrail.Amount      = Convert.ToDecimal(checkamounttb.Text);
                            banktrail.EntryName   = nameof(BankTrailEntry.CheckCreated);
                            banktrail.CheckID     = savedCheck.CheckID;
                            banktrail.EntryNameID = (int)BankTrailEntry.CheckCreated;
                            banktrail.EmployeeID  = App.EmployeeID;
                            banktrail.DateCreated = DateTime.Now;
                            db.BankTrails.Add(banktrail);

                            ImusCityGovernmentSystem.Model.FundBank account = db.FundBanks.Find(fundBankId);
                            account.CurrentBalance -= Convert.ToDecimal(checkamounttb.Text);

                            disbursement.VoucherNo  = string.Join("-", fundBank.Fund.FundPrefix, disbursement.VoucherNo);
                            disbursement.FundBankID = fundBankId;

                            db.SaveChanges();

                            var audit = new AuditTrailModel
                            {
                                Activity   = "Created new check entry DIS ID: " + DisbursementID.ToString(),
                                ModuleName = this.GetType().Name,
                                EmployeeID = App.EmployeeID
                            };

                            SystemClass.InsertLog(audit);
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Check created successfully!");
                            PrintReport(check.CheckID);

                            checknotb.Clear();
                            checkdesctb.Clear();
                            checkamounttb.Clear();
                            currentbalancetb.Text = "";
                            LoadFund();
                        }
                    }
                }
                else
                {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show(SystemClass.DBConnectionErrorMessage);
                }
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                MessageBox.Show(ex.ToString());
            }
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                ImusCityGovernmentSystem.Model.Check check = db.Checks.Find(CheckID);
                check.Status = checkstatuscb.SelectedIndex;


                if (checkstatuscb.SelectedIndex == (int)CheckStatus.Cancelled)
                {
                    check.CancelledBy   = App.EmployeeID;
                    check.CancelledDate = DateTime.Now;

                    ImusCityGovernmentSystem.Model.BankTrail    banktrail    = new BankTrail();
                    ImusCityGovernmentSystem.Model.Disbursement disbursement = db.Disbursements.Find(check.DisbursementID);
                    banktrail.DebitCredit = "C";
                    banktrail.FundBankID  = disbursement.FundBankID;
                    banktrail.Amount      = Convert.ToDecimal(check.Amount);
                    banktrail.EntryName   = nameof(BankTrailEntry.CheckCancelled);
                    banktrail.CheckID     = check.CheckID;
                    banktrail.EntryNameID = (int)BankTrailEntry.CheckCancelled;
                    banktrail.EmployeeID  = App.EmployeeID;
                    banktrail.DateCreated = DateTime.Now;
                    db.BankTrails.Add(banktrail);

                    ImusCityGovernmentSystem.Model.FundBank account = db.FundBanks.Find(disbursement.FundBankID);
                    account.CurrentBalance += Convert.ToDecimal(check.Amount);
                }
                else if (checkstatuscb.SelectedIndex == (int)CheckStatus.Deleted)
                {
                    check.DeletedBy   = App.EmployeeID;
                    check.DeletedDate = DateTime.Now;

                    ImusCityGovernmentSystem.Model.BankTrail    banktrail    = new BankTrail();
                    ImusCityGovernmentSystem.Model.Disbursement disbursement = db.Disbursements.Find(check.DisbursementID);
                    banktrail.DebitCredit = "C";
                    banktrail.FundBankID  = disbursement.FundBankID;
                    banktrail.Amount      = Convert.ToDecimal(check.Amount);
                    banktrail.EntryName   = nameof(BankTrailEntry.CheckDeleted);
                    banktrail.CheckID     = check.CheckID;
                    banktrail.EntryNameID = (int)BankTrailEntry.CheckDeleted;
                    banktrail.EmployeeID  = App.EmployeeID;
                    banktrail.DateCreated = DateTime.Now;
                    db.BankTrails.Add(banktrail);

                    ImusCityGovernmentSystem.Model.FundBank account = db.FundBanks.Find(disbursement.FundBankID);
                    account.CurrentBalance += Convert.ToDecimal(check.Amount);
                }


                db.SaveChanges();

                var audit = new AuditTrailModel
                {
                    Activity   = "Updated check in the database. CHECK NUMBER: " + check.CheckNo,
                    ModuleName = this.GetType().Name,
                    EmployeeID = App.EmployeeID
                };

                SystemClass.InsertLog(audit);

                MessageBox.Show("Check entry updated successfully");
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
Beispiel #4
0
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                if (fundcb.SelectedValue == null)
                {
                    MessageBox.Show("Please select fund");
                }
                else if (bankcb.SelectedValue == null)
                {
                    MessageBox.Show("Please select bank");
                }
                else if (String.IsNullOrEmpty(accountnumbertb.Text))
                {
                    MessageBox.Show("Please input account number");
                }
                else if (db.FundBanks.Any(m => m.AccountNumber == accountnumbertb.Text))
                {
                    MessageBox.Show("The account number is already used");
                }
                else if (String.IsNullOrEmpty(startingbalancetb.Text))
                {
                    MessageBox.Show("Please input starting balance");
                }
                else if (String.IsNullOrEmpty(advicenumbertb.Text))
                {
                    MessageBox.Show("Please input advice number");
                }
                else if (String.IsNullOrEmpty(flooramounttb.Text))
                {
                    MessageBox.Show("Please input floor amount");
                }
                else
                {
                    ImusCityGovernmentSystem.Model.FundBank account = new FundBank();
                    account.FundID          = (int)fundcb.SelectedValue;
                    account.BankID          = (int)bankcb.SelectedValue;
                    account.AccountNumber   = accountnumbertb.Text;
                    account.CurrentBalance  = Convert.ToDecimal(startingbalancetb.Text);
                    account.StartingBalance = Convert.ToDecimal(startingbalancetb.Text);
                    account.IsActive        = true;
                    account.DateAdded       = DateTime.Now;
                    account.AdviceNo        = Convert.ToInt32(advicenumbertb.Text);
                    account.IsProcessed     = true;
                    account.AmountLimit     = Convert.ToDecimal(flooramounttb.Text);
                    db.FundBanks.Add(account);

                    ImusCityGovernmentSystem.Model.BankTrail banktrail = new BankTrail();
                    banktrail.DebitCredit = "D";
                    banktrail.FundBankID  = account.FundBankID;
                    banktrail.Amount      = Convert.ToDecimal(startingbalancetb.Text);
                    banktrail.EntryName   = nameof(BankTrailEntry.FundCreation);
                    banktrail.CheckID     = null;
                    banktrail.EntryNameID = (int)BankTrailEntry.FundCreation;
                    banktrail.EmployeeID  = App.EmployeeID;
                    banktrail.DateCreated = DateTime.Now;
                    db.BankTrails.Add(banktrail);

                    db.SaveChanges();

                    var audit = new AuditTrailModel
                    {
                        Activity   = "Added new bank account in the database. FUNDBANK ID: " + account.FundBankID.ToString(),
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);

                    MessageBox.Show("Account added successfully");
                    SystemClass.ClearTextBoxes(this);
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }