1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Merge branch 'master' of github.com:hillelcoren/invoice-ninja

This commit is contained in:
Hillel Coren 2016-02-03 10:08:35 +02:00
commit 86b6d9dc10
4 changed files with 41 additions and 0 deletions

View File

@ -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;

View File

@ -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 [

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,
];
}
}

View File

@ -20,6 +20,10 @@ class AddSourceCurrencyToExpenses extends Migration
$table->renameColumn('currency_id', 'invoice_currency_id');
$table->unsignedInteger('expense_currency_id');
});
Schema::table('expenses', function (Blueprint $table) {
// set account value so we're able to create foreign constraint
DB::statement('update expenses e
left join accounts a on a.id = e.account_id