150 lines
5.1 KiB
PHP
Executable File
150 lines
5.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Models\ManufacturerModel;
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
|
class Manufacturer extends BaseController
|
|
{
|
|
|
|
public $session;
|
|
use ResponseTrait;
|
|
protected $ManufacturerModel;
|
|
public function __construct()
|
|
{
|
|
|
|
$this->session = session();
|
|
$this->ManufacturerModel = new ManufacturerModel();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
|
|
|
$ManufacturerModel = new ManufacturerModel();
|
|
$spare_manufacturer = $ManufacturerModel->where('business_id',$this->session->get('logged_user_business_id'))->findAll();
|
|
$data['manufacturer']=$spare_manufacturer;
|
|
|
|
return view('manufacturer_list',$data);
|
|
}
|
|
|
|
|
|
|
|
public function create_manufacturer($manufacturer_id)
|
|
{
|
|
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
|
try {
|
|
$manufacturer_name = $this->request->getPost('manufacturername');
|
|
$quality = $this->request->getPost('quality');
|
|
$ManufacturerModel = new ManufacturerModel();
|
|
|
|
if ($manufacturer_id>0) {
|
|
$manufacturer = $ManufacturerModel->where(['manufacturer_name' => $manufacturer_name, 'isactive' => 1])
|
|
->where('manufacturer_id !=', $manufacturer_id)
|
|
->findAll();
|
|
} else {
|
|
$manufacturer = $ManufacturerModel->where(['manufacturer_name' => $manufacturer_name, 'isactive' => 1])->findAll();
|
|
}
|
|
|
|
if (!empty($manufacturer)) {
|
|
$result = "Name Already Exist";
|
|
return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 200);
|
|
}
|
|
|
|
$data = [
|
|
'manufacturer_name' => $manufacturer_name,
|
|
'quality' => $quality,
|
|
];
|
|
|
|
if (!$manufacturer_id) {
|
|
$data['business_id'] = $this->session->get('logged_user_business_id');
|
|
$inserted = $ManufacturerModel->insert($data);
|
|
if ($inserted) {
|
|
$result = $data;
|
|
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
|
} else {
|
|
$result = "Duplicate Match!";
|
|
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
|
}
|
|
} else {
|
|
$updated = $ManufacturerModel->update($manufacturer_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 create_manufacture_product_form()
|
|
{
|
|
try {
|
|
$manufacturer_name = $this->request->getPost('manufacturername');
|
|
$quality = $this->request->getPost('quality');
|
|
$ManufacturerModel = new ManufacturerModel();
|
|
$data = [
|
|
'manufacturer_name' => $manufacturer_name,
|
|
'quality' => $quality,
|
|
];
|
|
|
|
$data['business_id'] = $this->session->get('logged_user_business_id');
|
|
|
|
$manufacturer_find = $ManufacturerModel->where('manufacturer_name',$manufacturer_name)->first();
|
|
|
|
if (!$manufacturer_find) {
|
|
$inserted = $ManufacturerModel->insert($data);
|
|
if ($inserted) {
|
|
$manufacturer = $ManufacturerModel->where('manufacturer_id',$inserted)->first();
|
|
echo json_encode($manufacturer);
|
|
}
|
|
}else{
|
|
$result = "Duplicate Match!";
|
|
echo json_encode($result);
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
echo json_encode($e);
|
|
}
|
|
}
|
|
|
|
public function status_manufacturer()
|
|
{
|
|
|
|
try {
|
|
$manufacturer_id = $this->request->getPost('manufacturer_id');
|
|
$isactive = $this->request->getPost('isactive');
|
|
|
|
$ManufacturerModel = new ManufacturerModel();
|
|
$data = [
|
|
'isactive' => $isactive
|
|
];
|
|
$updated = $ManufacturerModel->update($manufacturer_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);
|
|
}
|
|
}
|
|
|
|
}
|