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

Merge pull request #684 from turbo124/master

Added Credit Transformer
This commit is contained in:
David Bomba 2016-02-03 14:22:20 +11:00
commit d90fa538ac
3 changed files with 37 additions and 0 deletions

View File

@ -136,6 +136,12 @@ class Client extends EntityModel
return $this->belongsTo('App\Models\Industry'); return $this->belongsTo('App\Models\Industry');
} }
public function credits()
{
return $this->hasMany('App\Models\Credit');
}
public function addContact($data, $isPrimary = false) public function addContact($data, $isPrimary = false)
{ {
$publicId = isset($data['public_id']) ? $data['public_id'] : false; $publicId = isset($data['public_id']) ? $data['public_id'] : false;

View File

@ -43,6 +43,7 @@ class ClientTransformer extends EntityTransformer
protected $availableIncludes = [ protected $availableIncludes = [
'contacts', 'contacts',
'invoices', 'invoices',
'credits',
]; ];
public function includeContacts(Client $client) public function includeContacts(Client $client)
@ -57,6 +58,12 @@ class ClientTransformer extends EntityTransformer
return $this->includeCollection($client->invoices, $transformer, ENTITY_INVOICE); return $this->includeCollection($client->invoices, $transformer, ENTITY_INVOICE);
} }
public function includeCredits(Client $client)
{
$transformer = new CreditTransformer($this->account, $this->serializer);
return $this->includeCollection($client->credits, $transformer, ENTITY_CREDIT);
}
public function transform(Client $client) public function transform(Client $client)
{ {
return [ return [

View File

@ -0,0 +1,24 @@
<?php namespace App\Ninja\Transformers;
use App\Models\Account;
use App\Models\Credit;
use League\Fractal;
class CreditTransformer extends EntityTransformer
{
public function transform(Credit $credit)
{
return [
'id' => (int) $credit->public_id,
'amount' => (float) $credit->amount,
'balance' => (float) $credit->balance,
'updated_at' => $this->getTimestamp($credit->updated_at),
'archived_at' => $this->getTimestamp($credit->deleted_at),
'is_deleted' => (bool) $credit->is_deleted,
'account_key' => $this->account->account_key,
'credit_date' => $credit->credit_date,
'credit_number' => $credit->credit_number,
'private_notes' => $credit->private_notes,
];
}
}