File "ReportSalesTax.php"
Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Models/ReportSalesTax.php
File size: 1.55 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ReportSalesTax extends Model
{
use HasFactory;
protected $table = 'report_sales_tax';
public const REPORTS_MODE = [
'previous_month' => 'previousMonth',
'current_month' => 'currentMonth',
'previous_year' => 'previousYear',
'current_year' => 'currentYear',
'all' => 'untilToday',
];
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 scopeUntilToday($query)
{
return $query;
}
public function scopeCustomRange($query, $date_range)
{
$query->whereBetween('date', [$date_range['year_from'], $date_range['year_to']]);
}
}