1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Transformers/RecurringQuoteTransformer.php

136 lines
5.7 KiB
PHP
Raw Normal View History

2019-05-05 02:49:01 +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-05 02:49:01 +02:00
namespace App\Transformers;
2021-08-24 04:57:46 +02:00
use App\Models\Activity;
use App\Models\Backup;
use App\Models\Document;
use App\Models\Quote;
2019-05-05 02:49:01 +02:00
use App\Models\RecurringQuote;
2021-08-24 04:57:46 +02:00
use App\Models\RecurringQuoteInvitation;
use App\Transformers\ActivityTransformer;
use App\Transformers\QuoteHistoryTransformer;
2019-05-05 02:49:01 +02:00
use App\Utils\Traits\MakesHash;
class RecurringQuoteTransformer extends EntityTransformer
{
use MakesHash;
2019-05-05 02:49:01 +02:00
protected $defaultIncludes = [
2021-08-24 04:57:46 +02:00
'invitations',
'documents',
2019-05-05 02:49:01 +02:00
];
protected $availableIncludes = [
2021-08-24 04:57:46 +02:00
'invitations',
'documents',
'activities',
// 'history',
2019-05-05 02:49:01 +02:00
// 'client',
];
2021-08-24 04:57:46 +02:00
public function includeHistory(RecurringQuote $quote)
{
$transformer = new QuoteHistoryTransformer($this->serializer);
2019-05-05 02:49:01 +02:00
2021-08-24 04:57:46 +02:00
return $this->includeCollection($quote->history, $transformer, Backup::class);
}
public function includeActivities(RecurringQuote $quote)
{
$transformer = new ActivityTransformer($this->serializer);
2021-08-24 04:57:46 +02:00
return $this->includeCollection($quote->activities, $transformer, Activity::class);
}
2021-08-24 04:57:46 +02:00
public function includeInvitations(RecurringQuote $quote)
{
$transformer = new RecurringQuoteInvitationTransformer($this->serializer);
2021-08-24 04:57:46 +02:00
return $this->includeCollection($quote->invitations, $transformer, RecurringQuoteInvitation::class);
}
2021-08-24 04:57:46 +02:00
public function includeDocuments(RecurringQuote $quote)
{
$transformer = new DocumentTransformer($this->serializer);
2021-08-24 04:57:46 +02:00
return $this->includeCollection($quote->documents, $transformer, Document::class);
}
2019-05-05 02:49:01 +02:00
public function transform(RecurringQuote $quote)
{
return [
'id' => $this->encodePrimaryKey($quote->id),
'user_id' => $this->encodePrimaryKey($quote->user_id),
2021-08-24 04:57:46 +02:00
'project_id' => $this->encodePrimaryKey($quote->project_id),
'assigned_user_id' => $this->encodePrimaryKey($quote->assigned_user_id),
2021-08-24 04:57:46 +02:00
'amount' => (float) $quote->amount,
'balance' => (float) $quote->balance,
'client_id' => (string) $this->encodePrimaryKey($quote->client_id),
'vendor_id' => (string) $this->encodePrimaryKey($quote->vendor_id),
'status_id' => (string) ($quote->status_id ?: 1),
2021-08-24 04:57:46 +02:00
'design_id' => (string) $this->encodePrimaryKey($quote->design_id),
'created_at' => (int) $quote->created_at,
'updated_at' => (int) $quote->updated_at,
'archived_at' => (int) $quote->deleted_at,
2021-08-24 04:57:46 +02:00
'is_deleted' => (bool) $quote->is_deleted,
'number' => $quote->number ?: '',
'discount' => (float) $quote->discount,
2019-09-27 00:14:02 +02:00
'po_number' => $quote->po_number ?: '',
2021-08-24 04:57:46 +02:00
'date' => $quote->date ?: '',
'last_sent_date' => $quote->last_sent_date ?: '',
'next_send_date' => $quote->next_send_date ?: '',
'due_date' => $quote->due_date ?: '',
2019-05-05 02:49:01 +02:00
'terms' => $quote->terms ?: '',
'public_notes' => $quote->public_notes ?: '',
'private_notes' => $quote->private_notes ?: '',
2021-08-24 04:57:46 +02:00
'uses_inclusive_taxes' => (bool) $quote->uses_inclusive_taxes,
2019-05-05 02:49:01 +02:00
'tax_name1' => $quote->tax_name1 ? $quote->tax_name1 : '',
2021-08-24 04:57:46 +02:00
'tax_rate1' => (float) $quote->tax_rate1,
2019-05-05 02:49:01 +02:00
'tax_name2' => $quote->tax_name2 ? $quote->tax_name2 : '',
2021-08-24 04:57:46 +02:00
'tax_rate2' => (float) $quote->tax_rate2,
'tax_name3' => $quote->tax_name3 ? $quote->tax_name3 : '',
2021-08-24 04:57:46 +02:00
'tax_rate3' => (float) $quote->tax_rate3,
'total_taxes' => (float) $quote->total_taxes,
2019-05-05 02:49:01 +02:00
'is_amount_discount' => (bool) ($quote->is_amount_discount ?: false),
2021-08-24 04:57:46 +02:00
'footer' => $quote->footer ?: '',
2019-05-05 02:49:01 +02:00
'partial' => (float) ($quote->partial ?: 0.0),
'partial_due_date' => $quote->partial_due_date ?: '',
2021-08-24 04:57:46 +02: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-05 02:49:01 +02:00
'has_tasks' => (bool) $quote->has_tasks,
'has_expenses' => (bool) $quote->has_expenses,
2021-08-24 04:57:46 +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,
'exchange_rate' => (float) $quote->exchange_rate,
'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,
'line_items' => $quote->line_items ?: (array) [],
'entity_type' => 'recurringQuote',
'frequency_id' => (string) $quote->frequency_id,
2019-05-05 02:49:01 +02:00
'remaining_cycles' => (int) $quote->remaining_cycles,
2021-08-24 04:57:46 +02:00
'recurring_dates' => (array) $quote->recurringDates(),
'auto_bill' => (string) $quote->auto_bill,
'auto_bill_enabled' => (bool) $quote->auto_bill_enabled,
'due_date_days' => (string) $quote->due_date_days ?: '',
'paid_to_date' => (float) $quote->paid_to_date,
'subscription_id' => (string)$this->encodePrimaryKey($quote->subscription_id),
2019-05-05 02:49:01 +02:00
];
}
}