diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 8927442..3b6c054 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -63,15 +63,18 @@ use CodeIgniter\Router\RouteCollection; $routes->post('add_business','BusinessController::add_business'); $routes->get('delete_business/(:any)','BusinessController::delete_business/$1'); $routes->get('get_business/(:any)','BusinessController::get_business/$1'); + $routes->get('business','BusinessController::business'); + $routes->post('business_edit','BusinessController::business_edit'); + $routes->get('branch_index/(:any)','BranchController::branch_index/$1'); $routes->get('new_business/(:any)','BranchController::new_business/$1'); $routes->get('delete_branch/(:any)','BranchController::delete_branch/$1'); $routes->get('get_branch/(:any)','BranchController::get_branch/$1'); $routes->post('edit_branch/(:any)','BranchController::edit_branch/$1'); $routes->post('add_branch/(:any)','BranchController::new_branch/$1'); + $routes->post('branch_edit','BranchController::branch_edit'); - \ No newline at end of file diff --git a/app/Controllers/BranchController.php b/app/Controllers/BranchController.php index a6b9d8d..7a22e00 100644 --- a/app/Controllers/BranchController.php +++ b/app/Controllers/BranchController.php @@ -96,6 +96,21 @@ class BranchController extends BaseController } } + 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 delete_branch($branch_id) { $model = new BranchModel(); diff --git a/app/Controllers/BusinessController.php b/app/Controllers/BusinessController.php index cad16eb..4647061 100644 --- a/app/Controllers/BusinessController.php +++ b/app/Controllers/BusinessController.php @@ -3,6 +3,7 @@ namespace App\Controllers; use App\Models\BusinessModel; +use App\Models\BranchModel; use App\Models\StaffModel; @@ -11,13 +12,15 @@ class BusinessController extends BaseController { public $session; protected $BusinessModel; + protected $BranchModel; protected $StaffModel; - + public function __construct() { $this->session = session(); $this->BusinessModel = new BusinessModel(); + $this->BranchModel = new BranchModel(); $this->StaffModel = new StaffModel(); } @@ -141,4 +144,66 @@ class BusinessController extends BaseController } + + public function business() + { + $branch_id =session()->get("logged_in_staff_branch_id"); + $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); + if ($branch_id) { + // $BusinessModel = new BusinessModel(); + $BranchModel = new BranchModel(); + $data['branch'] =$BranchModel->select('branches.*, business.*') + ->join('business', 'business.business_id = branches.business_id') + ->where('branches.branch_id',$branch_id) + ->first(); + + echo view('layout/header', ['Data'=>$staffdata]); + echo view('business',$data); + echo view('layout/footer'); + } + } + + + public function business_edit() + { + $uploadFilePath = ROOTPATH . 'public/uploads/'; + + $file_name = $this->file_Upload($this->request->getFile('business_logo'), $uploadFilePath); + $data = $this->request->getPost(); + $data['logo'] = $file_name; + + $business_id = $this->request->getPost('business_id'); + + if($business_id){ + $update = $this->BusinessModel->update($business_id, $data); + }else{ + $insert = $this->BusinessModel->insert($data); + } + + return json_encode(true); + + // if($insert){ + // $client_data = $this->clientModel->where(['id' => $insert, 'is_active' => 1])->first(); + // return $this->respond(['status' => true,'code' => 200,'data' => $client_data], 200); + + // }else{ + // return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); + + // } + + } + + + public function file_Upload($fileToUpload, $filepath) + { + if ($fileToUpload !== null && $fileToUpload->isValid() && !$fileToUpload->hasMoved()) { + $fileName = $fileToUpload->getName(); + $fileToUpload->move($filepath, $fileName); + return $fileName; + } else { + return ""; + } + } + + } diff --git a/app/Models/BusinessModel.php b/app/Models/BusinessModel.php index 9f8b865..87ed136 100644 --- a/app/Models/BusinessModel.php +++ b/app/Models/BusinessModel.php @@ -5,7 +5,7 @@ class BusinessModel extends Model { protected $table = 'business'; protected $primaryKey = 'business_id'; - protected $allowedFields = ['business_id','business_unique_id','branch_unique_id','business_name','isactive']; + protected $allowedFields = ['business_id','business_unique_id','branch_unique_id','logo', 'business_name','isactive']; public function getBusinessById($business_id) { return $this->db->table('business')->where('business_id', $business_id)->get()->getRowArray(); diff --git a/app/Views/business.php b/app/Views/business.php new file mode 100644 index 0000000..06afd7f --- /dev/null +++ b/app/Views/business.php @@ -0,0 +1,296 @@ +