1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Api work/Bug fixes

This commit is contained in:
David Bomba 2016-02-17 19:10:33 +11:00
parent a6e9c5198d
commit aef4658873
5 changed files with 26 additions and 2 deletions

View File

@ -139,6 +139,10 @@ class Client extends EntityModel
return $this->hasMany('App\Models\Credit');
}
public function expenses()
{
return $this->hasMany('App\Models\Expense','client_id','id')->withTrashed();
}
public function addContact($data, $isPrimary = false)
{

View File

@ -197,6 +197,11 @@ class Invoice extends EntityModel implements BalanceAffecting
return $this->hasMany('App\Models\Invitation')->orderBy('invitations.contact_id');
}
public function expenses()
{
return $this->hasMany('App\Models\Expense','invoice_id','id')->withTrashed();
}
public function markInvitationsSent($notify = false)
{
foreach ($this->invitations as $invitation) {

View File

@ -47,6 +47,7 @@ class ClientTransformer extends EntityTransformer
protected $availableIncludes = [
'invoices',
'credits',
'expenses',
];
public function includeContacts(Client $client)
@ -67,6 +68,13 @@ class ClientTransformer extends EntityTransformer
return $this->includeCollection($client->credits, $transformer, ENTITY_CREDIT);
}
public function includeExpenses(Client $client)
{
$transformer = new ExpenseTransformer($this->account, $this->serializer);
return $this->includeCollection($client->expenses, $transformer, ENTITY_EXPENSE);
}
public function transform(Client $client)
{
return [

View File

@ -28,6 +28,7 @@ class InvoiceTransformer extends EntityTransformer
'invitations',
'payments',
'client',
'expenses',
];
public function includeInvoiceItems(Invoice $invoice)
@ -51,9 +52,16 @@ class InvoiceTransformer extends EntityTransformer
public function includeClient(Invoice $invoice)
{
$transformer = new ClientTransformer($this->account, $this->serializer);
return $this->includeItem($invoice->client, $transformer, 'client');
return $this->includeItem($invoice->client, $transformer, ENTITY_CLIENT);
}
public function includeExpenses(Invoice $invoice)
{
$transformer = new ExpenseTransformer($this->account, $this->serializer);
return $this->includeCollection($invoice->expenses, $transformer, ENTITY_EXPENSE);
}
public function transform(Invoice $invoice)
{
return [

View File

@ -17,7 +17,6 @@ class VendorContactTransformer extends EntityTransformer
'archived_at' => $this->getTimestamp($contact->deleted_at),
'is_primary' => (bool) $contact->is_primary,
'phone' => $contact->phone,
'last_login' => $contact->last_login,
'account_key' => $this->account->account_key,
];
}