diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php index 8d51d4b0..98604094 100755 --- a/app/Controllers/Books.php +++ b/app/Controllers/Books.php @@ -38,19 +38,28 @@ class Books extends BaseController { helper('session'); $data['session_bid'] = get_business_id(); + + // Fetch categories from the model + $model = new BooksModel(); + $categories = $model->getCategories(); + if ($id === '0') { - $data['page_name'] = 'Add Book'; + $data['page_name'] = 'Add Book'; $data['details'] = []; - } else if ($id !== '0') { - $data['page_name'] = 'Edit Book'; - $model = new BooksModel(); - $model->setTable('books'); - $details = $model->where(['book_id' => $id, 'isactive' => 1])->first(); - $data['details'] = $details; + } elseif ($id !== '0') { + $data['page_name'] = 'Edit Book'; + + $imageData = $model->getBooksAndImagesByBookId($id); + + $data['details'] = $imageData[0]; + } + + $data['categories'] = $categories; // Pass the categories to the view + $this->render_page('book_form', $data); } - + ## For inserting/updating details of book public function insert_books() { @@ -58,51 +67,11 @@ class Books extends BaseController $session_uid = get_logged_user_id(); $session_bid = get_business_id(); - // $validationRule = [ - // 'userfile' => [ - // 'label' => 'Image File', - // 'rules' => [ - // 'uploaded[coverpicture]', - // 'is_image[coverpicture]', - // 'mime_in[coverpicture,image/jpg,image/jpeg,image/gif,image/png,image/webp]', - - // ], - // ], - // ]; - - // if (!$this->validate($validationRule) && $this->request->getPost('coverpicture') === '') { - // $data = ['errors' => $this->validator->getErrors()]; - // print_r($data); - // return 'hello'; - // } - // $img = $this->request->getFile('coverpicture'); - // $book_id = $this->request->getPost('book_id'); - $business_id = $this->request->getPost('business_id'); - // $filePath = 'public/uploads/' . $this->request->getPost('coverpicture'); - - // ## File Already Existing or not - // if ($img->isValid() && !$img->hasMoved()) { - // $fileName = $img->getName(); - // $img->move('public/uploads/', $fileName); - - - // // Delete the previous image file if it exists - // if ($book_id) { - // $previousFileName = $this->request->getPost('previous_file'); - // if ($previousFileName && is_file('public/uploads/' . $previousFileName)) { - // link('public/uploads/' . $previousFileName); - // } - // } - // } else { - // $fileName = $this->request->getPost('previous_file', ''); // Use the previous filename if no new image is provided - // } - - - $BooksModel = new BooksModel(); + $BooksModel = new BooksModel(); $data = [ 'title' => $this->request->getPost('title'), - // 'cover_picture' => $fileName, + 'publication_date' => $this->request->getPost('publication_date'), 'publisher' => $this->request->getPost('publisher'), 'genre' => $this->request->getPost('genre'), @@ -112,23 +81,69 @@ class Books extends BaseController 'price' => $this->request->getPost('price'), 'isbn_code' => $this->request->getPost('isbn_code'), 'tax'=>$this->request->getPost('tax'), - 'business_id' => $business_id + 'business_id'=>$session_bid + ]; $book_id = $this->request->getPost('book_id'); // Get the book ID for update purpose if (empty($book_id)) { // It's an insert operation $data['isactive'] = 1; - $data['category'] = 1; $data['created_by'] = $session_uid; - $BooksModel->insert($data); + $bookId = $BooksModel->insert($data); + + + // Retrieve the selected category ID from the form + $category_id = $this->request->getPost('category_id'); + + if ($category_id) { + // Insert the book-category association into the book_categories table + $BooksModel->db->table('book_categories')->insert(['book_id' => $bookId, 'category_id' => $category_id]); + } + if (!empty($_FILES['img_name']['name'])) { + // A new image has been uploaded + + // First, delete the previous image file if it exists + if (!empty($imageData) && file_exists(WRITEPATH . 'public/uploads/' . $imageData[0]->img_name)) { + unlink(WRITEPATH . 'public/uploads/' . $imageData[0]->img_name); + } + + + $imageData = [ + 'book_id' => $bookId, // Assuming $last_inserted_id contains the ID of the inserted scheme + 'img_name' => $_FILES['img_name']['name'], + 'is_cover' => 1, // Set this based on your requirements + 'type' => $_FILES['img_name']['type'] + ]; + + // Move the uploaded image to a desired location + $imagePath = 'public/uploads/' . $_FILES['img_name']['name']; + move_uploaded_file($_FILES['img_name']['tmp_name'], $imagePath); + + // Update image data in the 'book_images' table + $BooksModel->insertImage($imageData); + } + // print_r($bookId); print_r($imageData); print_r($category_id);die; + } else { // It's an update operation $isactive = $this->request->getPost('isactive'); $data['isactive'] = ($isactive == 'on') ? 1 : 0; $data['updated_by'] = $session_uid; $BooksModel->update($book_id, $data); + + // Retrieve the selected category ID from the form + $category_id = $this->request->getPost('category_id'); + + // Remove existing category associations + $BooksModel->db->table('book_categories')->where('book_id', $book_id)->delete(); + + if ($category_id) { + // Insert the book-category association into the book_categories table + $BooksModel->db->table('book_categories')->insert(['book_id' => $book_id, 'category_id' => $category_id]); + } } + return redirect()->route('book_list'); } diff --git a/app/Controllers/Scheme.php b/app/Controllers/Scheme.php index 91ede95e..65c1dfe4 100644 --- a/app/Controllers/Scheme.php +++ b/app/Controllers/Scheme.php @@ -44,10 +44,13 @@ class Scheme extends BaseController } else if ($id !== '0') { $data['page_name'] = 'Edit Scheme'; $model = new SchemeModel(); - $model->setTable('books'); - $edit_user_details = $model->where(['book_id' => $id])->first(); + - $data['scheme'] = $edit_user_details; + $imageData = $model->getBooksAndImagesByBookId($id); + + $data['scheme'] = $imageData[0]; + + // print_r($data);die(); } $data['session_bid'] = $session_bid; @@ -101,12 +104,35 @@ class Scheme extends BaseController 'category_id' => $category->id ]); } - } + if (!empty($_FILES['img_name']['name'])) { + // A new image has been uploaded + + // First, delete the previous image file if it exists + if (!empty($imageData) && file_exists(WRITEPATH . 'public/uploads/' . $imageData[0]->img_name)) { + unlink(WRITEPATH . 'public/uploads/' . $imageData[0]->img_name); + } + + $imageData = [ + 'book_id' => $last_inserted_id, // Assuming $last_inserted_id contains the ID of the inserted scheme + 'img_name' => $_FILES['img_name']['name'], + 'is_cover' => 1, // Set this based on your requirements + 'type' => $_FILES['img_name']['type'] + ]; + + // Move the uploaded image to a desired location + $imagePath = 'public/uploads/' . $_FILES['img_name']['name']; + move_uploaded_file($_FILES['img_name']['tmp_name'], $imagePath); + + // Update image data in the 'book_images' table + $SchemeModel->insertImage($imageData); + } +} else { // It's an update operation $isactive = $this->request->getPost('isactive'); $data['isactive'] = ($isactive == 'on') ? 1 : 0; $data['updated_by'] = $session_uid; + $SchemeModel->update($scheme_id, $data); } return redirect()->route('scheme_list'); diff --git a/app/Models/BooksModel.php b/app/Models/BooksModel.php index 80dfc8d6..bd03e8f6 100644 --- a/app/Models/BooksModel.php +++ b/app/Models/BooksModel.php @@ -57,5 +57,39 @@ class BooksModel extends Model return $books; } +public function insertBooksCategory($book_id, $category_id) +{ + $data = [ + 'book_id' => $book_id, + 'category_id' => $category_id, + ]; + + $db = \Config\Database::connect(); + $builder = $db->table('book_categories'); + $builder->insert($data); +} +public function getCategories() + { + // Use the Query Builder to retrieve categories from the 'categories' table + $categories = $this->db->table('category')->get()->getResultArray(); + + return $categories; + } + public function getBooksAndImagesByBookId($id) +{ + $builder = $this->db->table('books'); + $builder->select('books.*, book_images.img_name, book_images.is_cover, book_images.type'); + $builder->join('book_images', 'book_images.book_id = books.book_id', 'left'); + $builder->where('books.book_id', $id); + + $query = $builder->get(); + + return $query->getResultArray(); +} +public function insertImage($imageData) +{ + return $this->db->table('book_images')->insert($imageData); +} + } diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php index 79a7a894..1b9f76a6 100644 --- a/app/Models/CustomerModel.php +++ b/app/Models/CustomerModel.php @@ -9,11 +9,7 @@ class CustomerModel extends Model { protected $table = 'customers'; protected $primaryKey = 'customer_id '; -<<<<<<< HEAD - protected $allowedFields = ['customer_id ','first_name','city','last_name','email','mobile_no','country','state','postal_code' ,'address','profile_picture','date_of_birth','gender','mode','isactive','business_id']; -======= protected $allowedFields = ['customer_id ','first_name','city','last_name','email','mobile_no','country','state','postal_code' ,'address','profile_picture','date_of_birth','gender','mode','type','isactive','business_id','created_by','updated_by']; ->>>>>>> caaaaa0ffd2a11af5f49570cb1fadb521e89b52f public function insertCustomer($data) { diff --git a/app/Models/SchemeModel.php b/app/Models/SchemeModel.php index 513bc406..158775c1 100644 --- a/app/Models/SchemeModel.php +++ b/app/Models/SchemeModel.php @@ -42,8 +42,26 @@ class SchemeModel extends Model return $schemes; } +public function getBooksAndImagesByBookId($id) +{ + $builder = $this->db->table('books'); + $builder->select('books.*, book_images.img_name, book_images.is_cover, book_images.type'); + $builder->join('book_images', 'book_images.book_id = books.book_id', 'left'); + $builder->where('books.book_id', $id); + + $query = $builder->get(); + + return $query->getResultArray(); +} + +public function insertImage($imageData) +{ + return $this->db->table('book_images')->insert($imageData); +} + + + - // public function getSchemeDuration($schemeId) // { // $query = $this->select('duration') @@ -109,6 +127,15 @@ public function getAllSchemes() { return $this->findAll(); } + public function updateImage($schemeId, $imageData) +{ + $builder = $this->db->table('book_images'); + $builder->set($imageData); + $builder->where('book_id', $schemeId); + $builder->update(); +} + + } diff --git a/app/Views/book_form.php b/app/Views/book_form.php index 6bef9284..ee316445 100644 --- a/app/Views/book_form.php +++ b/app/Views/book_form.php @@ -3,19 +3,19 @@ @@ -27,111 +27,147 @@

getFlashdata('success')) : ?> -
getFlashdata('success') ?>
+
getFlashdata('success') ?>
-
"> + ">
- - + +
Please provide.
- - -
- - -
Please provide.
-
-
-
-
- - -
Please provide.
-
-
- - -
Please provide.
-
-
- -
-
- - - -
- - - -
- - - -
-
-
-
- - - -
- - -
- - - -
- -
-
+
+ + +
Please provide.
+
+
+
+
+ + +
Please provide.
+
+
+ + +
Please provide.
+
+
+ +
+
+ + + +
+ + + +
+ + + + +
+
+
+
+ + + +
+ + +
+ + + +
+ + +
+ +
- - + +
- - + +
- - - - - - -
- -
-
-
-
-
-
-
-
- -
- - + + + + + +
+ +
-
-
-
- - +
+ + +
+
+ + Image Preview + + + +
+
+ + -
- > - -
-
+
+ > + +
+
+ }); +}); + - - - + \ No newline at end of file diff --git a/app/Views/invoice_list.php b/app/Views/invoice_list.php index bc37a5fe..0691b7f0 100644 --- a/app/Views/invoice_list.php +++ b/app/Views/invoice_list.php @@ -62,17 +62,16 @@ Invoice Number Invoice Date Customer Name + Status - Approve INV - Action - view - Print - + Total + Action + @@ -82,16 +81,17 @@ - " class="approve-button"> - + ₹ + " class="approve-button" title="Approve the Invoice">  + - " class="edit-button"> + " class="edit-button" title="Edit the Invoice">  - " class="edit-button"> + " class="edit-button" title="Edit the Invoice">  - - " class="download-pdf-button"> - " class="print-address-button"> + + " class="download-pdf-button" title="Download the Invoice">  + " class="print-address-button" title="Print Address">  diff --git a/app/Views/scheme_form.php b/app/Views/scheme_form.php index b348d8f3..ba4db65b 100644 --- a/app/Views/scheme_form.php +++ b/app/Views/scheme_form.php @@ -23,7 +23,7 @@
- +
Please provide.
@@ -32,15 +32,32 @@
Please provide.
+
-
+ + +
+ + +
+
+ + Image Preview + + + +
+ + + + - +
> @@ -65,4 +82,5 @@
+ \ No newline at end of file