Blog

Creating Payslip module in vtiger crm 5.4.0

Posted by : Leo T Abraham on 13 November, 2013

The following method explains how payslip module can be created in Vtiger CRM 5.4.0. It can be edited and can be used as a custom module.

Go to the root directory of your CRM. Create a file named create-payslip.php.

Copy the following code to the created file.

<?php
// Turn on debugging level
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
// Create module instance and save it first
$module = new Vtiger_Module();
$module->name = 'Payslip';
$module->save();
$module->initWebservice();
// Initialize all the tables required
$module->initTables();
/**
* Creates the following table:
* vtiger_payslip (payslipid INTEGER)
* vtiger_payslipcf(payslipid INTEGER PRIMARY KEY)
* vtiger_payslipgrouprel((payslipid INTEGER PRIMARY KEY, groupname VARCHAR(100))
*/
// Add the module to the Menu (entry point from UI)
$menu = Vtiger_Menu::getInstance('Tools');
$menu->addModule($module);

// Add the basic module block
$block1 = new Vtiger_Block();
$block1->label = 'LBL_PAYSLIP_INFORMATION';
$module->addBlock($block1);

// Add custom block (required to support Custom Fields)
$block2 = new Vtiger_Block();
$block2->label = 'LBL_CUSTOM_INFORMATION';
$module->addBlock($block2);

/** Create required fields and add to the block */
$field1 = new Vtiger_Field();
$field1->name = 'payslipname';
$field1->label = 'Payslip Name';
$field1->table = $module->basetable;
$field1->column = 'payslipname';
$field1->columntype = 'VARCHAR(255)';
$field1->uitype = 2;
$field1->typeofdata = 'V~M';
$block1->addField($field1); /** Creates the field and adds to block */
// Set at-least one field to identifier of module record
$module->setEntityIdentifier($field1);

$field2 = new Vtiger_Field();
$field2->name = 'paysliptype';
$field2->label = 'Payslip Type';
$field1->table = $module->basetable;
$field2->column = 'paysliptype';
$field2->columntype = 'VARCHAR(100)';
$field2->uitype = 15;
$field2->typeofdata = 'V~O'; // Varchar~Optional
$field2->setPicklistValues( Array ('Employee', 'Trainee') );
$block1->addField($field2); /** table and column are automatically set */

$field3 = new Vtiger_Field();
$field3->name = 'month';
$field3->label = 'Month';
$field3->table = $module->basetable;
$field3->uitype = 23;
$field3->typeofdata = 'D~M'; // Date~Mandatory
$block1->addField($field3); /** table, column, label, set to default values */

/*
$field4 = new Vtiger_Field();
$field4->name = 'linkto';
$field4->label= 'Link To';
$field4->table = 'vtiger_payslip';
$field4->column = 'linkto';
$field4->columntype = 'VARCHAR(100)';
$field4->uitype = 10;
$field4->typeofdata = 'V~O';
$field4->helpinfo = 'Relate to an existing module entry';
$block1->addField($field4);
$field4->setRelatedModules(Array('Accounts'));
*/

/** Common fields that should be in every module, linked to vtiger CRM core table
*/
$field5 = new Vtiger_Field();
$field5->name = 'assigned_user_id';
$field5->label = 'Assigned To';
$field5->table = 'vtiger_crmentity';
$field5->column = 'smownerid';
$field5->uitype = 53;
$field5->typeofdata = 'V~M';
$block1->addField($field5);
$field6 = new Vtiger_Field();
$field6->name = 'CreatedTime';
$field6->label= 'Created Time';
$field6->table = 'vtiger_crmentity';
$field6->column = 'createdtime';
$field6->uitype = 70;
$field6->typeofdata = 'T~O';
$field6->displaytype= 2;
$block1->addField($field6);
$field7 = new Vtiger_Field();
$field7->name = 'ModifiedTime';
$field7->label= 'Modified Time';
$field7->table = 'vtiger_crmentity';
$field7->column = 'modifiedtime';
$field7->uitype = 70;
$field7->typeofdata = 'T~O';
$field7->displaytype= 2;
$block1->addField($field7);
/** END */

// Create default custom filter (mandatory)
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$module->addFilter($filter1);
// Add fields to the filter created
$filter1->addField($field1)->addField($field2, 1)->addField($field5, 2);
// Create one more filter
$filter2 = new Vtiger_Filter();
$filter2->name = 'All2';
$module->addFilter($filter2);
// Add fields to the filter
$filter2->addField($field1);
$filter2->addField($field2, 1);
// Add rule to the filter field
$filter2->addRule($field1, 'CONTAINS', 'Test');

/** Associate other modules to this module */
$module->setRelatedList(Vtiger_Module::getInstance('Accounts'), 'Accounts', Array('ADD','SELECT'));
$module->setRelatedList(Vtiger_Module::getInstance('Documents'), 'Documents', Array('ADD','SELECT'), 'get_attachments');

/** Set sharing access of this module */
$module->setDefaultSharing('Private');
/** Enable and Disable available tools */
$module->enableTools(Array('Import', 'Export'));
$module->disableTools('Merge');

/*
$acc = Vtiger_Module::getInstance('Accounts');
$acc->setRelatedList(Vtiger_Module::getInstance('Payslip'), 'Payslip',Array('ADD'),'get_dependents_list');
*/
$accList = Vtiger_Module::getInstance('Accounts');
$accList->setRelatedList(Vtiger_Module::getInstance('Payslip'), 'Payslip',Array('ADD'));
?>

Next what you have to do is: Copy all the files from ROOT DIRECTORY/vtlib/ModuleDir/5.4.0

Create a folder Payslip in the folder ROOT DIRECTORY/modules and paste all the copied files.

There you can see 3 files named ModuleFile.php, ModuleFile.js, ModuleFileAjax.php. Rename the files as Payslip.php, Payslip.js, PayslipAjax.php respectively.

Open the file Payslip.php and change class ModuleClass extends CRMEntity to class Payslip extends CRMEntity.

Run the file create-payslip.php which you have initially created. If you are trying it in localhost, call http://localhost/ROOTDIRECTORY/create-payslip.php

That is it. Go to More menu and run the Payslip module.


 

user image
DouglasEa
Great website! It looks really good! Keep up the excellent job!
user image
Admin
Delete the existing payslip module. Refer the link to delete a module: http://www.codeigniter.in/blog/post/how-to-delete-a-module-from-vtiger-crm Once it is deleted, delete all the files associated with the module. After all are deleted, download the Payslip module from the location: www.codeigniter.in/projects/Payslip.zip Unzip the file and copy it to modules folder. Once it is done create the file create-payslip.php in the root folder as mentioned in the article and execute the file. Now click on the installed payslip module.
user image
anandan
i try this successfully created payslip module but click payslip module, i got blank page. how solve this probled.