Tuesday 5 December 2017

Configuring Email Campaign Schedulers in SugarCRM/SuiteCRM

In SugarCRM/SuiteCRM, we have to add cron jobs for running email campaigns successfully. so for scheduling it we have different methods for windows server & linux servers..

1) For Windows servers, we have to create a bat file & add it in windows task scheduler to run...
Create a bat file named schedler.bat , then put below content in that file.

cd C:\wamp\www\crmC:\wamp\bin\php\php5.3.4\php.exe -f cron.php

In Above script after CD , the location is where the crm is located... & then in the second line we have to mention the path of PHP exe located in your server, In my case location is that, it may vary for yours. so change according to that..

2) For Linux Server, we have to add command in cron jobs section..

    time            /usr/local/bin/php -q /home/user/public_html/CRM/cron.php >/dev/null 2>&1



Monday 4 December 2017

Sending mails From Modules in SugarCRM/SuiteCRM?

During CRM Customization, their may be requirement araise to send manual mails apart from default emails settedup in the SugarCRM. In those  scenarios, you can send html mails through the system..
So Script will be:-

<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
include_once('config.php');
require_once('include/SugarLogger/LoggerManager.php');
require_once('data/SugarBean.php');
require_once ('include/TimeDate.php');
require_once('include/entryPoint.php');
require_once('include/MVC/SugarApplication.php');
require_once ('include/modules.php');
require_once('include/utils.php');
require_once("modules/Administration/Administration.php");
require_once('include/SugarEmailAddress/SugarEmailAddress.php');
require_once("include/SugarPHPMailer.php");

//Download the file from Below Library
require_once('include/database/PearDatabase.php');

global $current_user, $timedate;

$db = DBManagerFactory::getInstance();


$to_email = ($_GET['test_email_address']);


if($_GET['test_email_address']=="")
die("To Email Address is missing");

$from_name = ($_GET['from_name']);
$from_email = ($_GET['from_email']);

$host = ($_GET['host']);
$port = ($_GET['port']);

$user_name = ($_GET['user_name']);
$password = ($_GET['password']);


// For Email sending
$mail = new SugarPHPMailer();
$admin = new Administration();
 
$admin->retrieveSettings();
if ($admin->settings['mail_sendtype'] == "SMTP") 
{
$mail->Host = $host;
$mail->Port = $port;
// if ($admin->settings['mail_smtpauth_req']) 
// {
$mail->SMTPAuth = TRUE;
$mail->Username = $user_name;
$mail->Password = $password;
//    }
   $mail->Mailer   = "smtp";
  // $mail->SMTPSecure = 'ssl';
   $mail->SMTPKeepAlive = true;
}
else {
$mail->mailer = 'sendmail';
}

$from = $from_email;
$fromName = $from_name;  
$mail->From     = $from;
$mail->FromName = $fromName;

$mail->ContentType = "text/html"; //"text/plain"

$mail->IsHTML(true);

$mail->AddAddress($to_email,"");
$mail->Subject =  "Client Update Test Email";   

$body= "This is a Test Email for Auto Client Update";
$mail->Body = from_html($body);

$success = $mail->Send();

if($success)
{
echo "Email Send";
}
else
{
echo "Error in Email Sending";
}

?>

Including Customized Modules/Fields in Global search in Sugarcrm/SuiteCRM

Defaultly in CRM, all modules & customized fields wont be available for global search . For making this module available for global search we have to do some tweaks..

First of all For enabling the modules we have to navigate to

CRM/custom/modules/

Open a file called unified_search_modules_display.php

Check or eg; if we want to enable search for Agreement module, then:-

'Agreement' => 
  array (
    'visible' => true,
  ),

Include this line in that file if you want to show that particular module....

If you didnt want to include taht module change to:-

'Agreement' => 
  array (
    'visible' => false,
  ),


So After Quick Repair & Rebuild this module will come in the List...

Now For enabling specific customized fields in Search.. For eg: agreementref_c in search then:-

1) Navigate to CRM/custom/Extension/modules/Agreement/Ext/Vardefs/

Create a file named customGlobalSearchFields.php

in That Include:-

<?php
$dictionary['Agreement']['fields']['agreementref_c']['unified_search'] = true;

?>


2) Now Go to CRM/custom/modules/Agreement/metadata/

open File called SearchFields.php

In That Include:-

'agreementref_c' => 
  array (
    'query_type' => 'default',
  ),

  So After Quick Repair & Rebuild , and do a search the result will come...

Save Dynamic Values in Fields after saving SugarCRM/SuiteCRM

Sometimes requirement may arise like, you have to calculate a dynamic value and save ina field upon saving a record. For eg: If you want to calculate commission of amount dynamicaly, Generating reference Number dynamically, Retreive some data from other module and save it in a partcular field  .etc we can use this method...

So For this for eg: If we want to do this partcular thing in a module called Agreements then:
Navigate to CRM/custom/modules/Agreeements/

Create a file called logic_hooks.php

The Main Purpose of this file is to handle this type of functions....

So The content of this file will be like this:-

<?php

$hook_version = 1; 

$hook_array = Array(); 

$hook_array['before_save'] = Array(); // before saving the record

$hook_array['after_save'] = Array();  // after saving record

$hook_array['process_record'] = Array(); //while processing the records view & list

$hook_array['before_save'][] = Array(1, 'CalculateCommission', 'custom/modules/Agreement/auto_calcs.php','AutoCals', 'CalculateCommission'); 

$hook_array['after_save'][] = Array(1, 'Generateref', 'custom/modules/Agreement/auto_calcs.php','AutoCals', 'Generateref'); 


?>


Now as I mentioned the location "custom/modules/Agreement/auto_calcs.php"

Create  a file called auto_calcs.php... Create Main function as Autocals... This you can provide names as your own wish...  Here am giving you an example only...

For eg: $hook_array['before_save'][] = Array(1, 'Title ur Giving For Function/any name', 'Location of file where u r defining the function','Main function name', 'Sub Function Name');


So asper our values our autocalcs.php file will be looking like:-

<?php

class AutoCals {


 function CalculateCommission($bean, $event, $arguments){
global $db;
$id=$bean->id;
$sql2 ="$query";
$row2 =$bean->db->query($sql2);
$record =$bean->db->fetchByAssoc($row2);

$amount=$record['amount'];

$commission=$amount*(10/100);
  $bean->commission = $commission;


}


 function Generateref($bean, $event, $arguments){
    global $db;
    $sid=$bean->id;

    //Refno. Calculation
$newrefno="generated";


$sql5 ="UPDATE `table` SET `refno`='$newrefno' WHERE `id`='$sid'";
$row5 =$bean->db->query($sql5);

    }



}

?>

perfrom a quick Repair & Rebuild to affect the changes..

Customizing Values of Fields in List view of SugarCRM/SuiteCRM?


Sometimes we want to change the colour or show some value in the list view of Sugar/Suite CRM. This we cannot do like the customization od edit & detail view explained in the previous posts. Here we have to do something different...
Here we have to make changes in the Core File itself..
 For eg: Consider you have an agreement module, You want to change colour of one field in agreement module to green or red. Like If agreement status is approved then the field should go green if it is unapproved its colour should go red..

 For that Navigate to CRM/modules/Agreement/ Folder..

 In that open file called Agreement.php

 <?php

 require_once('modules/Agreement/Agreement_sugar.php');
class Agreement extends Agreement_sugar {

function __construct(){
parent::__construct();
}


function fill_in_additional_list_fields()
{
parent::fill_in_additional_list_fields();

if($this->status_c=="Approved")
{
$this->status_c='<span style="color:green">'.$this->status_c.'</span>';

}


if($this->status_c=="Unapproved")
{
$this->status_c='<span style="color:red">'.$this->status_c.'</span>';

}



}



}


?>



If You want to do some calculations dynamic also, we can do it Like:-
 <?php

 require_once('modules/Agreement/Agreement_sugar.php');
class Agreement extends Agreement_sugar {

function __construct(){
parent::__construct();
}


function fill_in_additional_list_fields()
{
parent::fill_in_additional_list_fields();


$amount=$this->amount_c;

//Want to calculate 10% of the amount dynamically and assign to another field called commission then

$percentageamount=$amount*(10/100);

//assign calculated value to our field

$this->commission_c=$percentageamount;

}



}


?>

After that Do a quick Repair & Rebuild & check it..

Customizing Values of Fields in Edit view of SugarCRM/SuiteCRM?

Sometimes we have to display some related values in a module from other modules in CRM, But may be we cannot directly put it through studio. In these cases we have to customize the edit & detail view of that module..
For eg: Consider You have agreeement Module, In that module suppose direcly u r linking a partcular customer record only, but if u want to show in the detail view of partcular agreement like, Customers address, Phone number, Contactable status.etc.., direcly this is not possible via studio So For this purpose we have to customize...

1) First You have to open the partcular Module, Here For eg: Agreement Module..
Then CRM/custom/modules/Agreement/

Check a folder named view is their.. If not Create it...

create a file called  view.edit.php 

    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    
require_once('include/MVC/View/views/view.edit.php');

    class CasesViewEdit extends ViewEdit{


            function display() {

global $db;
if(empty($this->bean->id)){
global $app_strings;
sugar_die($app_strings['ERROR_NO_RECORD']);
}

$recordid= $this->bean->id;

$sql1 ="Query Here";
$row1 =$db->query($sql1);
$res =$db->fetchByAssoc($row1);
        //For eg:
        $address=$res['address']



$this->ss->assign("Employee_Address", $address);

                $this->ev->process();
                
                
                echo $this->ev->display();


                }

                function process() {
                    
                parent::process();
            
                }
    

    
    
    }
?>  


  Now open the folder CRM/custom/modules/metadata

  Open the file named  editviewdefs.php..

  Look for the corresponding field u craeated from studio:-
  for eg:-

        'lbl_detailview_panel1' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'address_c',
            'studio' => 'visible',
            'label' => 'LBL_ADDRESS',
            'customCode' => '{$Employee_Address}',
          ),
        ),
      ),

      Look For the specific field, & include the value in array like this..  'customCode' => '{$Employee_Address}',


      Now do a Quick Repair & Rebuild, the chnages will be saved..

Customizing Values of Fields in Detail view of SugarCRM/SuiteCRM?

Sometimes we have to display some related values in a module from other modules in CRM, But may be we cannot directly put it through studio. In these cases we have to customize the edit & detail view of that module..
For eg: Consider You have agreeement Module, In that module suppose direcly u r linking a partcular customer record only, but if u want to show in the detail view of partcular agreement like, Customers address, Phone number, Contactable status.etc.., direcly this is not possible via studio So For this purpose we have to customize...

1) First You have to open the partcular Module, Here For eg: Agreement Module..
Then CRM/custom/modules/Agreement/

Check a folder named view is their.. If not Create it...

create a file called  view.detail.php

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');


require_once('include/MVC/View/views/view.detail.php');

class AgreementViewDetail extends ViewDetail {


  function AgreementViewDetail(){
  parent::ViewDetail();
  }


  function display(){

global $db;
if(empty($this->bean->id)){
global $app_strings;
sugar_die($app_strings['ERROR_NO_RECORD']);
}

$recordid= $this->bean->id;

$sql1 ="Query Here";
$row1 =$db->query($sql1);
$res =$db->fetchByAssoc($row1);
        //For eg:
        $address=$res['address']



$this->ss->assign("Employee_Address", $address);


        $this->dv->process();
echo $this->dv->display();

}




}
  ?>


  Now open the folder CRM/custom/modules/metadata

  Open the file named  detailviewdefs.php..

  Look for the corresponding field u craeated from studio:-
  for eg:-

        'lbl_detailview_panel1' =>
      array (
        0 =>
        array (
          0 =>
          array (
            'name' => 'address_c',
            'studio' => 'visible',
            'label' => 'LBL_ADDRESS',
            'customCode' => '{$Employee_Address}',
          ),
        ),
      ),

      Look For the specific field, & include the value in array like this..  'customCode' => '{$Employee_Address}',


      Now do a Quick Repair & Rebuild, the chnages will be saved..

Customizing Header & Footer of Detail View , List View & Edit View in SugarCRM/SuiteCRM?

If you want to Include some texts or some marquees inside the edit view, detail view or list view in SugarCRM Views, Ever confused how to do it?

1) For Editing Detail View Header & footer..
Navigate to CRM/include/DetailView\ Folder.. Inside that You can see header.tpl & footer.tpl Files..

2) For Editing Edit View Header & Footer

Navigate to CRM/include/EditView\ Folder.. Inside that You can see header.tpl & footer.tpl files..

3) For Editing List View Header/Footer
Navigate to CRM/include/ListView\ Folder.. Inside that You can see header.tpl & footer.tpl files..

For Eg:

1)You want to show some particular texts inside detail view of some specific module only.. Then
Open DetailView header.tpl file
Include this in the file  where the script starts like this:-

{{if $module==Accounts}}
<center><label style="font:'Arial Black', Gadget, sans-serif; font-size:30px; font-weight:bold;">Clients </label></center>
{{/if}}


Now do a quick repair & rebuild, the change you can see the accounts module detail view..

2) If you want to show particular Record Title in the heading of detail View...
Open DetailView header.tpl file, edit and Include this:-

{{if $module==Accounts}}
<center>
<label style="font:'Arial', Gadget, sans-serif; color:red; font-size:20px; font-weight:bold;">  {$fields.name.options[$fields.name.value]}</label>
</center>
{{/if}}

where " name "  is the field value u want to show..

Suppose you want to show Client Indusry which is in DB has field name client_industry_c then, the code will be like:-

{{if $module==Accounts}}
<center>
<label style="font:'Arial', Gadget, sans-serif; color:red; font-size:20px; font-weight:bold;">  {$fields.client_industry_c.options[$fields.client_industry_c.value]}</label>
</center>
{{/if}}


After doing this, perform a quick Repair & rebuild, the changes you can view..

Where all the Dropdown Values of SugarCRM/SuiteCRM Saved? / Module name not appearing in SugarCRM MenuList?

In Sugarcrm you know that we can create dropdown lists. But its not saved in the database directly. Think some of you will be confused or tried hard to find out where it is stored. Actually it is stored in CRM/custom/language/en_us.lang.php.
This File have many Purposes...


  •  It stores the labels of all modules in the CRM system. So in old CRM versions, If you create some module and its Module name not showing in the main menu, You can include in this File. 

For eg:-

$app_list_strings['moduleList']['Attendance']='Attendance Log';


  •  All dropdown lists will be saving in this file.. 


For eg: if we create a dropdown called companytype_list, that will saved like this in the same file..

$GLOBALS['app_list_strings']['companytype_list']=array (
'' => '',
'Engineering' => 'Engineering',
'Fashion_Industry' => 'Fashion Industry',
'Food_Beverages' => 'Food & Beverages',
'IT' => 'IT',
'Medical' => 'Medical',
'Supermarkets' => 'Supermarkets',
'Automative' => 'Automative',
'Others' => 'Others',
);

so If you want to skip creating dropdown lists in multiple CRMs, Just copy paste same array in the en_us.lang.php file & do a Quick repair & rebuild from Admin.

Redirecting Default Home page in SugarCRM/ SuiteCRM to Custom Modules

In this Post Iam gonna explain how to show your customized module or module of your choice after logging from sugarCRM. Defaultly after logging in sugarcrm you are redirecting to Dashboard right? Sometime for developers they want it to redirect to attendance module or something.. So How to do this?

For that we have to know whats workflow in Sugarcrm when logging is happening. Actually in Sugarcrm after you submit your username & password, system is actually redirecting to USER Module for checking the Permissions. So we have to define logic hooks inside User Module and we have to redirect it to the specific module we want. So the steps we have to do to acheive this :-

1) Go to CRM/custom/modules/Users.. look for a file named logic_hooks.php. If its is not their create one , If it is their please edit the same with following contents.

<?php

 $hook_version = 1; 
$hook_array = Array(); 
$hook_array['after_login'] = Array(); 
$hook_array['after_login'][] = Array(1, 'attendance', 'custom/modules/Users/attendance.php','attendance', 'attendance');

?>

2. Create a file called attendance.php in custom/modules/Users/ Folder and put a function like

<?php
class attendance 
{
function attendance(&$bean, $event, $arguments)
{

SugarApplication::redirect("index.php?module=Attendance&action=attendance");

       }


}

?>

3.After This peform a Repair & Rebuild.. Now check after login, the page will be redirected to attendance module..