2019-04-04 17:12:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Common\Components;
|
|
|
|
|
2019-04-12 00:06:55 +02:00
|
|
|
use Common\Document;
|
2019-04-04 17:12:32 +02:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
|
|
|
abstract class Discount extends Row
|
|
|
|
{
|
2019-04-12 00:06:55 +02:00
|
|
|
protected $guarded = [];
|
|
|
|
|
2019-04-12 01:18:09 +02:00
|
|
|
public static function build(Document $document)
|
2019-04-12 00:06:55 +02:00
|
|
|
{
|
|
|
|
$model = parent::build($document, true);
|
|
|
|
|
|
|
|
$model->is_sconto = 1;
|
2019-04-12 01:11:32 +02:00
|
|
|
$model->qta = 1;
|
2019-04-12 00:06:55 +02:00
|
|
|
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
2019-04-04 17:12:32 +02:00
|
|
|
public function getIvaAttribute()
|
|
|
|
{
|
|
|
|
return $this->attributes['iva'];
|
|
|
|
}
|
|
|
|
|
2019-07-11 18:10:38 +02:00
|
|
|
public function isMaggiorazione()
|
|
|
|
{
|
2019-07-12 17:35:14 +02:00
|
|
|
return $this->totale_imponibile < 0;
|
2019-07-11 18:10:38 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 17:12:32 +02:00
|
|
|
/**
|
|
|
|
* Effettua i conti per l'IVA.
|
|
|
|
*/
|
|
|
|
protected function fixIva()
|
|
|
|
{
|
2019-04-05 04:42:02 +02:00
|
|
|
$this->attributes['iva'] = parent::getIvaAttribute();
|
2019-04-04 17:12:32 +02:00
|
|
|
|
|
|
|
$descrizione = $this->aliquota->descrizione;
|
|
|
|
if (!empty($descrizione)) {
|
|
|
|
$this->attributes['desc_iva'] = $descrizione;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->fixIvaIndetraibile();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static function boot($bypass = false)
|
|
|
|
{
|
|
|
|
parent::boot(true);
|
|
|
|
|
2019-05-04 03:28:33 +02:00
|
|
|
$table = parent::getTableName();
|
|
|
|
|
|
|
|
static::addGlobalScope('discounts', function (Builder $builder) use ($table) {
|
|
|
|
$builder->where($table.'.is_sconto', '=', 1);
|
2019-04-04 17:12:32 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|