1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00
invoiceninja/app/Models/Product.php
2017-02-23 16:33:02 +02:00

96 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Laracasts\Presenter\PresentableTrait;
/**
* Class Product.
*/
class Product extends EntityModel
{
use PresentableTrait;
use SoftDeletes;
/**
* @var array
*/
protected $dates = ['deleted_at'];
/**
* @var string
*/
protected $presenter = 'App\Ninja\Presenters\ProductPresenter';
/**
* @var array
*/
protected $fillable = [
'product_key',
'notes',
'cost',
'qty',
'default_tax_rate_id',
'custom_value1',
'custom_value2',
];
/**
* @return array
*/
public static function getImportColumns()
{
return [
'product_key',
'notes',
'cost',
];
}
/**
* @return array
*/
public static function getImportMap()
{
return [
'product|item' => 'product_key',
'notes|description|details' => 'notes',
'cost|amount|price' => 'cost',
];
}
/**
* @return mixed
*/
public function getEntityType()
{
return ENTITY_PRODUCT;
}
/**
* @param $key
*
* @return mixed
*/
public static function findProductByKey($key)
{
return self::scope()->where('product_key', '=', $key)->first();
}
/**
* @return mixed
*/
public function user()
{
return $this->belongsTo('App\Models\User')->withTrashed();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function default_tax_rate()
{
return $this->belongsTo('App\Models\TaxRate');
}
}