From 34754b55b026a55564bd119be437c2a67fb38ca0 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 14 Jun 2024 16:40:58 +0530 Subject: [PATCH] CHANGE_TRACKER_ISSUE_PUSH : AADHAVAN --- app/Config/Routes.php | 7 +- app/Controllers/Client.php | 24 +++-- app/Controllers/Login.php | 18 ++++ app/Controllers/Purchase.php | 18 ++-- app/Controllers/Users.php | 82 +++++++++++++++ app/Filters/AuthMVC.php | 24 +++++ app/Helpers/MailHelper.php | 33 ++++++ app/Helpers/session.php | 9 ++ app/Views/client_form.php | 48 ++++++++- app/Views/complaint_list.php | 2 + app/Views/edit_account_form.php | 33 ++++-- app/Views/forgot_password.php | 171 ++++++++++++++++++++++++++++++ app/Views/login_form.php | 17 ++- app/Views/reset_password.php | 181 ++++++++++++++++++++++++++++++++ app/Views/sales_order_form.php | 89 ++++++++++------ app/Views/vehicle_form.php | 2 +- app/Views/vendor_form.php | 14 ++- 17 files changed, 709 insertions(+), 63 deletions(-) create mode 100644 app/Filters/AuthMVC.php create mode 100644 app/Views/forgot_password.php create mode 100644 app/Views/reset_password.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6cb9828..e1720c0 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -12,12 +12,17 @@ $routes->setTranslateURIDashes(false); $routes->set404Override(); //Login// $routes->get('/', 'Login::index'); -$routes->get('log_out', 'Login::index'); +$routes->get('log_out', 'Login::logout'); $routes->post("authenticate", "Login::authenticate"); $routes->get("edit_account/(:any)", "Users::edit_account/$1"); $routes->post("edit_mail/(:any)", "Users::edit_mail/$1"); $routes->post("change_password/(:any)", "Users::change_password/$1"); +$routes->post("change_password_forget", "Users::change_password_forget"); $routes->post("add_account", "Users::add_account"); +$routes->match(['get','post'],'/forgot_password','Users::forgot_password'); +$routes->match(['get','post'],'/verify_otp','Users::verify_otp'); + + // $routes->get("new_user/(:any)", "Users::new_user/$1"); // $routes->get("delete_user/(:any)", "Users::delete_user/$1"); //end Login// diff --git a/app/Controllers/Client.php b/app/Controllers/Client.php index 0a1ef4f..04734b8 100644 --- a/app/Controllers/Client.php +++ b/app/Controllers/Client.php @@ -59,12 +59,12 @@ class Client extends BaseController if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); } $ClientModel = new ClientModel(); - + $mobile_no = $this->request->getPost('mobile'); $data = [ 'client_name' => $this->request->getPost('client_name'), 'email' => $this->request->getPost('email'), 'address' => $this->request->getPost('address'), - 'mobile_no' => $this->request->getPost('mobile'), + 'mobile_no' =>$mobile_no, 'city' => $this->request->getPost('city'), 'state' => $this->request->getPost('state'), 'postal_code' => $this->request->getPost('postalcode'), @@ -74,20 +74,30 @@ class Client extends BaseController 'branch_id' => $this->session->get('logged_user_branch_id') ]; // print_r($data);die; - + $client_id = $this->request->getPost('client_id'); if (!empty($client_id)) { - $ClientModel->update($client_id, $data); - } else { + $update= $ClientModel->update($client_id, $data); - $ClientModel->insert($data); + if($update){ + return json_encode("update"); + } + + } else { + if($ClientModel->where('mobile_no', $mobile_no)->first()){ + $error = "Mobile number already exists"; + return json_encode(false); + }else{ + $ClientModel->insert($data); + return json_encode(true); + } } - return redirect()->to('client_index'); + // return redirect()->to('client_index'); } public function delete_client($client_id) diff --git a/app/Controllers/Login.php b/app/Controllers/Login.php index af5940a..e20fbf6 100644 --- a/app/Controllers/Login.php +++ b/app/Controllers/Login.php @@ -19,6 +19,24 @@ class Login extends BaseController return view('login_form'); } + + public function logout() + { + // Remove specific session variables + $this->session->remove('logged_user'); + $this->session->remove('logged_user_branch_id'); + $this->session->remove('logged_user_business_id'); + $this->session->remove('logged_user_role'); + $this->session->remove('logged_user_name'); + + // Destroy the session + $this->session->destroy(); + + // Redirect to the home page or login page + return redirect()->to('/'); + } + + public function authenticate() { $loginModel = new LoginModel(); diff --git a/app/Controllers/Purchase.php b/app/Controllers/Purchase.php index 671508d..6fc80f1 100644 --- a/app/Controllers/Purchase.php +++ b/app/Controllers/Purchase.php @@ -51,7 +51,10 @@ class Purchase extends BaseController $PurchaseOrderModel = new PurchaseOrderModel(); $VendorModel = new VendorModel(); - $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->select('vendor_id,vendor_name')->findAll(); + $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_branch_id')) + ->where('isactive', 1) + ->select('vendor_id,vendor_name') + ->findAll(); @@ -60,9 +63,9 @@ class Purchase extends BaseController $branch = $BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray(); $business = $BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray(); $ProductModel = new ProductModel(); - $product=$ProductModel - ->where('isactive',1) - ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); + $product=$ProductModel->where('isactive',1) + ->where('branch_id',$this->session->get('logged_user_branch_id')) + ->findAll(); $data['product']=$product; $data['branch'] = $branch; $data['business'] = $business; @@ -78,7 +81,10 @@ class Purchase extends BaseController $purchase=$PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray(); $VendorModel = new VendorModel(); - $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))->select('vendor_id,vendor_name')->findAll(); + $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_business_id')) + ->where('isactive', 1) + ->select('vendor_id,vendor_name') + ->findAll(); $data['vendor']=$vendor; $data['purchase'] = $purchase; @@ -88,7 +94,7 @@ class Purchase extends BaseController $VendorModel = new VendorModel(); $vendor = $VendorModel->findAll(); $data['vendor'] = $vendor; - +// $data['vendor_id'] = $purchase['vendor_id']; // print_r($vendor);die; $vendorId=$purchase['vendor_id']; diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php index 17f421c..9e7b57d 100644 --- a/app/Controllers/Users.php +++ b/app/Controllers/Users.php @@ -11,6 +11,8 @@ use App\Models\JobcardModel; use App\Models\BikemodelsModel; use App\Models\BikemakeModel; +use App\Helpers\MailHelper; + class Users extends BaseController { @@ -73,6 +75,86 @@ class Users extends BaseController return view('user_list',['users' => $users, 'roleModel' => $roleModel]); } + public function forgot_password() + { + $UsersModel = new UsersModel(); + + + if($this->request->getmethod() == 'post') + { + + $email = $this->request->getVar('email'); + $staff_data = $UsersModel->where('email', $email)->find(); + + + if ($staff_data) + { + $otp = rand(1000 , 9999); + $MailHelper = new MailHelper(); + $MailHelper->send_otp_email($this->request->getVar('email') , $otp ); + + $data['status'] = 'success'; + $data['otp'] = $otp; + echo json_encode($data); + } + else + { + $data['status'] = 'failed'; + echo json_encode($data); + } + + }else{ + // print_r("11111111111111111111");die; + return view('forgot_password.php'); + } + } + + public function verify_otp() + { + $UsersModel = new UsersModel(); + + if($this->request->getmethod() == 'post') + { + $otp = $this->request->getVar('otp'); + $verify_otp = $this->request->getVar('verify_otp'); + + if ($otp == $verify_otp) + { + $email = $this->request->getVar('email'); + $data = $UsersModel->where('email', $email)->find(); + if ($data) + { + $this->session->setTempdata('user_id',$data[0]['user_id'],3); + $this->session->setTempdata('email',$data[0]['email'],3); + $this->session->setTempdata('mail_success', "OTP verified sucessfully",3); + return view('reset_password.php'); + } + } + else + { + $this->session->setTempdata('error', "You entered wrong OTP.Please retry",3); + return view('forgot_password.php'); + } + + + } + } + + + public function change_password_forget() + { + $UsersModel = new UsersModel(); + + if($this->request->getmethod() == 'post') + { + $userData = $this->request->getVar(); + $user_id = $this->request->getVar('user_id'); + $userData['password'] = password_hash($userData['password'], PASSWORD_DEFAULT); + $UsersModel->where('user_id', $user_id )->set($userData)->update(); + $this->session->setTempdata('mail_success', "Password set sucessfully",3); + return redirect()->to(base_url()); + } + } public function user_list($branch_id) { diff --git a/app/Filters/AuthMVC.php b/app/Filters/AuthMVC.php new file mode 100644 index 0000000..aa40610 --- /dev/null +++ b/app/Filters/AuthMVC.php @@ -0,0 +1,24 @@ +to(base_url('/login')); + } + + } + + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) + { + // Do something here + } +} + diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 881411b..82802e9 100644 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -42,6 +42,39 @@ class MailHelper } } + public static function send_otp_email($email_id,$otp) + { + + + + $subject = 'BB-Sign Verify Document'; + $message = "Hai , +
+ We have a requested forgot password OTP :".$otp; + + + + try { + + $email = \Config\Services::email(); + $email->setMailType('html'); + $email->setFrom('bbone@venbait.in', 'BB-Sign'); + + $email->setTo($email_id); + + $email->setSubject($subject); + $email->setMessage($message); + + if ($email->send()) { + return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...','data' => $email_id,],200); + } else { + return json_encode(['status' => 'failed','code' => 404,'message'=>'Email Sent Failed...','data' => $email_id ],404); + } + + } catch (\Exception $e) { + return json_encode(['status' => 'failed','code' => 500,'data' => $email_id],500); + } + } } ?> \ No newline at end of file diff --git a/app/Helpers/session.php b/app/Helpers/session.php index e29140e..9ec6bbf 100644 --- a/app/Helpers/session.php +++ b/app/Helpers/session.php @@ -10,4 +10,13 @@ if (!function_exists('get_branch_id')) { } } +if (!function_exists('check_session')) { + function check_session() + { + // $ci =& get_instance(); + $session = \Config\Services::session(); + return $session->get('isLoggedIn'); + } +} + ?> \ No newline at end of file diff --git a/app/Views/client_form.php b/app/Views/client_form.php index 34c9e59..19ae56d 100644 --- a/app/Views/client_form.php +++ b/app/Views/client_form.php @@ -15,7 +15,7 @@
-
" method="post"> +

Client Details :

@@ -24,7 +24,8 @@
- + +
@@ -68,7 +69,7 @@
- +
@@ -83,4 +84,45 @@ if(charcode>= 48 && charcode <= 57)return true; return false; } + + + $('#client_form_submit').click(function (event) { + event.preventDefault(); + + // action="" + var formData = $('#client_form').serialize(); + + $.ajax({ + type: 'POST', + url: '', + data: formData, + dataType: 'json', + success: function(response) { + console.log(response); + if(response == 'update'){ + toastr.success('Client Updated Succssfully'); + + window.location.href = ''; + }else if(response){ + toastr.success('Client Added Succssfully'); + + window.location.href = ''; + }else{ + toastr.warning('Mobile number already exists'); + $('#mobile_error').html('Mobile number already exists'); + $('#mobile').css('border', '1px solid red'); + $('#mobile').focus(); + setTimeout(() => { + $('#mobile').css('border', '1px solid #ced4da'); + + }, 2000); + } + }, + error: function(xhr, status, error) { + // Handle error response here + console.error(xhr.responseText); + } + }); + }) + \ No newline at end of file diff --git a/app/Views/complaint_list.php b/app/Views/complaint_list.php index e08b367..87b2394 100644 --- a/app/Views/complaint_list.php +++ b/app/Views/complaint_list.php @@ -132,6 +132,8 @@ if (!complaint_id) { complaint_id = 0; } + $(params).attr('disabled', true); + $.ajax({ type: 'POST', url: '' + complaint_id, diff --git a/app/Views/edit_account_form.php b/app/Views/edit_account_form.php index 70b9ae3..c097f49 100644 --- a/app/Views/edit_account_form.php +++ b/app/Views/edit_account_form.php @@ -242,21 +242,36 @@ diff --git a/app/Views/forgot_password.php b/app/Views/forgot_password.php new file mode 100644 index 0000000..12ae7db --- /dev/null +++ b/app/Views/forgot_password.php @@ -0,0 +1,171 @@ + + + + + Forgotpassword + + + + + + + + + /assets/css/bootstrap-material.min.css" rel="stylesheet" type="text/css" id="bs-default-stylesheet" /> + /assets/css/app-material.min.css" rel="stylesheet" type="text/css" id="app-default-stylesheet" /> + + /assets/css/bootstrap-material-dark.min.css" rel="stylesheet" type="text/css" id="bs-dark-stylesheet" /> + /assets/css/app-material-dark.min.css" rel="stylesheet" type="text/css" id="app-dark-stylesheet" /> + + + /assets/css/icons.min.css" rel="stylesheet" type="text/css" /> + + + /assets/css/style.css" rel="stylesheet" type="text/css" /> + + + + + + + + + + +
+ © +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/login_form.php b/app/Views/login_form.php index 6b1649f..f1611a3 100644 --- a/app/Views/login_form.php +++ b/app/Views/login_form.php @@ -60,11 +60,18 @@
- +
- - + +
+ +
+
+ +
+
+
@@ -84,9 +91,11 @@ +
diff --git a/app/Views/reset_password.php b/app/Views/reset_password.php new file mode 100644 index 0000000..465b49e --- /dev/null +++ b/app/Views/reset_password.php @@ -0,0 +1,181 @@ + + + + + Reset Password + + + + + + /assets/images/favicon.ico"> + + + /assets/css/bootstrap-corporate.min.css" rel="stylesheet" type="text/css" id="bs-default-stylesheet" /> + /assets/css/app-corporate.min.css" rel="stylesheet" type="text/css" id="app-default-stylesheet" /> + + /assets/css/bootstrap-corporate-dark.min.css" rel="stylesheet" type="text/css" id="bs-dark-stylesheet" /> + /assets/css/app-corporate-dark.min.css" rel="stylesheet" type="text/css" id="app-dark-stylesheet" /> + + + /assets/css/icons.min.css" rel="stylesheet" type="text/css" /> + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index 80396fb..66411c4 100644 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -1,4 +1,14 @@ + + +
@@ -152,11 +162,11 @@ Item Details Rate Qty - Taxable Amount + Taxable Amt Tax - Tax Amount + Tax Amt - Total Amount + Tot Amt @@ -168,7 +178,7 @@ - + - + @@ -198,17 +208,17 @@ min="0" value="" onchange="updateThirdColumnValue(this); updateTaxAmount(this)"> - + '; } ?> - + - + " readonly> - + + + + + --> + @@ -445,8 +455,11 @@ $(document).ready(function() { var makeAndModel = response.makeName + ' ' + response.modelName; $('#makeAndModel').val(makeAndModel); - productarray = response.product; - + if(response.product.length){ + productarray = response.product; + }else{ + productarray = "No Product"; + } }, error: function(xhr, status, error) { @@ -567,8 +580,8 @@ $(document).ready(function() { var cgst = parseInt(product.cgst); var sgst = parseInt(product.sgst); var totalTax = cgst + sgst; - // var total_tax_amount = product.unit_price * totalTax / 100; - var total_tax_amount = product.total_amount; + var total_tax_amount = product.unit_price * totalTax / 100; + // var total_tax_amount = product.total_amount; $(this).closest('tr').find('.item-quantity').attr('max', product.qty_stock); @@ -595,9 +608,18 @@ $(document).ready(function() { function calculateSubtotal() { var subtotal = 0; $('.item-amount').each(function() { - subtotal += parseFloat($(this).val()) || 0; + // subtotal += parseFloat($(this).val()) || 0; + + var value1 = $(this).val(); + var qty = $(this).parent().parent().find('.item-quantity').val(); + var rate = $(this).parent().parent().find('.item-rate').val(); + // console.log(value1); + // console.log(value2); + + subtotal += qty * rate; }); return subtotal; + } // Function to calculate total tax @@ -671,10 +693,12 @@ $(document).ready(function() { // Event listener for "Add More Item" button $('#addItem').click(function() { - console.log(productarray.length); - if (productarray.length > 0) { + console.log(productarray); + if(productarray == 'No Product'){ + toastr.warning("First Add the Product!"); + }else if (productarray.length > 0) { var newRow = '' + - ''; for (var i = 0; i < productarray.length; i++) { var product = productarray[i]; @@ -692,8 +716,8 @@ $(document).ready(function() { '' + '' + '' + - '' + - '' + + '' + + '' + '' + '
' + ''; @@ -818,12 +842,15 @@ function onlyNumbers(event) { @@ -919,7 +946,9 @@ $(document).ready(function() { });