Tutorial22 Aug 2017

FOP Crash Course

FOP is a powerful tool to build huge ERP applications and custom software. It consists of a description language that is capable of code-generating 90% of your needs leaving you only defining customizations.

Software

Let's begin with a basic software:

Software<"My Software", "Detailed Explaination">.
I18nSetLocaleBrowser<>.

A Simple Table

Let's create a datascheme

DescriptionTable<"carfleet", "Car Fleet", "Car">.
DescriptionColumn<"carfleet",
   "model", "Model", "text", "";
   "hp", "Horse Power", "hp", "";
   "year", "Year", "integer", "";
   "buydate", "Bought on", "date", "";
   "service", "Service Instructions", "bigtext", "">.

DataType<"hp", "PS", "0", "0">.

One X has many Y

Lets say that one car has many trips. Let's expand the code for car.

DropdownDatatypeTable<"car", "carfleet", "`model`">.
DataType<"km", "km", "0", "1">.

DescriptionTable<"trip", "Trips", "Trip">.
DescriptionColumn<"trip",
	"car", "Car", "car", "";
	"from", "From", "text", "";
	"to", "To", "text", "";
	"distance", "Distance", "km", "">.

ListColumnReference<"carfleet", "trip", "car", "Trips of this Car">.
DetailViewFeatureDefault<"carfleet", "carfleet_trip_car">.

Calculated Columns

Sometimes, you want to compute values instead of storing them

DescriptionColumn<"carfleet", "total", "Total Distance", "km", "(SELECT SUM(distance) FROM trip WHERE car = carfleet.ID)">.

Securing the login

Now let's make the whole thing secure:

DescriptionTable<"user", "Users", "User">.
DescriptionColumn<"user",
	"username", "Username", "text", "";
	"password", "Password", "password", "">.
Login<"user", "username", "password">.

Summary

This is our code:

Software<"My Software", "Detailed Explaination">.
I18nSetLocaleBrowser<>.

DescriptionTable<"carfleet", "Car Fleet", "Car">.
DescriptionColumn<"carfleet",
	"model", "Model", "text", "";
	"hp", "Horse Power", "hp", "";
	"year", "Year", "integer", "";
	"buydate", "Bought on", "date", "";
	"service", "Service Instructions", "bigtext", "">.

DataType<"hp", "PS", "0", "0">.

DropdownDatatypeTable<"car", "carfleet", "`model`">.
DataType<"km", "km", "0", "1">.

DescriptionTable<"trip", "Trips", "Trip">.
DescriptionColumn<"trip",
	"car", "Car", "car", "";
	"from", "From", "text", "";
	"to", "To", "text", "";
	"distance", "Distance", "km", "">.

ListColumnReference<"carfleet", "trip", "car", "Trips of this Car">.
DetailViewFeatureDefault<"carfleet", "carfleet_trip_car">.

DescriptionColumn<"carfleet", "total", "Total Distance", "km", "(SELECT SUM(distance) FROM trip WHERE car = carfleet.ID)">.

DescriptionTable<"user", "Users", "User">.
DescriptionColumn<"user",
	"username", "Username", "text", "";
	"password", "Password", "password", "">.
Login<"user", "username", "password">.

As you see, FOP is a mighty tool to build complex software from scratch. This is the end of our tutorial, but there are much more possibilities. Some are listed here:

  • Access Control table-wise
  • Access Control table item-wise
  • Access Control table column-wise
  • Access Control on menus and actions
  • Custom buttons and menus
  • Mass-edit operations
  • Mass-edit forms
  • View a table as a chart
  • Import / Export CSV and other formats (you customize which im/export actions are available)