1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Transformers/InvoiceTransformer.php

124 lines
4.5 KiB
PHP
Raw Normal View History

2019-04-02 07:16:39 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2019-04-02 07:16:39 +02:00
namespace App\Transformers;
2019-04-17 02:58:23 +02:00
2019-04-02 07:16:39 +02:00
use App\Models\Invoice;
2019-09-23 05:22:24 +02:00
use App\Models\InvoiceInvitation;
use App\Transformers\InvoiceInvitationTransformer;
2019-04-17 02:58:23 +02:00
use App\Utils\Traits\MakesHash;
2019-04-02 07:16:39 +02:00
class InvoiceTransformer extends EntityTransformer
{
2019-04-03 02:09:22 +02:00
use MakesHash;
2019-04-02 07:16:39 +02:00
protected $defaultIncludes = [
// 'invoice_items',
];
protected $availableIncludes = [
2019-09-23 05:22:24 +02:00
'invitations',
2019-04-02 07:16:39 +02:00
// 'payments',
// 'client',
// 'documents',
];
2019-09-23 05:22:24 +02:00
public function includeInvitations(Invoice $invoice)
{
$transformer = new InvoiceInvitationTransformer($this->serializer);
return $this->includeCollection($invoice->invitations, $transformer, InvoiceInvitation::class);
}
2019-04-17 02:58:23 +02:00
/*
2019-04-02 07:16:39 +02:00
public function includeInvoiceItems(Invoice $invoice)
{
2019-04-03 02:09:22 +02:00
$transformer = new InvoiceItemTransformer($this->serializer);
2019-04-02 07:16:39 +02:00
return $this->includeCollection($invoice->invoice_items, $transformer, ENTITY_INVOICE_ITEM);
}
2019-04-17 02:58:23 +02:00
2019-04-02 07:16:39 +02:00
public function includePayments(Invoice $invoice)
{
$transformer = new PaymentTransformer($this->account, $this->serializer, $invoice);
return $this->includeCollection($invoice->payments, $transformer, ENTITY_PAYMENT);
}
public function includeClient(Invoice $invoice)
{
$transformer = new ClientTransformer($this->account, $this->serializer);
return $this->includeItem($invoice->client, $transformer, ENTITY_CLIENT);
}
public function includeExpenses(Invoice $invoice)
{
$transformer = new ExpenseTransformer($this->account, $this->serializer);
return $this->includeCollection($invoice->expenses, $transformer, ENTITY_EXPENSE);
}
public function includeDocuments(Invoice $invoice)
{
$transformer = new DocumentTransformer($this->account, $this->serializer);
$invoice->documents->each(function ($document) use ($invoice) {
$document->setRelation('invoice', $invoice);
});
return $this->includeCollection($invoice->documents, $transformer, ENTITY_DOCUMENT);
}
*/
public function transform(Invoice $invoice)
{
return [
2019-04-03 02:09:22 +02:00
'id' => $this->encodePrimaryKey($invoice->id),
2019-09-27 00:14:02 +02:00
'amount' => (float) $invoice->amount ?: '',
'balance' => (float) $invoice->balance ?: '',
'client_id' => (string) $invoice->client_id,
'status_id' => (string) ($invoice->status_id ?: 1),
2019-04-02 07:16:39 +02:00
'updated_at' => $invoice->updated_at,
'archived_at' => $invoice->deleted_at,
2019-04-23 06:16:41 +02:00
'invoice_number' => $invoice->invoice_number,
2019-09-27 00:14:02 +02:00
'discount' => (float) $invoice->discount ?: '',
'po_number' => $invoice->po_number ?: '',
2019-04-02 07:16:39 +02:00
'invoice_date' => $invoice->invoice_date ?: '',
'due_date' => $invoice->due_date ?: '',
2019-04-23 06:16:41 +02:00
'terms' => $invoice->terms ?: '',
2019-04-02 07:16:39 +02:00
'public_notes' => $invoice->public_notes ?: '',
'private_notes' => $invoice->private_notes ?: '',
'is_deleted' => (bool) $invoice->is_deleted,
2019-09-27 00:14:02 +02:00
'invoice_type_id' => (int) $invoice->invoice_type_id ?: '',
2019-04-02 07:16:39 +02:00
'tax_name1' => $invoice->tax_name1 ? $invoice->tax_name1 : '',
2019-09-27 00:14:02 +02:00
'tax_rate1' => (float) $invoice->tax_rate1 ?: '',
2019-04-02 07:16:39 +02:00
'tax_name2' => $invoice->tax_name2 ? $invoice->tax_name2 : '',
2019-09-27 00:14:02 +02:00
'tax_rate2' => (float) $invoice->tax_rate2 ?: '',
2019-04-02 07:16:39 +02:00
'is_amount_discount' => (bool) ($invoice->is_amount_discount ?: false),
'invoice_footer' => $invoice->invoice_footer ?: '',
'partial' => (float) ($invoice->partial ?: 0.0),
'partial_due_date' => $invoice->partial_due_date ?: '',
2019-09-27 00:14:02 +02:00
'custom_value1' => (string) $invoice->custom_value1 ?: '',
'custom_value2' => (string) $invoice->custom_value2 ?: '',
'custom_value3' => (string) $invoice->custom_value3 ?: '',
'custom_value4' => (string) $invoice->custom_value4 ?: '',
2019-04-23 06:16:41 +02:00
'has_tasks' => (bool) $invoice->has_tasks,
2019-04-02 07:16:39 +02:00
'has_expenses' => (bool) $invoice->has_expenses,
'custom_text_value1' => $invoice->custom_text_value1 ?: '',
'custom_text_value2' => $invoice->custom_text_value2 ?: '',
2019-09-23 05:22:24 +02:00
'line_items' => $invoice->line_items ?: '',
2019-04-02 07:16:39 +02:00
'backup' => $invoice->backup ?: '',
2019-09-27 00:14:02 +02:00
'settings' => $invoice->settings ?: '',
2019-05-16 00:26:21 +02:00
2019-04-02 07:16:39 +02:00
];
}
}