| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- class Record extends Model
- {
- use HasFactory;
- protected $fillable = [
- 'member_id',
- 'supplier_id',
- // 'causal_id',
- 'payment_method_id',
- 'date',
- //'month',
- //'year',
- 'type',
- //'amount',
- //'note',
- 'commercial',
- 'corrispettivo_fiscale',
- 'deleted',
- 'financial_movement',
- 'amount',
- 'numero_fattura',
- ];
- public function member()
- {
- return $this->belongsTo(Member::class);
- }
- public function supplier()
- {
- return $this->belongsTo(Supplier::class);
- }
- public function payment_method()
- {
- return $this->belongsTo(PaymentMethod::class);
- }
- public function rows()
- {
- return $this->hasMany(RecordRow::class);
- }
- public function getTotal()
- {
- $vat = 0;
- foreach($this->rows as $r)
- {
- if ($r->vat_id > 0)
- {
- $v = \App\Models\Vat::where('id', $r->vat_id)->first();
- if ($v && $v->value > 0)
- $vat += $r->amount / 100 * $v->value;
- }
- }
- return $this->rows->sum('amount') + $vat;
- }
- }
|