67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Modules\Inventory\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
use App\Modules\Core\Models\User;
|
||
|
|
|
||
|
|
class InventoryTransferOrder extends Model
|
||
|
|
{
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'doc_no',
|
||
|
|
'from_warehouse_id',
|
||
|
|
'to_warehouse_id',
|
||
|
|
'status',
|
||
|
|
'remarks',
|
||
|
|
'posted_at',
|
||
|
|
'created_by',
|
||
|
|
'updated_by',
|
||
|
|
'posted_by',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'posted_at' => 'datetime',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected static function boot()
|
||
|
|
{
|
||
|
|
parent::boot();
|
||
|
|
|
||
|
|
static::creating(function ($model) {
|
||
|
|
if (empty($model->doc_no)) {
|
||
|
|
$model->doc_no = 'TRF-' . date('YmdHis') . '-' . rand(100, 999);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public function fromWarehouse(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Warehouse::class, 'from_warehouse_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toWarehouse(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Warehouse::class, 'to_warehouse_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function items(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(InventoryTransferItem::class, 'transfer_order_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function createdBy(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(User::class, 'created_by');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function postedBy(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(User::class, 'posted_by');
|
||
|
|
}
|
||
|
|
}
|