FEATURE_MAKE_AND_MODEL_MODEL:AADHAVAN

This commit is contained in:
aadhavan valli 2024-04-08 17:50:50 +05:30
parent fb1f32769d
commit 3c26494a55
6 changed files with 559 additions and 2 deletions

View File

@ -74,4 +74,25 @@ $routes->get("delete_vehicle/(:any)", "Vehicle::delete_vehicle/$1");
//dashboard
$routes->get('dashboard', 'Users::dashboard');
$routes->get('dashboard', 'Users::dashboard');
//---------------------- Make And Model
// Make
$routes->get('make_index', 'Make::index');
$routes->post('create_make', 'Make::create_make');
// Model
$routes->get('bike_model_index/(:any)', 'Model::index/$1');
$routes->post('create_model', 'Model::create_model');
$routes->post('status_model', 'Model::status_model');

55
app/Controllers/Make.php Normal file
View File

@ -0,0 +1,55 @@
<?php
namespace App\Controllers;
use App\Models\BikemakeModel;
use CodeIgniter\API\ResponseTrait;
class Make extends BaseController
{
public $session;
use ResponseTrait;
public function __construct()
{
$this->session = session();
$this->BikemakeModel = new BikemakeModel();
}
public function index()
{
$BikemakeModel = new BikemakeModel();
$make = $BikemakeModel->findAll();
$data['make']=$make;
return view('make_list',$data);
}
public function create_make()
{
try {
$make_name = $this->request->getPost('makename');
$BikemakeModel = new BikemakeModel();
$data = [
'make' => $make_name
];
$inserted = $BikemakeModel->insert($data);
if ($inserted) {
$result = $data;
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else {
$result = "No Match's";
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
}
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e],500);
}
}
}

99
app/Controllers/Model.php Normal file
View File

@ -0,0 +1,99 @@
<?php
namespace App\Controllers;
use App\Models\BikemodelsModel;
use App\Models\BikemakeModel;
use CodeIgniter\API\ResponseTrait;
class Model extends BaseController
{
public $session;
use ResponseTrait;
public function __construct()
{
$this->session = session();
$this->BikemodelsModel = new BikemodelsModel();
$this->BikemakeModel = new BikemakeModel();
}
public function index($make_id)
{
$BikemodelsModel = new BikemodelsModel();
$BikemakeModel = new BikemakeModel();
$make_value = $BikemakeModel->where('make_id',$make_id)->select('make_id,make')->find();
$make_name= $make_value[0]['make'];
$make_id= $make_value[0]['make_id'];
$model = $BikemodelsModel->where('make_id',$make_id)->findAll();
$data['model']=$model;
$data['make_name'] =$make_name;
$data['make_id'] =$make_id;
return view('bike_model_list',$data);
}
public function create_model()
{
try {
$make_id = $this->request->getPost('make_id');
$model_name = $this->request->getPost('modelname');
$BikemodelsModel = new BikemodelsModel();
$data = [
'make_id' => $make_id,
'model_name' => $model_name
];
$inserted = $BikemodelsModel->insert($data);
if ($inserted) {
$result = $data;
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else {
$result = "No Match's";
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
}
} catch (\Exception $exception) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
}
}
public function status_model()
{
try {
$model_id = $this->request->getPost('model_id');
$isactive = $this->request->getPost('isactive');
$BikemodelsModel = new BikemodelsModel();
$data = [
'isactive' => $isactive
];
$updated = $BikemodelsModel->update($model_id, $data);
$model_list = $BikemodelsModel->findAll();
if ($updated) {
$result = $data;
return $this->respond(['status' => 'success','code' => 200,'data' => $model_list],200);
} else {
$result = "No Match's";
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
}
} catch (\Exception $exception) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
}
}
}

View File

@ -0,0 +1,194 @@
<?php include('layout/header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Bike Model List - <?php echo $make_name; ?></h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="">
<a href="#" data-toggle="modal" data-target="#bike_model_login-modal_1" class="btn btn-primary waves-effect">
<i class="ri-add-line"></i>
</a>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<!-- <h4 class="header-title">Business List</h4> -->
<table id="datatable-buttons" class="table table-striped dt-responsive nowrap w-100" style="width:100% !important;">
<thead>
<tr>
<th>Model Name</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($model as $item): ?>
<tr>
<td><?php echo $item['model_name']; ?></td>
<td>
<?php if($item['isactive'] == 1) { ?>
<span style="color:green" >Active</span>
<?php } else if($item['isactive'] == 0) { ?>
<span style="color:red">Inactive</span>
<?php } ?>
</td>
<td>
<?php if($item['isactive'] == 1) { ?>
<a style="color:red" data-id="<?php echo $item['model_id'];?>" data-isactive="<?php echo $item['isactive'];?>" title="Deactivate" onclick="statusChange(this)" class="fa fa-user-times" ></a>
<?php } else if($item['isactive'] == 0) { ?>
<a style="color:green" data-id="<?php echo $item['model_id'];?>" data-isactive="<?php echo $item['isactive'];?>" title="Activate" onclick="statusChange(this)" class="fa fa-user" ></a>
<?php } ?>
</td>
<td>
</td>
<?php endforeach; ?>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div> <!-- end card -->
</div> <!-- end col -->
</div>
<!-- Start Bike Model Create Pop-UP -->
<div id="bike_model_login-modal_1" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="text-center mt-2 mb-4">
<Label>Add Models</Label>
</div>
<form id="model_form_data" class="px-3">
<div class="form-group">
<input class="form-control" type="text" id="make_id" required="" value="<?php echo $make_id; ?>" placeholder="Make Name...." style="display:none;">
<label for="makename">Make Name </label>
<input class="form-control" type="text" id="makename" required="" value="<?php echo $make_name; ?>" placeholder="Make Name...." disabled>
<label for="modelname">Model Name </label>
<input class="form-control" type="text" id="modelname" required="" placeholder="Model Name....">
</div>
<div class="form-group text-center">
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitModels(this)">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- End Bike Model Create Pop-UP -->
<?php include('layout/footer.php'); ?>
<script>
function submitModels(params) {
console.log( $('#modelname').val());
var formData = {
make_id: $('#make_id').val(),
modelname: $('#modelname').val()
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."create_model"?>',
data: formData,
dataType: 'json',
success: function(response) {
// Handle success response here
console.log(response);
$('#bike_model_login-modal_1').modal('hide');
$('#modelname').val('');
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
function statusChange(params) {
var status = params.getAttribute('data-isactive');
var model_id = params.getAttribute('data-id');
if(status == 1){
var isactive= 0;
}else{
var isactive= 1;
}
var formData = {
model_id: model_id,
isactive: isactive
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."status_model"?>',
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
if (response.status == "success") {
$('tbody').html('');
$.each(response.data, function(index, item) {
var row = '<tr>' +
'<td>' + item.model_name + '</td>' +
'<td>';
if (item.isactive == 1) {
row += '<span style="color:green">Active</span>';
} else if (item.isactive == 0) {
row += '<span style="color:red">Inactive</span>';
}
row += '</td><td>';
// Check the isactive status and set the icon color accordingly
if (item.isactive == 1) {
row += '<a style="color:red" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Deactivate" onclick="statusChange(this)" class="fa fa-user-times"></a>';
} else if (item.isactive == 0) {
row += '<a style="color:green" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Activate" onclick="statusChange(this)" class="fa fa-user"></a>';
}
row += '</td><td></td></tr>';
// Append the row to the tbody
$('tbody').append(row);
});
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
</script>

View File

@ -38,6 +38,11 @@
background-color: #2aa762 !important; /* Set background color to a solid color */
opacity: 1 !important; /* Set opacity to 1 to remove transparency */
}
.icon-large {
font-size: 1.5em; /* Adjust the font size as needed */
}
</style>
</head>
@ -127,7 +132,13 @@
</ul>
</div>
</li>
<li>
<a href="<?php echo base_url('make_index') ?>">
<i class="fas fa-bicycle"></i>
<span> Make </span>
</a>
</li>
<?php if(session()->get('logged_user_role') == 'Floor Manager' ||
session()->get('logged_user_role') == 'Job Card Manager') { ?>

177
app/Views/make_list.php Normal file
View File

@ -0,0 +1,177 @@
<?php include('layout/header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Make List</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="">
<a href="#" data-toggle="modal" data-target="#bike_make_login-modal" class="btn btn-primary waves-effect">
<i class="ri-add-line"></i>
</a>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<table id="datatable-buttons" class="table table-striped dt-responsive nowrap w-100" style="width:100% !important;">
<thead>
<tr>
<th>Bike Make</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($make as $item): ?>
<tr>
<td><?php echo $item['make']; ?></td>
<td>
<a href="#" data-toggle="modal" data-target="#bike_model_login-modal" class="add-button" title="Add" data-id="<?php echo $item['make_id']; ?>" data-value="<?php echo $item['make']; ?>" onclick="setMakeName(this)">
<i class="ri-add-line icon-large"></i>
</a>
<a href="<?= "bike_model_index/" . $item['make_id']; ?>" class="view-list-button" title="Model List">
<i class="ri-list-check-2 icon-large"></i>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Start Bike Make Create Pop-UP -->
<div id="bike_make_login-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="text-center mt-2 mb-4">
<Label>Add Bike Make</Label>
</div>
<form id="model_form_data" class="px-3">
<div class="form-group">
<label for="makename">Make Name </label>
<input class="form-control" type="text" id="bike_make_name" required="" placeholder="Make Name....">
</div>
<div class="form-group text-center">
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitMake(this)">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- End Bike Make Create Pop-UP -->
<!-- Start Bike Model Create Pop-UP -->
<div id="bike_model_login-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="text-center mt-2 mb-4">
<Label>Add Models</Label>
</div>
<form id="model_form_data" class="px-3">
<div class="form-group">
<input class="form-control" type="text" id="make_id" required="" placeholder="Make Name...." style="display:none;">
<label for="makename">Make Name </label>
<input class="form-control" type="text" id="makename" required="" placeholder="Make Name...." disabled>
<label for="modelname">Model Name </label>
<input class="form-control" type="text" id="modelname" required="" placeholder="Model Name....">
</div>
<div class="form-group text-center">
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitModel(this)">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- End Bike Model Create Pop-UP -->
<?php include('layout/footer.php'); ?>
<script>
function setMakeName(params) {
$('#make_id').val(params.getAttribute('data-id'));
$('#makename').val(params.getAttribute('data-value'));
}
function submitModel(params) {
console.log( $('#modelname').val());
var formData = {
make_id: $('#make_id').val(),
modelname: $('#modelname').val()
};
$.ajax({
type: 'POST',
url: 'create_model',
data: formData,
dataType: 'json',
success: function(response) {
// Handle success response here
console.log(response);
$('#bike_model_login-modal').modal('hide');
$('#modelname').val('');
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
function submitMake(params) {
var formData = {
makename: $('#bike_make_name').val()
};
$.ajax({
type: 'POST',
url: 'create_make',
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
$('#bike_model_login-modal').modal('hide');
$('#bike_make_name').val('');
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
</script>