1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Ninja/Transformers/PaymentTermTransformer.php
David Bomba 9d1cb37835
Payment Terms via API (#1808)
Added the ability to get payment_terms, payment_term and create a new payment_term via the API.
2018-01-14 23:21:10 +11:00

37 lines
1.2 KiB
PHP

<?php
namespace App\Ninja\Transformers;
use App\Models\PaymentTerm;
/**
* @SWG\Definition(definition="PaymentTerm", required={"payment_term_id"}, @SWG\Xml(name="PaymentTerm"))
*/
class PaymentTermTransformer extends EntityTransformer
{
/**
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
* @SWG\Property(property="num_days", type="number", format="integer", example=10, readOnly=true)
* @SWG\Property(property="name", type="string", example="Net 7")
*/
public function __construct($account = null, $serializer = null, $paymentTerm = null)
{
parent::__construct($account, $serializer);
$this->paymentTerm = $paymentTerm;
}
public function transform(PaymentTerm $paymentTerm)
{
return array_merge($this->getDefaults($paymentTerm), [
'num_days' => (int) $paymentTerm->num_days,
'name' => trans('texts.payment_terms_net') . ' ' . $paymentTerm->getNumDays(),
'updated_at' => $this->getTimestamp($paymentTerm->updated_at),
'archived_at' => $this->getTimestamp($paymentTerm->deleted_at),
'is_default' => $paymentTerm->account_id == 0 ? 1 : 0,
]);
}
}