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

64 lines
2.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)
2017-01-30 20:40:43 +01:00
* @SWG\Property(property="invoice_id", type="integer", example=1)
*/
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,
'transaction_reference' => $payment->transaction_reference,
2016-01-05 13:51:27 +01:00
'payment_date' => $payment->payment_date,
'updated_at' => $this->getTimestamp($payment->updated_at),
'archived_at' => $this->getTimestamp($payment->deleted_at),
'is_deleted' => (bool) $payment->is_deleted,
'payment_type_id' => (int) $payment->payment_type_id,
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,
2016-05-03 22:02:29 +02:00
]);
2015-11-27 13:55:28 +01:00
}
2016-06-23 11:38:06 +02:00
}