feat: Enhance email functionality and PDF generation for Sales Orders
- Enabled SMTP debugging in PHPMailer for better error tracking. - Added a "Test send email" link in the Inventory Detail View for quick email testing. - Implemented automatic PDF generation and email sending upon Sales Order creation. - Created a new action for sending Sales Order emails with attached PDFs. - Added a new AJAX action for testing outgoing email server configurations. - Updated outgoing server settings to use new SMTP credentials. - Improved email templates for better user experience. - Added test scripts for validating PDF generation and email sending.
This commit is contained in:
63
modules/SalesOrder/actions/SendSaleOrderMailAjax.php
Normal file
63
modules/SalesOrder/actions/SendSaleOrderMailAjax.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
class SalesOrder_SendSaleOrderMailAjax_Action extends Vtiger_BasicAjax_Action
|
||||
{
|
||||
public function process(Vtiger_Request $request)
|
||||
{
|
||||
$recordId = $request->get('record');
|
||||
$response = new Vtiger_Response();
|
||||
|
||||
try {
|
||||
// Get record model
|
||||
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, 'SalesOrder');
|
||||
|
||||
// Load Outgoing Server config
|
||||
$outgoingServerSettingsModel = Settings_Vtiger_Systems_Model::getInstanceFromServerType('email', 'OutgoingServer');
|
||||
|
||||
// Include mailer
|
||||
require_once 'vtlib/Vtiger/Mailer.php';
|
||||
$mailer = new Vtiger_Mailer();
|
||||
|
||||
$mailer->IsSMTP();
|
||||
$mailer->Host = $outgoingServerSettingsModel->get('server');
|
||||
$mailer->Port = 587;
|
||||
$mailer->SMTPAuth = $outgoingServerSettingsModel->isSmtpAuthEnabled();
|
||||
$mailer->Username = $outgoingServerSettingsModel->get('server_username');
|
||||
$mailer->Password = $outgoingServerSettingsModel->get('server_password');
|
||||
$mailer->SMTPSecure = 'tls';
|
||||
$mailer->From = $outgoingServerSettingsModel->get('from_email_field');
|
||||
$mailer->FromName = 'Vtiger CRM';
|
||||
$mailer->AddAddress('souldibachir3150@gmail.com');
|
||||
$mailer->Subject = 'Sales Order #' . $recordModel->get('salesorder_no');
|
||||
|
||||
$mailer->Body = 'Attached is your Sales Order from Vtiger CRM.';
|
||||
|
||||
// Attach PDF
|
||||
$pdfPath = 'storage/SalesOrder_' . $recordId . '.pdf';
|
||||
$this->generatePDF($recordId, $pdfPath);
|
||||
$mailer->AddAttachment($pdfPath);
|
||||
|
||||
// Force send immediately
|
||||
$sent = $mailer->Send(true);
|
||||
|
||||
if ($sent) {
|
||||
$response->setResult(['success' => true, 'message' => '✅ Sales Order email sent successfully!']);
|
||||
} else {
|
||||
$response->setResult(['success' => false, 'message' => '⚠️ Failed to send Sales Order email.']);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$response->setError($e->getCode(), $e->getMessage());
|
||||
}
|
||||
|
||||
$response->emit();
|
||||
}
|
||||
|
||||
private function generatePDF($recordId, $pdfPath)
|
||||
{
|
||||
require_once 'modules/SalesOrder/SalesOrderPDFController.php';
|
||||
$pdfController = new Vtiger_SalesOrderPDFController('SalesOrder');
|
||||
$pdfController->loadRecord($recordId);
|
||||
$pdfContent = $pdfController->Output('', 'S'); // Output as string
|
||||
file_put_contents($pdfPath, $pdfContent);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user