Book module Message : ps

This commit is contained in:
VE10-Sanjeev 2023-10-13 15:55:01 +05:30
parent 69a7ff7e4a
commit 5a7d027a2b
5 changed files with 105 additions and 21 deletions

View File

@ -54,6 +54,7 @@ class Books extends BaseController
## For inserting/updating details of book
public function insert_books()
{
try{
helper('session');
$session_uid = get_logged_user_id();
$session_bid = get_business_id();
@ -121,13 +122,29 @@ class Books extends BaseController
$data['isactive'] = 1;
$data['category'] = 1;
$data['created_by'] = $session_uid;
$BooksModel->insert($data);
if ($BooksModel->insert($data)) {
session()->setFlashdata('success', 'Book has been added successfully.');
$this->logger->info("Books: has been added successfully. Inserted ID = " . $BooksModel->insertID());
} else {
session()->setFlashdata('error', 'Book could not be added. Please try again..');
$this->logger->error("Books: Err could not be added. Please try again.");
}
} 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);
if ($BooksModel->update($book_id, $data)) {
session()->setFlashdata('success', 'Book has been updated successfully.');
$this->logger->info("Books: has been updated successfully. Updated Book ID = " . $book_id);
} else {
session()->setFlashdata('error', 'Book update failed. Please try again.');
$this->logger->error("Books: Err Failed to update ID =" . $book_id);
}
}
} catch (\Exception $e) {
$this->logger->error("Book: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
return redirect()->route('book_list');
}
@ -135,21 +152,55 @@ class Books extends BaseController
## For delete the book details (Which means inactive the details)
public function delete_books($id)
{
helper('session');
$session_uid = get_logged_user_id();
$BooksModel = new BooksModel();
$existingBook = $BooksModel->find($id);
if (!$existingBook) {
return redirect()->route('book_list');
try {
helper('session');
$session_uid = get_logged_user_id();
$BooksModel = new BooksModel();
$where = ['book_id' => (int)$id, 'isactive =' => 1];
// $existingBook = $BooksModel->find($id);
$existingBook = $BooksModel->where($where)->find($id);
if ($existingBook) {
$this->logger->Info("BOOK: Going to Inactive ID = ".$id);
$data = ['isactive' => 0 , 'updated_by' => $session_uid];
if ($BooksModel->update($id, $data)) {
$activeBookImages = $BooksModel->getData('book_images', $where);
if(!empty($activeBookImages)){
for ($y = 0; $y < count($activeBookImages); $y++) {
$bookImgIds[$y] = $activeBookImages[$y]->book_img_id;
}
if(!empty($bookImgIds)){
$this->logger->Info("BOOK: Images Going to Inactived = ".implode(" ",$bookImgIds));
$inactive_img_whereIn[0] = 'book_img_id';
$inactive_img_whereIn[1] = $bookImgIds;
$BooksModel->inactiveMissingDetails('book_images',$where, $inactive_img_whereIn);
}
}
$activeBookCategory = $BooksModel->getData('book_categories', $where);
if(!empty($activeBookCategory)){
for ($z = 0; $z < count($activeBookCategory); $z++) {
$bookCategoryIds[$z] = $activeBookCategory[$z]->id;
}
if(!empty($bookCategoryIds)){
$this->logger->Info("BOOK: Categories Going to Inactived = ".implode(" ",$bookCategoryIds));
$inactive_category_whereIn[0] = 'id';
$inactive_category_whereIn[1] = $bookCategoryIds;
$BooksModel->inactiveMissingDetails('book_categories',$where, $inactive_category_whereIn);
}
}
session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("BOOK: has been Inactived successfully. Inactived ID = " . $id);
} else {
$this->logger->error("BOOK: Not able to Inactive ID =" . $id);
throw new \Exception("Data Not able to Deleted");
}
}
} catch (\Exception $e) {
$this->logger->error("Book: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
$data['isactive'] = 0;
$data['updated_by'] = $session_uid;
$BooksModel->update($id, $data);
return redirect()->route('book_list');
}
}

View File

@ -58,4 +58,22 @@ class BooksModel extends Model
return $books;
}
public function getData($table, $where = null,$whereIn = null)
{
$query = $this->db->table($table);
if ($where) {
$query->where($where);
}
if($whereIn){
// $query->whereIn($column_name,$missingValues)
$query->whereIn($whereIn[0],$whereIn[1]);
}
return $query->get()->getResult();
}
public function inactiveMissingDetails($table_name,$where,$whereIn){
$dataToUpdate = ['isactive' => 0];
$this->db->table($table_name)->where($where)->whereIn($whereIn[0],$whereIn[1])->update($dataToUpdate);
}
}

View File

@ -9,11 +9,8 @@ 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','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)
{

View File

@ -53,7 +53,7 @@
</div>
<div class="form-group col-md-6">
<label for="isbn_code" class="col-form-label">ISBN CODE<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="isbn_code" name="isbn_code" value="<?= isset($details['publication_date']) ? $details['publication_date'] : '' ?>"required />
<input type="text" class="form-control" id="isbn_code" name="isbn_code" value="<?= isset($details['isbn_code']) ? $details['isbn_code'] : '' ?>"required />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
@ -83,7 +83,7 @@
<div class="form-group col-md-6">
<label for="publication_date" class="col-form-label">Publication Date<span class="text-danger"></span></label>
<input type="date" class="form-control" id="publication_date" name="publication_date" placeholder="Publication Date (format : DD/MM/YYYY)" data-toggle="input-mask" data-mask-format="00/00/0000" value="<?= isset($details['publication_date']) ? $details['publication_date'] : '' ?>" />
<input type="date" class="form-control" id="publication_date" name="publication_date" placeholder="Publication Date (format : DD/MM/YYYY)" value="<?= isset($details['publication_date']) ? $details['publication_date'] : '' ?>">
</div>

View File

@ -7,6 +7,24 @@
</div>
<br>
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
<?php if (session()->getFlashdata('success')) : ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= session('success') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php endif; ?>
<?php if (session()->getFlashdata('error')) : ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= session('error') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php endif; ?>
<?php endif; ?>
<div class="table-responsive">
<!-- <table id="basic-datatable" class="table dt-responsive w-100"> -->
<table id="scroll-horizontal-datatable_new" class="table w-100 nowrap">