Validating Bank Account Details – Cancelling the Save

For reasons that I am not going to go in to, oh wait, yeah I am 🙂 we needed to do some basic validation against back account details (CRS692/E) added in to M3.

We store our supplier bank account numbers in M3 and when a payment proposal is generated, we will extract the proposal with an in-house written application which will output a text file that can be submitted to our bank.

The problem we have is that a user can make a mistake and not key in the correct number of values for the bank account and we’d end up in the situation where we can’t change the payment proposal and we can’t submit our batch file, the good part is that as long as we have the correct number of characters for a bank account, then even it is wrong we can submit it to the bank and THEN it will reject it. This means that the batch file has to be manually keyed in to our banking software – not fun and somewhat error prone.

So to protect our staff from themselves and unspeakable horrors of rekeying batches a script was born.

The script is very primitive, it will count the number of characters for each of the bank account fields and if they don’t match it will change the background colour of the textbox to orange (and green for those textboxes that have the correct number of characters), then it will cancel the users save attempt.

Anyways, enough with the chitchat…

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript
{
	class ValidateBankDetails_000
	{
		var giicInstanceController : IInstanceController = null;    // this is where we will store the IInstanceController to make it available to the rest of the class
		var ggrdContentGrid : Grid = null;                          // this is the Grid that we get passed by the Init()

		public function Init(element: Object, args: Object, controller : Object, debug : Object)
		{
			giicInstanceController = controller;
			ggrdContentGrid = controller.RenderEngine.Content;
			

			giicInstanceController.add_Requesting(OnRequesting);
		}
		
		
		public function OnRequesting(sender: Object, e: CancelRequestEventArgs)
		{
			try
			{
				if(e.CommandType == MNEProtocol.CommandTypeKey)     // we're looking for a key event
				{
					if(e.CommandValue == MNEProtocol.KeyEnter)      // specifically we're looking the enter key event
					{
						if(true == giicInstanceController.RenderEngine.PanelHeader.EndsWith("CRS692/E"))   // are we on panel E?
						{
							if(false == validBankAccount())         // is the bank account valid?
							{
								e.Cancel = true;                    // it wasn't valid so cancel the request
							}
						}
					}
					else if( (e.CommandValue == MNEProtocol.KeyF3) || (e.CommandValue == MNEProtocol.KeyF03))
					{
						giicInstanceController.remove_Requesting(OnRequesting);
					}
				}
			}
			catch(ex)
			{
			    MessageBox.Show(ex.message);
			}
		}
		
        // this is the heart of the class
        // we will turn the background textbox to green
        // if we have a semi-valid account
        // If we know that we don't have the correct number
        // of characters then we set the background to orange
        // and we cancel the saving of the information
		public function validBankAccount()
		{
			var bResult : boolean = false;
			try
			{
				var bError : boolean = false;       // this is where we keep track of if there is an error
				
				var bBankOK : boolean = false;
				var bBranchOK : boolean = false;
				var bAccountOK : boolean = false;
				var bSuffixOK : boolean = false;
				
                // our bank accounts are set up with 4 compontents
				var tbBank : TextBox = ScriptUtil.FindChild(ggrdContentGrid, "W1BF02");
				var tbBranch : TextBox = ScriptUtil.FindChild(ggrdContentGrid, "W2BF04");
				var tbAccount : TextBox = ScriptUtil.FindChild(ggrdContentGrid, "W3BF07");
				var tbSuffix : TextBox = ScriptUtil.FindChild(ggrdContentGrid, "W4BF03");
				
				var strError : String = null;
				
                // in our world, our bank is two characters
				if(false == String.IsNullOrEmpty(tbBank.Text))
				{
					if(tbBank.Text.Length != 2)
					{
						strError = "Bank is incorrect";
						tbBank.Background = System.Windows.Media.Brushes.Orange;
						bError = true;
					}
					else
					{
						bBankOK = true;
					}
				}
				else bBankOK = true;
				
				if(true == bBankOK)
				{
					tbBank.Background = System.Windows.Media.Brushes.LightGreen;
				}
				
                // 4 characters for the branch
				if(false == String.IsNullOrEmpty(tbBranch.Text))
				{
					if(tbBranch.Text.Length != 4)
					{
						tbBranch.Background = System.Windows.Media.Brushes.Orange;
						bError = true;
					}
					else
					{
						bBranchOK = true;
					}
				}
				else bBranchOK = true;
				
				if(true == bBranchOK)
				{
					tbBranch.Background = System.Windows.Media.Brushes.LightGreen;
				}
				
                // 7 characters for the account
				if(false == String.IsNullOrEmpty(tbAccount.Text))
				{
					if(tbAccount.Text.Length != 7)
					{
						tbAccount.Background = System.Windows.Media.Brushes.Orange;
						bError = true;
					}
					else bAccountOK = true;
				}
				else bAccountOK = true;
				
				if(true == bAccountOK)
				{
					tbAccount.Background = System.Windows.Media.Brushes.LightGreen;
				}
				
                // three characters for the suffix
				if(false == String.IsNullOrEmpty(tbSuffix.Text))
				{
					if(tbSuffix.Text.Length != 3)
					{
						tbSuffix.Background = System.Windows.Media.Brushes.Orange;
						bError = true;
					}
					else bSuffixOK = true;
				}
				else bSuffixOK = true;
				
				if(true == bSuffixOK)
				{
					tbSuffix.Background = System.Windows.Media.Brushes.LightGreen;
				}
				
				if( (false == bSuffixOK) && (false == bAccountOK) && (false == bBranchOK) && (false == bBankOK) )
				{
				}
				else bResult = true;

			}
			catch(ex)
			{
				MessageBox.Show("Error validating the bank account");
			}
			if(true == bError)
			{
                // cancel the save
				bResult = false;
				MessageBox.Show("Sorry, but you haven't entered the account number correctly");
			}
			return(bResult);
		}
	}
}

This entry was posted in Development, M3 / MoveX. Bookmark the permalink.

2 Responses to Validating Bank Account Details – Cancelling the Save

  1. John Chandler says:

    Hi,

    I really like the script…but what I don’t quite understand is why you don’t use MEC to extract and create the file for the bank transfer?
    Is this becuase you already had the routines to extract the relevant data from the M3 Payment Proposal Tables.

    Many thanks

    //jgc

    • potatoit says:

      I found MEC terrible for handling this sort of thing – though probably some background…

      We initially had MEC extracting the information for us, it left us with some problems…
      * Providing access to the output file for our users in a secure fashion (so one user couldn’t see the EFT files)
      * The MEC scripts weren’t written correctly – due to other projects this wasn’t discovered in the 30 day ‘warranty’ period
      * MEC leaves behind the payment proposal, so it has to be manually deleted
      * No feedback to the user on progress – if MEC has actually done its job
      * it’s just another cost and a complex cost
      * way too easy for the user to turn the “Delete Proposals” function back on, so MEC would fail to extract the information as the proposal would be deleted before it had the opportunity to extract the data. There is less visibility on MEC doing its magic to the end user, so this becomes more of a problem.
      * at the time, there was one person in the APAC region who had a clue about MEC and I wasn’t thrilled with the quality or timeliness of work we were getting

      With the custom program we had full control over how we generate the files – we also have the potential to upload them directly in to the banking website with some minor modifications to the code (still waiting on the bank to make uploads an option).
      It was quicker and easier to write (total of about 4 – 6 hours to write the program and maintain it), some validation could be included and by its very nature, other users cannot see EFTs that have been exported by other staff.
      And finally, once the EFT has been exported, we automatically delete the proposal from M3.

      MEC has its place, but for something like this it was far easier, cheaper and less frustrating for our users to create something purpose specific.

      Also, we will be looking at moving this over to jscripts + webservices so it is totally housed within LSO, providing a far cleaner user experience.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s