2019-03-27 15:50:13 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2021-01-04 08:54:54 +11:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 13:32:07 +10:00
|
|
|
*/
|
2019-03-27 15:50:13 +11:00
|
|
|
|
2019-03-28 13:36:36 +11:00
|
|
|
namespace App\Transformers;
|
2019-03-27 15:50:13 +11:00
|
|
|
|
|
|
|
|
use App\Models\Client;
|
2020-06-23 07:56:32 +10:00
|
|
|
use App\Models\Document;
|
2019-03-27 15:50:13 +11:00
|
|
|
use App\Models\Invoice;
|
|
|
|
|
use App\Models\Payment;
|
2019-12-16 22:34:38 +11:00
|
|
|
use App\Models\Paymentable;
|
2019-04-03 11:09:22 +11:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-03-27 15:50:13 +11:00
|
|
|
|
|
|
|
|
class PaymentTransformer extends EntityTransformer
|
|
|
|
|
{
|
2019-04-03 11:09:22 +11:00
|
|
|
use MakesHash;
|
2019-08-26 18:25:05 +10:00
|
|
|
|
2019-03-28 13:36:36 +11:00
|
|
|
protected $serializer;
|
|
|
|
|
|
2020-06-24 20:17:42 +10:00
|
|
|
protected $defaultIncludes = [
|
2020-08-15 10:51:26 +10:00
|
|
|
'paymentables',
|
2020-08-06 13:04:09 +10:00
|
|
|
'documents',
|
2020-06-24 20:17:42 +10:00
|
|
|
];
|
2019-03-27 15:50:13 +11:00
|
|
|
|
|
|
|
|
protected $availableIncludes = [
|
2020-02-06 23:00:22 +11:00
|
|
|
'client',
|
|
|
|
|
'invoices',
|
2020-06-23 08:47:42 +10:00
|
|
|
'paymentables',
|
2020-09-06 19:38:10 +10:00
|
|
|
'documents',
|
2019-03-27 15:50:13 +11:00
|
|
|
];
|
|
|
|
|
|
2019-03-28 13:36:36 +11:00
|
|
|
public function __construct($serializer = null)
|
2019-03-27 15:50:13 +11:00
|
|
|
{
|
2020-03-10 12:50:06 +01:00
|
|
|
parent::__construct();
|
|
|
|
|
|
2019-03-28 13:36:36 +11:00
|
|
|
$this->serializer = $serializer;
|
2019-03-27 15:50:13 +11:00
|
|
|
}
|
|
|
|
|
|
2019-11-18 21:46:01 +11:00
|
|
|
public function includeInvoices(Payment $payment)
|
2019-03-27 15:50:13 +11:00
|
|
|
{
|
2019-03-28 13:36:36 +11:00
|
|
|
$transformer = new InvoiceTransformer($this->serializer);
|
2019-03-27 15:50:13 +11:00
|
|
|
|
2019-11-18 21:46:01 +11:00
|
|
|
return $this->includeCollection($payment->invoices, $transformer, Invoice::class);
|
2019-03-27 15:50:13 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function includeClient(Payment $payment)
|
|
|
|
|
{
|
2019-03-28 13:36:36 +11:00
|
|
|
$transformer = new ClientTransformer($this->serializer);
|
2019-03-27 15:50:13 +11:00
|
|
|
|
2019-03-28 13:36:36 +11:00
|
|
|
return $this->includeItem($payment->client, $transformer, Client::class);
|
2019-03-27 15:50:13 +11:00
|
|
|
}
|
2019-12-16 22:34:38 +11:00
|
|
|
|
|
|
|
|
public function includePaymentables(Payment $payment)
|
|
|
|
|
{
|
|
|
|
|
$transformer = new PaymentableTransformer($this->serializer);
|
|
|
|
|
|
|
|
|
|
return $this->includeCollection($payment->paymentables, $transformer, Paymentable::class);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 07:56:32 +10:00
|
|
|
public function includeDocuments(Payment $payment)
|
|
|
|
|
{
|
|
|
|
|
$transformer = new DocumentTransformer($this->serializer);
|
2020-09-06 19:38:10 +10:00
|
|
|
|
2020-06-23 07:56:32 +10:00
|
|
|
return $this->includeCollection($payment->documents, $transformer, Document::class);
|
|
|
|
|
}
|
2019-12-16 22:34:38 +11:00
|
|
|
|
2019-03-27 15:50:13 +11:00
|
|
|
public function transform(Payment $payment)
|
|
|
|
|
{
|
2019-03-28 13:36:36 +11:00
|
|
|
return [
|
2019-04-03 11:09:22 +11:00
|
|
|
'id' => $this->encodePrimaryKey($payment->id),
|
2019-11-07 09:57:09 +11:00
|
|
|
'user_id' => $this->encodePrimaryKey($payment->user_id),
|
|
|
|
|
'assigned_user_id' => $this->encodePrimaryKey($payment->assigned_user_id),
|
2019-03-27 15:50:13 +11:00
|
|
|
'amount' => (float) $payment->amount,
|
2019-12-16 22:34:38 +11:00
|
|
|
'refunded' => (float) $payment->refunded,
|
2019-12-17 21:50:45 +11:00
|
|
|
'applied' => (float) $payment->applied,
|
2019-03-27 15:50:13 +11:00
|
|
|
'transaction_reference' => $payment->transaction_reference ?: '',
|
2019-12-16 22:34:38 +11:00
|
|
|
'date' => $payment->date ?: '',
|
|
|
|
|
'is_manual' => (bool) $payment->is_manual,
|
2020-09-06 19:38:10 +10:00
|
|
|
'created_at' => (int) $payment->created_at,
|
|
|
|
|
'updated_at' => (int) $payment->updated_at,
|
|
|
|
|
'archived_at' => (int) $payment->deleted_at,
|
2019-03-27 15:50:13 +11:00
|
|
|
'is_deleted' => (bool) $payment->is_deleted,
|
2020-06-18 08:55:35 +10:00
|
|
|
'type_id' => (string) $payment->type_id ?: '',
|
2019-10-02 18:50:54 +10:00
|
|
|
'invitation_id' => (string) $payment->invitation_id ?: '',
|
2020-02-20 07:44:12 +11:00
|
|
|
'private_notes' => (string) $payment->private_notes ?: '',
|
2019-12-17 21:50:45 +11:00
|
|
|
'number' => (string) $payment->number ?: '',
|
2020-03-05 18:14:57 +11:00
|
|
|
'custom_value1' => (string) $payment->custom_value1 ?: '',
|
|
|
|
|
'custom_value2' => (string) $payment->custom_value2 ?: '',
|
|
|
|
|
'custom_value3' => (string) $payment->custom_value3 ?: '',
|
|
|
|
|
'custom_value4' => (string) $payment->custom_value4 ?: '',
|
2019-11-18 21:46:01 +11:00
|
|
|
'client_id' => (string) $this->encodePrimaryKey($payment->client_id),
|
2019-12-16 22:34:38 +11:00
|
|
|
'client_contact_id' => (string) $this->encodePrimaryKey($payment->client_contact_id),
|
|
|
|
|
'company_gateway_id' => (string) $this->encodePrimaryKey($payment->company_gateway_id),
|
|
|
|
|
'status_id'=> (string) $payment->status_id,
|
|
|
|
|
'project_id' => (string) $this->encodePrimaryKey($payment->project_id),
|
|
|
|
|
'vendor_id' => (string) $this->encodePrimaryKey($payment->vendor_id),
|
2020-03-06 22:10:59 +11:00
|
|
|
'currency_id' => (string) $payment->currency_id ?: '',
|
2020-03-06 22:21:17 +11:00
|
|
|
'exchange_rate' => (float) $payment->exchange_rate ?: 1,
|
2020-03-06 22:10:59 +11:00
|
|
|
'exchange_currency_id' => (string) $payment->exchange_currency_id ?: '',
|
2019-04-20 08:47:10 +10:00
|
|
|
];
|
2019-03-27 15:50:13 +11:00
|
|
|
}
|
|
|
|
|
}
|