1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Add invoice history as an optional include

This commit is contained in:
David Bomba 2020-06-01 21:49:11 +10:00
parent 06a8ee1215
commit d3666b41f5
3 changed files with 51 additions and 10 deletions

View File

@ -19,6 +19,7 @@ use App\Helpers\Invoice\InvoiceSumInclusive;
use App\Jobs\Client\UpdateClientBalance;
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
use App\Jobs\Invoice\CreateInvoicePdf;
use App\Models\Backup;
use App\Models\CompanyLedger;
use App\Models\Currency;
use App\Models\Filterable;
@ -208,7 +209,7 @@ class Invoice extends BaseModel
public function history()
{
$this->activities->with('backup');
return $this->hasManyThrough(Backup::class, Activity::class);
}
// public function credits()

View 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,
];
}
}

View File

@ -11,10 +11,12 @@
namespace App\Transformers;
use App\Models\Backup;
use App\Models\Document;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Transformers\DocumentTransformer;
use App\Transformers\InvoiceHistoryTransformer;
use App\Transformers\InvoiceInvitationTransformer;
use App\Utils\Traits\MakesHash;
@ -29,6 +31,7 @@ class InvoiceTransformer extends EntityTransformer
protected $availableIncludes = [
'invitations',
'history'
// 'payments',
// 'client',
// 'documents',
@ -40,16 +43,15 @@ class InvoiceTransformer extends EntityTransformer
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)
{
$transformer = new PaymentTransformer($this->account, $this->serializer, $invoice);