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

166 lines
6.9 KiB
PHP
Raw Normal View History

2019-05-03 00:29:04 +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
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
2019-05-03 00:29:04 +02:00
namespace App\Transformers;
2021-05-06 23:41:37 +02:00
use App\Models\Activity;
use App\Models\Backup;
2020-09-17 23:49:22 +02:00
use App\Models\Document;
2019-05-03 00:29:04 +02:00
use App\Models\Invoice;
2019-05-03 00:33:32 +02:00
use App\Models\RecurringInvoice;
2020-09-17 23:49:22 +02:00
use App\Models\RecurringInvoiceInvitation;
2021-05-06 23:41:37 +02:00
use App\Transformers\ActivityTransformer;
use App\Transformers\InvoiceHistoryTransformer;
2019-05-03 00:29:04 +02:00
use App\Utils\Traits\MakesHash;
class RecurringInvoiceTransformer extends EntityTransformer
{
use MakesHash;
2019-05-03 00:29:04 +02:00
protected $defaultIncludes = [
2020-09-17 23:49:22 +02:00
'invitations',
'documents',
2019-05-03 00:29:04 +02:00
];
protected $availableIncludes = [
2020-09-17 23:49:22 +02:00
'invitations',
'documents',
2021-05-06 23:41:37 +02:00
'activities',
'history',
2019-05-03 00:29:04 +02:00
// 'client',
];
/*
public function includeInvoiceItems(Invoice $invoice)
{
$transformer = new InvoiceItemTransformer($this->serializer);
return $this->includeCollection($invoice->invoice_items, $transformer, ENTITY_INVOICE_ITEM);
}
public function includeInvitations(Invoice $invoice)
{
$transformer = new InvitationTransformer($this->account, $this->serializer);
return $this->includeCollection($invoice->invitations, $transformer, ENTITY_INVITATION);
}
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);
}
2020-09-17 23:49:22 +02:00
*/
public function includeHistory(RecurringInvoice $invoice)
{
$transformer = new InvoiceHistoryTransformer($this->serializer);
return $this->includeCollection($invoice->history, $transformer, Backup::class);
}
2021-05-06 23:41:37 +02:00
public function includeActivities(RecurringInvoice $invoice)
{
$transformer = new ActivityTransformer($this->serializer);
return $this->includeCollection($invoice->activities, $transformer, Activity::class);
}
2020-09-17 23:49:22 +02:00
public function includeInvitations(RecurringInvoice $invoice)
{
$transformer = new RecurringInvoiceInvitationTransformer($this->serializer);
2020-09-17 23:49:22 +02:00
return $this->includeCollection($invoice->invitations, $transformer, RecurringInvoiceInvitation::class);
}
2020-09-17 23:49:22 +02:00
public function includeDocuments(RecurringInvoice $invoice)
{
$transformer = new DocumentTransformer($this->serializer);
2020-09-17 23:49:22 +02:00
return $this->includeCollection($invoice->documents, $transformer, Document::class);
}
2019-05-03 00:29:04 +02:00
public function transform(RecurringInvoice $invoice)
{
return [
'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),
2020-09-14 00:21:59 +02:00
'amount' => (float) $invoice->amount,
'balance' => (float) $invoice->balance,
2020-09-15 08:44:58 +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),
'created_at' => (int) $invoice->created_at,
'updated_at' => (int) $invoice->updated_at,
'archived_at' => (int) $invoice->deleted_at,
'is_deleted' => (bool) $invoice->is_deleted,
'number' => $invoice->number ?: '',
2020-09-14 00:21:59 +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->next_send_date ?: '',
2019-05-03 00:29:04 +02:00
'due_date' => $invoice->due_date ?: '',
'terms' => $invoice->terms ?: '',
'public_notes' => $invoice->public_notes ?: '',
'private_notes' => $invoice->private_notes ?: '',
'uses_inclusive_taxes' => (bool) $invoice->uses_inclusive_taxes,
2019-05-03 00:29:04 +02:00
'tax_name1' => $invoice->tax_name1 ? $invoice->tax_name1 : '',
2020-09-14 00:21:59 +02:00
'tax_rate1' => (float) $invoice->tax_rate1,
2019-05-03 00:29:04 +02:00
'tax_name2' => $invoice->tax_name2 ? $invoice->tax_name2 : '',
2020-09-14 00:21:59 +02:00
'tax_rate2' => (float) $invoice->tax_rate2,
'tax_name3' => $invoice->tax_name3 ? $invoice->tax_name3 : '',
2020-09-14 00:21:59 +02:00
'tax_rate3' => (float) $invoice->tax_rate3,
'total_taxes' => (float) $invoice->total_taxes,
2019-05-03 00:29:04 +02:00
'is_amount_discount' => (bool) ($invoice->is_amount_discount ?: false),
'footer' => $invoice->footer ?: '',
2019-05-03 00:29:04 +02:00
'partial' => (float) ($invoice->partial ?: 0.0),
'partial_due_date' => $invoice->partial_due_date ?: '',
2020-09-10 03:05:42 +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-05-03 00:29:04 +02:00
'has_tasks' => (bool) $invoice->has_tasks,
'has_expenses' => (bool) $invoice->has_expenses,
'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) [],
2020-09-14 13:11:46 +02:00
'entity_type' => 'recurringInvoice',
'frequency_id' => (string) $invoice->frequency_id,
2019-05-03 00:29:04 +02:00
'remaining_cycles' => (int) $invoice->remaining_cycles,
2020-09-13 12:20:11 +02:00
'recurring_dates' => (array) $invoice->recurringDates(),
'auto_bill' => (string) $invoice->auto_bill,
2020-09-16 12:08:51 +02:00
'auto_bill_enabled' => (bool) $invoice->auto_bill_enabled,
2020-09-15 08:44:58 +02:00
'due_date_days' => (string) $invoice->due_date_days ?: '',
'paid_to_date' => (float) $invoice->paid_to_date,
2021-03-29 12:19:30 +02:00
'subscription_id' => (string)$this->encodePrimaryKey($invoice->subscription_id),
2019-05-03 00:29:04 +02:00
];
}
}