mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on API functionality
This commit is contained in:
parent
6d09bda646
commit
992802c164
@ -71,7 +71,8 @@ class AccountApiController extends BaseAPIController
|
||||
'invoices' => ['invoice_items', 'user', 'client', 'payments'],
|
||||
'products' => [],
|
||||
'tax_rates' => [],
|
||||
'expenses' => ['client', 'invoice', 'vendor']
|
||||
'expenses' => ['client', 'invoice', 'vendor'],
|
||||
'payments' => ['invoice'],
|
||||
];
|
||||
|
||||
foreach ($map as $key => $values) {
|
||||
|
@ -85,6 +85,23 @@ 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)
|
||||
{
|
||||
|
||||
|
@ -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,10 +220,11 @@ 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 PaymentTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($payment, $transformer, 'invoice');
|
||||
|
||||
|
@ -169,6 +169,11 @@ class Account extends Eloquent
|
||||
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)
|
||||
{
|
||||
$this->attributes['industry_id'] = $value ?: null;
|
||||
|
@ -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 [
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user