From ebb6e7840cb44531b3e09096f0ff450f012826ad Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Wed, 17 Jul 2024 16:14:36 +0530 Subject: [PATCH] CHANGE_ADD_DELETE_BUTTON_DOC_NOT_SHARED_ADD_NEW_IN_HISTROY : AADHAVAN --- app/Config/Routes.php | 1 + app/Controllers/BusinessController.php | 3 +- app/Controllers/MasterController.php | 43 ++++- app/Helpers/MailHelper.php | 84 ++++------ app/Views/business_form.php | 213 +++++++++++++++---------- app/Views/layout/header.php | 34 ++-- app/Views/share_docs.php | 45 +++++- 7 files changed, 269 insertions(+), 154 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index aafa66c..f6fb9e0 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -76,6 +76,7 @@ use CodeIgniter\Router\RouteCollection; $routes->get('client_docs_histroy/(:any)','MasterController::client_docs_histroy/$1'); $routes->match(['get','post'],'/change_doc_status','MasterController::change_doc_status'); $routes->match(['get','post'],'/rememeber_notification','MasterController::rememeber_notification'); + $routes->match(['get','post'],'/delete_doc','MasterController::delete_doc'); $routes->match(['get','post'],'/test','MasterController::test'); $routes->post('doc_generate_otp','MasterController::doc_generate_otp'); $routes->post('doc_verify_otp','MasterController::doc_verify_otp'); diff --git a/app/Controllers/BusinessController.php b/app/Controllers/BusinessController.php index 1568721..51938fe 100644 --- a/app/Controllers/BusinessController.php +++ b/app/Controllers/BusinessController.php @@ -176,8 +176,9 @@ class BusinessController extends BaseController $mail_config = $this->request->getPost(); $r_mail = $this->request->getPost('r_email'); $MailHelper = new MailHelper(); - print_r($MailHelper->check_mail_config($r_mail, $mail_config));die; + $mail_check_status = $MailHelper->check_mail_config($r_mail, $mail_config); + return $mail_check_status; } catch (\Exception $exception) { return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500); } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index ef586f5..cef4a2b 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -571,6 +571,8 @@ class MasterController extends BaseController $placeHolder = '%'.$key.'%'; $data['body_html'] = str_replace($placeHolder,$value,$data['body_html']); } + $data['business_list'] = $this->BusinessModel->findAll(); + echo view('layout/header', ['Data'=>$userData]); echo view('client_docs_preview',$data); echo view('layout/footer'); @@ -662,6 +664,7 @@ class MasterController extends BaseController { // try { + $client_mail_id = ''; $doc_id = $this->request->getPost('doc_id'); $is_active = $this->request->getPost('is_active'); $data['is_active'] = $is_active; @@ -675,7 +678,7 @@ class MasterController extends BaseController ->join('client_branch', 'client_docs.client_branch_id = client_branch.id', 'left') ->join('client', 'client_branch.client_id = client.client_id', 'left') ->where('client_docs.id', $doc_id)->get()->getRow(); - + $client_mail_id = $clientData->email; if($clientData->individual == 1){ $clientData = $this->ClientDocsModel->select('client.name as client_name, client.*, client_branch.sms, client_branch.whatsapp') ->join('client_branch', 'client_docs.client_branch_id = client_branch.id', 'left') @@ -699,6 +702,8 @@ class MasterController extends BaseController $message = "Dear " . $clientData->client_name . ",
" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.

" . $url; // print_r($clientData->email);die; $mail_config = [ + 'protocol' => 'smtp', + 'mailType' => 'html', 'SMTPHost' => $businessData->smtp_host, 'SMTPUser' => $businessData->smtp_user, 'SMTPPass' => $businessData->smtp_pass, @@ -706,7 +711,7 @@ class MasterController extends BaseController 'sender_email' => $businessData->business_mail, 'sender_name' => $businessData->business_name ]; - $MailHelper->send_url_email($clientData->email , '', $subject, $message, $mail_config); + $mail_status = $MailHelper->send_url_email($clientData->email , '', $subject, $message, $mail_config); $notificationHelper = new NotificationHelper(); $number ='91'. $clientData->mobile_no; // Replace with dynamic recipient number if($clientData->whatsapp == 1){ @@ -719,6 +724,15 @@ class MasterController extends BaseController $statusData['created_by'] = $this->session->get('is_staff_logged_in'); $statusData['status'] = 'Shared'; $this->DocsStatusModel->insert($statusData); + + $statusData['note'] = $clientData->email; + if($mail_status['status'] == 'success'){ + $statusData['status'] = 'Mail Success'; + $this->DocsStatusModel->insert($statusData); + }else{ + $statusData['status'] = 'Mail Failed'; + $this->DocsStatusModel->insert($statusData); + } }else{ $statusData['client_docs_id'] = $doc_id; $statusData['is_staff'] = 1; @@ -729,7 +743,11 @@ class MasterController extends BaseController $updated = $this->ClientDocsModel->update($doc_id, $data); if ($updated) { - return $this->response->setJSON(['status' => 'success','code' => 200,'data' => true],200); + if($is_active == 1){ + return $this->response->setJSON(['status' => 'success','code' => 200,'data' => "Document Shared with Email - ". $client_mail_id],200); + }else{ + return $this->response->setJSON(['status' => 'success','code' => 200,'data' => "Document Reverted "],200); + } } else { $result = "No Match's"; return $this->response->setJSON(['status' => 'failed','code' => 404,'data' => $result],404); @@ -765,11 +783,12 @@ class MasterController extends BaseController // ->where('business.business_id',$this->session->get('logged_in_staff_business_id')) ->where('business_id', $clientData->business_id) ->get()->getRow(); - // print_r($businessData);die; $subject = 'BB-Sign Verify Document'; $message = "Dear " . $clientData->client_name . ",
" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.

" . $url; $mail_config = [ + 'protocol' => 'smtp', + 'mailType' => 'html', 'SMTPHost' => $businessData->smtp_host, 'SMTPUser' => $businessData->smtp_user, 'SMTPPass' => $businessData->smtp_pass, @@ -795,6 +814,22 @@ class MasterController extends BaseController } } + public function delete_doc() + { + try { + $doc_id = $this->request->getPost('doc_id'); + + $delete_doc = $this->ClientDocsModel->where('id', $doc_id)->delete(); + $delete_history = $this->DocsStatusModel->where('client_docs_id', $doc_id)->delete(); + + + + return $this->respond(['success' => true, 'data' => 'Doc Deleted SuccessFully']); + } catch (\Exception $exception) { + return $this->response->setJSON(['status' => 'failed','code' => 500,'data' => $exception],500); + } + } + public function doc_generate_otp() { try { diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 26615aa..ae4ebe8 100644 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -15,14 +15,14 @@ class MailHelper try { $email = \Config\Services::email(); - $email->initialize([ - 'protocol' => $config['protocol'], - 'SMTPHost' => $config['SMTPHost'], - 'SMTPUser' => $config['SMTPUser'], - 'SMTPPass' => $config['SMTPPass'], - 'SMTPPort' => $config['SMTPPort'], - // 'mailType' => $config['mailType'] - ]); + // $email->initialize([ + // 'protocol' => $config['protocol'], + // 'SMTPHost' => $config['SMTPHost'], + // 'SMTPUser' => $config['SMTPUser'], + // 'SMTPPass' => $config['SMTPPass'], + // 'SMTPPort' => $config['SMTPPort'], + // // 'mailType' => $config['mailType'] + // ]); // $email->setFrom($config['sender_email'], $config['sender_name']);/ $email->setMailType('html'); @@ -50,36 +50,22 @@ class MailHelper public static function send_url_email($email_id, $branch_email, $subject, $message, $mail_config = []) { - // print_r("helllo");die; - // try { - $default_config = [ - 'protocol' => 'smtp', - 'SMTPHost' => 'mail.venbait.in', - 'SMTPUser' => 'bbone@venbait.in', - 'SMTPPass' => 'xk!L(N_-R#};', - 'SMTPPort' => 465, - 'mailType' => 'html', - 'sender_email' => 'bbone@venbait.in', - 'sender_name' => 'BB-Sign' - ]; - // Merge default config with provided config - $config = array_merge($default_config, $mail_config); $email = \Config\Services::email(); $email->initialize([ - 'protocol' => $config['protocol'], - 'SMTPHost' => $config['SMTPHost'], - 'SMTPUser' => $config['SMTPUser'], - 'SMTPPass' => $config['SMTPPass'], - 'SMTPPort' => (int)$config['SMTPPort'], - 'mailType' => $config['mailType'] + 'protocol' => $mail_config['protocol'], + 'SMTPHost' => $mail_config['SMTPHost'], + 'SMTPUser' => $mail_config['SMTPUser'], + 'SMTPPass' => $mail_config['SMTPPass'], + 'SMTPPort' => (int)$mail_config['SMTPPort'], + 'mailType' => $mail_config['mailType'] ]); - $email->setFrom($config['sender_email'], $config['sender_name']); + $email->setFrom($mail_config['sender_email'], $mail_config['sender_name']); $email->setTo($email_id); $email->setSubject($subject); $email->setMessage($message); @@ -99,42 +85,36 @@ class MailHelper public static function check_mail_config($r_email, $mail_config = []) { - $default_config = [ - 'protocol' => 'smtp', - 'SMTPHost' => 'mail.venbait.in', - 'SMTPUser' => 'bbone@venbait.in', - 'SMTPPass' => 'xk!L(N_-R#};', - 'SMTPPort' => 465, - 'mailType' => 'html', - 'sender_email' => 'bbone@venbait.in', - 'sender_name' => 'BB-Sign' - ]; + if (empty($mail_config['protocol']) || empty($mail_config['SMTPHost']) || + empty($mail_config['SMTPUser']) || empty($mail_config['SMTPPass']) || + empty($mail_config['SMTPPort']) || empty($mail_config['mailType']) || + empty($mail_config['sender_email']) ) { + return json_encode(['status' => 'failed', 'code' => 400, 'message' => 'Incomplete Mail Configuration', 'data' => $r_email]); + } - // Merge default config with provided config - $config = array_merge($default_config, $mail_config); $email = \Config\Services::email(); - $email->initialize([ - 'protocol' => $config['protocol'], - 'SMTPHost' => $config['SMTPHost'], - 'SMTPUser' => $config['SMTPUser'], - 'SMTPPass' => $config['SMTPPass'], - 'SMTPPort' => (int)$config['SMTPPort'], - 'mailType' => $config['mailType'] + 'protocol' => $mail_config['protocol'], + 'SMTPHost' => $mail_config['SMTPHost'], + 'SMTPUser' => $mail_config['SMTPUser'], + 'SMTPPass' => $mail_config['SMTPPass'], + 'SMTPPort' => (int)$mail_config['SMTPPort'], + 'mailType' => $mail_config['mailType'] ]); - - $email->setFrom($config['sender_email'], "Sender Name"); + + $email->setFrom($mail_config['sender_email'], ''); $email->setTo($r_email); $email->setSubject("Test Mail Configuration"); $email->setMessage("Test Mail Configuration"); - + if ($email->send()) { return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $r_email]); } else { log_message('error', 'Email sending failed: ' . $email->printDebugger(['headers'])); - return ['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $r_email]; + return json_encode(['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $r_email]); } } + } diff --git a/app/Views/business_form.php b/app/Views/business_form.php index f85aaaa..6562d4c 100644 --- a/app/Views/business_form.php +++ b/app/Views/business_form.php @@ -57,9 +57,12 @@
Mail Settings
- +
+
+
+
@@ -78,12 +81,18 @@
-
Test Mail
+
Test Mail
- +
+
+ + + + /assets/images/submit-spin.svg" width="29px" height="29px" class="ml-2" id="submit-spin" style="display:none; margin-top: 2.1rem !important;"> +
@@ -97,13 +106,12 @@ '> '> - - - - - - - + 0){ ?> + + + + +
@@ -119,62 +127,67 @@ +
diff --git a/app/Views/share_docs.php b/app/Views/share_docs.php index 7c886da..cfade6e 100644 --- a/app/Views/share_docs.php +++ b/app/Views/share_docs.php @@ -133,7 +133,7 @@ - + History @@ -146,7 +146,11 @@ Reminder - + + + + Delete +
@@ -593,6 +597,8 @@ if(status == 1){ var is_active= 0; }else{ + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); var is_active= 1; } @@ -606,8 +612,13 @@ data: formData, dataType: 'json', success: function(response) { + setTimeout(function() { + $('.loader').fadeOut(); + $('.loader-mask').fadeOut('slow'); + }, 1000); console.log(response); if (response.data) { + toastr.success(response.data, 'Success'); window.location.reload(); } }, @@ -646,7 +657,32 @@ } - + function DeleteDoc(params) { + var doc_id = params.getAttribute('data-id'); + + var formData = { + doc_id: doc_id, + }; + $.ajax({ + type: 'POST', + url: '', + data: formData, + dataType: 'json', + success: function(response) { + console.log(response); + if (response.data) { + window.location.reload(); + } + }, + error: function(xhr, status, error) { + // Handle error response here + console.error(xhr.responseText); + } + }); + + + } + @@ -680,6 +716,9 @@ }else if(item.status == "Rejected"){ reason_or_ip = ' - Reason('; reason_or_ip_end = ')'; + }else if(item.status == "Mail Success" || item.status == "Mail Failed"){ + reason_or_ip = ' - Email-Id('; + reason_or_ip_end = ')'; }else{ reason_or_ip = ''; reason_or_ip_end = '';