[Vtigercrm-developers] Add documents to a custom module

William Bejarano william.bejarano at ito-software.com
Mon Jun 25 08:44:05 PDT 2012


Hello everybody

I created a new module and need add a documents field, I used 27 and 28
Uitype in this script,


// Just a bit of HTML formatting
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">';

echo '<html><head><title>vtlib Module Script</title>';
echo '<style type="text/css">@import url("themes/softed/style.css");br {
display: block; margin: 2px; }</style>';
echo '</head><body class=small style="font-size: 12px; margin: 2px;
padding: 2px;">';
echo '<a href="index.php"><img src="themes/softed/images/vtiger-crm.gif"
alt="vtiger CRM" title="vtiger CRM" border=0></a><hr style="height: 1px">';

// 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 = 'PayslipName';
$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 */

/** Create required fields and add to the block */
$fieldDoc2 = new Vtiger_Field();
$fieldDoc2->name = 'documentoa';
$fieldDoc2->label = 'documentoa';
$fieldDoc2->table = 'vtiger_notes';
$fieldDoc2->column = 'documentoa';
$fieldDoc2->columntype = 'VARCHAR(200)';
$fieldDoc2->uitype = 27;
$fieldDoc2->typeofdata = 'V~0';
$block1->addField($fieldDoc2); /** Creates the field and adds to block */
//$fieldDoc2->setRelatedModules(Array('Documents'));

/** Create required fields and add to the block */
$fieldDoc3 = new Vtiger_Field();
$fieldDoc3->name = 'documento';
$fieldDoc3->label = 'documento';
$fieldDoc3->table = 'vtiger_notes';
$fieldDoc3->column = 'documento';
$fieldDoc3->columntype = 'VARCHAR(200)';
$fieldDoc3->uitype = 28;
$fieldDoc3->typeofdata = 'V~0';
$block1->addField($fieldDoc3); /** Creates the field and adds to block */
//$fieldDoc3->setRelatedModules(Array('Documents'));



// Set at-least one field to identifier of module record
$module->setEntityIdentifier($field1);

$field2 = new Vtiger_Field();
$field2->name = 'PayslipType';
$field2->label = 'Payslip Type';
$field2->columntype = 'VARCHAR(100)';
$field2->uitype = 15;
$field2->typeofdata = 'V~O';// Varchar~Optional
$block1->addField($field2); /** table and column are automatically set */

$field2->setPicklistValues( Array ('Employee', 'Trainee'));

$field3 = new Vtiger_Field();
$field3->name = 'Month';
$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 contact';
$block1->addField($field4);
$field4->setRelatedModules(Array('Contacts'));

/** 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('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');

echo '</body></html>';


1)  The maximum upload size it is equal than 0MB.
2)  When i try upload a document, it isn't saved (I modified the maximum
upload with firebug)
3) In the section "More Information" on "document" cannot attach a file

Thks



-- 
*William Bejarano*
Ing. Sistemas
www.ito-software.co
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20120625/b850bcaa/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Untitled.jpg
Type: image/jpeg
Size: 34538 bytes
Desc: not available
Url : http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20120625/b850bcaa/attachment-0001.jpg 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot-Administrator - Payslipi - vtiger CRM 5 -	Commercial Open Source CRM - Google Chrome.png
Type: image/png
Size: 99966 bytes
Desc: not available
Url : http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20120625/b850bcaa/attachment-0001.png 


More information about the vtigercrm-developers mailing list