diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php index 4f72650..b3aa6cd 100644 --- a/app/Controllers/Books.php +++ b/app/Controllers/Books.php @@ -99,8 +99,9 @@ class Books extends BaseController } else { // It's an update operation - $isactive = $this->request->getPost('isactive'); - $data['isactive'] = ($isactive == 'on') ? 1 : 0; + // $isactive = $this->request->getPost('isactive'); + // $data['isactive'] = ($isactive == 'on') ? 1 : 0; + $data['isactive'] = 1; $data['updated_by'] = $session_uid; $BooksModel->update($causes_id, $data); diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index ef36556..bf208bc 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -7,6 +7,32 @@ use App\Models\HomeModel; 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'); @@ -33,7 +59,6 @@ class Home extends BaseController $where['users.branch_id'] = $branch_id; } break; - case 'donor': case 'volunteer': if ($branch_id) { $where['users.branch_id'] = $branch_id; @@ -42,7 +67,7 @@ class Home extends BaseController break; } } - + $data['donordetails'] = $model->donordetails($where); $data['donordetails']['label'] = "donors"; @@ -51,6 +76,36 @@ class Home extends BaseController } + 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 diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index b101f95..d494240 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -108,7 +108,7 @@ class Invoice extends BaseController $upt_data = $model->updateData('donations_accepted', $data, $where); } } - session()->setFlashdata('success', 'Data has been added successfully.'); + session()->setFlashdata('success', 'Recepit Updated Successfully.'); return redirect()->route('donations_accepted'); } catch (\Throwable $e) @@ -140,7 +140,8 @@ class Invoice extends BaseController // Get customer names for the dropdown, events details, and books details $data['currency'] = $this->BusinessModel->select('currency')->where($where)->findAll(); - + $data['currency_code'] = $this->BusinessModel->select('currency')->where($where)->first()['currency'] ?? null; + $data['causes'] = $bmodel->select('*')->where('business_id', (int)get_business_id())->where('isactive',1)->get()->getResult(); $data['campaign'] = $model->getData('campaign', $where); $data['invoice_number_formatting'] = $model->getData('business', $where); @@ -165,7 +166,7 @@ class Invoice extends BaseController $cus_where = ['business_id' => (int)get_business_id() , 'isactive' => 1, 'donor_type'=>$data['receipt_type']]; $data['typebaseddonors'] = $model->getData('donor', $cus_where); $data['alldonors'] = $model->getData('donor', ['business_id' => (int)get_business_id() , 'isactive' => 1]); - +// print_r($data);die; $this->render_page('invoice_form', $data); } @@ -201,7 +202,7 @@ class Invoice extends BaseController $this->AuditHistoryModel->save($audit_data); /************************************* */ - if($upt_data){ session()->setFlashdata('success', 'Data has been accepted successfully.');echo true; } + if($upt_data){ session()->setFlashdata('success', 'Recepit has been accepted successfully.');echo true; } else echo false; } @@ -234,7 +235,7 @@ class Invoice extends BaseController ]; $this->AuditHistoryModel->save($audit_data); /************************************* */ - session()->setFlashdata('success', 'Data has been rejected successfully.'); + session()->setFlashdata('success', 'Recepit has been rejected successfully.'); return redirect()->route('receipt_list'); } diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php index 8be1431..2847fa2 100644 --- a/app/Models/HomeModel.php +++ b/app/Models/HomeModel.php @@ -6,8 +6,7 @@ class HomeModel extends Model public function donordetails($where) { - $totalDonors = $this->db->table('donor') - ->where($where)->countAll(); + $totalDonors = $this->db->table('donor')->where($where)->countAllResults(); $activeDonors = $this->db->table('donor')->select('donor.*, users.branch_id,users.business_id as users_business_id') ->join('users', 'users.user_id = donor.created_by AND users.business_id = donor.business_id', 'left') @@ -36,5 +35,87 @@ class HomeModel extends Model $result = $query->select('branch_id')->where($bwhere)->get()->getRow(); return $result ? (int)$result->branch_id : 0; } + public function dashboard_account($where){ + $query = $this->db->table('users') + ->select('users.user_id,receipt.receipt_header,SUM(receipt.amount) AS total_amount') + ->select("CONCAT_WS(' ', users.first_name, users.last_name) AS full_name") + ->join('receipt', 'receipt.created_by = users.user_id', 'left') + ->where('users.isactive', 1) + ->where('receipt.receipt_header', 'Receipt') + ->where($where) + ->like('users.role', 'volunteer') + ->groupby('users.user_id, full_name'); + $result = $query->get()->getResult(); + // echo $this->db->getLastQuery()->getQuery();die; + $total_amount_today = $this->db->table('receipt') + ->select('SUM(amount) AS total_amount_today') + ->join('users', 'receipt.created_by = users.user_id', 'left') + ->where('receipt.receipt_header', 'Receipt') + ->where($where) + ->where('DATE(receipt.created_on) = CURDATE()') + ->get()->getRow(); + $today = ($total_amount_today) ? $total_amount_today->total_amount_today : 0; + + + + $total_amount_current_month = $this->db->table('receipt') + ->select('SUM(amount) AS total_amount_current_month') + ->join('users', 'receipt.created_by = users.user_id', 'left') + ->where('receipt.receipt_header', 'Receipt') + ->where($where) + ->where('YEAR(receipt.created_on)', date('Y')) + ->where('MONTH(receipt.created_on)', date('m')) + ->get()->getRow(); + $month = ($total_amount_current_month) ? $total_amount_current_month->total_amount_current_month : 0; + + $total_amount_current_financial_year = $this->db->table('receipt') + ->select('SUM(amount) AS total_amount_current_financial_year') + ->join('users', 'receipt.created_by = users.user_id', 'left') + ->where('receipt.receipt_header', 'Receipt') + ->where($where) + ->where('receipt.created_on >=', date('Y-04-01')) + ->where('receipt.created_on <', date('Y-04-01', strtotime('+1 year'))) + ->get()->getRow(); + $financial_year = ($total_amount_current_financial_year) ? $total_amount_current_financial_year->total_amount_current_financial_year : 0; + + + $final['volunter'] = $result; + $final['month'] = (int)$month; + $final['today'] = (int)$today; + $final['year'] = (int)$financial_year; + return $final; + } + + public function dashboard_volunteer($where){ + $common_query = $this->db->table('users') + ->select('users.user_id, SUM(receipt.amount) AS total_amount') + ->select("CONCAT_WS(' ', users.first_name, users.last_name) AS full_name") + ->join('receipt', 'receipt.created_by = users.user_id', 'left') + ->where($where) + ->like('users.role', 'volunteer') + ->groupby('users.user_id'); + + $today_collection = clone $common_query; + $today_collection = $today_collection->where('DATE(receipt.created_on)', date('Y-m-d'))->get()->getRow(); + $final['today_collection'] = ($today_collection) ? (int)$today_collection->total_amount : 0; + + $overall_collection = clone $common_query; + $overall_collection = $overall_collection->get()->getRow(); + // echo $this->db->getLastQuery()->getQuery();die; + $final['overall_collection'] = ($overall_collection) ? (int)$overall_collection->total_amount : 0; + + $settlement_today = clone $common_query; + $settlement_today = $settlement_today->where('DATE(receipt.created_on)', date('Y-m-d')) + ->where('receipt.receipt_header', 'Receipt') + ->get()->getRow(); + $final['settlement_today'] = ($settlement_today) ? (int)$settlement_today->total_amount : 0; + + $settlement_overall = clone $common_query; + $settlement_overall = $settlement_overall->where('receipt.receipt_header', 'Receipt')->get()->getRow(); + $final['settlement_overall'] = ($settlement_overall) ? (int)$settlement_overall->total_amount : 0; + + return $final; + } + } diff --git a/app/Views/auth_login.php b/app/Views/auth_login.php index 57c66ea..db6830b 100644 --- a/app/Views/auth_login.php +++ b/app/Views/auth_login.php @@ -21,7 +21,9 @@ " rel="stylesheet" type="text/css" /> - +