2019-04-02 07:16:39 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. 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
|
|
|
|
2020-06-01 13:49:11 +02:00
|
|
|
use App\Models\Backup;
|
2020-07-02 12:14:19 +02:00
|
|
|
use App\Models\Client;
|
2020-04-10 07:07:36 +02:00
|
|
|
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-08-26 10:25:05 +02:00
|
|
|
|
2019-04-02 07:16:39 +02:00
|
|
|
protected $defaultIncludes = [
|
2020-04-10 07:07:36 +02:00
|
|
|
'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);
|
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-06-01 13:49:11 +02:00
|
|
|
public function includeHistory(Invoice $invoice)
|
|
|
|
{
|
|
|
|
$transformer = new InvoiceHistoryTransformer($this->serializer);
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-06-01 13:49:11 +02:00
|
|
|
return $this->includeCollection($invoice->history, $transformer, Backup::class);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
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);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-06-01 13:49:11 +02:00
|
|
|
/*
|
2019-12-30 22:59:12 +01:00
|
|
|
public function includePayments(Invoice $invoice)
|
|
|
|
{
|
|
|
|
$transformer = new PaymentTransformer($this->account, $this->serializer, $invoice);
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->includeCollection($invoice->payments, $transformer, ENTITY_PAYMENT);
|
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
public function includeExpenses(Invoice $invoice)
|
|
|
|
{
|
|
|
|
$transformer = new ExpenseTransformer($this->account, $this->serializer);
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->includeCollection($invoice->expenses, $transformer, ENTITY_EXPENSE);
|
|
|
|
}
|
2020-04-10 07:07:36 +02:00
|
|
|
*/
|
|
|
|
public function includeDocuments(Invoice $invoice)
|
|
|
|
{
|
|
|
|
$transformer = new DocumentTransformer($this->serializer);
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-04-10 07:07:36 +02:00
|
|
|
return $this->includeCollection($invoice->documents, $transformer, Document::class);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
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),
|
2019-11-06 23:57:09 +01:00
|
|
|
'user_id' => $this->encodePrimaryKey($invoice->user_id),
|
2020-10-14 22:58:20 +02:00
|
|
|
'project_id' => $this->encodePrimaryKey($invoice->project_id),
|
2019-11-06 23:57:09 +01:00
|
|
|
'assigned_user_id' => $this->encodePrimaryKey($invoice->assigned_user_id),
|
2019-10-27 22:36:09 +01:00
|
|
|
'amount' => (float) $invoice->amount,
|
|
|
|
'balance' => (float) $invoice->balance,
|
2019-10-11 00:11:36 +02:00
|
|
|
'client_id' => (string) $this->encodePrimaryKey($invoice->client_id),
|
2020-02-24 11:15:30 +01:00
|
|
|
'vendor_id' => (string) $this->encodePrimaryKey($invoice->vendor_id),
|
2019-09-12 03:28:41 +02:00
|
|
|
'status_id' => (string) ($invoice->status_id ?: 1),
|
2020-03-07 23:15:11 +01:00
|
|
|
'design_id' => (string) $this->encodePrimaryKey($invoice->design_id),
|
2020-10-12 11:38:55 +02:00
|
|
|
'recurring_id' => (string) $this->encodePrimaryKey($invoice->recurring_id),
|
2020-09-06 11:38:10 +02:00
|
|
|
'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,
|
2019-11-27 11:27:24 +01:00
|
|
|
'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 ?: '',
|
2019-11-27 11:27:24 +01:00
|
|
|
'date' => $invoice->date ?: '',
|
2019-12-22 11:28:41 +01:00
|
|
|
'last_sent_date' => $invoice->last_sent_date ?: '',
|
2019-12-16 12:34:38 +01:00
|
|
|
'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 ?: '',
|
2019-11-10 22:12:21 +01:00
|
|
|
'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,
|
2019-10-05 04:28:23 +02:00
|
|
|
'tax_name3' => $invoice->tax_name3 ? $invoice->tax_name3 : '',
|
|
|
|
'tax_rate3' => (float) $invoice->tax_rate3,
|
2019-12-04 02:06:14 +01:00
|
|
|
'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
|
2020-09-06 11:38:10 +02: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,
|
|
|
|
'exchange_rate' => (float) $invoice->exchange_rate,
|
2020-03-06 06:08:44 +01:00
|
|
|
'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,
|
2020-09-06 11:38:10 +02:00
|
|
|
'line_items' => $invoice->line_items ?: (array) [],
|
2020-03-02 11:22:37 +01:00
|
|
|
'entity_type' => 'invoice',
|
2020-09-08 23:33:21 +02:00
|
|
|
'reminder1_sent' => $invoice->reminder1_sent ?: '',
|
|
|
|
'reminder2_sent' => $invoice->reminder2_sent ?: '',
|
|
|
|
'reminder3_sent' => $invoice->reminder3_sent ?: '',
|
|
|
|
'reminder_last_sent' => $invoice->reminder_last_sent ?: '',
|
2019-04-02 07:16:39 +02:00
|
|
|
];
|
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|