Files
sam-manage/app/Models/Stats/StatSalesDaily.php

42 lines
951 B
PHP
Raw Permalink Normal View History

<?php
namespace App\Models\Stats;
use Illuminate\Database\Eloquent\Model;
class StatSalesDaily extends Model
{
protected $connection = 'sam_stat';
protected $table = 'stat_sales_daily';
protected $casts = [
'stat_date' => 'date',
'order_count' => 'integer',
'order_amount' => 'decimal:2',
'sales_count' => 'integer',
'sales_amount' => 'decimal:2',
'shipment_count' => 'integer',
'shipment_amount' => 'decimal:2',
];
public function scopeForTenant($query, ?int $tenantId)
{
if ($tenantId) {
return $query->where('tenant_id', $tenantId);
}
return $query;
}
public function scopeForDateRange($query, string $from, string $to)
{
return $query->whereBetween('stat_date', [$from, $to]);
}
public function scopeForDate($query, string $date)
{
return $query->where('stat_date', $date);
}
}