52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Dealer extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
protected $fillable = [
|
|
'dealer_code', 'name', 'address', 'pic'
|
|
];
|
|
|
|
/**
|
|
* Get all of the transactions for the Dealer
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function transactions()
|
|
{
|
|
return $this->hasMany(Transaction::class, 'dealer_id', 'id');
|
|
}
|
|
|
|
public function opnames(){
|
|
return $this->hasMany(Opname::class);
|
|
}
|
|
|
|
public function outgoingMutations()
|
|
{
|
|
return $this->hasMany(Mutation::class, 'from_dealer_id');
|
|
}
|
|
|
|
public function incomingMutations()
|
|
{
|
|
return $this->hasMany(Mutation::class, 'to_dealer_id');
|
|
}
|
|
|
|
public function stocks()
|
|
{
|
|
return $this->hasMany(Stock::class);
|
|
}
|
|
|
|
public function products()
|
|
{
|
|
return $this->belongsToMany(Product::class, 'stocks', 'dealer_id', 'product_id')
|
|
->withPivot('quantity')
|
|
->withTimestamps();
|
|
}
|
|
}
|