CHANGE_MAIL_CONFIG_CHANGE : AADHAVAN

This commit is contained in:
aadhavan valli 2024-07-11 18:06:25 +05:30
parent 118a5c200c
commit 876646938f
15 changed files with 371 additions and 108 deletions

View File

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

View File

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

View File

@ -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 . ",<br>" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.<br><br>" . $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 ='<a href="' . generate_signed_url('preview', ['doc_id'=>md5((string)$doc_id)], 36000) . '">Preview and Approve Document</a>';
// $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 . ",<br>" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.<br><br>" . $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.');
}

View File

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

View File

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

View File

@ -6,6 +6,9 @@ class MailHelper
{
public static function send_otp_email($email_id, $otp)
{
$subject = 'BB-Sign Verify Document';
$message = "Hai,
<br>
@ -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];
// }
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -52,6 +52,30 @@
<!-- basic summernote-->
<div id="summernote-footer"></div>
</div>
</div>
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-bell mr-1"></i> Mail Settings</h5>
<div class="form-row">
<div class="form-group col-md-6">
<label for="subject-input">Email</label>
<input type="mail" id="email" class="form-control" value="<?= isset($business['email']) ? $business['email'] : '' ?>">
</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'] : '' ?>">
</div>
<div class="form-group col-md-6">
<label for="subject-input">Password</label>
<input type="text" id="password" class="form-control" value="<?= isset($business['smtp_pass']) ? $business['smtp_pass'] : '' ?>">
</div>
<div class="form-group col-md-6">
<label for="subject-input">Host</label>
<input type="text" id="host" class="form-control" value="<?= isset($business['smtp_host']) ? $business['smtp_host'] : '' ?>">
</div>
<div class="form-group col-md-6">
<label for="subject-input">Port</label>
<input type="text" id="port" class="form-control" value="<?= isset($business['smtp_port']) ? $business['smtp_port'] : '' ?>">
</div>
</div>
</form>
@ -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);

View File

@ -49,13 +49,21 @@
<?php foreach ($clientBranchList as $value) :?>
<tr>
<td><?= $value['client_name']; ?></td>
<td><?= $value['name']; ?></td>
<?php if($value['individual'] == 1) { ?>
<td><?= $value['client_name']; ?></td>
<?php }else{ ?>
<td><?= $value['name']; ?></td>
<?php } ?>
<td><?= $value['gst_no']; ?></td>
<td><?= $value['address']; ?></td>
<td><?= $value['city']; ?></td>
<td><?= $value['state']; ?></td>
<td><?= $value['pin_code']; ?></td>
<td><?= $value['mobile_no']; ?></td>
<?php if($value['individual'] == 1) { ?>
<td><?= $value['client_mobile_no']; ?></td>
<?php }else{ ?>
<td><?= $value['mobile_no']; ?></td>
<?php } ?>
<td>
<?php if ($value['is_active'] == 0): ?>
<span style="color: red;">Inactive</span>
@ -106,8 +114,9 @@
<form id="client_branch_model_form_data" class="px-4">
<input type="text" id="id" hidden>
<div class="row">
<input type="text" id="individual" hidden>
<div class="row branch_hide_edit">
<div class="col-md-4">
<div class="form-group">
<label for="client">Client</label>
@ -146,7 +155,7 @@
</div>
</div>
</div>
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="fas fa-bell mr-1"></i> Address Details</h5>
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="mdi mdi-office-building mr-1"></i> Address Details</h5>
<div class="row">
<div class="col-md-6">
@ -176,7 +185,7 @@
</div>
<div class="col-md-3">
<div class="form-group">
<label for="postalcode">Pin Code</label>
<label for="postalcode">PIN Code</label>
<input class="form-control" name="pin_code" type="text" id="pin_code" required="" placeholder="Pin Code">
</div>
</div>
@ -190,7 +199,7 @@
<div class="col-md-2">
<div class="form-group">
<label for="sms">SMS</label>
<input style="float:right;width: 20px;height: 20px;" name="sms" type="checkbox" id="sms" required="" checked>
<input style="float:right;width: 20px;height: 20px;" name="sms" type="checkbox" id="sms" checked>
</div>
</div>
<div class="col-md-2">
@ -199,7 +208,7 @@
<div class="col-md-2">
<div class="form-group">
<label for="whatsapp">WhatsApp</label>
<input style="float:right;width: 20px;height: 20px;" name="whatsapp" type="checkbox" id="whatsapp" required="" checked>
<input style="float:right;width: 20px;height: 20px;" name="whatsapp" type="checkbox" id="whatsapp" checked>
</div>
</div>
@ -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 = '<?= base_url("edit_client_branch"); ?>';
@ -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

View File

@ -22,7 +22,7 @@
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Client List</h4>
<div class="page-title-right">
<a href="" id="downloadLink" > download Sample file </a>
<a href="" id="downloadLink" > Download Sample file </a>
<input type="file" id="clientFileUpload" style="display: none;" />
<a id="upload_client_button" class="btn btn-primary waves-effect waves-light" onclick="document.getElementById('clientFileUpload').click();">
@ -117,6 +117,11 @@
<div class="modal-content">
<div class="modal-header">
<h4 id="branch_action_type">Add Client</h4>
<div style="margin-left: 34px;margin-top: 10px;">
<label for="">Individual</label>
<input type="checkbox" id="individual_client" name="individual_client">
</div>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
@ -136,7 +141,7 @@
</div>
<div class="col-md-4">
<div class="form-group">
<label for="panno">Pan No</label>
<label for="panno">PAN No</label>
<input class="form-control" parsley-trigger="change" name="pan_no" type="text" id="pan_no" required="" placeholder="PAN No" pattern="[A-Z]{5}[0-9]{4}[A-Z]{1}" title="Please enter a valid PAN in the format ABCDE1234F">
<span id="error-message" style="color:red;display:none;">Invalid PAN Number.</span>
</div>
@ -155,12 +160,12 @@
</div>
</div>
<div class="create_client">
<h5 class="mb-3 text-uppercase bg-light p-2">
<div class="">
<h5 class="mb-3 text-uppercase bg-light p-2 create_client">
<i class="mdi mdi-office-building mr-1"></i> Branch
</h5>
<div class="row">
<div class="row create_client">
<div class="col-md-4">
<div class="form-group">
<label for="branchname">Branch Name</label>
@ -186,8 +191,12 @@
<input class="form-control" name="branch_mobile_no" type="text" id="branch_mobile_no" oninput="this.value = this.value.replace(/[^0-9]/g, '');" required="" minlength="6" maxlength="16" placeholder="Mobile No">
</div>
</div>
<!-- </div> -->
<!-- <div class="row"> -->
</div>
<h5 class="mb-3 text-uppercase bg-light p-2 client_address_area">
<i class="mdi mdi-office-building mr-1"></i> Address Details
</h5>
<div class="row client_address_area" >
<div class="col-md-4">
<div class="form-group">
<label for="address">Address</label>
@ -214,15 +223,15 @@
</div>
<div class="col-md-4">
<div class="form-group">
<label for="postalcode">Pin Code</label>
<label for="postalcode">PIN Code</label>
<input class="form-control" name="pin_code" type="text" id="pin_code" required="" placeholder="Pin Code">
</div>
</div>
</div>
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="fas fa-bell mr-1"></i> Notification</h5>
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-bell mr-1"></i> Notification</h5>
<div class="row">
<div class="row client_notification_area">
<!-- </div> -->
<div class="col-md-2">
<div class="form-group">
@ -263,10 +272,43 @@
<script>
$('#individual_client').click(function () {
if($(this).prop('checked')){
$('.create_client').hide();
// $('#client_address_area').show();
$('#gst_no').prop('required', false);
$('#branch_email').prop('required', false);
$('#contact').prop('required', false);
$('#state_code').prop('required', false);
$('#branch_name').prop('required', false);
$('#branch_mobile_no').prop('required', false);
$('#sms').prop('required', false);
$('#whatsapp').prop('required', false);
}else{
$('.create_client').show();
$('#gst_no').prop('required', true);
$('#branch_email').prop('required', true);
$('#contact').prop('required', true);
$('#country').prop('required', true);
$('#state_code').prop('required', true);
$('#branch_name').prop('required', true);
$('#address').prop('required', true);
$('#city').prop('required', true);
$('#state').prop('required', true);
$('#pin_code').prop('required', true);
$('#branch_mobile_no').prop('required', true);
$('#sms').prop('required', true);
$('#whatsapp').prop('required', true);
}
})
$(document).ready(function() {
$('.edit').click(function (params) {
$('.create_client').hide();
$('.client_address_area').hide();
$('.client_notification_area').hide();
$('#gst_no').prop('required', false);
$('#branch_email').prop('required', false);
$('#contact').prop('required', false);
@ -339,7 +381,6 @@
function submitBranch(params) {
var formData = {
pan_no: $('#pan_no').val(),
email: $('#email').val(),
@ -347,25 +388,31 @@
mobile_no: $('#mobile_no').val()
};
if ($('#client_id').val()) {
if ($('#client_id').val())
{
formData.client_id = $('#client_id').val();
var url = '<?= base_url("client_edit/"); ?>'+ $('#client_id').val();
}else{
var url = '<?= base_url("client_create"); ?>';
formData.gst_no = $('#gst_no').val();
formData.branch_email = $('#branch_email').val();
formData.contact = $('#contact').val();
formData.country = $('#country').val();
formData.state_code = $('#state_code').val();
formData.branch_name = $('#branch_name').val();
if($('#individual_client').prop('checked')){
formData.individual = 1;
// formData.whatsapp = $('#individual_client').prop('checked');
}else{
formData.gst_no = $('#gst_no').val();
formData.branch_email = $('#branch_email').val();
formData.contact = $('#contact').val();
formData.state_code = $('#state_code').val();
formData.branch_name = $('#branch_name').val();
formData.branch_mobile_no = $('#branch_mobile_no').val();
}
formData.sms = $('#sms').prop('checked');
formData.whatsapp = $('#whatsapp').prop('checked');
formData.address = $('#address').val();
formData.country = $('#country').val();
formData.city = $('#city').val();
formData.state = $('#state').val();
formData.pin_code = $('#pin_code').val();
formData.branch_mobile_no = $('#branch_mobile_no').val();
formData.sms = $('#sms').val();
formData.whatsapp = $('#whatsapp').val();
}
var form = $(params).parent().parent();
@ -466,12 +513,23 @@
dataType: 'json',
success: function(response) {
console.log(response);
// console.log(response.individual);
$('#client_id').val(response.client_id);
$('#name').val(response.name);
$('#pan_no').val(response.pan_no);
$('#email').val(response.email);
$('#mobile_no').val(response.mobile_no);
console.log("response.individual:", response.individual);
if(response.individual == 1){
$('#individual_client').prop('checked', true);
console.log("Checkbox checked");
}else{
$('#individual_client').prop('checked', false);
console.log("Checkbox unchecked");
}
$('#individual_client').attr('disabled',true);
},
error: function(xhr, status, error) {
// Handle error response here

View File

@ -26,7 +26,7 @@
<!-- <div class="rightbar-overlay"></div> -->
<script>
function handleBusinessClick(businessId) {
// console.log("Business ID:", businessId.id);
console.log("Business ID:", businessId.id);
$.ajax({
url: '<?= base_url("set_business_in_session/") ?>' + businessId.id,
@ -50,17 +50,24 @@
var session_business_id = '<?php echo $_SESSION['logged_in_staff_business_id'] ?>';
// Loop through business_list and create <a> tags
business_list.forEach(function(business) {
business_list.forEach(function(business, index) {
var aTag = document.createElement('a');
aTag.className = 'dropdown-item business_list_header';
aTag.href = '#'; // You can set the URL you need here
aTag.textContent = business.business_name; // Set the text content
aTag.id = business.business_id; // Set the text content
aTag.setAttribute('onclick', 'handleBusinessClick(this)');
if(index == 0 || index == '0'){
// aTag.classList.add('active'); // Add a class to indicate the selected business
// document.getElementById('dropdown-selected-text').textContent = business.business_name; // Set initial text
// $(aTag).trigger('click');
}
if (business.business_id == session_business_id) {
aTag.classList.add('active'); // Add a class to indicate the selected business
document.getElementById('dropdown-selected-text').textContent = business.business_name; // Set initial text
}
dropdownMenu.appendChild(aTag); // Append the <a> tag to <div>
});
<?php } ?>

View File

@ -561,6 +561,7 @@
contentType: false,
processData: false,
success: function(response) {
console.log(response);
if(response){
toastr.success('Document created.', 'Success');
window.location.reload();
@ -596,7 +597,7 @@
data: formData,
dataType: 'json',
success: function(response) {
console.log(response.data);
console.log(response);
if (response.data) {
window.location.reload();
}
@ -622,6 +623,7 @@
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
if (response.data) {
window.location.reload();
}