donation/app/Controllers/Home.php

135 lines
4.5 KiB
PHP

<?php
namespace App\Controllers;
use App\Models\HomeModel;
## Home Controllers only for Dashboards,Report Modules
class Home extends BaseController
{
public function index()
{
helper('session');
$session_role = get_user_role();
if (!empty($session_role)) {
switch ($session_role) {
case 'admin':
case 'auditor':
$this->dashboard();
break;
case 'accounts':
$this->dashboard_accounts();
break;
case 'volunteer':
$this->dashboard_volunteers();
break;
default:
$data['page_name'] = 'Dashboard';
$this->render_page('dashboard', $data);
}
}
}
//Default Dashboard..
public function dashboard()
{
// echo "hwllo"
helper('session');
$session_role = get_user_role();
$session_bid = get_business_id();
$session_uid = get_logged_user_id();
// echo $session_bid, $session_role; die;
$data['page_name'] = 'Dashboard';
$model = new HomeModel();
$bwhere = ['user_id'=> $session_uid,'business_id'=> $session_bid,'isactive'=> 1];
$branch_id = $model->getbranchid($bwhere);
$where = ['donor.business_id' => $session_bid];
if (!empty($session_role)) {
switch ($session_role) {
case 'auditor':
$where['donor.created_by'] = $session_uid;
break;
case 'accounts':
if ($branch_id) {
$where['users.branch_id'] = $branch_id;
}
break;
case 'volunteer':
if ($branch_id) {
$where['users.branch_id'] = $branch_id;
}
$where['donor.created_by'] = $session_uid;
break;
}
}
$data['donordetails'] = $model->donordetails($where);
$data['donordetails']['label'] = "donors";
$this->render_page('dashboard', $data);
}
public function dashboard_accounts()
{
helper('session');
$session_bid = get_business_id();
$model = new HomeModel();
$where = ['users.business_id' => $session_bid];
$data = $model->dashboard_account($where);
$data['page_name'] = 'Dashboard';
// $this->render_page('dashboard', $data);
$this->render_page('dashboard_accounts', $data);
}
public function dashboard_volunteers()
{
helper('session');
$session_bid = get_business_id();
$session_uid = get_logged_user_id();
$model = new HomeModel();
$bwhere = ['user_id'=> $session_uid,'users.business_id'=> $session_bid,'users.isactive'=> 1];
$branch_id = $model->getbranchid($bwhere);
$data = $model->dashboard_volunteer($bwhere);
$data['page_name'] = 'Dashboard';
$this->render_page('dashboard', $data);
}
## Dynamic Validation For Existing Check AJAX Call
# USED in 1) User Module
# 2) Recepit-DonorQuickAdd Module
# 3) Contributor(or)Donor Module
# 4) Buiness(Or)Organsation Module
## PLEASE mention here wherever you used this.
public function check_existing()
{
$value = $this->request->getPost('value');
$table = $this->request->getPost('module');
$field = $this->request->getPost('field');
$model = new HomeModel();
$model->setTable((string)$table);
$where = [$field => $value];
$check_existing = $model->where($where)->findAll();
$statement_string = ucfirst(str_replace('_', ' ', (string)$field));
$data = ['status' => false, 'message' => ''];
if (!empty($check_existing)) {
$data['status'] = true;
$data['message'] = $statement_string." Already existing";
}
return $this->response->setJSON(['data' => $data]);
}
}