diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 032fff4f4c04..ab3e1babfbf2 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -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() diff --git a/app/Transformers/InvoiceHistoryTransformer.php b/app/Transformers/InvoiceHistoryTransformer.php new file mode 100644 index 000000000000..891fab4de0eb --- /dev/null +++ b/app/Transformers/InvoiceHistoryTransformer.php @@ -0,0 +1,38 @@ + $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, + ]; + } +} diff --git a/app/Transformers/InvoiceTransformer.php b/app/Transformers/InvoiceTransformer.php index eed103abfe2a..e3c49eb70530 100644 --- a/app/Transformers/InvoiceTransformer.php +++ b/app/Transformers/InvoiceTransformer.php @@ -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);