mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 06:14:36 -04:00
Add invoice history as an optional include
This commit is contained in:
parent
06a8ee1215
commit
d3666b41f5
@ -19,6 +19,7 @@ use App\Helpers\Invoice\InvoiceSumInclusive;
|
|||||||
use App\Jobs\Client\UpdateClientBalance;
|
use App\Jobs\Client\UpdateClientBalance;
|
||||||
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
|
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
|
||||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||||
|
use App\Models\Backup;
|
||||||
use App\Models\CompanyLedger;
|
use App\Models\CompanyLedger;
|
||||||
use App\Models\Currency;
|
use App\Models\Currency;
|
||||||
use App\Models\Filterable;
|
use App\Models\Filterable;
|
||||||
@ -208,7 +209,7 @@ class Invoice extends BaseModel
|
|||||||
|
|
||||||
public function history()
|
public function history()
|
||||||
{
|
{
|
||||||
$this->activities->with('backup');
|
return $this->hasManyThrough(Backup::class, Activity::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function credits()
|
// public function credits()
|
||||||
|
38
app/Transformers/InvoiceHistoryTransformer.php
Normal file
38
app/Transformers/InvoiceHistoryTransformer.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Transformers;
|
||||||
|
|
||||||
|
use App\Models\Backup;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
|
class InvoiceHistoryTransformer extends EntityTransformer
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
protected $defaultIncludes = [
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $availableIncludes = [
|
||||||
|
];
|
||||||
|
|
||||||
|
public function transform(Backup $backup)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->encodePrimaryKey($backup->id),
|
||||||
|
'activity_id' => $this->encodePrimaryKey($backup->activity_id),
|
||||||
|
'json_backup' => (string) $backup->json_backup ?: '',
|
||||||
|
'html_backup' => (string) $backup->html_backup ?: '',
|
||||||
|
'created_at' => (int)$backup->created_at,
|
||||||
|
'updated_at' => (int)$backup->updated_at,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -11,10 +11,12 @@
|
|||||||
|
|
||||||
namespace App\Transformers;
|
namespace App\Transformers;
|
||||||
|
|
||||||
|
use App\Models\Backup;
|
||||||
use App\Models\Document;
|
use App\Models\Document;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\InvoiceInvitation;
|
use App\Models\InvoiceInvitation;
|
||||||
use App\Transformers\DocumentTransformer;
|
use App\Transformers\DocumentTransformer;
|
||||||
|
use App\Transformers\InvoiceHistoryTransformer;
|
||||||
use App\Transformers\InvoiceInvitationTransformer;
|
use App\Transformers\InvoiceInvitationTransformer;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
@ -29,6 +31,7 @@ class InvoiceTransformer extends EntityTransformer
|
|||||||
|
|
||||||
protected $availableIncludes = [
|
protected $availableIncludes = [
|
||||||
'invitations',
|
'invitations',
|
||||||
|
'history'
|
||||||
// 'payments',
|
// 'payments',
|
||||||
// 'client',
|
// 'client',
|
||||||
// 'documents',
|
// 'documents',
|
||||||
@ -40,16 +43,15 @@ class InvoiceTransformer extends EntityTransformer
|
|||||||
|
|
||||||
return $this->includeCollection($invoice->invitations, $transformer, InvoiceInvitation::class);
|
return $this->includeCollection($invoice->invitations, $transformer, InvoiceInvitation::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function includeHistory(Invoice $invoice)
|
||||||
|
{
|
||||||
|
$transformer = new InvoiceHistoryTransformer($this->serializer);
|
||||||
|
|
||||||
|
return $this->includeCollection($invoice->history, $transformer, Backup::class);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public function includeInvoiceItems(Invoice $invoice)
|
|
||||||
{
|
|
||||||
$transformer = new InvoiceItemTransformer($this->serializer);
|
|
||||||
|
|
||||||
return $this->includeCollection($invoice->invoice_items, $transformer, ENTITY_INVOICE_ITEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function includePayments(Invoice $invoice)
|
public function includePayments(Invoice $invoice)
|
||||||
{
|
{
|
||||||
$transformer = new PaymentTransformer($this->account, $this->serializer, $invoice);
|
$transformer = new PaymentTransformer($this->account, $this->serializer, $invoice);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user