Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
99 lines
2.7 KiB
PHP
99 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Prunable;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class ProductionQuantity extends Model
|
|
{
|
|
use Prunable;
|
|
use SoftDeletes;
|
|
|
|
public static $importing = false; // Add this flag
|
|
|
|
protected $fillable = [
|
|
'plant_id',
|
|
'shift_id',
|
|
'line_id',
|
|
'item_id',
|
|
'serial_number',
|
|
'production_order',
|
|
'operator_id',
|
|
// "success_status",
|
|
// "notok_at",
|
|
// "no_of_employee",
|
|
// "list_of_employee",
|
|
'created_at',
|
|
'updated_at',
|
|
];
|
|
|
|
public function plant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Plant::class);
|
|
}
|
|
|
|
public function shift(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Shift::class);
|
|
}
|
|
|
|
public function line(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Line::class);
|
|
}
|
|
|
|
public function item(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Item::class);
|
|
}
|
|
|
|
protected static function booted()
|
|
{
|
|
static::created(function ($productionQuantity) {
|
|
|
|
if (static::$importing) { // Check flag here
|
|
return;
|
|
}
|
|
|
|
$productionPlan = ProductionPlan::where('plant_id', $productionQuantity->plant_id)
|
|
->where('shift_id', $productionQuantity->shift_id)
|
|
->where('line_id', $productionQuantity->line_id)
|
|
->whereDate('created_at', today())
|
|
// ->where('plan_quantity', $productionQuantity->plan_quantity)
|
|
->latest()
|
|
->first();
|
|
|
|
if (! $productionPlan) {
|
|
$productionPlan = ProductionPlan::where('plant_id', $productionQuantity->plant_id)
|
|
->where('shift_id', $productionQuantity->shift_id)
|
|
->where('line_id', $productionQuantity->line_id)
|
|
->whereDate('created_at', Carbon::yesterday())
|
|
// ->where('plan_quantity', $productionQuantity->plan_quantity)
|
|
->latest()
|
|
->first();
|
|
}
|
|
|
|
$operatorName = Filament::auth()->user()->name;
|
|
|
|
if ($productionPlan) {
|
|
$productionPlan->update([
|
|
'production_quantity' => $productionPlan->production_quantity + 1,
|
|
'updated_at' => now(),
|
|
// 'operator_id'=> $operatorName,
|
|
]);
|
|
}
|
|
});
|
|
}
|
|
|
|
public function prunable(): Builder
|
|
{
|
|
return static::where('created_at', '<=', now()->subMonthsNoOverflow(6));
|
|
}
|
|
}
|