How to Customize SugarCRM for Generation of a User’s Activity Schedule

How to Customize SugarCRM for Generation of a User’s Activity ScheduleAuthor: Pavel Chumachenko, Software Engineer

We continue to reveal the secrets of SugarCRM customization, and our today tutorial contains a step-by-step guide how to generate user’s activity schedule with the help of a module.

To be precise, we will cover the advanced SugarCRM framework, namely, the possibility to create a module for SugarCRM 6, which does not require any storage in a SugarCRM database, but, at the same time, provides the additional upgraded features for CRM system users, i.e. the generation of a user’s activity schedule.

It should be noted that the module under discussion can also be applied in the SugarCRM 7 (either through backward-capability mode, or with some customizations of the existing module). By the way, you can find more examples of SugarCRM customization in our video tutorials library. Various useful enhancements, solutions to the most important tasks are available here: https://integroscrm.com/sugarcrm-video-tutorials-and-webinars/.

What do we need for our SugarCRM customization?

So, the issue is to customize SugarCRM with such a functionality that will generate the working schedule of a company’s employee. To solve it, we need to create a module that does not require any storage in a SugarCRM database, by this, to determine its own module view and to connect the generation of the Excel-file to the PHP Excel library.

Here are the 4 steps of a new module creation:

  • Declaring a new module, its connection to a CRM system.
  • Defining of a controller, the navigation across the actions, building-up of the controller’s internal logic.
  • Creation of module views with the internal logic.
  • Adding the logic to Excel-file generation

Step 1. Declaring a new module, its connection to a CRM system

First of all, you need to create a module, and then add it to the list of SugarCRM modules. Let’s name the module, for example, PX_FlexibleSchedule.

In order to create a standard module, you should create a folder PX_FlexibleSchedule in the “modules” directory.

The contents of this folder:
SugarCRM customization; generation of a user's activity schedule
At this step it is necessary to download the PHP Excel library, the language file en_us.lang.php from the language folder and to define PX_FlexibleSchedule_sugar.php file, PX_FlexibleSchedule.php file, Menu.php, vardefs.php file. Here and force, we will not refer to the content of the language file en_us.lang.php, because it is a standard language file, there are no bottlenecks there.

The files PX_FlexibleSchedule.php and PX_FlexibleSchedule_sugar.php are also standard ones, except that the following values are set to the PX_FlexibleSchedule_sugar.php file:

Here it should be noted that the field $table_name remains to be empty, because the database table is not created.

We should leave only action index in Menu.php file:

Please, mention that initially the data array should be the following in vardefs.php file:

While declaring the module you need not add anything, particularly, the attribute ‘table’ and the inheritance from VardefManager.

What is more, the key moment is that any field, added into $dictionary, should certainly have the parameter ‘source’ => ‘non-db‘.

The last step of declaring a module is to register in inside SugarCRM. To do it is necessary to set the following data into the file custom/Extension/application/Ext/Include/Scheduler.php:

And also you should define the module name in the appropriate language file.

As soon as you perform QuickRepair and Rebuild of the system, the just registered module will appear in a CRM system. By this, the system should not request to perform any SQL queries, because at it was mentioned earlier the special module table is not created inside CRM system.

Step 2. Defining of a controller, the navigation across the actions, building-up of the controller’s internal logic

The next step is to define the controller.php file.

To do it you need to connect the standard controller and to inherit the module controller from it.

Here it is important to override the standard actions, so that while switching to them, the customized module views should be replaced, but not the standard ones.

Similarly, in such a way the other actions should be overridden with the only difference that the different actions should be replaced by the different views.

The correspondence of Action and View:

Action            View
index‘confirm_schedule’
listview‘confirm_schedule’
detail‘confirm_schedule’
confirm_schedule‘confirm_schedule’
generate_schedule‘generate_schedule’
save‘generate_schedule’

The action confirm_schedule is charged with entering the Employee’s Name, the selection of working days, defining Start Time and End Time of the activity schedule, etc., and generate_schedule – for entering directly the working hours by weekdays. The action ‘save’ is charged with switching from ‘confirm_schedule‘ view to ‘generate_schedule‘. It is necessary to override the function ‘post_save()’ so that the switching between views is performed correctly:

It is also necessary to create the action, that’ll be charged with the generation of the Excel-file. We define it as follows:

We’ll define the function ‘$this->excelGenerate()’ a bit further.

Step 3. Creation of module views with the internal logic

It’s high time to define the custom module view. To do this, you should create the following files under views:
SugarCRM customization; generation of a user's activity schedule
As well as the metadata for them:
SugarCRM customization; generation of a user's activity schedule
You should declare the buttons in confirm_scheduleviewdefs.php file:

And also to determine the initial field, for example:

At this stage, all the added fields should also be placed to vardefs.php file.
Create the hidden fields in generate_scheduleviewdefs.php file that will store the value of the fields from the previous module view:

As well as the custom buttons:

Panels‘ data array is remained to be empty, as the fields will be added automatically there, depending on the selected days.

The view view.confirm_schedule.php and view.generate_schedule.php are inherited from module EditView. You should replace $this-> type with the name of a particular view right within the Module Builder.

It is necessary to override the function ‘preDisplay()’ in view.confirm_schedule.php file for correct Smarty template:

Also, you should add the fields for validation onto the view.confirm_schedule.php file.

This can be done as follows:

The similar actions should be performed in view.generate_schedule.php except that 2 methods of schedule filling and values overriding in hidden fields are added:

The needed fields are added in the method fill_form in the following way:

Step 4. Adding the logic to Excel-file generation

In order to generate Excel-file, you need to connect PHP Excel library files to the controller.php file:

And also determine ‘excellGenerate()’ method.

Firstly, we need to create an Excel object, to define its basic properties, and choose the active sheet:

Then we should difference between the Start Date of schedule and End Date of schedule and set the value for each day:

It is necessary to set the needed format:

The generated Excel-file displaying a user’s activity schedule will be saved on a user PC.

The Results of Our SugarCRM Customization

That’s what we have at the result:
SugarCRM customization; generation of a user's activity schedule
SugarCRM customization; generation of a user's activity schedule
SugarCRM customization; generation of a user's activity schedule
To draw the conclusion we want to highlight the obvious pros of such SugarCRM customization . Firstly, from the system perspective, it is not needed to store the generated schedules inside CRM system. Secondly, from a user’s perspective, it is very convenient to get the ready activity schedule right from his PC.

As always, feel free to contact us if you need advice on how to customize SugarCRM to make it more convenient and efficient for your needs.





Leave your details and we’ll get right back to you
First Name

Last Name

Email

Phone
Message

I have read the Integros privacy policy and consent to the processing of my personal data.



Other SugarCRM customization tutorials:

Leave a Reply

Your email address will not be published. Required fields are marked *