1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
invoiceninja/app/Transformers/InvoiceTransformer.php

148 lines
6.0 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).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
* @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
use App\Models\Backup;
2020-07-02 12:14:19 +02:00
use App\Models\Client;
use App\Models\Document;
2019-04-02 07:16:39 +02:00
use App\Models\Invoice;
2019-09-23 05:22:24 +02:00
use App\Models\InvoiceInvitation;
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 = [
'invitations',
'documents',
2019-04-02 07:16:39 +02:00
];
protected $availableIncludes = [
2020-07-02 12:14:19 +02:00
// 'invitations',
'history',
2019-04-02 07:16:39 +02:00
// 'payments',
2020-07-02 12:14:19 +02:00
'client',
2019-04-02 07:16:39 +02:00
// '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);
}
public function includeHistory(Invoice $invoice)
{
$transformer = new InvoiceHistoryTransformer($this->serializer);
return $this->includeCollection($invoice->history, $transformer, Backup::class);
}
2020-07-02 12:14:19 +02:00
public function includeClient(Invoice $invoice)
{
$transformer = new ClientTransformer($this->serializer);
return $this->includeItem($invoice->client, $transformer, Client::class);
}
/*
public function includePayments(Invoice $invoice)
{
$transformer = new PaymentTransformer($this->account, $this->serializer, $invoice);
return $this->includeCollection($invoice->payments, $transformer, ENTITY_PAYMENT);
}
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->serializer);
return $this->includeCollection($invoice->documents, $transformer, Document::class);
}
2019-04-02 07:16:39 +02:00
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),
'project_id' => $this->encodePrimaryKey($invoice->project_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),
'vendor_id' => (string) $this->encodePrimaryKey($invoice->vendor_id),
'status_id' => (string) ($invoice->status_id ?: 1),
'design_id' => (string) $this->encodePrimaryKey($invoice->design_id),
2020-10-12 11:38:55 +02:00
'recurring_id' => (string) $this->encodePrimaryKey($invoice->recurring_id),
'created_at' => (int) $invoice->created_at,
'updated_at' => (int) $invoice->updated_at,
'archived_at' => (int) $invoice->deleted_at,
2020-02-27 00:32:44 +01:00
'is_deleted' => (bool) $invoice->is_deleted,
'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 ?: '',
'last_sent_date' => $invoice->last_sent_date ?: '',
'next_send_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 ?: '',
'uses_inclusive_taxes' => (bool) $invoice->uses_inclusive_taxes,
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 ?: '',
2020-11-02 11:12:58 +01:00
'has_tasks' => (bool) false, //@deprecated v5.0.23
'has_expenses' => (bool) false, //@deprecated v5.0.23
'custom_surcharge1' => (float) $invoice->custom_surcharge1,
'custom_surcharge2' => (float) $invoice->custom_surcharge2,
'custom_surcharge3' => (float) $invoice->custom_surcharge3,
'custom_surcharge4' => (float) $invoice->custom_surcharge4,
'exchange_rate' => (float) $invoice->exchange_rate,
'custom_surcharge_tax1' => (bool) $invoice->custom_surcharge_tax1,
'custom_surcharge_tax2' => (bool) $invoice->custom_surcharge_tax2,
'custom_surcharge_tax3' => (bool) $invoice->custom_surcharge_tax3,
'custom_surcharge_tax4' => (bool) $invoice->custom_surcharge_tax4,
'line_items' => $invoice->line_items ?: (array) [],
'entity_type' => 'invoice',
'reminder1_sent' => $invoice->reminder1_sent ?: '',
'reminder2_sent' => $invoice->reminder2_sent ?: '',
'reminder3_sent' => $invoice->reminder3_sent ?: '',
'reminder_last_sent' => $invoice->reminder_last_sent ?: '',
'paid_to_date' => (float) $invoice->paid_to_date,
2019-04-02 07:16:39 +02:00
];
}
}