CHANGE_purchase_module:ss
This commit is contained in:
parent
8600b6a6cc
commit
cd21a65995
@ -18,7 +18,7 @@ class Email extends BaseConfig
|
|||||||
/**
|
/**
|
||||||
* The mail sending protocol: mail, sendmail, smtp
|
* The mail sending protocol: mail, sendmail, smtp
|
||||||
*/
|
*/
|
||||||
public string $protocol = 'mail';
|
public string $protocol = 'smtp';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The server path to Sendmail.
|
* The server path to Sendmail.
|
||||||
@ -28,27 +28,27 @@ class Email extends BaseConfig
|
|||||||
/**
|
/**
|
||||||
* SMTP Server Hostname
|
* SMTP Server Hostname
|
||||||
*/
|
*/
|
||||||
public string $SMTPHost = '';
|
public string $SMTPHost = 'mail.venbait.in';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Username
|
* SMTP Username
|
||||||
*/
|
*/
|
||||||
public string $SMTPUser = '';
|
public string $SMTPUser = 'bbone@venbait.in';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Password
|
* SMTP Password
|
||||||
*/
|
*/
|
||||||
public string $SMTPPass = '';
|
public string $SMTPPass = 'xk!L(N_-R#};';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Port
|
* SMTP Port
|
||||||
*/
|
*/
|
||||||
public int $SMTPPort = 25;
|
public int $SMTPPort = 465;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Timeout (in seconds)
|
* SMTP Timeout (in seconds)
|
||||||
*/
|
*/
|
||||||
public int $SMTPTimeout = 5;
|
public int $SMTPTimeout = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable persistent SMTP connections
|
* Enable persistent SMTP connections
|
||||||
@ -62,7 +62,7 @@ class Email extends BaseConfig
|
|||||||
* to the server. 'ssl' means implicit SSL. Connection on port
|
* to the server. 'ssl' means implicit SSL. Connection on port
|
||||||
* 465 should set this to ''.
|
* 465 should set this to ''.
|
||||||
*/
|
*/
|
||||||
public string $SMTPCrypto = 'tls';
|
public string $SMTPCrypto = 'ssl';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable word-wrap
|
* Enable word-wrap
|
||||||
@ -77,7 +77,7 @@ class Email extends BaseConfig
|
|||||||
/**
|
/**
|
||||||
* Type of mail, either 'text' or 'html'
|
* Type of mail, either 'text' or 'html'
|
||||||
*/
|
*/
|
||||||
public string $mailType = 'text';
|
public string $mailType = 'html';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Character set (utf-8, iso-8859-1, etc.)
|
* Character set (utf-8, iso-8859-1, etc.)
|
||||||
@ -118,4 +118,14 @@ class Email extends BaseConfig
|
|||||||
* Enable notify message from server
|
* Enable notify message from server
|
||||||
*/
|
*/
|
||||||
public bool $DSN = false;
|
public bool $DSN = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SMTP Debugging level. Set to 0 to disable debugging.
|
||||||
|
* Set to 1 to output server connection status only.
|
||||||
|
* Set to 2 for more detailed debugging output.
|
||||||
|
* Set to 3 for maximum debugging output.
|
||||||
|
*/
|
||||||
|
public int $SMTPDebug = 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use App\Models\PurchaseOrderModel;
|
|||||||
use App\Models\BusinessModel;
|
use App\Models\BusinessModel;
|
||||||
use App\Models\PurchaseOrderChildModel;
|
use App\Models\PurchaseOrderChildModel;
|
||||||
use Mpdf\Mpdf;
|
use Mpdf\Mpdf;
|
||||||
|
use App\Helpers\MailHelper;
|
||||||
|
|
||||||
|
|
||||||
class Purchase extends BaseController
|
class Purchase extends BaseController
|
||||||
@ -297,12 +298,15 @@ class Purchase extends BaseController
|
|||||||
|
|
||||||
$PurchaseOrderChildModel->insert($child_data);
|
$PurchaseOrderChildModel->insert($child_data);
|
||||||
|
|
||||||
|
// send purhase data through mail
|
||||||
|
$VendorModel = new VendorModel();
|
||||||
|
$vendor = $VendorModel->where('vendor_id',$this->request->getPost('vendor_id'))->findAll();
|
||||||
|
$this->download_purchase_invoice($purchase_order_id, $vendor[0]['vendor_email']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return redirect()->to('purchase_index');
|
return redirect()->to('purchase_index');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,21 +407,12 @@ public function delete_purchase_product()
|
|||||||
// Return error response if deletion fails
|
// Return error response if deletion fails
|
||||||
return $this->response->setJSON(['success' => false]);
|
return $this->response->setJSON(['success' => false]);
|
||||||
}
|
}
|
||||||
public function download_purchase_invoice($purchase_order_id)
|
public function download_purchase_invoice($purchase_order_id, $mail = null)
|
||||||
{
|
{
|
||||||
// echo "hello"; die;
|
|
||||||
// Fetch the invoice data based on $invoice_id
|
// Fetch the invoice data based on $invoice_id
|
||||||
$model = new PurchaseOrderModel();
|
$model = new PurchaseOrderModel();
|
||||||
$data = $model->getPurchasePdf($purchase_order_id);
|
$data = $model->getPurchasePdf($purchase_order_id);
|
||||||
|
|
||||||
$items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
|
$items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// print_r($items);die();
|
|
||||||
|
|
||||||
// print_r($invoiceItems);die();
|
|
||||||
|
|
||||||
// Create an mPDF object
|
// Create an mPDF object
|
||||||
$mpdf = new Mpdf([
|
$mpdf = new Mpdf([
|
||||||
'mode' => '',
|
'mode' => '',
|
||||||
@ -432,43 +427,36 @@ public function download_purchase_invoice($purchase_order_id)
|
|||||||
'margin_footer' =>-30,
|
'margin_footer' =>-30,
|
||||||
'orientation' => 'P',
|
'orientation' => 'P',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
|
$mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
|
||||||
// Set PDF properties
|
// Set PDF properties
|
||||||
$mpdf->SetTitle('Invoice');
|
$mpdf->SetTitle('Invoice');
|
||||||
$mpdf->SetAuthor($data[0]->branch_name);
|
$mpdf->SetAuthor($data[0]->branch_name);
|
||||||
$mpdf->SetCreator('');
|
$mpdf->SetCreator('');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Generate the PDF content (HTML)
|
|
||||||
// if ($data[0]->status === 'Draft') {
|
|
||||||
// // Set the watermark text and options
|
|
||||||
// $mpdf->SetWatermarkText('Draft');
|
|
||||||
// $mpdf->showWatermarkText = true;
|
|
||||||
// }
|
|
||||||
// if ($data[0]->status === 'Cancelled') {
|
|
||||||
// // Set the watermark text and options
|
|
||||||
// $mpdf->SetWatermarkText('Cancelled');
|
|
||||||
// $mpdf->showWatermarkText = true;
|
|
||||||
// }
|
|
||||||
// if ($data[0]->status === 'Void') {
|
|
||||||
// // Set the watermark text and options
|
|
||||||
// $mpdf->SetWatermarkText('Void');
|
|
||||||
// $mpdf->showWatermarkText = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// Generate the PDF content (HTML) with data
|
// Generate the PDF content (HTML) with data
|
||||||
$html = view('invoice_purchase_template', ['sales' => $data,'items'=>$items]);
|
$html = view('invoice_purchase_template', ['sales' => $data,'items'=>$items]);
|
||||||
// echo $html;die;
|
|
||||||
// Load HTML into the mPDF instance
|
// Load HTML into the mPDF instance
|
||||||
$mpdf->WriteHTML($html);
|
$mpdf->WriteHTML($html);
|
||||||
|
if($mail == null)
|
||||||
|
{
|
||||||
// Output the PDF to the browser for download
|
// Output the PDF to the browser for download
|
||||||
$mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
|
$mpdf->Output($data[0]->order_number.'-' . date('Y-m-d H-i-s') . '.pdf', 'D');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pdfFilePath = $data[0]->order_number.'-' . date('Y-m-d-H-i-s') . '.pdf';
|
||||||
|
$mpdf->Output($pdfFilePath, 'F');
|
||||||
|
|
||||||
|
$data['mail'] = $mail;
|
||||||
|
$data['subject'] = "The Mechanic";
|
||||||
|
$data['message'] = "test";
|
||||||
|
$data['attachment'] = $pdfFilePath;
|
||||||
|
$mail_response = MailHelper::send_email($data);
|
||||||
|
if(json_decode($mail_response)->code == 200)
|
||||||
|
{
|
||||||
|
unlink($pdfFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
47
app/Helpers/MailHelper.php
Normal file
47
app/Helpers/MailHelper.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
|
||||||
|
class MailHelper
|
||||||
|
{
|
||||||
|
public static function send_email($params)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
$email = $params['mail'];
|
||||||
|
$subject = $params['subject'];
|
||||||
|
$message = $params['message'];
|
||||||
|
|
||||||
|
$email = \Config\Services::email();
|
||||||
|
$email->setMailType('html');
|
||||||
|
$email->setFrom('bbone@venbait.in', 'The Mechnaic');
|
||||||
|
|
||||||
|
$email->setTo($email);
|
||||||
|
|
||||||
|
$email->setSubject($subject);
|
||||||
|
$email->setMessage($message);
|
||||||
|
|
||||||
|
if(isset($params['attachment'])) { $email->attach($params['attachment']); }
|
||||||
|
|
||||||
|
if ($email->send()) {
|
||||||
|
return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...','data' => $email,],200);
|
||||||
|
} else {
|
||||||
|
return json_encode(['status' => 'failed','code' => 404,'message'=>'Email Sent Failed...','data' => $email ],404);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return json_encode(['status' => 'failed','code' => 500,'data' => $emaill],500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@ -25,12 +25,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Style for the table containing business details */
|
/* Style for the table containing business details */
|
||||||
table.business-details-table {
|
table.business-details-table, table.addresses-table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
table.business-details-table td {
|
table.business-details-table td, table.addresses-table td {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
@ -52,12 +52,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Style for the table containing invoice info */
|
/* Style for the table containing invoice info */
|
||||||
table.invoice-info-table {
|
table.invoice-info-table, table.shipping-table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
table.invoice-info-table th,
|
table.invoice-info-table th,
|
||||||
table.invoice-info-table td {
|
table.invoice-info-table td,
|
||||||
|
table.shipping-table th,
|
||||||
|
table.shipping-table td {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,10 +185,12 @@ p {
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<table class="main-table">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
<table class="addresses-table">
|
<table class="addresses-table">
|
||||||
<tr >
|
<tr >
|
||||||
<th class="billing-address">Vendor Address</th>
|
<th class="billing-address">Vendor Address</th>
|
||||||
<th class="shipping-address">Shipping Address</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr >
|
<tr >
|
||||||
<td class="billing-address">
|
<td class="billing-address">
|
||||||
@ -203,6 +207,16 @@ p {
|
|||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</td>
|
</td>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<table class="shipping-table">
|
||||||
|
<tr >
|
||||||
|
<th class="shipping-address">Shipping Address</th>
|
||||||
|
</tr>
|
||||||
|
<tr >
|
||||||
<td class="shipping-address">
|
<td class="shipping-address">
|
||||||
<?php foreach ($sales as $value) : ?>
|
<?php foreach ($sales as $value) : ?>
|
||||||
|
|
||||||
@ -215,8 +229,15 @@ p {
|
|||||||
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</td>
|
</td>
|
||||||
|
<tr>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
<br> <br>
|
<br> <br>
|
||||||
<table class="invoice-related-table">
|
<table class="invoice-related-table">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@ -29,8 +29,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-4">
|
||||||
<label for="inputEmail4" class="col-form-label">Email</label>
|
<label for="inputEmail4" class="col-form-label">Email<span class="text-danger">*</span></label>
|
||||||
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($vendor['vendor_email']) ? $vendor['vendor_email'] : '' ?>" >
|
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($vendor['vendor_email']) ? $vendor['vendor_email'] : '' ?>" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
invoice_2024-04-23-10-47-37.pdf
Normal file
BIN
invoice_2024-04-23-10-47-37.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-48-33.pdf
Normal file
BIN
invoice_2024-04-23-10-48-33.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-50-01.pdf
Normal file
BIN
invoice_2024-04-23-10-50-01.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-50-31.pdf
Normal file
BIN
invoice_2024-04-23-10-50-31.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-51-05.pdf
Normal file
BIN
invoice_2024-04-23-10-51-05.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-51-30.pdf
Normal file
BIN
invoice_2024-04-23-10-51-30.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-51-58.pdf
Normal file
BIN
invoice_2024-04-23-10-51-58.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-52-13.pdf
Normal file
BIN
invoice_2024-04-23-10-52-13.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-52-49.pdf
Normal file
BIN
invoice_2024-04-23-10-52-49.pdf
Normal file
Binary file not shown.
BIN
invoice_2024-04-23-10-53-13.pdf
Normal file
BIN
invoice_2024-04-23-10-53-13.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user