RFC Architecture for Finance Project (The Invoicing Project)


Introduction

RFC is an open source initiative for Finance projects. It has reusable components like invoicing, accounting and purchase modules. In this section we will discuss about the invoicing section of the RFC architecture.

You can download the project details from http://www.codeplex.com/FinanceDotNET

The RFC Architecture

RFC stands on a three tier architecture framework. It uses enterprise blocks heavily for data access layer, security, validation etc. The core of RFC is the business logic layer which can be used in a decoupled manner in your project. Currently the data access layer only supports SQL Server. 


 

The current sections

Currently RFC supports three major section Invoicing, purchase and journal section. Journal section is a double entry accounting system which is the heart of RFC. Any entries made in to invoicing or purchase is finally sent to the journal section.
 

The Invoicing part

You can download the invoicing requirements from http://www.codeplex.com/FinanceDotNET/SourceControl/ListDownloadableCommits.aspx
I really do not want to make this article large by pasting the requirement document.

Folders in the project

Folder Name

What does it have

Root

In the root folder we have the user interface of the application.

App_Data

It has the database i.e. Invoicing.MDF

Invoicing

This has the business classes for the invoicing application.

InvoicingDataLayer

This has the data access layer of the project.

The Invoicing table structure

The invoicing part has two important tables one is the product table and the other is the Invoice table.

Mst_product table

Productid

This is unique key which identifies the product.

ProductDescription

A simple description about the product.

UnitCost

Per unit cost of the product

 

 

 

Invoice table

InvoiceReference

This is unique key which identifies a invoice uniquely.

Invoice comments

A short  text which describes the comments

UnitCost

Per unit cost of the product

Product

This is the product reference from the  product master table

Qty

How much quantity of the product was ordered?

Amount

Total Amount to be paid by the customer

PaidAmount

Many times the customer will not pay the complete amount so a paid amount field.

Customer Name and Address

This describes the customer credentials.

TaxAmount

Tax on the current amount.

Business class structure and code

Invoice has two business classes invoice class i.e. "lsInvoice" and product class i.e. "ClsProduct". Both of these call the "ClsInvoiceDB" class to database operations.

Business class and code explanation

Below is the "insert" method of  "clsInvoice"  class. It actually creates the object of "clsInvoiceDB" to connect to the SQL Server database.

     public void Insert()
        {
            clsInvoiceDB objInvoiceDB = new clsInvoiceDB();
            objInvoiceDB.InsertInvoice(_InvoiceReference, _InvoiceComments,
            _InvoiceDate, _ProductId, _Qty, _Amount, _TaxAmount, _PaidAmount,
            _CustomerName, _CustomerAddress, _UnitCost);
        }

The insert invoice class code is something as shown below.

       public void InsertInvoice(string _InvoiceReference, string _InvoiceComments, DateTime _InvoiceDate, int _productId,
     int _Qty, double _Amount, double _TaxAmount, double _PaidAmount, string _CustomerName, string _CustomerAddress, double _UnitCost)
        {
            SqlConnection ObjConnection = new SqlConnection();
            ObjConnection.ConnectionString = ConfigurationSettings.AppSetting
["ConnectionString"];
            ObjConnection.Open();
            SqlCommand objCommand = new SqlCommand();
            objCommand.Connection = ObjConnection;
            objCommand.CommandText = "usp_InsertInvoice";
            objCommand.CommandType = CommandType.StoredProcedure;
            objCommand.Parameters.Add(new SqlParameter("InvoiceReference", _InvoiceReference));
            objCommand.Parameters.Add(new SqlParameter("@InvoiceComments", _InvoiceComments));
            objCommand.Parameters.Add(new SqlParameter("@InvoiceDate", _InvoiceDate));
            objCommand.Parameters.Add(new SqlParameter("@ProductId", _productId));
            objCommand.Parameters.Add(new SqlParameter("@Qty", _Qty));
            objCommand.Parameters.Add(new SqlParameter("@Amount", _Amount));
            objCommand.Parameters.Add(new SqlParameter("@TaxAmount", _TaxAmount));
            objCommand.Parameters.Add(new SqlParameter("@PaidAmount", _PaidAmount));
            objCommand.Parameters.Add(new SqlParameter("@CustomerName", _CustomerName));
            objCommand.Parameters.Add(new SqlParameter("@CustomerAddress", _CustomerAddress));
            objCommand.Parameters.Add(new SqlParameter("@UnitCost", _UnitCost));
            objCommand.ExecuteNonQuery();
            ObjConnection.Close();
        }

In the same way other methods of the business component and DAL interact. I am not pasting the code here as the article will become bulky. You can download the project from the codeplex to get a fell of the same.

ASPX pages

There are two ASPX pages one is the Invoice entry screen (InvoiceEntry.aspx) and the second is the product selection screen (SelectProducts.aspx). The UI consumes the business object in a very standard format. To get more understanding you can see the "setObjectFromUI" method where all the values from the UI is passed to the business object.

       public void setObjectFromUI(clsInvoice objInvoice)
        {
            try
            {
                objInvoice.CustomerName = txtCustomerName.Text;
                objInvoice.CustomerAddress = txtCustomerAddress.Text;
                objInvoice.InvoiceComments = txtComments.Text;
                objInvoice.InvoiceReference = txtInvoiceNumber.Text;
            }
         }

Finally in the button events the operations of the classes like insert , update and delete is called. For instance you can see in the update invoice click event we have called the "Update" operation. Any exceptions raised from the user interface is finally caught and displayed in the error message label

       protected void btnUpdateInvoice_Click(object sender, EventArgs e)
        {
            clsInvoice objInvoice = new clsInvoice();
            try
            {
                setObjectFromUI(objInvoice);
                objInvoice.Update();
                clearText();
                LoadGrid();
                clearSession();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message.ToString();
            }
        }

The whole project goes with the same style of coding business object, DAL and the consumption in the UI. So if you are able to follow the above code you should be able to understand the other part of the project also.

Next version planning

  • The data access layer will now go through Enterprise data access layer.
  • Business validation will go through the enterprise validation application blocks
  • Integration with the accounting system


Similar Articles