1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00
invoiceninja/app/Models/Product.php
2019-01-30 22:25:37 +11:00

95 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',
'tax_name1',
'tax_rate1',
'tax_name2',
'tax_rate2',
'custom_value1',
'custom_value2',
];
/**
* @return array
*/
public static function getImportColumns()
{
return [
'product_key',
'notes',
'cost',
'custom_value1',
'custom_value2',
];
}
/**
* @return array
*/
public static function getImportMap()
{
return [
'product|item' => 'product_key',
'notes|description|details' => 'notes',
'cost|amount|price' => 'cost',
'custom_value1' => 'custom_value1',
'custom_value2' => 'custom_value2',
];
}
/**
* @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();
}
}