Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic
This commit is contained in:
commit
0dfb590319
@ -18,7 +18,7 @@ class Email extends BaseConfig
|
||||
/**
|
||||
* The mail sending protocol: mail, sendmail, smtp
|
||||
*/
|
||||
public string $protocol = 'mail';
|
||||
public string $protocol = 'smtp';
|
||||
|
||||
/**
|
||||
* The server path to Sendmail.
|
||||
@ -28,27 +28,27 @@ class Email extends BaseConfig
|
||||
/**
|
||||
* SMTP Server Hostname
|
||||
*/
|
||||
public string $SMTPHost = '';
|
||||
public string $SMTPHost = 'mail.venbait.in';
|
||||
|
||||
/**
|
||||
* SMTP Username
|
||||
*/
|
||||
public string $SMTPUser = '';
|
||||
public string $SMTPUser = 'bbone@venbait.in';
|
||||
|
||||
/**
|
||||
* SMTP Password
|
||||
*/
|
||||
public string $SMTPPass = '';
|
||||
public string $SMTPPass = 'xk!L(N_-R#};';
|
||||
|
||||
/**
|
||||
* SMTP Port
|
||||
*/
|
||||
public int $SMTPPort = 25;
|
||||
public int $SMTPPort = 465;
|
||||
|
||||
/**
|
||||
* SMTP Timeout (in seconds)
|
||||
*/
|
||||
public int $SMTPTimeout = 5;
|
||||
public int $SMTPTimeout = 1000;
|
||||
|
||||
/**
|
||||
* Enable persistent SMTP connections
|
||||
@ -62,7 +62,7 @@ class Email extends BaseConfig
|
||||
* to the server. 'ssl' means implicit SSL. Connection on port
|
||||
* 465 should set this to ''.
|
||||
*/
|
||||
public string $SMTPCrypto = 'tls';
|
||||
public string $SMTPCrypto = 'ssl';
|
||||
|
||||
/**
|
||||
* Enable word-wrap
|
||||
@ -77,7 +77,7 @@ class Email extends BaseConfig
|
||||
/**
|
||||
* Type of mail, either 'text' or 'html'
|
||||
*/
|
||||
public string $mailType = 'text';
|
||||
public string $mailType = 'html';
|
||||
|
||||
/**
|
||||
* Character set (utf-8, iso-8859-1, etc.)
|
||||
@ -118,4 +118,14 @@ class Email extends BaseConfig
|
||||
* Enable notify message from server
|
||||
*/
|
||||
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\PurchaseOrderChildModel;
|
||||
use Mpdf\Mpdf;
|
||||
use App\Helpers\MailHelper;
|
||||
|
||||
|
||||
class Purchase extends BaseController
|
||||
@ -297,12 +298,15 @@ class Purchase extends BaseController
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
@ -403,21 +407,12 @@ public function delete_purchase_product()
|
||||
// Return error response if deletion fails
|
||||
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
|
||||
$model = new PurchaseOrderModel();
|
||||
$data = $model->getPurchasePdf($purchase_order_id);
|
||||
|
||||
$items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
|
||||
|
||||
|
||||
|
||||
// print_r($items);die();
|
||||
|
||||
// print_r($invoiceItems);die();
|
||||
|
||||
$items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
|
||||
// Create an mPDF object
|
||||
$mpdf = new Mpdf([
|
||||
'mode' => '',
|
||||
@ -432,43 +427,36 @@ public function download_purchase_invoice($purchase_order_id)
|
||||
'margin_footer' =>-30,
|
||||
'orientation' => 'P',
|
||||
]);
|
||||
|
||||
|
||||
|
||||
$mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
|
||||
// Set PDF properties
|
||||
$mpdf->SetTitle('Invoice');
|
||||
$mpdf->SetAuthor($data[0]->branch_name);
|
||||
$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
|
||||
$html = view('invoice_purchase_template', ['sales' => $data,'items'=>$items]);
|
||||
// echo $html;die;
|
||||
// Load HTML into the mPDF instance
|
||||
$mpdf->WriteHTML($html);
|
||||
if($mail == null)
|
||||
{
|
||||
// Output the PDF to the browser for download
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
// Output the PDF to the browser for download
|
||||
$mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
|
||||
}
|
||||
|
||||
}
|
||||
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' => $email],500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@ -25,12 +25,12 @@
|
||||
}
|
||||
|
||||
/* Style for the table containing business details */
|
||||
table.business-details-table {
|
||||
table.business-details-table, table.addresses-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table.business-details-table td {
|
||||
table.business-details-table td, table.addresses-table td {
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
@ -52,12 +52,14 @@
|
||||
}
|
||||
|
||||
/* Style for the table containing invoice info */
|
||||
table.invoice-info-table {
|
||||
table.invoice-info-table, table.shipping-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -183,40 +185,59 @@ p {
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table class="addresses-table">
|
||||
<tr >
|
||||
<th class="billing-address">Vendor Address</th>
|
||||
<th class="shipping-address">Shipping Address</th>
|
||||
</tr>
|
||||
<tr >
|
||||
<td class="billing-address">
|
||||
<table class="main-table">
|
||||
<tr>
|
||||
<td>
|
||||
<table class="addresses-table">
|
||||
<tr >
|
||||
<th class="billing-address">Vendor Address</th>
|
||||
</tr>
|
||||
<tr >
|
||||
<td class="billing-address">
|
||||
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
<?= $value->vendor_name ?><br>
|
||||
<?= $value->vendor_address != '' ? $value->vendor_address." , <br>" : ''; ?>
|
||||
<?= $value->vendor_city ?>
|
||||
<?php if ($value->vendor_postal!=0): ?>
|
||||
<?= $value->vendor_postal ?><br>
|
||||
<?php endif; ?>
|
||||
<?= $value->contact_person_mobile1." ." ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</td>
|
||||
<tr>
|
||||
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
<?= $value->vendor_name ?><br>
|
||||
<?= $value->vendor_address != '' ? $value->vendor_address." , <br>" : ''; ?>
|
||||
<?= $value->vendor_city ?>
|
||||
<?php if ($value->vendor_postal!=0): ?>
|
||||
<?= $value->vendor_postal ?><br>
|
||||
<?php endif; ?>
|
||||
<?= $value->contact_person_mobile1." ." ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<tr>
|
||||
<td class="shipping-address">
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
|
||||
<?= $value->billing_address != '' ? $value->vendor_address." , <br>" : ''; ?>
|
||||
<?= $value->billing_city ?>
|
||||
<?php if ($value->billing_postal_code!=0): ?>
|
||||
<?= $value->billing_postal_code ?><br>
|
||||
<?php endif; ?>
|
||||
|
||||
<td>
|
||||
<table class="shipping-table">
|
||||
<tr >
|
||||
<th class="shipping-address">Shipping Address</th>
|
||||
</tr>
|
||||
<tr >
|
||||
<td class="shipping-address">
|
||||
<?php foreach ($sales as $value) : ?>
|
||||
|
||||
<?= $value->billing_address != '' ? $value->vendor_address." , <br>" : ''; ?>
|
||||
<?= $value->billing_city ?>
|
||||
<?php if ($value->billing_postal_code!=0): ?>
|
||||
<?= $value->billing_postal_code ?><br>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php endforeach; ?>
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
</td>
|
||||
<tr>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<br> <br>
|
||||
<table class="invoice-related-table">
|
||||
<thead>
|
||||
|
||||
@ -29,8 +29,8 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputEmail4" class="col-form-label">Email</label>
|
||||
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($vendor['vendor_email']) ? $vendor['vendor_email'] : '' ?>" >
|
||||
<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'] : '' ?>" required>
|
||||
</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