1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Transformers/PaymentTransformer.php

110 lines
3.9 KiB
PHP
Raw Normal View History

2019-03-27 05:50:13 +01: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-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;
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-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 = [
'client',
'invoices',
2020-06-23 00:47:42 +02:00
'paymentables',
'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
{
parent::__construct();
2019-03-28 03:36:36 +01:00
$this->serializer = $serializer;
2019-03-27 05:50:13 +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
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
}
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-06-22 23:56:32 +02:00
return $this->includeCollection($payment->documents, $transformer, Document::class);
}
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),
'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,
'refunded' => (float) $payment->refunded,
'applied' => (float) $payment->applied,
2019-03-27 05:50:13 +01:00
'transaction_reference' => $payment->transaction_reference ?: '',
'date' => $payment->date ?: '',
'is_manual' => (bool) $payment->is_manual,
'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 ?: '',
'private_notes' => (string) $payment->private_notes ?: '',
'number' => (string) $payment->number ?: '',
'custom_value1' => (string) $payment->custom_value1 ?: '',
'custom_value2' => (string) $payment->custom_value2 ?: '',
'custom_value3' => (string) $payment->custom_value3 ?: '',
'custom_value4' => (string) $payment->custom_value4 ?: '',
'client_id' => (string) $this->encodePrimaryKey($payment->client_id),
'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),
'currency_id' => (string) $payment->currency_id ?: '',
2020-03-06 12:21:17 +01:00
'exchange_rate' => (float) $payment->exchange_rate ?: 1,
'exchange_currency_id' => (string) $payment->exchange_currency_id ?: '',
2019-04-20 00:47:10 +02:00
];
2019-03-27 05:50:13 +01:00
}
}