2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2017-02-26 11:53:06 +01:00
|
|
|
use Cache;
|
2016-01-07 20:39:51 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2015-03-25 20:56:31 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class PaymentTerm.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2016-01-07 20:39:51 +01:00
|
|
|
class PaymentTerm extends EntityModel
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2017-02-26 11:53:06 +01:00
|
|
|
use SoftDeletes;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2016-01-07 20:39:51 +01:00
|
|
|
public $timestamps = true;
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-01-07 20:39:51 +01:00
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-01-07 20:39:51 +01:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
|
|
|
return ENTITY_PAYMENT_TERM;
|
|
|
|
}
|
2017-02-26 11:53:06 +01:00
|
|
|
|
2017-04-18 09:22:46 +02:00
|
|
|
public function getNumDays()
|
|
|
|
{
|
|
|
|
return $this->num_days == -1 ? 0 : $this->num_days;
|
|
|
|
}
|
|
|
|
|
2017-02-26 11:53:06 +01:00
|
|
|
public static function getSelectOptions()
|
|
|
|
{
|
2017-06-13 10:14:32 +02:00
|
|
|
$terms = PaymentTerm::whereAccountId(0)->get();
|
2017-02-26 11:53:06 +01:00
|
|
|
|
|
|
|
foreach (PaymentTerm::scope()->get() as $term) {
|
|
|
|
$terms->push($term);
|
|
|
|
}
|
|
|
|
|
2017-04-18 09:22:46 +02:00
|
|
|
foreach ($terms as $term) {
|
|
|
|
$term->name = trans('texts.payment_terms_net') . ' ' . $term->getNumDays();
|
|
|
|
}
|
|
|
|
|
2017-02-26 11:53:06 +01:00
|
|
|
return $terms->sortBy('num_days');
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|