2020-01-07 01:13:47 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-01-07 01:13:47 +01:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-01-07 01:13:47 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-01-07 01:13:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Transformers;
|
|
|
|
|
2023-10-26 04:57:44 +02:00
|
|
|
use App\Models\Activity;
|
2020-08-14 00:08:10 +02:00
|
|
|
use App\Models\Backup;
|
2023-08-07 10:57:25 +02:00
|
|
|
use App\Models\Client;
|
2020-01-07 01:13:47 +01:00
|
|
|
use App\Models\Credit;
|
2023-10-26 04:57:44 +02:00
|
|
|
use App\Models\CreditInvitation;
|
2020-04-15 02:30:52 +02:00
|
|
|
use App\Models\Document;
|
2020-01-07 01:13:47 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2022-06-17 16:56:35 +02:00
|
|
|
use League\Fractal\Resource\Item;
|
2020-01-07 01:13:47 +01:00
|
|
|
|
|
|
|
class CreditTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $defaultIncludes = [
|
2020-02-24 11:20:39 +01:00
|
|
|
'invitations',
|
2020-06-22 07:52:20 +02:00
|
|
|
'documents',
|
2020-02-24 11:20:39 +01:00
|
|
|
];
|
2020-01-07 01:13:47 +01:00
|
|
|
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $availableIncludes = [
|
2021-05-06 23:41:37 +02:00
|
|
|
'activities',
|
2022-06-17 16:56:35 +02:00
|
|
|
'client',
|
2020-01-07 01:13:47 +01:00
|
|
|
];
|
|
|
|
|
2021-05-06 23:41:37 +02:00
|
|
|
public function includeActivities(Credit $credit)
|
|
|
|
{
|
|
|
|
$transformer = new ActivityTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($credit->activities, $transformer, Activity::class);
|
|
|
|
}
|
|
|
|
|
2020-08-14 00:08:10 +02:00
|
|
|
public function includeHistory(Credit $credit)
|
|
|
|
{
|
|
|
|
$transformer = new InvoiceHistoryTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($credit->history, $transformer, Backup::class);
|
|
|
|
}
|
|
|
|
|
2020-01-07 01:13:47 +01:00
|
|
|
public function includeInvitations(Credit $credit)
|
|
|
|
{
|
|
|
|
$transformer = new CreditInvitationTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($credit->invitations, $transformer, CreditInvitation::class);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2022-06-17 16:56:35 +02:00
|
|
|
public function includeClient(Credit $credit): Item
|
|
|
|
{
|
|
|
|
$transformer = new ClientTransformer($this->serializer);
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2022-06-17 16:56:35 +02:00
|
|
|
return $this->includeItem($credit->client, $transformer, Client::class);
|
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
public function includeDocuments(Credit $credit)
|
|
|
|
{
|
|
|
|
$transformer = new DocumentTransformer($this->serializer);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
return $this->includeCollection($credit->documents, $transformer, Document::class);
|
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2020-01-07 01:13:47 +01:00
|
|
|
public function transform(Credit $credit)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->encodePrimaryKey($credit->id),
|
|
|
|
'user_id' => $this->encodePrimaryKey($credit->user_id),
|
2020-10-14 22:58:20 +02:00
|
|
|
'project_id' => $this->encodePrimaryKey($credit->project_id),
|
2020-01-07 01:13:47 +01:00
|
|
|
'assigned_user_id' => $this->encodePrimaryKey($credit->assigned_user_id),
|
2022-02-08 11:39:59 +01:00
|
|
|
'vendor_id' => (string) $this->encodePrimaryKey($credit->vendor_id),
|
2020-01-07 01:13:47 +01:00
|
|
|
'amount' => (float) $credit->amount,
|
|
|
|
'balance' => (float) $credit->balance,
|
|
|
|
'client_id' => (string) $this->encodePrimaryKey($credit->client_id),
|
|
|
|
'status_id' => (string) ($credit->status_id ?: 1),
|
2020-03-07 23:15:11 +01:00
|
|
|
'design_id' => (string) $this->encodePrimaryKey($credit->design_id),
|
2020-09-06 11:38:10 +02:00
|
|
|
'created_at' => (int) $credit->created_at,
|
|
|
|
'updated_at' => (int) $credit->updated_at,
|
|
|
|
'archived_at' => (int) $credit->deleted_at,
|
2020-04-15 02:30:52 +02:00
|
|
|
'is_deleted' => (bool) $credit->is_deleted,
|
2020-01-07 01:13:47 +01:00
|
|
|
'number' => $credit->number ?: '',
|
|
|
|
'discount' => (float) $credit->discount,
|
|
|
|
'po_number' => $credit->po_number ?: '',
|
|
|
|
'date' => $credit->date ?: '',
|
|
|
|
'last_sent_date' => $credit->last_sent_date ?: '',
|
2021-05-25 23:31:17 +02:00
|
|
|
'next_send_date' => $credit->next_send_date ?: '',
|
2020-08-14 00:10:31 +02:00
|
|
|
'reminder1_sent' => $credit->reminder1_sent ?: '',
|
|
|
|
'reminder2_sent' => $credit->reminder2_sent ?: '',
|
|
|
|
'reminder3_sent' => $credit->reminder3_sent ?: '',
|
|
|
|
'reminder_last_sent' => $credit->reminder_last_sent ?: '',
|
2020-01-07 01:13:47 +01:00
|
|
|
'due_date' => $credit->due_date ?: '',
|
|
|
|
'terms' => $credit->terms ?: '',
|
|
|
|
'public_notes' => $credit->public_notes ?: '',
|
|
|
|
'private_notes' => $credit->private_notes ?: '',
|
|
|
|
'uses_inclusive_taxes' => (bool) $credit->uses_inclusive_taxes,
|
|
|
|
'tax_name1' => $credit->tax_name1 ? $credit->tax_name1 : '',
|
|
|
|
'tax_rate1' => (float) $credit->tax_rate1,
|
|
|
|
'tax_name2' => $credit->tax_name2 ? $credit->tax_name2 : '',
|
|
|
|
'tax_rate2' => (float) $credit->tax_rate2,
|
|
|
|
'tax_name3' => $credit->tax_name3 ? $credit->tax_name3 : '',
|
|
|
|
'tax_rate3' => (float) $credit->tax_rate3,
|
|
|
|
'total_taxes' => (float) $credit->total_taxes,
|
|
|
|
'is_amount_discount' => (bool) ($credit->is_amount_discount ?: false),
|
|
|
|
'footer' => $credit->footer ?: '',
|
|
|
|
'partial' => (float) ($credit->partial ?: 0.0),
|
|
|
|
'partial_due_date' => $credit->partial_due_date ?: '',
|
|
|
|
'custom_value1' => (string) $credit->custom_value1 ?: '',
|
|
|
|
'custom_value2' => (string) $credit->custom_value2 ?: '',
|
|
|
|
'custom_value3' => (string) $credit->custom_value3 ?: '',
|
|
|
|
'custom_value4' => (string) $credit->custom_value4 ?: '',
|
|
|
|
'has_tasks' => (bool) $credit->has_tasks,
|
|
|
|
'has_expenses' => (bool) $credit->has_expenses,
|
2020-09-06 11:38:10 +02:00
|
|
|
'custom_surcharge1' => (float) $credit->custom_surcharge1,
|
|
|
|
'custom_surcharge2' => (float) $credit->custom_surcharge2,
|
|
|
|
'custom_surcharge3' => (float) $credit->custom_surcharge3,
|
|
|
|
'custom_surcharge4' => (float) $credit->custom_surcharge4,
|
2020-04-15 02:30:52 +02:00
|
|
|
'custom_surcharge_tax1' => (bool) $credit->custom_surcharge_tax1,
|
|
|
|
'custom_surcharge_tax2' => (bool) $credit->custom_surcharge_tax2,
|
|
|
|
'custom_surcharge_tax3' => (bool) $credit->custom_surcharge_tax3,
|
|
|
|
'custom_surcharge_tax4' => (bool) $credit->custom_surcharge_tax4,
|
2020-09-06 11:38:10 +02:00
|
|
|
'line_items' => $credit->line_items ?: (array) [],
|
2020-03-02 11:22:37 +01:00
|
|
|
'entity_type' => 'credit',
|
2020-09-06 11:38:10 +02:00
|
|
|
'exchange_rate' => (float) $credit->exchange_rate,
|
2021-01-24 07:44:14 +01:00
|
|
|
'paid_to_date' => (float) $credit->paid_to_date,
|
2021-03-10 01:08:58 +01:00
|
|
|
'subscription_id' => $this->encodePrimaryKey($credit->subscription_id),
|
2024-01-25 11:22:04 +01:00
|
|
|
'invoice_id' => $credit->invoice_id ? $this->encodePrimaryKey($credit->invoice_id) : '',
|
2024-03-07 20:56:44 +01:00
|
|
|
'tax_info' => $credit->tax_data ?: new \stdClass(),
|
2024-05-20 09:00:34 +02:00
|
|
|
'e_invoice' => $credit->e_invoice ?: new \stdClass(),
|
2024-03-07 20:56:44 +01:00
|
|
|
|
2020-01-07 01:13:47 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|