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

42 lines
972 B
PHP
Raw Normal View History

<?php
namespace App\Models\Stats;
use Illuminate\Database\Eloquent\Model;
class StatProductionDaily extends Model
{
protected $connection = 'sam_stat';
protected $table = 'stat_production_daily';
protected $casts = [
'stat_date' => 'date',
'production_qty' => 'decimal:2',
'defect_qty' => 'decimal:2',
'defect_rate' => 'decimal:2',
'efficiency_rate' => 'decimal:2',
'wo_created_count' => 'integer',
'wo_completed_count' => 'integer',
];
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);
}
}