From 99cb6327a62adbe8ab53ffabf8732ce5e2946630 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Wed, 27 Nov 2024 12:03:04 +0000 Subject: [PATCH] FIX_Validation implemented In forms --- app/Controllers/Event.php | 11 ++ app/Controllers/Subscription.php | 22 +++- app/Models/HomeModel.php | 2 +- app/Models/SubscriptionModel.php | 6 +- app/Views/book_form.php | 56 ++++++---- app/Views/customer_form.php | 18 +++ app/Views/event_form.php | 23 +++- app/Views/invoice_form.php | 183 ++++++++++++++++++------------- app/Views/user_form.php | 18 +++ 9 files changed, 234 insertions(+), 105 deletions(-) diff --git a/app/Controllers/Event.php b/app/Controllers/Event.php index 5fc2b643..2c610ee0 100755 --- a/app/Controllers/Event.php +++ b/app/Controllers/Event.php @@ -62,6 +62,17 @@ class Event extends BaseController public function insert_event() { $this->logger->info("Event: Inserting/Updating Details"); + $validationRules = [ + 'ename' => 'required' + ]; + + if (!$this->validate($validationRules)) { + $validation = \Config\Services::validation(); + $errorMessage = $validation->getErrors(); + $firstError = reset($errorMessage); + return redirect()->back()->with('error', $firstError)->withInput(); + } + try { helper('session'); $session_bid = get_business_id(); diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index 5325bb1e..68ee6c3e 100755 --- a/app/Controllers/Subscription.php +++ b/app/Controllers/Subscription.php @@ -20,16 +20,16 @@ class Subscription extends BaseController if (!empty($session_role) && $session_role !== "sadmin") { $this->logger->info("Invoice: Listing In Admin BID = " . $session_bid); - $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>2]; + $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>2,'S.invoice_id !='=>"",'S.sub_id !='=>""]; } else { $this->logger->info("Invoice: Listing In the Super-Admin "); - $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>2]; + $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>2,'S.invoice_id !='=>"",'S.sub_id !='=>""]; } $model = new InvoiceModel(); $data['page_name'] = 'Subscription Invoice Details'; $data['invoice'] = $model->getSubscriptionInvoiceDetail($where); - + $this->logger->info("Invoice: Listing Count ." . count($data['invoice'])); $data['active_schemes'] = $model->getActiveSchemes(); @@ -70,6 +70,22 @@ public function add_subscription() { $session_bid = get_business_id(); $session_uid = get_logged_user_id(); + $validationRules = [ + 'customer_name' => 'required', + 'from_subscription' => 'required', + 'to_subscription' => 'required', + 'shipping_address_id' => 'required', + 'invoice_date' => 'required|valid_date', + 'scheme' => 'required' + ]; + + if (!$this->validate($validationRules)) { + $validation = \Config\Services::validation(); + $errorMessage = $validation->getErrors(); + $firstError = reset($errorMessage); + return redirect()->back()->with('error', $firstError)->withInput(); + } + $SubscriptionModel = new SubscriptionModel(); $data = [ 'scheme_id' =>$this->request->getPost('scheme'), diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php index d09bee6a..1af30939 100755 --- a/app/Models/HomeModel.php +++ b/app/Models/HomeModel.php @@ -104,7 +104,7 @@ class HomeModel extends Model $query = $this->db->table('subscription AS S') ->select('S.business_id, BK.title as name, BK.short_code, BK.book_id as id, S.scheme_id, LEFT(BK.title, 1) AS first_letter, COUNT(S.customer_id) AS count, BI.wp_img_url') ->select('COUNT(S.customer_id) AS overall, COUNT(IF(S.isactive = 1, S.customer_id, NULL)) AS activeoverall, COUNT(IF(S.is_renew = 0 AND S.isactive = 1, S.customer_id, NULL)) AS nonrenewal, COUNT(IF(S.is_renew = 1 AND S.isactive = 1, S.customer_id, NULL)) AS renewal, SUM(CASE WHEN S.created_on >= NOW() - INTERVAL 30 DAY THEN 1 ELSE 0 END) AS new_subscribers') - ->select('COUNT(IF(S.status = 1, S.customer_id, NULL)) AS active,COUNT(IF(S.status = 0, S.customer_id, NULL)) AS expired,COUNT(IF(S.is_renew > 0 AND S.status = 1, S.customer_id, NULL)) AS renew') + ->select('COUNT(IF(S.status = 1, S.customer_id, NULL)) AS active,COUNT(IF(S.is_renew = 0 AND S.status = 0, S.customer_id, NULL)) AS expired,COUNT(IF(S.is_renew > 0 AND S.status = 1, S.customer_id, NULL)) AS renew') ->join('customers AS C', 'C.customer_id = S.customer_id AND C.isactive = 1', 'left') ->join('books AS BK', 'BK.book_id = S.scheme_id', 'left') ->join('book_categories AS BC', 'BC.book_id = S.scheme_id AND BC.isactive = 1', 'left') diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index 909b36ee..f1d1f393 100755 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -248,9 +248,9 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va $builder->orderBy('s.to_subscription', 'asc'); $query = $builder->get(); $result = $query->getResultArray(); - $lastQuery = $this->db->getLastQuery(); - $finalQueryString = $lastQuery->getQuery(); - + $lastQuery = $this->db->getLastQuery(); + $finalQueryString = $lastQuery->getQuery(); + // echo $finalQueryString;die; return $result; } public function getSubscriptionDetailsBySchemeName($selectedScheme, $downloadType){ diff --git a/app/Views/book_form.php b/app/Views/book_form.php index 2e6b67c3..c754dbeb 100755 --- a/app/Views/book_form.php +++ b/app/Views/book_form.php @@ -21,6 +21,24 @@

+ getFlashdata('success') || session()->getFlashdata('error')) : ?> + getFlashdata('success')) : ?> + + + getFlashdata('error')) : ?> + + +

getFlashdata('success')) : ?>
getFlashdata('success') ?>
@@ -34,40 +52,40 @@
- - + +
- - + +
- - + +
- - + +
- - + +
- +
@@ -84,13 +102,13 @@
- +
- +
@@ -186,16 +204,14 @@ document.getElementById('myForm').addEventListener('submit', function(event) { var form = event.target; - // Check if form is valid if (!form.checkValidity()) { - form.reportValidity(); // Display validation error messages - event.preventDefault(); // Prevent form submission if it's not valid - $('#submitBtn').prop('disabled', false); // Re-enable the button - - // Display custom alert message + event.preventDefault(); + form.reportValidity(); + $('#submitBtn').prop('disabled', false); + alert('Please fill out all required fields correctly.'); } else { - $('#submitBtn').prop('disabled', true); // Disable the button to prevent duplicate submissions + $('#submitBtn').prop('disabled', true); } }); diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php index 5d540b14..43b3e071 100755 --- a/app/Views/customer_form.php +++ b/app/Views/customer_form.php @@ -7,6 +7,24 @@ ); ?>

+ getFlashdata('success') || session()->getFlashdata('error')) : ?> + getFlashdata('success')) : ?> + + + getFlashdata('error')) : ?> + + +