





















































In this article by Mark Brummel, the author of Learning Dynamics NAV Patterns, we will learn how to create an application using Dynamics Nav. While creating an application, we can apply patterns and coding concepts into a new module that is recognizable for the users to be as a Microsoft Dynamics NAV application, and is easy to understand and maintain by other developers.
The solution that we will make is for a small bed and breakfast (B&B), allowing them to manage their rooms and reservations. This can be integrated into the financial part of Dynamics NAV.
It is not the intention of this article to make a full-featured finished product. We will discuss the basic design principles, and the decision making processes. Therefore, we simplify the functional process. One of the restrictions in our application is that we rent rooms per night.
This article will be covering the following topics:
(For more resources related to this topic, see here.)
We borrowed the term classes from the object-oriented programming as a collection of things that belong together. Classes can be tables or code units in Microsoft Dynamics NAV.
The first step in our process is to define the classes. These will be created as tables or code units, following the patterns that we have learned:
Setup |
This is the generic set of parameters for the application. |
Guest |
This is the person who stays at our B&B. This can be one or two persons, or a group (family). |
Room |
Our B&B has a number of rooms with different attributes that determine the price, together with the season. |
Season |
This is the time of the year. |
Price |
This is the price for one night in a room. |
Reservation |
Rooms can be reserved on a daily basis with a starting and ending date. |
Stay |
This is the set of one or more consecutive nights at our B&B. |
Check-In |
This is the start of a stay, checking in for reservation. |
Check-Out |
At the end of a stay, we would like to send a bill. |
Clean |
Whenever a room is cleaned, we would like to register this. |
Evaluation |
Each stay can be evaluated by a customer. |
Invoice |
This generate a Sales Invoice for a Stay. |
The second step is to decide per class which Architectural Patterns we can use. In some special cases, we might need to write down new patterns, based on the data structures that are not used in the standard application.
For the application setup, we will use the Singleton pattern. This allows us to define a single set of values for the entire application that is kept in memory during the lifetime of the system.
To register our guests, we will use the standard Customer table in Dynamics NAV. This has pros and cons.
The good thing about doing this is the ability to use all the standard analysis options in the application for our customers without reinventing the wheel. Some B&B users might decide to also sell souvenirs or local products so that they can use items and the standard trade part of Dynamics NAV. We can also use the campaigns in the Relationship Management module.
The bad part, or challenge, is upgradability. If we were to add fields to the customer table, or modify the standard page elements, we will have to merge these into the application each time we get a new version of the product, which is once per month. We will use the new delta file, as well as the testability framework to challenge this.
The architectural pattern for a room is a tough decision. Most users of our system run a small B&B, so we can consider rooms to be the setup data. Number Series is not a required pattern. We will therefore decide to implement a Supplemental Table.
Each B&B can setup their own seasons. They are used to determine price, but when not used, the system will have to work too. We implement a Supplemental Table too.
Rooms can have a default price, or a price per season and a guest. Based on this requirement, we will implement the Rules Pattern that allows us a complex array of setup values.
We want to carefully trace reservations and cancellations per room and per guest. We would like to analyze the data based on the season. For this feature, we will implement the Journal-Batch-Line pattern and introduce an Entry table that is managed by the Journal.
We would like to register each unique stay in our system rather than individual nights. This allows us to easily combine parameters, and generate a total price. We will implement this as a Master Data, based on the requirement to be able to use number series. The Stay does not have requirements for a lines table, nor does it represent a document in our organization.
When a guest checks in to the bed and breakfast, we can check a reservation and apply the reservation to the Stay.
When a guest leaves, we would like to setup the final bill, and ask to evaluate the stay. This process will be a method on the Stay class with encapsulated functions, creating the sales invoice, and generating an evaluation document.
Rooms have to be cleaned each day when a guest stays, but at least once a week when the room is empty.
We will use the entry pattern without a journal. Clean will be a method on the Room class. Each day we will generate entries using the Job Queue Entry pattern. The Room will also have a method that indicates if a room has been cleaned.
A Stay in our B&B can be evaluated by our guests. The evaluation has a different criteria. We will use the Document Pattern.
We can create the method as an encapsulated method of the Stay class. In order to link the Sales Invoice to the Stay, we will add the Stay No. field to the Sales Header, the Sales Invoice Header, and the Sales Cr.Memo Header tables.
Based on the Architectural Patterns, we can define a set of objects that we can start working with, which is as follows:
Object names are limited to 30 characters, which is challenging for naming them. The Bed and Breakfast name illustrates this challenge. Only use abbreviation when the limitation of length is a problem.
In this article, you learned how to define classes for building an application. You have also learned about the kinds of architectural patterns that will be involved in creating the classes in your application.
Further resources on this subject: