Issues (50)

src/Models/Invoice.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Squareetlabs\VeriFactu\Models;
6
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\SoftDeletes;
9
use Illuminate\Database\Eloquent\Factories\HasFactory;
10
use Squareetlabs\VeriFactu\Enums\InvoiceType;
11
12
class Invoice extends Model
13
{
14
    use HasFactory;
0 ignored issues
show
The trait Illuminate\Database\Eloquent\Factories\HasFactory requires the property $factoryClass which is not provided by Squareetlabs\VeriFactu\Models\Invoice.
Loading history...
15
    use SoftDeletes;
16
17
    protected static function newFactory()
18
    {
19
        return \Database\Factories\Squareetlabs\VeriFactu\Models\InvoiceFactory::new();
20
    }
21
22
    protected static function booted()
23
    {
24
        static::saving(function ($invoice) {
25
            // Preparar datos para el hash
26
            $hashData = [
27
                'issuer_tax_id' => $invoice->issuer_tax_id,
28
                'invoice_number' => $invoice->number,
29
                'issue_date' => $invoice->date instanceof \Illuminate\Support\Carbon ? $invoice->date->format('Y-m-d') : $invoice->date,
30
                'invoice_type' => $invoice->type instanceof \BackedEnum ? $invoice->type->value : (string)$invoice->type,
0 ignored issues
show
The type BackedEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
                'total_tax' => (string)$invoice->tax,
32
                'total_amount' => (string)$invoice->total,
33
                'previous_hash' => $invoice->previous_hash ?? '', // Si implementas encadenamiento
34
                'generated_at' => now()->format('c'),
35
            ];
36
            $hashResult = \Squareetlabs\VeriFactu\Helpers\HashHelper::generateInvoiceHash($hashData);
37
            $invoice->hash = $hashResult['hash'];
38
        });
39
    }
40
41
    protected $table = 'invoices';
42
43
    protected $fillable = [
44
        'uuid',
45
        'number',
46
        'date',
47
        'customer_name',
48
        'customer_tax_id',
49
        'customer_country',
50
        'issuer_name',
51
        'issuer_tax_id',
52
        'issuer_country',
53
        'amount',
54
        'tax',
55
        'total',
56
        'type',
57
        'external_reference',
58
        'description',
59
        'status',
60
        'issued_at',
61
        'cancelled_at',
62
        'hash',
63
    ];
64
65
    protected $casts = [
66
        'date' => 'date',
67
        'type' => InvoiceType::class,
68
        'amount' => 'decimal:2',
69
        'tax' => 'decimal:2',
70
        'total' => 'decimal:2',
71
    ];
72
73
    public function breakdowns()
74
    {
75
        return $this->hasMany(Breakdown::class);
76
    }
77
78
    public function recipients()
79
    {
80
        return $this->hasMany(Recipient::class);
81
    }
82
}