Scheme Message : ps

This commit is contained in:
VE10-Sanjeev 2023-10-13 16:38:19 +05:30
parent 5a7d027a2b
commit f726377124
5 changed files with 131 additions and 54 deletions

View File

@ -120,7 +120,6 @@ class Books extends BaseController
if (empty($book_id)) { if (empty($book_id)) {
// It's an insert operation // It's an insert operation
$data['isactive'] = 1; $data['isactive'] = 1;
$data['category'] = 1;
$data['created_by'] = $session_uid; $data['created_by'] = $session_uid;
if ($BooksModel->insert($data)) { if ($BooksModel->insert($data)) {
session()->setFlashdata('success', 'Book has been added successfully.'); session()->setFlashdata('success', 'Book has been added successfully.');
@ -172,7 +171,7 @@ class Books extends BaseController
$this->logger->Info("BOOK: Images Going to Inactived = ".implode(" ",$bookImgIds)); $this->logger->Info("BOOK: Images Going to Inactived = ".implode(" ",$bookImgIds));
$inactive_img_whereIn[0] = 'book_img_id'; $inactive_img_whereIn[0] = 'book_img_id';
$inactive_img_whereIn[1] = $bookImgIds; $inactive_img_whereIn[1] = $bookImgIds;
$BooksModel->inactiveMissingDetails('book_images',$where, $inactive_img_whereIn); $BooksModel->inactiveMissingDetails('book_images',$data,$where, $inactive_img_whereIn);
} }
} }
$activeBookCategory = $BooksModel->getData('book_categories', $where); $activeBookCategory = $BooksModel->getData('book_categories', $where);
@ -184,7 +183,7 @@ class Books extends BaseController
$this->logger->Info("BOOK: Categories Going to Inactived = ".implode(" ",$bookCategoryIds)); $this->logger->Info("BOOK: Categories Going to Inactived = ".implode(" ",$bookCategoryIds));
$inactive_category_whereIn[0] = 'id'; $inactive_category_whereIn[0] = 'id';
$inactive_category_whereIn[1] = $bookCategoryIds; $inactive_category_whereIn[1] = $bookCategoryIds;
$BooksModel->inactiveMissingDetails('book_categories',$where, $inactive_category_whereIn); $BooksModel->inactiveMissingDetails('book_categories',$data,$where, $inactive_category_whereIn);
} }
} }

View File

@ -57,6 +57,7 @@ class Scheme extends BaseController
## For inserting/updating details of scheme ## For inserting/updating details of scheme
public function insert_scheme() public function insert_scheme()
{ {
try{
helper('session'); helper('session');
$session_bid = get_business_id(); $session_bid = get_business_id();
$session_uid = get_logged_user_id(); $session_uid = get_logged_user_id();
@ -76,30 +77,32 @@ class Scheme extends BaseController
if (empty($scheme_id)) { if (empty($scheme_id)) {
// It's an insert operation // It's an insert operation
$data['isactive'] = 1; $data['isactive'] = 1;
$data['created_by'] = $session_uid; $data['created_by'] = $session_uid;
$SchemeModel->insert($data); if ($SchemeModel->insert($data)) {
// $last_inserted_id = 100; $last_inserted_id = $SchemeModel->insertID();
$last_inserted_id = $SchemeModel->insertID(); // Retrieve the category name 'membership'
$category_name = 'membership';
// Retrieve the category name 'membership' // Find the category ID for 'membership' from the category table
$category_name = 'membership'; $db = db_connect();
$category = $db->table('category')
// Find the category ID for 'membership' from the category table ->select('id')
$db = db_connect(); ->where('name', $category_name)
$category = $db->table('category') ->get()
->select('id') ->getRow();
->where('name', $category_name) // Check if the category exists
->get() if ($category) {
->getRow(); // Insert data into book_categories table
$db->table('book_categories')->insert([
// Check if the category exists 'book_id' => $last_inserted_id,
if ($category) { 'category_id' => $category->id,
// Insert data into book_categories table 'created_by' => $session_uid
$db->table('book_categories')->insert([ ]);
'book_id' => $last_inserted_id, }
'category_id' => $category->id session()->setFlashdata('success', 'Scheme has been added successfully.');
]); $this->logger->info("Scheme: has been added successfully. Inserted ID = " . $last_inserted_id);
} else {
session()->setFlashdata('error', 'Scheme could not be added. Please try again..');
$this->logger->error("Scheme: Err could not be added. Please try again.");
} }
} }
else { else {
@ -107,37 +110,59 @@ class Scheme extends BaseController
$isactive = $this->request->getPost('isactive'); $isactive = $this->request->getPost('isactive');
$data['isactive'] = ($isactive == 'on') ? 1 : 0; $data['isactive'] = ($isactive == 'on') ? 1 : 0;
$data['updated_by'] = $session_uid; $data['updated_by'] = $session_uid;
$SchemeModel->update($scheme_id, $data); if ($SchemeModel->update($scheme_id, $data)) {
session()->setFlashdata('success', 'Scheme has been updated successfully.');
$this->logger->info("Scheme: has been updated successfully. Updated Scheme ID = " . $scheme_id);
} else {
session()->setFlashdata('error', 'Scheme update failed. Please try again.');
$this->logger->error("Scheme: Err Failed to update ID =" . $scheme_id);
}
} }
} catch (\Exception $e) {
$this->logger->error("Scheme: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
return redirect()->route('scheme_list'); return redirect()->route('scheme_list');
} }
## For delete the Scheme details (Which means inactive the details) ## For delete the Scheme details (Which means inactive the details)
public function delete_scheme($id) public function delete_scheme($id)
{ {
$SchemeModel = new SchemeModel(); try {
helper('session');
$session_uid = get_logged_user_id();
$SchemeModel = new SchemeModel();
$where = ['book_id' => (int)$id, 'isactive =' => 1];
// $existingScheme = $SchemeModel->find($id);
$existingScheme = $SchemeModel->where($where)->find($id);
if ($existingScheme) {
$this->logger->Info("Scheme: Going to Inactive ID = ".$id);
$data = ['isactive' => 0 , 'updated_by' => $session_uid];
if ($SchemeModel->update($id, $data)) {
$activeSchemeCategory = $SchemeModel->getData('book_categories', $where);
if(!empty($activeSchemeCategory)){
for ($z = 0; $z < count($activeSchemeCategory); $z++) {
$SchemeCategoryIds[$z] = $activeSchemeCategory[$z]->id;
}
if(!empty($SchemeCategoryIds)){
$this->logger->Info("Scheme: Categories Going to Inactived = ".implode(" ",$SchemeCategoryIds));
$inactive_category_whereIn[0] = 'id';
$inactive_category_whereIn[1] = $SchemeCategoryIds;
$SchemeModel->inactiveMissingDetails('book_categories',$data,$where, $inactive_category_whereIn);
}
}
// Check if the business ID exists session()->setFlashdata('success', 'Deleted successfully.');
$existingScheme = $SchemeModel->find($id); $this->logger->info("Scheme: has been Inactived successfully. Inactived ID = " . $id);
} else {
if (!$existingScheme) { $this->logger->error("Scheme: Not able to Inactive ID =" . $id);
// return redirect()->to(base_url('Business/index'))->with('error', 'Business not found.'); throw new \Exception("Data Not able to Deleted");
return redirect()->route('scheme_list'); }
}
} catch (\Exception $e) {
$this->logger->error("Scheme: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
} }
helper('session');
$session_uid = get_logged_user_id();
// Delete the business record
$data['isactive'] = 0;
$data['updated_by'] = $session_uid;
//echo 'id='.$id;
print_r($data);
//die();
$SchemeModel->update($id, $data);
// print_r($data);die();
//$BusinessModel->delete($id);
// return redirect()->to(base_url('Business/index'))->with('success', 'Business deleted successfully.');
return redirect()->route('scheme_list'); return redirect()->route('scheme_list');
} }
} }

View File

@ -71,9 +71,17 @@ public function getData($table, $where = null,$whereIn = null)
return $query->get()->getResult(); return $query->get()->getResult();
} }
public function inactiveMissingDetails($table_name,$where,$whereIn){ public function inactiveMissingDetails($table_name,$dataToUpdate,$where = null,$whereIn = null)
$dataToUpdate = ['isactive' => 0]; {
$this->db->table($table_name)->where($where)->whereIn($whereIn[0],$whereIn[1])->update($dataToUpdate); $this->db->table($table_name);
} $query = $this->db->table($table_name);
if ($where) {
$query->where($where);
}
if ($whereIn) {
$query->whereIn($whereIn[0], $whereIn[1]);
}
return $query->update($dataToUpdate);
}
} }

View File

@ -9,7 +9,7 @@ class SchemeModel extends Model
{ {
protected $table = 'books'; protected $table = 'books';
protected $primaryKey = 'book_id'; protected $primaryKey = 'book_id';
protected $allowedFields = ['book_id ','title','sku','description','price','features','duration','business_id','updated_by','category','isactive']; protected $allowedFields = ['book_id ','title','sku','description','price','features','duration','business_id','updated_by','category','isactive','created_by'];
public function insertScheme($data) public function insertScheme($data)
{ {
@ -25,6 +25,7 @@ class SchemeModel extends Model
$builder->join('category', 'category.id = book_categories.category_id', 'left'); $builder->join('category', 'category.id = book_categories.category_id', 'left');
$builder->where('books.business_id', $business_id); $builder->where('books.business_id', $business_id);
$builder->where('category.name', 'membership'); $builder->where('category.name', 'membership');
$builder->where('books.isactive', 1);
$query = $builder->get(); $query = $builder->get();
@ -109,6 +110,32 @@ public function getAllSchemes()
{ {
return $this->findAll(); return $this->findAll();
} }
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,$dataToUpdate,$where = null,$whereIn = null)
{
$this->db->table($table_name);
$query = $this->db->table($table_name);
if ($where) {
$query->where($where);
}
if ($whereIn) {
$query->whereIn($whereIn[0], $whereIn[1]);
}
return $query->update($dataToUpdate);
}
} }

View File

@ -7,6 +7,24 @@
</div><!-- end col--> </div><!-- end col-->
<br> <br>
<h4 class="header-title mb-3"><?= $page_name; ?></h4> <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"> <div class="table-responsive">
<!-- <table id="datatable-buttons" class="table dt-responsive w-100"> --> <!-- <table id="datatable-buttons" class="table dt-responsive w-100"> -->
<table id="scroll-horizontal-datatable_scheme" class="table w-100 nowrap"> <table id="scroll-horizontal-datatable_scheme" class="table w-100 nowrap">