Hi,
Thanks for the reply.
I thought because it is blacklisted in Sugarcrm, it is blacklisted here too. Please find the below details about system details, objective and approach.
System Details:
What is your SuiteCRM version?
v.7.10.9
PHP?
v7.2
MySQL?
mysqli v5.0.12
Webserver?
Apache
Operating System?
ubuntu v18.04.1
Primary Objective:
On click of a button “send letter”, it should create a word file by fetching some field’s data, and send an email to the recipient with that word file as attachment.
Approach I am working on:
I have created a button, on click of that button, one controller file (controller.php) gets called which creates a word document by fetching values from some fields and gets saved in a folder. Then, a function in file “phpWord.php” fetches that file and sends an email.
Code Snippet of controller.php:
public function action_releaseLetter(){
$employee = new nhrem_nhr_employee();
$employee->retrieve($_REQUEST['id']);
$db= DbManagerFactory::getInstance();
$q = "SELECT accounts_nhrem_nhr_employee_1accounts_ida FROM accounts_nhrem_nhr_employee_1_c where accounts_nhrem_nhr_employee_1_c.accounts_nhrem_nhr_employee_1nhrem_nhr_employee_idb = '".$_REQUEST['id']."' " ;
$res = $db->query($q);
$row = $db->fetchByAssoc($res);
$account = new Account();
$account->retrieve($row['accounts_nhrem_nhr_employee_1accounts_ida']);
$sqlEmail="SELECT `email_addresses`.`email_address` AS `email_address` FROM `email_addresses`, `email_addr_bean_rel` WHERE `email_addr_bean_rel`.`bean_id`='".$_REQUEST['id']."' AND `email_addr_bean_rel`.`bean_module`='nhrem_nhr_employee' AND `email_addr_bean_rel`.`email_address_id`=`email_addresses`.`id` AND `email_addr_bean_rel`.deleted = 0 ";
$resultEmail=$db->query($sqlEmail) ;
$rowEmail = $db->fetchByAssoc($resultEmail);
echo "em: ".$rowEmail['email_address'];
$fullname = ucwords($employee->name_as_identity);
$current_date = date('Y-m-d');
$company = $this->modifyCompanyName($account->name).", ".$employee->dpro_work_location ;
echo "full_name: ".$fullname."<br/>";
echo "Company: ".$company."<br/>";
$included_files = get_included_files();
if($employee->date_of_leaving != ''){
$lwd = $employee->date_of_leaving;
}else{
$lwd = $current_date;
}
$date1 = date_create($employee->expected_of_joining);
$date2 = date_create($lwd);
$interval = date_diff($date1,$date2);
$date_diff = $interval->format("%a");
echo "<br/>".$date_diff."<br/>";
echo "type: ".$employee->employee_type ;
$PHPWord = new PHPWord();
$document;
if($date_diff < 180){
if($employee->employee_type == 'billable'){
$document = $PHPWord->loadTemplate("Service_Certificate-External-SCE-v17.1-220217.docx");
}else{
$document = $PHPWord->loadTemplate("Service_Certificate-Internal-SCI-v17.1-220217.docx");
}
}else{
$document = $PHPWord->loadTemplate(‘Resignation_Acceptance_with_Service_Cert-RAEC-v17.1-220217.docx’);
}
$doc = PHPWord_Template();
$doc->setValue(‘fullname’, $fullname);
$document->setValue(‘pan’, $employee->identity_no);
$document->setValue(‘doj’, date(‘dS F, Y’,strtotime($employee->expected_of_joining)));
$document->setValue(‘lwd’, date(‘dS F, Y’,strtotime($lwd)));
if($employee->employee_type == ‘billable’){
$document->setValue(‘company’, $company);
}
$document->setValue(‘designation’, $employee->dpro_designation_offered);
$document->setValue(‘date_of_issue’, date(‘dS F, Y’,strtotime($current_date)));
$document->setValue(‘email’, $employee->email1);
$doc_name = ‘Service_Certificate_’.$fullname;
$document->save(‘downloadDoc/’.$doc_name.’.docx’);
$filename = $doc_name.’.docx’;
$file_ext = ‘.doc’;
$file_mime_type = ‘application/msword’;
$qId = “select UUID() as uid”;
$resId = $db->query($qId);
$rowId = $db->fetchByAssoc($resId);
$uid = $rowId[‘uid’];
$date_entered = date(‘Y-m-d:hh mm ss’);
//Move document to a different directory
//rename(‘downloadDoc/’.$filename,‘cache/upload/’.$uid);
exit;
}
Code from phpWord.php:
public function loadTemplate($strFilename) {
echo file_exists("Service_Certificate-External-SCE-v17.1-220217.docx");
if(file_exists($strFilename)) {
$template = new PHPWord_Template($strFilename);
return $template;
} else {
trigger_error('Template file '.$strFilename.' not found.', E_ERROR);
}
}
file_exists returns nothing, not even false.
Also, the template doc is in the same folder where the code file is.