CHANGE_ADD_DELETE_BUTTON_DOC_NOT_SHARED_ADD_NEW_IN_HISTROY : AADHAVAN

This commit is contained in:
aadhavan valli 2024-07-17 16:14:36 +05:30
parent ffaa98cb00
commit ebb6e7840c
7 changed files with 269 additions and 154 deletions

View File

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

View File

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

View File

@ -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 . ",<br>" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.<br><br>" . $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 . ",<br>" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.<br><br>" . $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 {

View File

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

View File

@ -57,9 +57,12 @@
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-envelope mr-1"></i> Mail Settings</h5>
<div class="form-row">
<div class="form-group col-md-6">
<label for="subject-input">Email</label>
<label for="subject-input">Sender Email</label>
<input type="mail" id="email" class="form-control" value="<?= isset($business['email']) ? $business['email'] : '' ?>">
</div>
<div class="form-group col-md-6">
</div>
<div class="form-group col-md-6">
<label for="subject-input">User Name</label>
<input type="text" id="user_name" class="form-control" value="<?= isset($business['smtp_user']) ? $business['smtp_user'] : '' ?>">
@ -78,12 +81,18 @@
</div>
</div>
<?php if(!isset($business['business_id'])){ ?>
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-bell mr-1"></i>Test Mail</h5>
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-envelope-open-text mr-1"></i>Test Mail</h5>
<div class="form-row" id="test_mail_config_div">
<div class="form-group col-md-6">
<label for="">Test Config Mail</label>
<label for="">Enter Your Mail-Id</label>
<input type="mail" class="form-control" id="r_email">
</div>
<div class="form-group col-md-6">
<label for=""></label>
<button class="btn btn-primary" id="test-email-btn" type="button" style="margin-top: 29px;">Test Email</button>
<img src="<?= base_url()."public"; ?>/assets/images/submit-spin.svg" width="29px" height="29px" class="ml-2" id="submit-spin" style="display:none; margin-top: 2.1rem !important;"></img>
</div>
<?php }else{ ?>
<div class="form-row">
<div class="form-group col-md-6">
@ -97,13 +106,12 @@
<input type="hidden" id="business_id" name="business_id" value="<?= isset($business['business_id']) ? $business['business_id'] : '' ?>">
<input type="hidden" id="header_html" value='<?= isset($business['business_id']) ? $business['header_html'] : '' ?>'>
<input type="hidden" id="footer_html" value='<?= isset($business['business_id']) ? $business['footer_html'] : '' ?>'>
<?php if(isset($business['business_id'])){?>
<button type="submit" id="savedata" class="btn btn-primary">Submit</button>
<?php }else{ ?>
<button class="btn btn-primary" id="test-email-btn" type="button">Test Email</button>
<button type="submit" id="savedata" class="btn btn-primary" style="display:none;">Submit</button>
<?php } ?>
<?php if(isset($business['business_id']) > 0){ ?>
<button type="submit" id="savedata" class="btn btn-primary" style="float: right;">Submit</button>
<?php }else{ ?>
<button type="submit" id="savedata" class="btn btn-primary" style="float: right;" disabled>Submit</button>
<?php } ?>
</div>
</div> <!-- end card -->
</div>
@ -119,62 +127,67 @@
<script>
$(document).ready(function() {
$('#summernote-header').summernote({
height: 150, // set the height of the editor
toolbar: [
$(document).ready(function() {
$('#summernote-header').summernote({
height: 150, // set the height of the editor
toolbar: [
['style', ['style']],
['font', ['bold', 'italic', 'underline', 'clear' ]],
['fontname', ['fontname']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph' , 'height']],
['table', ['table']],
['insert', [ 'picture']],
['view', ['fullscreen', 'codeview', 'help']],
['mybutton', ['customButton','Years']] // Custom button group
],
});
$('#summernote-footer').summernote({
height: 150, // set the height of the editor
toolbar: [
['style', ['style']],
['font', ['bold', 'italic', 'underline', 'clear' ]],
['fontname', ['fontname']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph' , 'height']],
['table', ['table']],
['insert', [ 'picture']],
['view', ['fullscreen', 'codeview', 'help']],
['mybutton', ['customButton','Years']] // Custom button group
],
});
setTimeout(() =>
{
$('#summernote-header').summernote('code', $('#header_html').val());
$('#summernote-footer').summernote('code', $('#footer_html').val());
['style', ['style']],
['font', ['bold', 'italic', 'underline', 'clear' ]],
['fontname', ['fontname']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph' , 'height']],
['table', ['table']],
['insert', [ 'picture']],
['view', ['fullscreen', 'codeview', 'help']],
['mybutton', ['customButton','Years']] // Custom button group
],
}, 500);
});
$('#summernote-footer').summernote({
height: 150, // set the height of the editor
toolbar: [
['style', ['style']],
['font', ['bold', 'italic', 'underline', 'clear' ]],
['fontname', ['fontname']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph' , 'height']],
['table', ['table']],
['insert', [ 'picture']],
['view', ['fullscreen', 'codeview', 'help']],
['mybutton', ['customButton','Years']] // Custom button group
],
});
setTimeout(() =>
{
$('#summernote-header').summernote('code', $('#header_html').val());
$('#summernote-footer').summernote('code', $('#footer_html').val());
}, 500);
});
$("#test-email-btn").on("click", function()
{
$('#submit-spin').show();
$(this).hide();
formData ={
sender_email : $('#email').val(),
r_email : $('#r_email').val(),
smtp_host : $('#host').val(),
smtp_user : $('#user_name').val(),
smtp_pass : $('#password').val(),
smtp_port : $('#port').val(),
SMTPHost : $('#host').val(),
SMTPUser : $('#user_name').val(),
SMTPPass : $('#password').val(),
SMTPPort : $('#port').val(),
mailType : 'html',
protocol : 'smtp',
};
// console.log(formData);
$.ajax({
@ -183,17 +196,17 @@ $(document).ready(function() {
data: formData,
json: true,
success: function(response) {
console.log(JSON.parse(response));
if(JSON.parse(response).status == 'success'){
$('#savedata').css('display','');
$('#test-email-btn').css('display','none');
toastr.success('Data saved successfully ', 'Success');
// window.location.href = '<?= base_url()."business_list"; ?>';
}else{
toastr.warning('Something went wrong', 'Warning');
}
console.log(response);
if(JSON.parse(response).status == 'success'){
$('#savedata').prop('disabled', false);
toastr.success('Mail Send successfully ', 'Success');
// window.location.href = '<?= base_url()."business_list"; ?>';
}else{
$('#savedata').prop('disabled', true);
toastr.warning('Please Check Mail Configuration', 'Warning');
}
},
error: function(xhr, status, error) {
@ -201,24 +214,58 @@ $(document).ready(function() {
console.error(xhr.responseText);
}
});
setTimeout(() => {
$('#submit-spin').hide();
$(this).show();
}, 2000);
})
$("#savedata").on("click", function()
{
var headerContent = $('#summernote-header').summernote('code');
var footerContent = $('#summernote-footer').summernote('code');
formData ={
business_id : $('#business_id').val(),
business_name : $('#business_name').val(),
header_html : headerContent,
footer_html : footerContent,
email : $('#email').val(),
smtp_host : $('#host').val(),
smtp_user : $('#user_name').val(),
smtp_pass : $('#password').val(),
smtp_port : $('#port').val(),
};
var isValid = true;
var firstEmptyField = null;
// Find all elements with 'required' attribute
$('form [required]').each(function() {
var field = $(this);
// Check if the field is empty
if (field.val().trim() === '') {
isValid = false;
if (!firstEmptyField) {
firstEmptyField = field;
}
// Highlight the empty field
field.addClass('error');
} else {
// Remove error class if the field is not empty
field.removeClass('error');
}
});
if (!isValid) {
// Focus on the first empty field and show an error message
toastr.warning('Please fill in all required fields.', 'Warning');
firstEmptyField.focus();
return; // Prevent the AJAX call
}
var headerContent = $('#summernote-header').summernote('code');
var footerContent = $('#summernote-footer').summernote('code');
formData ={
business_id : $('#business_id').val(),
business_name : $('#business_name').val(),
header_html : headerContent,
footer_html : footerContent,
email : $('#email').val(),
smtp_host : $('#host').val(),
smtp_user : $('#user_name').val(),
smtp_pass : $('#password').val(),
smtp_port : $('#port').val(),
};
$.ajax({
url: '<?= base_url()."add_business"; ?>',

View File

@ -160,22 +160,34 @@
</style>
<style>
.dropdown-menu-right {
right: auto !important;
top: auto !important;
/* left: auto !important; */
}
<style>
.dropdown-menu-right {
right: auto !important;
top: auto !important;
/* left: auto !important; */
}
.modal-xg {
max-width: 70%; /* Adjust the percentage as needed */
}
</style>
.modal-xg {
max-width: 70%; /* Adjust the percentage as needed */
}
</style>
</head>
<script>
$(window).on('load', function() {
// setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').fadeOut('slow');
// }, 500);
});
</script>
<body class="loading" data-layout-mode="horizontal" data-layout='{"mode": "light", "width": "fluid", "menuPosition": "fixed", "topbar": {"color": "dark"}, "showRightSidebarOnPageLoad": true}'>
<!-- <div class="loader-mask">
<div class="loader">
<img src="<?= base_url() . "public" ?>/assets/images/submit-spin.svg" height="40" width="40" alt="Loading...">
</div>
</div> -->
<!-- Begin page -->
<div id="wrapper">

View File

@ -133,7 +133,7 @@
</a>
<?php } ?>
<a id="doc_history_button" data-id="<?php echo $value['id']; ?>" class="dropdown-item" data-toggle="modal" data-target="#bike_make_login-modal" data-title="Share">
<a id="doc_history_button" data-id="<?php echo $value['id']; ?>" class="dropdown-item" data-toggle="modal" data-target="#bike_make_login-modal" data-title="History">
<i class="mdi mdi-history" style="margin-right: 16px !important;"></i>History
</a>
@ -146,7 +146,11 @@
<a class="dropdown-item" data-id="<?php echo $value['id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Remember" onclick="rememberNotification(this)">
<i class="mdi mdi-email-send" style="margin-right: 16px !important; margin-left: 5px;"></i>Reminder
</a>
<?php } ?>
<?php if($value['is_active'] == 0 ) { ?>
<a class="dropdown-item" data-id="<?php echo $value['id']; ?>" title="Delete" onclick="DeleteDoc(this)">
<i class="mdi mdi-delete" style="margin-right: 16px !important; margin-left: 5px;"></i>Delete
</a>
<?php } ?>
</div>
</div>
@ -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: '<?php echo base_url()."delete_doc"?>',
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);
}
});
}
</script>
@ -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 = '';