File "ReportPaymentsCollection.php"

Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Models/ReportPaymentsCollection.php
File size: 1.59 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ReportPaymentsCollection extends Model
{
    use HasFactory;
    protected $table = 'report_payment_collection';

    public const REPORTS_MODE = [
        'previous_month' => 'previousMonth',
        'current_month' => 'currentMonth',
        'previous_year' => 'previousYear',
        'current_year' => 'currentYear',
        'monthly' => 'monthly',
    ];

    public function scopePreviousMonth($query)
    {
        $start_date = now()->startOfMonth()->subMonth();
        $end_date = now()->endOfMonth()->subMonth();
        $query->whereBetween('date', [$start_date, $end_date]);
    }

    public function scopeCurrentMonth($query)
    {
        $start_date = now()->startOfMonth();
        $end_date = now()->endOfMonth();
        $query->whereBetween('date', [$start_date, $end_date]);
    }

    public function scopePreviousYear($query)
    {
        $start_date = now()->startOfYear()->subYear();
        $end_date = now()->endOfYear()->subYear();
        $query->whereBetween('date', [$start_date, $end_date]);
    }

    public function scopeCurrentYear($query)
    {
        $start_date = now()->startOfYear();
        $end_date = now()->endOfYear();
        $query->whereBetween('date', [$start_date, $end_date]);
    }

    public function scopeMonthly($query, $date)
    {
        $start_date = Carbon::make($date)->startOfMonth();
        $end_date = Carbon::make($date)->endOfMonth();
        $query->whereBetween('date', [$start_date, $end_date]);
    }
}