has('limit')) { $perPage = $request->limit; } $contact = Auth::guard('customer')->id(); $filters = $request->all(); $page = Invoice::with(['items', 'customer', 'creator', 'taxes']) ->where('status', '<>', Invoice::STATUS_DRAFT) ->applyFilters($filters) ->whereCustomer($contact) ->latest() ->paginateData($perPage); // The counter tallies issued documents alone. A credit note reverses // an invoice rather than adding one, so it is left out of the total // even though it is listed among the rows above. $received = Invoice::query() ->where('type', Invoice::TYPE_INVOICE) ->where('status', '<>', Invoice::STATUS_DRAFT) ->whereCustomer($contact) ->count(); return InvoiceResource::collection($page) ->additional(['meta' => [ 'invoiceTotalCount' => $received, ]]); } /** * Hand back a single billing document, looked up inside the portal's * company and narrowed to the signed-in contact. * * @param string $id * @return Response */ public function show(Company $company, $id) { $contact = Auth::guard('customer')->id(); $invoice = $company->invoices()->whereCustomer($contact)->where('id', $id)->first(); if ($invoice === null) { return response()->json(['error' => 'invoice_not_found'], Response::HTTP_NOT_FOUND); } return InvoiceResource::make($invoice); } }