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