mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Merge branch 'develop' of github.com:hillelcoren/invoice-ninja into develop
This commit is contained in:
commit
fdab849705
@ -71,6 +71,8 @@ class AccountApiController extends BaseAPIController
|
||||
'invoices' => ['invoice_items', 'user', 'client', 'payments'],
|
||||
'products' => [],
|
||||
'tax_rates' => [],
|
||||
'expenses' => ['client', 'invoice', 'vendor'],
|
||||
'payments' => ['invoice'],
|
||||
];
|
||||
|
||||
foreach ($map as $key => $values) {
|
||||
|
@ -85,6 +85,36 @@ class InvoiceApiController extends BaseAPIController
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Get(
|
||||
* path="/invoices/{invoice_id}",
|
||||
* summary="Individual Invoice",
|
||||
* tags={"invoice"},
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="A single invoice",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Invoice"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
|
||||
public function show($publicId)
|
||||
{
|
||||
|
||||
$invoice = Invoice::scope($publicId)->withTrashed()->first();
|
||||
|
||||
if(!$invoice)
|
||||
return $this->errorResponse(['message'=>'Invoice does not exist!'], 404);
|
||||
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Post(
|
||||
|
@ -58,8 +58,8 @@ class PaymentApiController extends BaseAPIController
|
||||
|
||||
$payments = $payments->orderBy('created_at', 'desc')->paginate();
|
||||
$paginator = $paginator->paginate();
|
||||
|
||||
$transformer = new PaymentTransformer(Auth::user()->account, Input::get('serializer'));
|
||||
|
||||
$data = $this->createCollection($payments, $transformer, 'payments', $paginator);
|
||||
|
||||
return $this->response($data);
|
||||
@ -98,11 +98,8 @@ class PaymentApiController extends BaseAPIController
|
||||
$payment = Payment::scope($publicId)->withTrashed()->firstOrFail();
|
||||
$this->paymentRepo->archive($payment);
|
||||
|
||||
$invoice = Invoice::scope($data['invoice_id'])->with('client')->with(['payments' => function($query) {
|
||||
$query->withTrashed();
|
||||
}])->first();
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
$transformer = new PaymentTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($payment, $transformer, 'invoice');
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
@ -113,12 +110,17 @@ class PaymentApiController extends BaseAPIController
|
||||
return $error;
|
||||
}
|
||||
|
||||
/*
|
||||
$invoice = Invoice::scope($data['invoice_id'])->with('client', 'invoice_items', 'invitations')->with(['payments' => function($query) {
|
||||
$query->withTrashed();
|
||||
}])->withTrashed()->first();
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
*/
|
||||
|
||||
$transformer = new PaymentTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($payment, $transformer, 'invoice');
|
||||
|
||||
return $this->response($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -175,13 +177,17 @@ class PaymentApiController extends BaseAPIController
|
||||
$this->contactMailer->sendPaymentConfirmation($payment);
|
||||
}
|
||||
|
||||
/*
|
||||
$invoice = Invoice::scope($invoice->public_id)->with('client', 'invoice_items', 'invitations')->with(['payments' => function($query) {
|
||||
$query->withTrashed();
|
||||
}])->first();
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
*/
|
||||
|
||||
$transformer = new PaymentTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($payment, $transformer, 'invoice');
|
||||
|
||||
return $this->response($data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,12 +220,13 @@ class PaymentApiController extends BaseAPIController
|
||||
|
||||
$this->paymentRepo->delete($payment);
|
||||
|
||||
/*
|
||||
$invoice = Invoice::scope($invoiceId)->with('client', 'invoice_items', 'invitations')->with(['payments' => function($query) {
|
||||
$query->withTrashed();
|
||||
}])->first();
|
||||
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($invoice, $transformer, 'invoice');
|
||||
*/
|
||||
$transformer = new PaymentTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($payment, $transformer, 'invoice');
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
|
@ -164,6 +164,15 @@ class Account extends Eloquent
|
||||
return $this->belongsTo('App\Models\TaxRate');
|
||||
}
|
||||
|
||||
public function expenses()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense','account_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Payment','account_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function setIndustryIdAttribute($value)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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) {
|
||||
|
@ -12,10 +12,14 @@ class AccountTransformer extends EntityTransformer
|
||||
{
|
||||
protected $defaultIncludes = [
|
||||
'users',
|
||||
// 'clients',
|
||||
'invoices',
|
||||
'products',
|
||||
'taxRates'
|
||||
'taxRates',
|
||||
'payments'
|
||||
];
|
||||
|
||||
protected $availableIncludes = [
|
||||
'clients',
|
||||
'invoices',
|
||||
];
|
||||
|
||||
public function includeUsers(Account $account)
|
||||
@ -48,6 +52,12 @@ class AccountTransformer extends EntityTransformer
|
||||
return $this->includeCollection($account->tax_rates, $transformer, 'taxRates');
|
||||
}
|
||||
|
||||
public function includePayments(Account $account)
|
||||
{
|
||||
$transformer = new PaymentTransformer($account, $this->serializer);
|
||||
return $this->includeCollection($account->payments, $transformer, 'payments');
|
||||
}
|
||||
|
||||
public function transform(Account $account)
|
||||
{
|
||||
return [
|
||||
|
@ -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 [
|
||||
|
@ -8,6 +8,7 @@ class ExpenseTransformer extends EntityTransformer
|
||||
{
|
||||
public function transform(Expense $expense)
|
||||
{
|
||||
|
||||
return [
|
||||
'id' => (int) $expense->public_id,
|
||||
'private_notes' => $expense->private_notes,
|
||||
@ -24,6 +25,9 @@ class ExpenseTransformer extends EntityTransformer
|
||||
'exchange_rate' => (float) $expense->exchange_rate,
|
||||
'invoice_currency_id' => (int) $expense->invoice_currency_id,
|
||||
'is_deleted' => (bool) $expense->is_deleted,
|
||||
'client_id' => isset($expense->client->public_id) ? (int) $expense->client->public_id : null,
|
||||
'invoice_id' => isset($expense->invoice->public_id) ? (int) $expense->invoice->public_id : null,
|
||||
'vendor_id' => isset($expense->vendor->public_id) ? (int) $expense->vendor->public_id : null,
|
||||
];
|
||||
}
|
||||
}
|
@ -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 [
|
||||
|
@ -57,6 +57,7 @@ class PaymentTransformer extends EntityTransformer
|
||||
'archived_at' => $this->getTimestamp($payment->deleted_at),
|
||||
'is_deleted' => (bool) $payment->is_deleted,
|
||||
'payment_type_id' => (int) $payment->payment_type_id,
|
||||
'invoice_id' => (int) $payment->invoice->public_id,
|
||||
];
|
||||
}
|
||||
}
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user