diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 24f6fa5..890689b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -6,7 +6,7 @@ use CodeIgniter\Router\RouteCollection; * @var RouteCollection $routes */ - $routes->get('/set_business_in_session/(:any)','StaffController::set_business_in_session/$1'); + $routes->get('/set_business_in_session/(:num)','StaffController::set_business_in_session/$1'); // $routes->get('/home','Home::index'); // $routes->post('/upload_1','Home::upload_1'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 4b8e657..393bcef 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -262,10 +262,11 @@ class ClientController extends BaseController public function client_branch_list() { // if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } - $data['clientBranchList'] = $this->ClientBranchModel->select('client_branch.*, client.name as client_name') + $data['clientBranchList'] = $this->ClientBranchModel->select('client_branch.*, client.name as client_name, client.mobile_no as client_mobile_no') ->join('client', 'client.client_id = client_branch.client_id', 'left') ->findAll(); - $data['client_list'] = $this->ClientModel->select('client_id, name')->where('is_active', 1)->findAll(); + + $data['client_list'] = $this->ClientModel->select('client_id, name')->where('individual',0)->where('is_active', 1)->findAll(); $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); $data['business_list'] = $this->BusinessModel->findAll(); @@ -292,6 +293,18 @@ class ClientController extends BaseController { $id = $this->request->getPost('id'); $data = $this->request->getPost(); + if($data['sms'] == 'true'){ + $data['sms'] = 1; + }else{ + $data['sms'] = 0; + } + + if($data['whatsapp'] == 'true'){ + // $data['sms'] = $clientData['sms']; + $data['whatsapp'] = 1; + }else{ + $data['whatsapp'] =0; + } $this->ClientBranchModel->update($id, $data); return json_encode('update'); } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 5c74073..50aa7ba 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -574,7 +574,10 @@ class MasterController extends BaseController { $docData = $this->request->getVar(); $docData['created_by'] = $this->session->has('is_staff_logged_in'); + $docData['business_id'] = $this->session->has('logged_in_staff_business_id'); $docData['body_html'] = $this->TemplateModel->where('template_id',$this->request->getVar('template_id'))->get()->getRow()->body_html; + print_r($docData);die; + $insert = $this->ClientDocsModel->insert($docData); if($insert){ $data['client_docs_id'] = $insert; @@ -607,10 +610,18 @@ class MasterController extends BaseController client_branch.gst_no , client_branch.mobile_no , client_branch.email , client_branch.address , client_branch.country , client_branch.state , - client_branch.city , client_branch.pin_code ') + client_branch.city , client_branch.pin_code , client.individual') ->join('client', 'client_branch.client_id = client.client_id', 'left') ->where('client_branch.id',$data['docData']->client_branch_id) ->get()->getRow(); + if($data['clientData']->individual == 1){ + $data['clientData'] = $this->ClientBranchModel->select('client.name , client.pan_no , + client.mobile_no , + client.email , client.individual') + ->join('client', 'client_branch.client_id = client.client_id', 'left') + ->where('client_branch.id',$data['docData']->client_branch_id) + ->get()->getRow(); + } $data['header_html'] = $data['docData']->header_html; $data['footer_html'] = $data['docData']->footer_html; $data['body_html'] = $data['docData']->body_html; @@ -732,6 +743,13 @@ 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(); + + 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') + ->join('client', 'client_branch.client_id = client.client_id', 'left') + ->where('client_docs.id', $doc_id)->get()->getRow(); + } $documentUrl = base_url(); // helper('url'); @@ -740,15 +758,23 @@ class MasterController extends BaseController // ->join('business', 'branches.business_id = business.business_id', 'left') // ->where('branches.branch_id',$this->session->get('logged_in_staff_branch_id')) // ->get()->getRow(); - $businessData = $this->BusinessModel->select('branches.* , business.business_name ') + $businessData = $this->BusinessModel->select('branches.* , business.business_name ,business.smtp_host, business.smtp_user, business.smtp_pass, business.smtp_port, business.email as business_mail') ->join('branches', 'business.business_id = branches.business_id', 'left') ->where('business.business_id',$this->session->get('logged_in_staff_business_id')) ->get()->getRow(); $subject = 'BB-Sign Verify Document'; // print_r($businessData);die; $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; - - $MailHelper->send_url_email($clientData->email , '', $subject, $message); + // print_r($clientData->email);die; + $mail_config = [ + 'SMTPHost' => $businessData->smtp_host, + 'SMTPUser' => $businessData->smtp_user, + 'SMTPPass' => $businessData->smtp_pass, + 'SMTPPort' => $businessData->smtp_port, + 'sender_email' => $businessData->business_mail, + 'sender_name' => $businessData->business_name + ]; + $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){ @@ -783,16 +809,23 @@ class MasterController extends BaseController public function rememeber_notification() { + try { $doc_id = $this->request->getPost('doc_id'); $MailHelper = new MailHelper(); // print_r($this->session->get());die; - $clientData = $this->ClientDocsModel->select('client.name as client_name, client_branch.email, client_branch.mobile_no, client_branch.whatsapp') + $clientData = $this->ClientDocsModel->select('client.name as client_name, client_branch.email, client_branch.mobile_no, client_branch.whatsapp, client.individual, client_docs.business_id') ->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(); + if($clientData->individual == 1){ + $clientData = $this->ClientDocsModel->select('client.name as client_name, client.email, client.mobile_no, client_branch.whatsapp, client.individual, client_docs.business_id') + ->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(); + } // helper('url'); $url ='Preview and Approve Document'; // $businessData = $this->BranchModel->select('branches.* , business.business_name ') @@ -800,11 +833,24 @@ class MasterController extends BaseController // ->where('branches.branch_id',$this->session->get('logged_in_staff_branch_id')) // ->get()->getRow(); $businessData = $this->BusinessModel->select('business.*') - ->where('business.business_id',$this->session->get('logged_in_staff_business_id')) + // ->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_send = $MailHelper->send_url_email($clientData->email , '', $subject, $message); + + $mail_config = [ + 'SMTPHost' => $businessData->smtp_host, + 'SMTPUser' => $businessData->smtp_user, + 'SMTPPass' => $businessData->smtp_pass, + 'SMTPPort' => $businessData->smtp_port, + 'sender_email' => $businessData->email, + 'sender_name' => $businessData->business_name + ]; + // print_r($mail_config);die; + + $mail_send = $MailHelper->send_url_email($clientData->email , '', $subject, $message, $mail_config); if (!$mail_send) { throw new \Exception('Email sending failed.'); } diff --git a/app/Controllers/StaffController.php b/app/Controllers/StaffController.php index a949d7e..e9efab6 100644 --- a/app/Controllers/StaffController.php +++ b/app/Controllers/StaffController.php @@ -38,10 +38,18 @@ class StaffController extends BaseController $this->TemplateModel = new TemplateModel(); } - public function set_business_in_session($business_id){ + public function set_business_in_session($business_id){ + // Unset the existing session variable if it exists + if ($this->session->has('logged_in_staff_business_id')) { + $this->session->remove('logged_in_staff_business_id'); + } + + // Set the new business ID in session $this->session->set('logged_in_staff_business_id', $business_id); + return json_encode(true); - } + } + public function login() { @@ -233,6 +241,7 @@ class StaffController extends BaseController if($this->request->getmethod() == 'POST') { $clientData = $this->request->getVar(); + // print_r($clientData);die; $clientData['created_by'] = $this->session->get('is_staff_logged_in'); $clientData['business_id'] = $this->session->get('logged_in_staff_business_id'); // $business= $this->BranchModel->select('*') @@ -247,18 +256,33 @@ class StaffController extends BaseController $insert = $this->ClientModel->insert($clientData); if($insert) { - $data['client_id'] = $insert; - $data['email'] = $clientData['branch_email']; + if($clientData['individual'] == 1){ + $data['individual'] = $clientData['individual']; + }else{ + $data['email'] = $clientData['branch_email']; + $data['name'] = $clientData['branch_name']; + $data['mobile_no'] = $clientData['branch_mobile_no']; + $data['gst_no'] = $clientData['gst_no']; + } $data['country'] = $clientData['country']; - $data['name'] = $clientData['branch_name']; $data['address'] = $clientData['address']; $data['city'] = $clientData['city']; $data['state'] = $clientData['state']; $data['pin_code'] = $clientData['pin_code']; - $data['mobile_no'] = $clientData['branch_mobile_no']; - $data['gst_no'] = $clientData['gst_no']; - $data['sms'] = $clientData['sms']; - $data['whatsapp'] = $clientData['whatsapp']; + $data['client_id'] = $insert; + if($clientData['sms'] == 'true'){ + $data['sms'] = 1; + }else{ + $data['sms'] = 0; + } + + if($clientData['whatsapp'] == 'true'){ + // $data['sms'] = $clientData['sms']; + $data['whatsapp'] = 1; + }else{ + $data['whatsapp'] =0; + } + // $data['whatsapp'] = $clientData['whatsapp']; $branch_insert = $this->ClientBranchModel->insert($data); diff --git a/app/Controllers/TestController.php b/app/Controllers/TestController.php index 8a99ec5..fcbf12f 100644 --- a/app/Controllers/TestController.php +++ b/app/Controllers/TestController.php @@ -92,12 +92,17 @@ class TestController extends Controller $data['docData'] = $this->ClientDocsModel->docPreview($doc_id); $data['expires'] = $this->request->getVar('expires'); - $data['clientData'] = $this->ClientBranchModel->select('client.name , client.pan_no ,client_branch.gst_no , client_branch.mobile_no , client_branch.email , client_branch.address , client_branch.country , client_branch.state , client_branch.city , client_branch.pin_code ') + $data['clientData'] = $this->ClientBranchModel->select('client.name ,client.individual, client.pan_no ,client_branch.gst_no , client_branch.mobile_no , client_branch.email , client_branch.address , client_branch.country , client_branch.state , client_branch.city , client_branch.pin_code ') ->join('client', 'client_branch.client_id = client.client_id', 'left') ->where('client_branch.id',$data['docData']->client_branch_id) ->get()->getRow(); - + if($data['clientData']->individual == 1){ + $data['clientData'] = $this->ClientBranchModel->select('client.name ,client.individual, client.pan_no, client.mobile_no , client.email ') + ->join('client', 'client_branch.client_id = client.client_id', 'left') + ->where('client_branch.id',$data['docData']->client_branch_id) + ->get()->getRow(); + } $data['header_html'] = $data['docData']->header_html; diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index c448ae5..3a32f20 100644 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -6,6 +6,9 @@ class MailHelper { public static function send_otp_email($email_id, $otp) { + + + $subject = 'BB-Sign Verify Document'; $message = "Hai,
@@ -13,12 +16,30 @@ 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->setFrom($config['sender_email'], $config['sender_name']);/ $email->setMailType('html'); $email->setFrom('bbone@venbait.in', 'BB-Sign'); $email->setTo($email_id); $email->setSubject($subject); $email->setMessage($message); + + // $email->setMailType('html'); + // $email->setFrom('bbone@venbait.in', 'BB-Sign'); + // $email->setTo($email_id); + // $email->setSubject($subject); + // $email->setMessage($message); + if ($email->send()) { return ['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $email_id]; } else { @@ -29,30 +50,60 @@ class MailHelper } } - public static function send_url_email($email_id, $branch_email, $subject, $message) + public static function send_url_email($email_id, $branch_email, $subject, $message, $mail_config = []) { - try { - - + // 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->setMailType('html'); - $email->setFrom('bbone@venbait.in', 'BB-Sign'); + + $email->initialize([ + 'protocol' => $config['protocol'], + 'SMTPHost' => $config['SMTPHost'], + 'SMTPUser' => $config['SMTPUser'], + 'SMTPPass' => $config['SMTPPass'], + 'SMTPPort' => (int)$config['SMTPPort'], + 'mailType' => $config['mailType'] + ]); + + $email->setFrom($config['sender_email'], $config['sender_name']); + // $email->setMailType('html'); + // $email->setFrom('bbone@venbait.in', 'BB-Sign'); $email->setTo($email_id); $email->setSubject($subject); $email->setMessage($message); - + + // $email->setMailType('html'); + // $email->setFrom('bbone@venbait.in', 'BB-Sign'); + // $email->setTo($email_id); + // $email->setSubject($subject); + // $email->setMessage($message); + // print_r($email);die; if ($email->send()) { return ['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $email_id]; } else { log_message('error', 'Email sending failed: ' . $email->printDebugger(['headers'])); return ['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $email_id]; } - } catch (\Exception $e) { - log_message('error', 'Exception occurred while sending email: ' . $e->getMessage()); - return ['status' => 'failed', 'code' => 500, 'message' => 'Exception: ' . $e->getMessage(), 'data' => $email_id]; - } + // } catch (\Exception $e) { + // log_message('error', 'Exception occurred while sending email: ' . $e->getMessage()); + // return ['status' => 'failed', 'code' => 500, 'message' => 'Exception: ' . $e->getMessage(), 'data' => $email_id]; + // } } } diff --git a/app/Models/BusinessModel.php b/app/Models/BusinessModel.php index 201c41c..c8e6cdb 100644 --- a/app/Models/BusinessModel.php +++ b/app/Models/BusinessModel.php @@ -5,7 +5,7 @@ class BusinessModel extends Model { protected $table = 'business'; protected $primaryKey = 'business_id'; - protected $allowedFields = ['business_id','business_unique_id','branch_unique_id','logo', 'business_name','isactive','letter_header','header_html','footer_html']; + protected $allowedFields = ['business_id','business_unique_id','branch_unique_id','logo', 'business_name','isactive','letter_header','header_html','footer_html', 'email', 'smtp_host', 'smtp_user', 'smtp_pass', 'smtp_port']; public function getBusinessById($business_id) { return $this->db->table('business')->where('business_id', $business_id)->get()->getRowArray(); diff --git a/app/Models/ClientBranchModel.php b/app/Models/ClientBranchModel.php index 0282f5e..ab8cdd0 100644 --- a/app/Models/ClientBranchModel.php +++ b/app/Models/ClientBranchModel.php @@ -13,7 +13,7 @@ class ClientBranchModel extends Model 'country', 'state', 'city', 'pin_code', 'otp', 'sms', 'whatsapp', 'is_active', - 'created_by', 'updated_by']; + 'created_by', 'updated_by', 'individual']; } \ No newline at end of file diff --git a/app/Models/ClientDocsModel.php b/app/Models/ClientDocsModel.php index ee56485..a77834f 100644 --- a/app/Models/ClientDocsModel.php +++ b/app/Models/ClientDocsModel.php @@ -7,7 +7,7 @@ class ClientDocsModel extends Model protected $table = 'client_docs'; protected $primaryKey = 'id'; - protected $allowedFields = ['client_branch_id','template_id','template_name','body_html','document_name','rejection_reason','is_approved','otp','ip_address','is_active' ,'place_holder_object','created_by','updated_by']; + protected $allowedFields = ['business_id','client_branch_id','template_id','template_name','body_html','document_name','rejection_reason','is_approved','otp','ip_address','is_active' ,'place_holder_object','created_by','updated_by']; diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index b585405..0786407 100644 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -7,7 +7,7 @@ class ClientModel extends Model protected $table = 'client'; protected $primaryKey = 'client_id'; - protected $allowedFields = [ 'business_id','branch_id', 'name','pan_no', 'mobile_no' , 'email' , 'is_active' ,'created_by','updated_by']; + protected $allowedFields = [ 'business_id','branch_id', 'name','pan_no', 'mobile_no' , 'individual', 'email' , 'is_active' ,'created_by','updated_by']; protected $beforeInsert = ['beforeInsert']; protected $beforeUpdate = ['beforeUpdate']; diff --git a/app/Views/business_form.php b/app/Views/business_form.php index 7717e21..326e8b2 100644 --- a/app/Views/business_form.php +++ b/app/Views/business_form.php @@ -52,6 +52,30 @@ + + +
Mail Settings
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
@@ -136,6 +160,11 @@ $("#savedata").on("click", function() 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(), }; console.log(formData); diff --git a/app/Views/client_branch_list.php b/app/Views/client_branch_list.php index 7b8539e..7cebea3 100644 --- a/app/Views/client_branch_list.php +++ b/app/Views/client_branch_list.php @@ -49,13 +49,21 @@ - + + + + + - + + + + + Inactive @@ -106,8 +114,9 @@
- -
+ + +
@@ -146,7 +155,7 @@
-
Address Details
+
Address Details
@@ -176,7 +185,7 @@
- +
@@ -190,7 +199,7 @@
- +
@@ -199,7 +208,7 @@
- +
@@ -275,40 +284,46 @@ }) function submitBranch(event,params) { - // event.preventDefault(); + event.preventDefault(); console.log($('#sms').is(':checked')); - if ($('#client').val() == 0) { - toastr.warning('Select Client'); - return; + if($('#individual').val() != 1){ + if ($('#client').val() == 0) { + toastr.warning('Select Client'); + return; + } } - - var sms = 0; - if($('#sms').is(':checked')){ - sms = 1; - } - - var whatsapp = 0; - if($('#whatsapp').is(':checked')){ - whatsapp = 1; + + if($('#individual').val() != 1){ + var formData = { + client_id: $('#client').val(), + gst_no: $('#gst_no').val(), + email: $('#email').val(), + contact: $('#contact').val(), + country: $('#country').val(), + state_code: $('#state_code').val(), + name: $('#branch_name').val(), + address: $('#address').val(), + city: $('#city').val(), + state: $('#state').val(), + pin_code: $('#pin_code').val(), + mobile_no: $('#mobile_no').val(), + sms: $('#sms').prop('checked'), + whatsapp: $('#whatsapp').prop('checked'), + }; + }else{ + var formData = { + country: $('#country').val(), + address: $('#address').val(), + city: $('#city').val(), + state: $('#state').val(), + pin_code: $('#pin_code').val(), + sms: $('#sms').prop('checked'), + whatsapp: $('#whatsapp').prop('checked'), + }; } - var formData = { - client_id: $('#client').val(), - gst_no: $('#gst_no').val(), - email: $('#email').val(), - contact: $('#contact').val(), - country: $('#country').val(), - state_code: $('#state_code').val(), - name: $('#branch_name').val(), - address: $('#address').val(), - city: $('#city').val(), - state: $('#state').val(), - pin_code: $('#pin_code').val(), - mobile_no: $('#mobile_no').val(), - sms: sms, - whatsapp: whatsapp, - }; + if ($('#id').val()) { var url = ''; @@ -378,17 +393,7 @@ dataType: 'json', success: function(response) { console.log(response); - $('#client').val(response.client_id).trigger('change'); - $('#branch_name').val(response.name); - $('#gst_no').val(response.gst_no); - $('#email').val(response.email); - $('#mobile_no').val(response.mobile_no); - $('#address').val(response.address); - $('#id').val(response.id); - $('#city').val(response.city); - $('#pin_code').val(response.pin_code); - $('#state').val(response.state); - $('#country').val(response.country); + if(response.sms == 1){ $('#sms').prop('checked', true); }else{ @@ -399,7 +404,30 @@ }else{ $('#whatsapp').prop('checked', false); } + + if(response.individual == 1){ + $('#individual').val(1); + $('.branch_hide_edit').hide(); + $('#client').prop('required', false); + $('#branch_name').prop('required', false); + $('#gst_no').prop('required', false); + $('#email').prop('required', false); + $('#mobile_no').prop('required', false); + }else{ + $('#branch_name').val(response.name); + $('#gst_no').val(response.gst_no); + $('#email').val(response.email); + $('#mobile_no').val(response.mobile_no); + } + $('#client').val(response.client_id).trigger('change'); + $('#address').val(response.address); + $('#id').val(response.id); + $('#city').val(response.city); + $('#pin_code').val(response.pin_code); + $('#state').val(response.state); + $('#country').val(response.country); + }, error: function(xhr, status, error) { // Handle error response here diff --git a/app/Views/client_list.php b/app/Views/client_list.php index 0a3ef37..6d67705 100644 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -22,7 +22,7 @@

Client List

- download Sample file + Download Sample file @@ -117,6 +117,11 @@ -
-
+
+
Branch
-
+
@@ -186,8 +191,12 @@
- - +
+
+ Address Details +
+
+
@@ -214,15 +223,15 @@
- +
-
Notification
+
Notification
-
+
@@ -263,10 +272,43 @@