diff --git a/app/Config/Email.php b/app/Config/Email.php index 4dce650..f7e3ae0 100644 --- a/app/Config/Email.php +++ b/app/Config/Email.php @@ -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; } diff --git a/app/Controllers/Purchase.php b/app/Controllers/Purchase.php index a1061cc..395862d 100644 --- a/app/Controllers/Purchase.php +++ b/app/Controllers/Purchase.php @@ -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'); } } \ No newline at end of file diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php new file mode 100644 index 0000000..98abefe --- /dev/null +++ b/app/Helpers/MailHelper.php @@ -0,0 +1,47 @@ +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); + } + } + + +} +?> \ No newline at end of file diff --git a/app/Views/invoice_purchase_template.php b/app/Views/invoice_purchase_template.php index c3267e4..d3cbd51 100644 --- a/app/Views/invoice_purchase_template.php +++ b/app/Views/invoice_purchase_template.php @@ -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 { - - - - - - -
Vendor AddressShipping Address
+ + + - -
+ + + + + + + - - vendor_name ?>
- vendor_address != '' ? $value->vendor_address." ,
" : ''; ?> - vendor_city ?> - vendor_postal!=0): ?> - vendor_postal ?>
- - contact_person_mobile1." ." ?> - - + +
Vendor Address
+ + + vendor_name ?>
+ vendor_address != '' ? $value->vendor_address." ,
" : ''; ?> + vendor_city ?> + vendor_postal!=0): ?> + vendor_postal ?>
+ + contact_person_mobile1." ." ?> + + +
- - - billing_address != '' ? $value->vendor_address." ,
" : ''; ?> - billing_city ?> - billing_postal_code!=0): ?> - billing_postal_code ?>
- - +
+ + + + + + + + + + + +
Shipping Address
+ + + billing_address != '' ? $value->vendor_address." ,
" : ''; ?> + billing_city ?> + billing_postal_code!=0): ?> + billing_postal_code ?>
+ + - -
+
+ +

diff --git a/app/Views/vendor_form.php b/app/Views/vendor_form.php index 299fca6..03a9409 100644 --- a/app/Views/vendor_form.php +++ b/app/Views/vendor_form.php @@ -29,8 +29,8 @@
- - + +
diff --git a/invoice_2024-04-23-10-47-37.pdf b/invoice_2024-04-23-10-47-37.pdf new file mode 100644 index 0000000..875fd93 Binary files /dev/null and b/invoice_2024-04-23-10-47-37.pdf differ diff --git a/invoice_2024-04-23-10-48-33.pdf b/invoice_2024-04-23-10-48-33.pdf new file mode 100644 index 0000000..48fadc2 Binary files /dev/null and b/invoice_2024-04-23-10-48-33.pdf differ diff --git a/invoice_2024-04-23-10-50-01.pdf b/invoice_2024-04-23-10-50-01.pdf new file mode 100644 index 0000000..8616cc3 Binary files /dev/null and b/invoice_2024-04-23-10-50-01.pdf differ diff --git a/invoice_2024-04-23-10-50-31.pdf b/invoice_2024-04-23-10-50-31.pdf new file mode 100644 index 0000000..8b9f4a1 Binary files /dev/null and b/invoice_2024-04-23-10-50-31.pdf differ diff --git a/invoice_2024-04-23-10-51-05.pdf b/invoice_2024-04-23-10-51-05.pdf new file mode 100644 index 0000000..f41edae Binary files /dev/null and b/invoice_2024-04-23-10-51-05.pdf differ diff --git a/invoice_2024-04-23-10-51-30.pdf b/invoice_2024-04-23-10-51-30.pdf new file mode 100644 index 0000000..98e9ca3 Binary files /dev/null and b/invoice_2024-04-23-10-51-30.pdf differ diff --git a/invoice_2024-04-23-10-51-58.pdf b/invoice_2024-04-23-10-51-58.pdf new file mode 100644 index 0000000..4deb866 Binary files /dev/null and b/invoice_2024-04-23-10-51-58.pdf differ diff --git a/invoice_2024-04-23-10-52-13.pdf b/invoice_2024-04-23-10-52-13.pdf new file mode 100644 index 0000000..5530def Binary files /dev/null and b/invoice_2024-04-23-10-52-13.pdf differ diff --git a/invoice_2024-04-23-10-52-49.pdf b/invoice_2024-04-23-10-52-49.pdf new file mode 100644 index 0000000..53fc6b3 Binary files /dev/null and b/invoice_2024-04-23-10-52-49.pdf differ diff --git a/invoice_2024-04-23-10-53-13.pdf b/invoice_2024-04-23-10-53-13.pdf new file mode 100644 index 0000000..2402609 Binary files /dev/null and b/invoice_2024-04-23-10-53-13.pdf differ