Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic

This commit is contained in:
aadhavan valli 2024-04-23 17:17:51 +05:30
commit 0dfb590319
15 changed files with 148 additions and 82 deletions

View File

@ -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;
} }

View File

@ -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
$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');
} }
} }

View 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);
}
}
}
?>

View File

@ -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,40 +185,59 @@ p {
</tr> </tr>
</table> </table>
<table class="addresses-table"> <table class="main-table">
<tr > <tr>
<th class="billing-address">Vendor Address</th> <td>
<th class="shipping-address">Shipping Address</th> <table class="addresses-table">
</tr> <tr >
<tr > <th class="billing-address">Vendor Address</th>
<td class="billing-address"> </tr>
<tr >
<td class="billing-address">
<?php foreach ($sales as $value) : ?> <?php foreach ($sales as $value) : ?>
<?= $value->vendor_name ?><br> <?= $value->vendor_name ?><br>
<?= $value->vendor_address != '' ? $value->vendor_address." , <br>" : ''; ?> <?= $value->vendor_address != '' ? $value->vendor_address." , <br>" : ''; ?>
<?= $value->vendor_city ?> <?= $value->vendor_city ?>
<?php if ($value->vendor_postal!=0): ?> <?php if ($value->vendor_postal!=0): ?>
<?= $value->vendor_postal ?><br> <?= $value->vendor_postal ?><br>
<?php endif; ?> <?php endif; ?>
<?= $value->contact_person_mobile1." ." ?> <?= $value->contact_person_mobile1." ." ?>
<?php endforeach; ?> <?php endforeach; ?>
</td>
<tr>
</tr>
</table>
</td> </td>
<tr> <td>
<td class="shipping-address"> <table class="shipping-table">
<?php foreach ($sales as $value) : ?> <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_address != '' ? $value->vendor_address." , <br>" : ''; ?>
<?= $value->billing_city ?> <?= $value->billing_city ?>
<?php if ($value->billing_postal_code!=0): ?> <?php if ($value->billing_postal_code!=0): ?>
<?= $value->billing_postal_code ?><br> <?= $value->billing_postal_code ?><br>
<?php endif; ?> <?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
</td>
<tr>
</tr>
</table>
</td> </td>
</tr> </tr>
</table> </table>
<br> <br> <br> <br>
<table class="invoice-related-table"> <table class="invoice-related-table">
<thead> <thead>

View File

@ -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>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.