mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 08:27:32 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			94 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			1.6 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',
 | |
|     ];
 | |
| 
 | |
|     /**
 | |
|      * @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');
 | |
|     }
 | |
| }
 |