fix filtering dealer and data with base on user login, partial update precheck and postcheck schema and view
This commit is contained in:
138
app/Models/Precheck.php
Normal file
138
app/Models/Precheck.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Precheck extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'transaction_id',
|
||||
'precheck_by',
|
||||
'precheck_at',
|
||||
'police_number',
|
||||
'spk_number',
|
||||
'front_image',
|
||||
'kilometer',
|
||||
'pressure_high',
|
||||
'pressure_low',
|
||||
'cabin_temperature',
|
||||
'cabin_temperature_image',
|
||||
'ac_condition',
|
||||
'ac_image',
|
||||
'blower_condition',
|
||||
'blower_image',
|
||||
'evaporator_condition',
|
||||
'evaporator_image',
|
||||
'compressor_condition',
|
||||
'precheck_notes'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'precheck_at' => 'datetime',
|
||||
'kilometer' => 'decimal:2',
|
||||
'pressure_high' => 'decimal:2',
|
||||
'pressure_low' => 'decimal:2',
|
||||
'cabin_temperature' => 'decimal:2',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the transaction associated with the Precheck
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function transaction()
|
||||
{
|
||||
return $this->belongsTo(Transaction::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user who performed the precheck
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function precheckBy()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'precheck_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the AC condition options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAcConditionOptions()
|
||||
{
|
||||
return ['kotor', 'rusak', 'baik', 'tidak ada'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blower condition options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getBlowerConditionOptions()
|
||||
{
|
||||
return ['kotor', 'rusak', 'baik', 'tidak ada'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the evaporator condition options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getEvaporatorConditionOptions()
|
||||
{
|
||||
return ['kotor', 'berlendir', 'bocor', 'bersih'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the compressor condition options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCompressorConditionOptions()
|
||||
{
|
||||
return ['kotor', 'rusak', 'baik', 'tidak ada'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter by transaction
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $transactionId
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeByTransaction($query, $transactionId)
|
||||
{
|
||||
return $query->where('transaction_id', $transactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter by user who performed precheck
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $userId
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeByUser($query, $userId)
|
||||
{
|
||||
return $query->where('precheck_by', $userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter by date range
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $startDate
|
||||
* @param string $endDate
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeByDateRange($query, $startDate, $endDate)
|
||||
{
|
||||
return $query->whereBetween('precheck_at', [$startDate, $endDate]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user