1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Merge pull request #570 from turbo124/master

Tax Rate Transformer added
This commit is contained in:
David Bomba 2015-12-21 18:37:29 +11:00
commit 428c1590e4
2 changed files with 42 additions and 0 deletions

View File

@ -4,6 +4,7 @@ use App\Models\Account;
use App\Models\AccountToken;
use App\Models\Contact;
use App\Models\Product;
use App\Models\TaxRate;
use League\Fractal;
use League\Fractal\TransformerAbstract;
@ -15,6 +16,7 @@ class AccountTransformer extends EntityTransformer
'invoices',
'contacts',
'products',
'taxRates'
];
public function includeUsers(Account $account)
@ -47,6 +49,13 @@ class AccountTransformer extends EntityTransformer
return $this->includeCollection($account->products, $transformer, 'products');
}
public function includeTaxRates(Account $account)
{
$transformer = new TaxRateTransformer($account, $this->serializer);
return $this->includeCollection($account->tax_rates, $transformer, 'taxRates');
}
public function transform(Account $account)
{
return [

View File

@ -0,0 +1,33 @@
<?php namespace App\Ninja\Transformers;
use App\Models\Account;
use App\Models\TaxRate;
use League\Fractal;
/**
* @SWG\Definition(definition="TaxRate", @SWG\Xml(name="TaxRate"))
*/
class TaxRateTransformer extends EntityTransformer
{
/**
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
* @SWG\Property(property="name", type="string", example="GST")
* @SWG\Property(property="account_key", type="string", example="34erfdf33fdff" readOnly=true)
* @SWG\Property(property="rate", type="float", example=17.5)
* @SWG\Property(property="updated_at", type="date-time", example="2016-01-01 12:10:00")
* @SWG\Property(property="archived_at", type="date-time", example="2016-01-01 12:10:00")
*/
public function transform(TaxRate $taxRate)
{
return [
'id' => (int) $taxRate->public_id,
'name' => $taxRate->name,
'rate' => (float) $taxRate->rate,
'updated_at' => $taxRate->updated_at,
'archived_at' => $taxRate->deleted_at,
'account_key' => $this->account->account_key,
];
}
}