147 lines
5.2 KiB
PHP
Executable File
147 lines
5.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Models\ComplaintModel;
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
class Complaint extends BaseController
|
|
{
|
|
public $session;
|
|
use ResponseTrait;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->session = session();
|
|
}
|
|
|
|
public function complaint_index()
|
|
{
|
|
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
|
$ComplaintModel = new ComplaintModel();
|
|
$complaint = $ComplaintModel->findAll();
|
|
$cubiccapacity = $ComplaintModel->getCubicCapacityName();
|
|
|
|
$data['complaint']=$complaint;
|
|
$data['cubiccapacity']=$cubiccapacity;
|
|
return view('complaint_list',$data);
|
|
}
|
|
|
|
public function create_complaint($complaint_id)
|
|
{
|
|
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
|
try {
|
|
$name = $this->request->getPost('name');
|
|
$cubic_capacity_id = $this->request->getPost('cubic_capacity_id');
|
|
// echo $cubic_capacity_id; die;
|
|
$ComplaintModel = new ComplaintModel();
|
|
$conditions = ['name' => $name, 'isactive' => 1];
|
|
|
|
if ($cubic_capacity_id) {
|
|
$conditions['cubic_capacity_id'] = $cubic_capacity_id;
|
|
}
|
|
|
|
if ($complaint_id > 0) {
|
|
$ComplaintModel->where('complaint_id !=', $complaint_id);
|
|
}
|
|
|
|
$complaint = $ComplaintModel->where($conditions)->findAll();
|
|
|
|
if (!empty($complaint)) {
|
|
$result = "Name Already Exist";
|
|
return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 200);
|
|
}
|
|
|
|
$data = [
|
|
"name" => $this->request->getPost('name'),
|
|
"labour_charge" => $this->request->getPost('labour_charge'),
|
|
"labour_cost_with_tax" => $this->request->getPost('labour_cost_with_tax'),
|
|
"cgst" => $this->request->getPost('tax')/2,
|
|
"sgst" => $this->request->getPost('tax')/2,
|
|
"tax" => $this->request->getPost('tax'),
|
|
"cubic_capacity_id" => $this->request->getPost('cubic_capacity_id') ? $this->request->getPost('cubic_capacity_id') : 0,
|
|
];
|
|
|
|
if (!$complaint_id) {
|
|
$ComplaintModel = new ComplaintModel();
|
|
$data['business_id'] = $this->session->get('logged_user_business_id');
|
|
$inserted = $ComplaintModel->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);
|
|
}
|
|
} else {
|
|
$ComplaintModel = new ComplaintModel();
|
|
// $data = $this->request->getPost();
|
|
$updated = $ComplaintModel->update($complaint_id,$data);
|
|
if ($updated) {
|
|
$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);
|
|
}
|
|
}
|
|
|
|
public function edit_complaint($complaint_id)
|
|
{
|
|
$complaintModel = new ComplaintModel();
|
|
$complaint = $complaintModel->where('complaint_id',$complaint_id)->findAll();
|
|
|
|
$data['page_name']= 'Edit Complaint';
|
|
$data['complaint']=$complaint;
|
|
return json_encode($data);
|
|
}
|
|
|
|
public function delete_complaint($complaint_id)
|
|
{
|
|
|
|
if (!empty($complaint_id)) {
|
|
$ComplaintModel = new ComplaintModel();
|
|
$data['isactive'] = 0;
|
|
|
|
if ($ComplaintModel->update($complaint_id, $data)) {
|
|
// Return success response
|
|
return redirect()->to('complaint_index');
|
|
}
|
|
}
|
|
|
|
// Return error response if deletion fails
|
|
return $this->response->setJSON(['success' => false]);
|
|
}
|
|
|
|
public function status_complaint()
|
|
{
|
|
|
|
try {
|
|
$complaint_id = $this->request->getPost('complaint_id');
|
|
$isactive = $this->request->getPost('isactive');
|
|
|
|
$ComplaintModel = new ComplaintModel();
|
|
$data = [
|
|
'isactive' => $isactive
|
|
];
|
|
$updated = $ComplaintModel->update($complaint_id, $data);
|
|
|
|
if ($updated) {
|
|
$result = $data;
|
|
return $this->respond(['status' => 'success','code' => 200],200);
|
|
} else {
|
|
$result = "No Match's";
|
|
return $this->respond(['status' => 'failed','code' => 404],404);
|
|
}
|
|
} catch (\Exception $exception) {
|
|
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|