Initial commit: Horux Backend API
- API REST para gestion de facturas electronicas mexicanas (CFDI) - Laravel 9 con autenticacion OAuth 2.0 (Passport) - Integracion con Syntage, Clerk y Facturama - 30 modelos Eloquent, 39 controladores - Documentacion completa en /docs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
230
app/Models/Invoice.php
Normal file
230
app/Models/Invoice.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Invoice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'api_id',
|
||||
'rfc_id',
|
||||
'version',
|
||||
'invoice_type_id',
|
||||
'usage_id',
|
||||
'payment_type_id',
|
||||
'payment_method_id',
|
||||
'zip_code',
|
||||
'currency_id',
|
||||
'exchange_rate',
|
||||
'status_id',
|
||||
'pac',
|
||||
'issued_at',
|
||||
'certified_at',
|
||||
'cancellation_status_id',
|
||||
'cancellation_type_id',
|
||||
'cancelled_at',
|
||||
'discount',
|
||||
'tax',
|
||||
'subtotal',
|
||||
'total',
|
||||
'paid_amount',
|
||||
'due_amount',
|
||||
'fully_paid_at',
|
||||
'last_payment_date',
|
||||
'issuer_rfc_id',
|
||||
'issuer_name',
|
||||
'receiver_rfc_id',
|
||||
'receiver_name',
|
||||
'is_issuer',
|
||||
'is_receiver',
|
||||
'internal_id',
|
||||
'reference',
|
||||
'credited_amount',
|
||||
'subtotal_credited_amount',
|
||||
'applied_taxes',
|
||||
'total_transferred_taxes',
|
||||
'transferred_local_taxes',
|
||||
'transferred_vat',
|
||||
'transferred_sin_tax',
|
||||
'total_retained_taxes',
|
||||
'retained_local_taxes',
|
||||
'retained_vat',
|
||||
'retained_income_tax',
|
||||
'retained_sin_tax',
|
||||
'is_conciliated',
|
||||
];
|
||||
|
||||
public function invoiceType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(InvoiceType::class);
|
||||
}
|
||||
|
||||
public function rfc(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Rfc::class);
|
||||
}
|
||||
|
||||
public function usage(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Usage::class);
|
||||
}
|
||||
|
||||
public function paymentType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PaymentType::class);
|
||||
}
|
||||
|
||||
public function paymentMethod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PaymentMethod::class);
|
||||
}
|
||||
|
||||
public function currency(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function status(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Status::class);
|
||||
}
|
||||
|
||||
public function cancellationType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CancellationType::class);
|
||||
}
|
||||
|
||||
public function cancellationStatus(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Status::class);
|
||||
}
|
||||
|
||||
public function issuerRfc(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Rfc::class);
|
||||
}
|
||||
|
||||
public function receiverRfc(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Rfc::class);
|
||||
}
|
||||
|
||||
public function invoiceLines(): HasMany
|
||||
{
|
||||
return $this->hasMany(InvoiceLine::class);
|
||||
}
|
||||
|
||||
public function conciliations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Conciliation::class);
|
||||
}
|
||||
|
||||
public function invoicePayments(): HasMany
|
||||
{
|
||||
return $this->hasMany(InvoicePayment::class);
|
||||
}
|
||||
|
||||
public function getRfcAttribute()
|
||||
{
|
||||
return $this->rfc()->first()->rfc;
|
||||
}
|
||||
|
||||
public function getStatusAttribute()
|
||||
{
|
||||
return $this->status()->first()->description;
|
||||
}
|
||||
|
||||
public function getCancellationTypeAttribute()
|
||||
{
|
||||
return $this->cancellationType()->first()->description;
|
||||
}
|
||||
|
||||
public function getCancellationStatusAttribute()
|
||||
{
|
||||
return $this->cancellationStatus()->first()->description;
|
||||
}
|
||||
|
||||
public function getIssuerRfcAttribute()
|
||||
{
|
||||
return $this->issuerRfc()->first()->rfc;
|
||||
}
|
||||
|
||||
public function getReceiverRfcAttribute()
|
||||
{
|
||||
return $this->receiverRfc()->first()->rfc;
|
||||
}
|
||||
|
||||
public function getTotalInMxnAttribute()
|
||||
{
|
||||
if ($this->exchange_rate) {
|
||||
$totalMXN = $this->total * $this->exchange_rate;
|
||||
} else {
|
||||
$totalMXN = $this->total;
|
||||
}
|
||||
return $totalMXN;
|
||||
}
|
||||
|
||||
public function getTaxInMxnAttribute()
|
||||
{
|
||||
if ($this->exchange_rate) {
|
||||
$taxMXN = $this->tax * $this->exchange_rate;
|
||||
} else {
|
||||
$taxMXN = $this->tax;
|
||||
}
|
||||
return $taxMXN;
|
||||
}
|
||||
|
||||
public function getTransferredVatInMxnAttribute()
|
||||
{
|
||||
if ($this->exchange_rate) {
|
||||
$transferredVatMXN = $this->transferred_vat * $this->exchange_rate;
|
||||
} else {
|
||||
$transferredVatMXN = $this->transferred_vat;
|
||||
}
|
||||
return $transferredVatMXN;
|
||||
}
|
||||
|
||||
public function getTransferredSinTaxInMxnAttribute()
|
||||
{
|
||||
if ($this->exchange_rate) {
|
||||
$transferredSinMXN = $this->transferred_sin_tax * $this->exchange_rate;
|
||||
} else {
|
||||
$transferredSinMXN = $this->transferred_sin_tax;
|
||||
}
|
||||
return $transferredSinMXN;
|
||||
}
|
||||
|
||||
public function getRetainedVatInMxnAttribute()
|
||||
{
|
||||
if ($this->exchange_rate) {
|
||||
$retainedVatMXN = $this->retained_vat * $this->exchange_rate;
|
||||
} else {
|
||||
$retainedVatMXN = $this->retained_vat;
|
||||
}
|
||||
return $retainedVatMXN;
|
||||
}
|
||||
|
||||
public function getRetainedIncomeTaxInMxnAttribute()
|
||||
{
|
||||
if ($this->exchange_rate) {
|
||||
$retainedIncomeTaxMXN = $this->retained_income_tax * $this->exchange_rate;
|
||||
} else {
|
||||
$retainedIncomeTaxMXN = $this->retained_income_tax;
|
||||
}
|
||||
return $retainedIncomeTaxMXN;
|
||||
}
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $hidden = ['rfc_id', 'status_id', 'cancellation_type_id', 'cancellation_status_id', 'issuer_rfc_id', 'receiver_rfc_id'];
|
||||
|
||||
protected $appends = ['rfc', 'status', 'cancellation_type', 'cancellation_status', 'issuer_rfc', 'receiver_rfc', 'total_in_mxn',
|
||||
'tax_in_mxn', 'transferred_vat_in_mxn', 'transferred_sin_tax_in_mxn', 'retained_vat_in_mxn', 'retained_income_tax_in_mxn'];
|
||||
}
|
||||
Reference in New Issue
Block a user