1
0
forked from poc/pds
Files
poc-pds1/app/Models/ProductionQuantity.php

60 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ProductionQuantity extends Model
{
use SoftDeletes;
protected $fillable = [
"plant_id",
"shift_id",
"line_id",
"item_id",
"serial_number",
];
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) {
$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)
->first();
if ($productionPlan) {
$productionPlan->update([
'production_quantity' => $productionPlan->production_quantity + 1,
'updated_at' => now(),
]);
}
});
}
}