2019-05-02 13:07:38 +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
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. 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-02 13:07:38 +02: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-06 04:20:18 +02:00
|
|
|
use App\Models\Client;
|
2020-06-22 12:56:31 +02:00
|
|
|
use App\Models\Document;
|
2023-10-26 04:57:44 +02:00
|
|
|
use App\Models\Quote;
|
2019-12-20 12:23:09 +01:00
|
|
|
use App\Models\QuoteInvitation;
|
2019-05-02 13:07:38 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2022-06-06 13:38:14 +02:00
|
|
|
use League\Fractal\Resource\Item;
|
2019-05-02 13:07:38 +02:00
|
|
|
|
|
|
|
class QuoteTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2019-08-26 10:25:05 +02:00
|
|
|
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $defaultIncludes = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'invitations',
|
|
|
|
'documents',
|
2020-02-24 11:20:39 +01:00
|
|
|
];
|
2019-05-02 13:07:38 +02:00
|
|
|
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $availableIncludes = [
|
2021-05-06 23:41:37 +02:00
|
|
|
'activities',
|
2022-06-06 13:38:14 +02:00
|
|
|
'client',
|
2019-05-02 13:07:38 +02:00
|
|
|
];
|
|
|
|
|
2021-05-06 23:41:37 +02:00
|
|
|
public function includeActivities(Quote $quote)
|
|
|
|
{
|
|
|
|
$transformer = new ActivityTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($quote->activities, $transformer, Activity::class);
|
|
|
|
}
|
|
|
|
|
2020-08-14 00:08:10 +02:00
|
|
|
public function includeHistory(Quote $quote)
|
|
|
|
{
|
|
|
|
$transformer = new InvoiceHistoryTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($quote->history, $transformer, Backup::class);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-20 12:23:09 +01:00
|
|
|
public function includeInvitations(Quote $quote)
|
2019-05-02 13:07:38 +02:00
|
|
|
{
|
2019-12-20 12:23:09 +01:00
|
|
|
$transformer = new QuoteInvitationTransformer($this->serializer);
|
2019-05-02 13:07:38 +02:00
|
|
|
|
2019-12-20 12:23:09 +01:00
|
|
|
return $this->includeCollection($quote->invitations, $transformer, QuoteInvitation::class);
|
2019-05-02 13:07:38 +02:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
/*
|
|
|
|
public function includePayments(quote $quote)
|
|
|
|
{
|
|
|
|
$transformer = new PaymentTransformer($this->account, $this->serializer, $quote);
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->includeCollection($quote->payments, $transformer, ENTITY_PAYMENT);
|
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
public function includeExpenses(quote $quote)
|
|
|
|
{
|
|
|
|
$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($quote->expenses, $transformer, ENTITY_EXPENSE);
|
|
|
|
}
|
|
|
|
*/
|
2020-06-22 12:56:31 +02:00
|
|
|
|
|
|
|
public function includeDocuments(Quote $quote)
|
|
|
|
{
|
|
|
|
$transformer = new DocumentTransformer($this->serializer);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-06-22 12:56:31 +02:00
|
|
|
return $this->includeCollection($quote->documents, $transformer, Document::class);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2022-06-06 13:41:29 +02:00
|
|
|
public function includeClient(Quote $quote): Item
|
2022-06-06 13:38:14 +02:00
|
|
|
{
|
|
|
|
$transformer = new ClientTransformer($this->serializer);
|
|
|
|
|
2022-06-06 13:41:29 +02:00
|
|
|
return $this->includeItem($quote->client, $transformer, Client::class);
|
2022-06-06 13:38:14 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
public function transform(Quote $quote)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->encodePrimaryKey($quote->id),
|
2019-11-06 23:57:09 +01:00
|
|
|
'user_id' => $this->encodePrimaryKey($quote->user_id),
|
|
|
|
'assigned_user_id' => $this->encodePrimaryKey($quote->assigned_user_id),
|
2019-12-20 12:23:09 +01:00
|
|
|
'amount' => (float) $quote->amount,
|
|
|
|
'balance' => (float) $quote->balance,
|
|
|
|
'client_id' => (string) $this->encodePrimaryKey($quote->client_id),
|
2020-09-06 11:38:10 +02:00
|
|
|
'status_id' => (string) $quote->status_id,
|
2020-03-07 23:15:11 +01:00
|
|
|
'design_id' => (string) $this->encodePrimaryKey($quote->design_id),
|
2020-09-06 11:38:10 +02:00
|
|
|
'invoice_id' => (string) $this->encodePrimaryKey($quote->invoice_id),
|
2022-02-08 11:39:59 +01:00
|
|
|
'vendor_id' => (string) $this->encodePrimaryKey($quote->vendor_id),
|
2020-09-06 11:38:10 +02:00
|
|
|
'updated_at' => (int) $quote->updated_at,
|
|
|
|
'archived_at' => (int) $quote->deleted_at,
|
|
|
|
'created_at' => (int) $quote->created_at,
|
2019-12-20 12:23:09 +01:00
|
|
|
'number' => $quote->number ?: '',
|
|
|
|
'discount' => (float) $quote->discount,
|
2019-09-27 00:14:02 +02:00
|
|
|
'po_number' => $quote->po_number ?: '',
|
2019-12-20 12:23:09 +01:00
|
|
|
'date' => $quote->date ?: '',
|
2019-12-22 11:28:41 +01:00
|
|
|
'last_sent_date' => $quote->last_sent_date ?: '',
|
2021-05-25 23:31:17 +02:00
|
|
|
'next_send_date' => $quote->next_send_date ?: '',
|
2020-08-14 00:10:31 +02:00
|
|
|
'reminder1_sent' => $quote->reminder1_sent ?: '',
|
|
|
|
'reminder2_sent' => $quote->reminder2_sent ?: '',
|
|
|
|
'reminder3_sent' => $quote->reminder3_sent ?: '',
|
|
|
|
'reminder_last_sent' => $quote->reminder_last_sent ?: '',
|
2019-12-20 12:23:09 +01:00
|
|
|
'due_date' => $quote->due_date ?: '',
|
2019-05-02 13:07:38 +02:00
|
|
|
'terms' => $quote->terms ?: '',
|
|
|
|
'public_notes' => $quote->public_notes ?: '',
|
|
|
|
'private_notes' => $quote->private_notes ?: '',
|
|
|
|
'is_deleted' => (bool) $quote->is_deleted,
|
2019-12-20 12:23:09 +01:00
|
|
|
'uses_inclusive_taxes' => (bool) $quote->uses_inclusive_taxes,
|
2019-05-02 13:07:38 +02:00
|
|
|
'tax_name1' => $quote->tax_name1 ? $quote->tax_name1 : '',
|
2019-12-20 12:23:09 +01:00
|
|
|
'tax_rate1' => (float) $quote->tax_rate1,
|
2019-05-02 13:07:38 +02:00
|
|
|
'tax_name2' => $quote->tax_name2 ? $quote->tax_name2 : '',
|
2019-12-20 12:23:09 +01:00
|
|
|
'tax_rate2' => (float) $quote->tax_rate2,
|
2019-10-05 04:28:23 +02:00
|
|
|
'tax_name3' => $quote->tax_name3 ? $quote->tax_name3 : '',
|
2019-12-20 12:23:09 +01:00
|
|
|
'tax_rate3' => (float) $quote->tax_rate3,
|
|
|
|
'total_taxes' => (float) $quote->total_taxes,
|
2019-05-02 13:07:38 +02:00
|
|
|
'is_amount_discount' => (bool) ($quote->is_amount_discount ?: false),
|
2019-12-20 12:23:09 +01:00
|
|
|
'footer' => $quote->footer ?: '',
|
2019-05-02 13:07:38 +02:00
|
|
|
'partial' => (float) ($quote->partial ?: 0.0),
|
|
|
|
'partial_due_date' => $quote->partial_due_date ?: '',
|
2019-12-20 12:23:09 +01:00
|
|
|
'custom_value1' => (string) $quote->custom_value1 ?: '',
|
|
|
|
'custom_value2' => (string) $quote->custom_value2 ?: '',
|
|
|
|
'custom_value3' => (string) $quote->custom_value3 ?: '',
|
|
|
|
'custom_value4' => (string) $quote->custom_value4 ?: '',
|
2019-05-02 13:07:38 +02:00
|
|
|
'has_tasks' => (bool) $quote->has_tasks,
|
|
|
|
'has_expenses' => (bool) $quote->has_expenses,
|
2020-09-06 11:38:10 +02:00
|
|
|
'custom_surcharge1' => (float) $quote->custom_surcharge1,
|
|
|
|
'custom_surcharge2' => (float) $quote->custom_surcharge2,
|
|
|
|
'custom_surcharge3' => (float) $quote->custom_surcharge3,
|
|
|
|
'custom_surcharge4' => (float) $quote->custom_surcharge4,
|
2020-12-10 11:48:16 +01:00
|
|
|
'custom_surcharge_tax1' => (bool) $quote->custom_surcharge_tax1,
|
|
|
|
'custom_surcharge_tax2' => (bool) $quote->custom_surcharge_tax2,
|
|
|
|
'custom_surcharge_tax3' => (bool) $quote->custom_surcharge_tax3,
|
|
|
|
'custom_surcharge_tax4' => (bool) $quote->custom_surcharge_tax4,
|
2020-09-06 11:38:10 +02:00
|
|
|
'line_items' => $quote->line_items ?: (array) [],
|
2020-03-02 11:22:37 +01:00
|
|
|
'entity_type' => 'quote',
|
2020-09-06 11:38:10 +02:00
|
|
|
'exchange_rate' => (float) $quote->exchange_rate,
|
2021-01-24 07:44:14 +01:00
|
|
|
'paid_to_date' => (float) $quote->paid_to_date,
|
2020-10-14 22:58:20 +02:00
|
|
|
'project_id' => $this->encodePrimaryKey($quote->project_id),
|
2021-03-10 01:08:58 +01:00
|
|
|
'subscription_id' => $this->encodePrimaryKey($quote->subscription_id),
|
|
|
|
|
2019-05-02 13:07:38 +02:00
|
|
|
];
|
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|