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


<?php

namespace App\Builders;

use Illuminate\Database\Eloquent\Builder;

class LoanBuilder extends Builder
{

    public function loan_total_paid($date = null) : self
    {
        return $this->withSum(['transactions' => function ($query) use ($date) {
            return $query->whereIn('transaction_type', ['repayment', 'pay_off'])
                ->when(!empty($date), function ($query) use ($date) {
                    $query->where('due_date', '<=', $date);
                })
                ->where('reversed', 0);
        }], 'credit');
    }

    public function loan_total_penalty($date = null): self
    {
        if (!empty($date)) {
            return $this->withSum(['schedules as schedules_sum_penalty_by_date' => function ($query) use ($date) {
                $query->where('due_date', '<=', $date);
            }], 'penalty');
        }
        return $this->withSum('schedules', 'penalty');
    }

    public function loan_total_fees($date = null): self
    {
        if (!empty($date)) {
            return $this->withSum(['schedules as schedules_sum_fees_by_date' => function ($query) use ($date) {
                $query->where('due_date', '<=', $date);
            }], 'fees');
        }

        return $this->withSum(['schedules'], 'fees');

    }

    public function loan_total_interest($date = null): self
    {
        if (!empty($date)) {
            return $this->withSum(['schedules as schedules_sum_interest_by_date' => function ($query) use ($date) {
                $query->where('due_date', '<=', $date);
            }], 'interest');
        }
        return $this->withSum('schedules', 'interest');
    }

    public function loan_total_principal($date = null) :self
    {
        if (!empty($date)) {
            return $this->withSum(['schedules as schedules_sum_principal_by_date' => function ($query) use ($date) {
                $query->where('due_date', '<=', $date);
            }], 'principal');
        }
        return $this->withSum('schedules', 'principal');
    }

    public function loan_total_interest_waived($date = null):self
    {
        if (!empty($date)) {
            return $this->withSum(['schedules as schedules_sum_interest_waived_by_date' => function ($query) use ($date) {
                $query->where('due_date', '<=', $date);
            }], 'interest_waived');
        }
        return $this->withSum('schedules', 'interest_waived');
    }

    public function loan_total_pay_off($date = null) :self
    {
        if (!empty($date)) {
            return $this->withSum(['schedules as schedules_sum_pay_off_by_date' => function ($query) use ($date) {
                $query->where('due_date', '<=', $date);
            }], 'pay_off');
        }
        return $this->withSum('schedules', 'pay_off');
    }

    public function transactions_sum_payment($start_date = null, $end_date = null): self
    {
        return $this->withSum(['transactions as transactions_sum_payment' => function ($query) use ($start_date, $end_date) {
            return $query->whereIn('transaction_type', ['repayment', 'pay_off'])
                ->where('reversed', 0)
                ->when(!empty($start_date) && !empty($end_date), function ($query) use ($start_date, $end_date) {
                    return $query->whereBetween('date', [$start_date, $end_date]);
                });
        }], 'credit');
    }

    public function transactions_sum_waived($start_date = null, $end_date = null): self
    {
        return $this->withSum(['transactions as transactions_sum_waived' => function ($query) use ($start_date, $end_date) {
            return $query->where('transaction_type', 'waiver')
                ->where('reversed', 0)
                ->when(!empty($start_date) && !empty($end_date), function ($query) use ($start_date, $end_date) {
                    return $query->whereBetween('date', [$start_date, $end_date]);
                });
        }], 'credit');
    }

    public function sum_principal($start_date = null, $end_date = null): self
    {
        return $this->withSum(['schedules' => function($query) use( $start_date,$end_date){
            return $query->when(!empty($start_date) && !empty($end_date),function($query) use($start_date,$end_date){
                return $query->whereBetween('due_date',[$start_date, $end_date]);
            }); 
        }], 'principal');
    }

    public function sum_interest($start_date = null, $end_date = null): self
    {
        return $this->withSum(['schedules' => function ($query) use ($start_date, $end_date) {
            return $query->when(!empty($start_date) && !empty($end_date), function ($query) use ($start_date, $end_date) {
                return $query->whereBetween('due_date', [$start_date, $end_date]);
            });
        }], 'interest');
    }

    public function sum_fees($start_date = null, $end_date = null): self
    {
        return $this->withSum(['schedules' => function ($query) use ($start_date, $end_date) {
            return $query->when(!empty($start_date) && !empty($end_date), function ($query) use ($start_date, $end_date) {
                return $query->whereBetween('due_date', [$start_date, $end_date]);
            });
        }], 'fees');
    }

    public function sum_penalty($start_date = null, $end_date = null): self
    {
        return $this->withSum(['schedules' => function ($query) use ($start_date, $end_date) {
            return $query->when(!empty($start_date) && !empty($end_date), function ($query) use ($start_date, $end_date) {
                return $query->whereBetween('due_date', [$start_date, $end_date]);
            });
        }], 'penalty');
    }

}

© KUJUNTI.ID