134 lines
3.6 KiB
PHP
134 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Models\BranchModel;
|
|
// use App\Models\RoleModel;
|
|
use App\Models\BusinessModel;
|
|
use App\Models\StaffModel;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
|
class BranchController extends BaseController
|
|
{
|
|
|
|
public $session;
|
|
protected $BranchModel;
|
|
protected $StaffModel;
|
|
|
|
use ResponseTrait;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->session = session();
|
|
$this->BranchModel = new BranchModel();
|
|
$this->StaffModel = new StaffModel();
|
|
|
|
}
|
|
|
|
public function branch_index()
|
|
{
|
|
$BranchModel = new BranchModel();
|
|
$BusinessModel = new BusinessModel();
|
|
$data['branch'] = $BranchModel->select('branches.*, business.business_name')
|
|
->join('business', 'branches.business_id = business.business_id', 'left')
|
|
->findAll();
|
|
$data['business_list'] = $BusinessModel->findAll();
|
|
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
|
|
|
|
echo view('layout/header', ['Data'=>$staffdata]);
|
|
echo view('branch_list',$data);
|
|
echo view('layout/footer');
|
|
}
|
|
|
|
|
|
public function new_business($business_id)
|
|
{
|
|
|
|
|
|
if ($business_id === '0') {
|
|
|
|
$data['business'] = [];
|
|
$data['page_name']="Add Business";
|
|
} else if ($business_id !== '0') {
|
|
|
|
$BusinessModel = new BusinessModel();
|
|
$business=$BusinessModel->getBusinessById($business_id);
|
|
$data['business']=$business;
|
|
$data['page_name']="Edit Business" ;
|
|
}
|
|
$data['business_id'] = $business_id;
|
|
|
|
return view('business_form',$data);
|
|
}
|
|
public function new_branch()
|
|
{
|
|
$data = $this->request->getPost();
|
|
$BranchModel = new BranchModel();
|
|
|
|
$BranchModel->insert($data);
|
|
|
|
return json_encode(true);
|
|
|
|
}
|
|
|
|
|
|
public function get_branch($branch_id)
|
|
{
|
|
if ($branch_id) {
|
|
$BranchModel = new BranchModel();
|
|
$branch =$BranchModel->where('branch_id',$branch_id)->first();
|
|
|
|
return json_encode($branch);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function edit_branch($branch_id)
|
|
{
|
|
if ($branch_id) {
|
|
$data = $this->request->getPost();
|
|
$BranchModel = new BranchModel();
|
|
|
|
$BranchModel->update($branch_id,$data);
|
|
return json_encode(true);
|
|
}
|
|
}
|
|
|
|
public function branch_edit()
|
|
{
|
|
$branch_id = $this->request->getPost('branch_id');
|
|
if ($branch_id) {
|
|
$data = $this->request->getPost();
|
|
$BranchModel = new BranchModel();
|
|
|
|
$BranchModel->update($branch_id,$data);
|
|
return json_encode(true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function status_branch()
|
|
{
|
|
try {
|
|
$branch_id = $this->request->getPost('branch_id');
|
|
$isactive = $this->request->getPost('isactive');
|
|
$data = ['isactive' => $isactive];
|
|
|
|
$updated = $this->BranchModel->update($branch_id, $data);
|
|
if ($updated) {
|
|
return $this->respond(['status' => 'success','code' => 200,'data' => true],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);
|
|
}
|
|
}
|
|
|
|
} |