mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
commit
d90fa538ac
@ -136,6 +136,12 @@ class Client extends EntityModel
|
||||
return $this->belongsTo('App\Models\Industry');
|
||||
}
|
||||
|
||||
public function credits()
|
||||
{
|
||||
return $this->hasMany('App\Models\Credit');
|
||||
}
|
||||
|
||||
|
||||
public function addContact($data, $isPrimary = false)
|
||||
{
|
||||
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
|
||||
|
@ -43,6 +43,7 @@ class ClientTransformer extends EntityTransformer
|
||||
protected $availableIncludes = [
|
||||
'contacts',
|
||||
'invoices',
|
||||
'credits',
|
||||
];
|
||||
|
||||
public function includeContacts(Client $client)
|
||||
@ -57,6 +58,12 @@ class ClientTransformer extends EntityTransformer
|
||||
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)
|
||||
{
|
||||
return [
|
||||
|
24
app/Ninja/Transformers/CreditTransformer.php
Normal file
24
app/Ninja/Transformers/CreditTransformer.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user