1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Ninja/Transformers/InvoiceTransformer.php

82 lines
3.5 KiB
PHP
Raw Normal View History

2015-11-03 15:21:17 +01:00
<?php namespace App\Ninja\Transformers;
2015-11-08 22:12:50 +01:00
use App\Models\Account;
use App\Models\Client;
2015-11-03 15:21:17 +01:00
use App\Models\Invoice;
use League\Fractal;
2015-11-08 21:34:26 +01:00
/**
2015-11-08 22:57:28 +01:00
* @SWG\Definition(definition="Invoice", required={"invoice_number"}, @SWG\Xml(name="Invoice"))
2015-11-08 21:34:26 +01:00
*/
2015-11-08 22:12:50 +01:00
class InvoiceTransformer extends EntityTransformer
2015-11-03 15:21:17 +01:00
{
2015-11-08 21:34:26 +01:00
/**
2015-11-08 22:53:13 +01:00
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
* @SWG\Property(property="amount", type="float", example=10, readOnly=true)
* @SWG\Property(property="balance", type="float", example=10, readOnly=true)
2015-11-08 21:34:26 +01:00
* @SWG\Property(property="client_id", type="integer", example=1)
2015-11-08 22:53:13 +01:00
* @SWG\Property(property="invoice_number", type="string", example="0001")
2015-11-08 21:34:26 +01:00
* @SWG\Property(property="invoice_status_id", type="integer", example=1)
*/
2015-11-03 15:21:17 +01:00
protected $defaultIncludes = [
'invoice_items',
2016-01-05 13:51:27 +01:00
'payments'
2015-11-03 15:21:17 +01:00
];
2015-11-27 13:55:28 +01:00
2015-11-08 22:12:50 +01:00
public function includeInvoiceItems(Invoice $invoice)
2015-11-03 15:21:17 +01:00
{
2015-11-27 13:55:28 +01:00
$transformer = new InvoiceItemTransformer($this->account, $this->serializer);
return $this->includeCollection($invoice->invoice_items, $transformer, ENTITY_INVOICE_ITEMS);
2015-11-03 15:21:17 +01:00
}
2016-01-05 13:51:27 +01:00
public function includePayments(Invoice $invoice)
{
$transformer = new PaymentTransformer($this->account, $this->serializer);
return $this->includeCollection($invoice->payments, $transformer, ENTITY_PAYMENT);
}
2015-11-03 15:21:17 +01:00
public function transform(Invoice $invoice)
{
return [
2015-11-08 21:34:26 +01:00
'id' => (int) $invoice->public_id,
2015-11-03 15:21:17 +01:00
'amount' => (float) $invoice->amount,
'balance' => (float) $invoice->balance,
2015-11-15 11:43:32 +01:00
'client_id' => (int) $invoice->client->public_id,
2015-11-07 13:15:37 +01:00
'invoice_status_id' => (int) $invoice->invoice_status_id,
2015-12-27 12:08:58 +01:00
'updated_at' => $this->getTimestamp($invoice->updated_at),
'archived_at' => $this->getTimestamp($invoice->deleted_at),
2015-11-07 13:15:37 +01:00
'invoice_number' => $invoice->invoice_number,
'discount' => (double) $invoice->discount,
'po_number' => $invoice->po_number,
'invoice_date' => $invoice->invoice_date,
'due_date' => $invoice->due_date,
2015-12-17 09:21:31 +01:00
'terms' => $invoice->terms,
2015-11-07 13:15:37 +01:00
'public_notes' => $invoice->public_notes,
'is_deleted' => (bool) $invoice->is_deleted,
2015-12-27 12:08:58 +01:00
'is_quote' => (bool) $invoice->is_quote,
2015-11-07 13:15:37 +01:00
'is_recurring' => (bool) $invoice->is_recurring,
'frequency_id' => (int) $invoice->frequency_id,
'start_date' => $invoice->start_date,
'end_date' => $invoice->end_date,
'last_sent_date' => $invoice->last_sent_date,
'recurring_invoice_id' => (int) $invoice->recurring_invoice_id,
'tax_name' => $invoice->tax_name,
'tax_rate' => (float) $invoice->tax_rate,
'amount' => (float) $invoice->amount,
'balance' => (float) $invoice->balance,
'is_amount_discount' => (bool) $invoice->is_amount_discount,
'invoice_footer' => $invoice->invoice_footer,
'partial' => (float) $invoice->partial,
'has_tasks' => (bool) $invoice->has_tasks,
2015-11-14 09:28:17 +01:00
'auto_bill' => (bool) $invoice->auto_bill,
2015-11-21 10:31:31 +01:00
'account_key' => $this->account->account_key,
'user_id' => (int) $invoice->user->public_id + 1,
'custom_value1' => $invoice->custom_value1,
'custom_value2' => $invoice->custom_value2,
'custom_taxes1' => (bool) $invoice->custom_taxes1,
'custom_taxes2' => (bool) $invoice->custom_taxes2,
2015-11-03 15:21:17 +01:00
];
}
}