diff --git a/app/Http/Controllers/AccountApiController.php b/app/Http/Controllers/AccountApiController.php index f4619892fccc..77e85243d7a9 100644 --- a/app/Http/Controllers/AccountApiController.php +++ b/app/Http/Controllers/AccountApiController.php @@ -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) { diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index 73088f0c87d8..8c4344f608b6 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -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) { diff --git a/app/Http/Controllers/PaymentApiController.php b/app/Http/Controllers/PaymentApiController.php index 7d896961de24..7022f0c3e840 100644 --- a/app/Http/Controllers/PaymentApiController.php +++ b/app/Http/Controllers/PaymentApiController.php @@ -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'); diff --git a/app/Models/Account.php b/app/Models/Account.php index e9947119dcfb..d3f64bb2eec0 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -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; diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index eed474346550..6a1c32f30e09 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -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 [ diff --git a/app/Ninja/Transformers/PaymentTransformer.php b/app/Ninja/Transformers/PaymentTransformer.php index 22642259751a..a1de09cd6ff4 100644 --- a/app/Ninja/Transformers/PaymentTransformer.php +++ b/app/Ninja/Transformers/PaymentTransformer.php @@ -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, ]; } } \ No newline at end of file