1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Transformers/InvoiceTransformer.php

134 lines
5.2 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),
'user_id' => $this->encodePrimaryKey($invoice->user_id),
'assigned_user_id' => $this->encodePrimaryKey($invoice->assigned_user_id),
'amount' => (float) $invoice->amount,
'balance' => (float) $invoice->balance,
2019-10-11 00:11:36 +02:00
'client_id' => (string) $this->encodePrimaryKey($invoice->client_id),
'status_id' => (string) ($invoice->status_id ?: 1),
'design_id' => (string) ($invoice->design_id ?: 1),
2019-04-02 07:16:39 +02:00
'updated_at' => $invoice->updated_at,
'archived_at' => $invoice->deleted_at,
'number' => $invoice->number ?: '',
2019-10-25 04:26:16 +02:00
'discount' => (float) $invoice->discount,
2019-09-27 00:14:02 +02:00
'po_number' => $invoice->po_number ?: '',
'date' => $invoice->date ?: '',
2019-04-02 07:16:39 +02:00
'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,
'uses_inclusive_taxes' => (bool) $invoice->uses_inclusive_taxes,
2019-10-02 10:50:54 +02:00
'invoice_type_id' => (string) $invoice->invoice_type_id ?: '',
2019-04-02 07:16:39 +02:00
'tax_name1' => $invoice->tax_name1 ? $invoice->tax_name1 : '',
2019-10-02 10:50:54 +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-10-02 10:50:54 +02:00
'tax_rate2' => (float) $invoice->tax_rate2,
'tax_name3' => $invoice->tax_name3 ? $invoice->tax_name3 : '',
'tax_rate3' => (float) $invoice->tax_rate3,
'total_taxes' => (float) $invoice->total_taxes,
2019-04-02 07:16:39 +02:00
'is_amount_discount' => (bool) ($invoice->is_amount_discount ?: false),
2019-10-30 07:08:18 +01:00
'footer' => $invoice->footer ?: '',
2019-04-02 07:16:39 +02:00
'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,
2019-10-29 12:12:59 +01:00
'custom_surcharge1' => (float)$invoice->custom_surcharge1,
'custom_surcharge2' => (float)$invoice->custom_surcharge2,
'custom_surcharge3' => (float)$invoice->custom_surcharge3,
'custom_surcharge4' => (float)$invoice->custom_surcharge4,
'custom_surcharge_taxes' => (bool) $invoice->custom_surcharge_taxes,
2019-10-29 12:12:59 +01:00
'line_items' => $invoice->line_items ?: (array)[],
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
];
}
}