1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Ninja/Transformers/PaymentTransformer.php

76 lines
3.1 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\Transformers;
2015-11-27 13:55:28 +01:00
use App\Models\Account;
use App\Models\Client;
2017-01-30 20:40:43 +01:00
use App\Models\Invoice;
use App\Models\Payment;
2015-11-27 13:55:28 +01:00
/**
* @SWG\Definition(definition="Payment", required={"invoice_id"}, @SWG\Xml(name="Payment"))
*/
class PaymentTransformer extends EntityTransformer
{
/**
2017-01-30 20:40:43 +01:00
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
* @SWG\Property(property="amount", type="number", format="float", example=10, readOnly=true)
2018-08-31 08:49:21 +02:00
* @SWG\Property(property="transaction_reference", type="string", example="Transaction Reference")
* @SWG\Property(property="payment_date", type="string", format="date", example="2018-01-01")
* @SWG\Property(property="updated_at", type="integer", example=1451160233, readOnly=true)
* @SWG\Property(property="archived_at", type="integer", example=1451160233, readOnly=true)
* @SWG\Property(property="is_deleted", type="boolean", example=false, readOnly=true)
* @SWG\Property(property="payment_type_id", type="integer", example=1)
2017-01-30 20:40:43 +01:00
* @SWG\Property(property="invoice_id", type="integer", example=1)
2017-05-16 15:00:56 +02:00
* @SWG\Property(property="private_notes", type="string", example="Notes...")
2017-01-30 20:40:43 +01:00
*/
2016-01-05 13:51:27 +01:00
protected $defaultIncludes = [];
2015-11-27 13:55:28 +01:00
2016-02-16 16:30:09 +01:00
protected $availableIncludes = [
'client',
'invoice',
];
2016-05-03 08:46:24 +02:00
public function __construct($account = null, $serializer = null, $invoice = null)
2015-11-27 13:55:28 +01:00
{
2016-05-03 08:46:24 +02:00
parent::__construct($account, $serializer);
2016-06-23 11:38:06 +02:00
2016-05-03 08:46:24 +02:00
$this->invoice = $invoice;
2015-11-27 13:55:28 +01:00
}
public function includeInvoice(Payment $payment)
{
$transformer = new InvoiceTransformer($this->account, $this->serializer);
2017-01-30 20:40:43 +01:00
2015-11-27 13:55:28 +01:00
return $this->includeItem($payment->invoice, $transformer, 'invoice');
}
public function includeClient(Payment $payment)
{
$transformer = new ClientTransformer($this->account, $this->serializer);
2017-01-30 20:40:43 +01:00
2015-11-27 13:55:28 +01:00
return $this->includeItem($payment->client, $transformer, 'client');
}
public function transform(Payment $payment)
{
2016-05-03 22:02:29 +02:00
return array_merge($this->getDefaults($payment), [
2015-11-27 13:55:28 +01:00
'id' => (int) $payment->public_id,
'amount' => (float) $payment->amount,
2018-06-26 16:15:54 +02:00
'transaction_reference' => $payment->transaction_reference ?: '',
'payment_date' => $payment->payment_date ?: '',
2016-01-05 13:51:27 +01:00
'updated_at' => $this->getTimestamp($payment->updated_at),
'archived_at' => $this->getTimestamp($payment->deleted_at),
'is_deleted' => (bool) $payment->is_deleted,
2018-06-26 16:15:54 +02:00
'payment_type_id' => (int) ($payment->payment_type_id ?: 0),
2016-05-03 08:46:24 +02:00
'invoice_id' => (int) ($this->invoice ? $this->invoice->public_id : $payment->invoice->public_id),
2016-06-23 11:38:06 +02:00
'invoice_number' => $this->invoice ? $this->invoice->invoice_number : $payment->invoice->invoice_number,
2018-06-26 16:15:54 +02:00
'private_notes' => $payment->private_notes ?: '',
2017-11-19 10:55:01 +01:00
'exchange_rate' => (float) $payment->exchange_rate,
'exchange_currency_id' => (int) $payment->exchange_currency_id,
2018-08-31 08:49:21 +02:00
'refunded' => (float) $payment->refunded,
'payment_status_id' => (int) $payment->payment_status_id,
2016-05-03 22:02:29 +02:00
]);
2015-11-27 13:55:28 +01:00
}
2016-06-23 11:38:06 +02:00
}