first commit
This commit is contained in:
65
app/Models/PurchaseOrderItem.php
Normal file
65
app/Models/PurchaseOrderItem.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PurchaseOrderItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'purchase_order_id',
|
||||
'product_id',
|
||||
'quantity',
|
||||
'unit_price',
|
||||
'subtotal',
|
||||
'received_quantity',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'quantity' => 'decimal:2',
|
||||
'unit_price' => 'decimal:2',
|
||||
'subtotal' => 'decimal:2',
|
||||
'received_quantity' => 'decimal:2',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'productName',
|
||||
'unit',
|
||||
'productId',
|
||||
'unitPrice',
|
||||
];
|
||||
|
||||
public function getProductIdAttribute(): string
|
||||
{
|
||||
return (string) $this->attributes['product_id'];
|
||||
}
|
||||
|
||||
public function getUnitPriceAttribute(): float
|
||||
{
|
||||
return (float) $this->attributes['unit_price'];
|
||||
}
|
||||
|
||||
public function getProductNameAttribute(): string
|
||||
{
|
||||
return $this->product ? $this->product->name : '';
|
||||
}
|
||||
|
||||
public function getUnitAttribute(): string
|
||||
{
|
||||
return $this->product ? $this->product->base_unit : '';
|
||||
}
|
||||
|
||||
public function purchaseOrder(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PurchaseOrder::class);
|
||||
}
|
||||
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user