80 lines
1.8 KiB
PHP
80 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class SurfaceAreaConstant extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'surface_area_constants';
|
|
|
|
protected $fillable = [
|
|
'standard',
|
|
'general_name',
|
|
'element_name_en',
|
|
'element_name_ru',
|
|
'product_standard',
|
|
'dia_inch',
|
|
'dia_mm',
|
|
'surface_area_m2',
|
|
// 'is_active',
|
|
];
|
|
|
|
protected $casts = [
|
|
'dia_mm' => 'decimal:2',
|
|
'surface_area_m2' => 'decimal:6',
|
|
// 'is_active' => 'boolean',
|
|
];
|
|
|
|
/**
|
|
* Get surface area constants by standard
|
|
*/
|
|
public static function byStandard($standard)
|
|
{
|
|
return self::where('standard', $standard)
|
|
// ->where('is_active', true)
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* Get surface area for specific element
|
|
*/
|
|
public static function getSurfaceArea($standard, $elementNameEn, $diaMm)
|
|
{
|
|
return self::where('standard', $standard)
|
|
->where('element_name_en', $elementNameEn)
|
|
->where('dia_mm', $diaMm)
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* Get unique diameters
|
|
*/
|
|
public static function getUniqueDiameters()
|
|
{
|
|
return self::select('dia_inch', 'dia_mm')
|
|
->distinct()
|
|
->orderBy('dia_mm')
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* Get unique element types
|
|
*/
|
|
public static function getUniqueElements($standard = null)
|
|
{
|
|
$query = self::select('element_name_en')
|
|
// ->where('is_active', true)
|
|
->distinct();
|
|
|
|
if ($standard) {
|
|
$query->where('standard', $standard);
|
|
}
|
|
|
|
return $query->pluck('element_name_en');
|
|
}
|
|
}
|