/** * @return Collection */ public function getCategories() { $set = $this->categories->sortByDesc(function (CategoryModel $category) { return $category->spent; }); return $set; }
/** * @return Collection */ public function getIncomes() { $set = $this->incomes->sortByDesc(function (stdClass $object) { return $object->amount; }); return $set; }
/** * Adds a OrderBy to the query * * @param string * @param string * @return $this */ public function orderBy($column, $direction = 'asc') { if ($column != null) { if ($direction === 'asc') { $this->collection = $this->collection->sortBy($column); } elseif ($direction === 'desc') { $this->collection = $this->collection->sortByDesc($column); } } return $this; }
/** * Get a collection of the entity's invoices. * * @param bool $includePending * @param array $parameters * * @return \Illuminate\Support\Collection */ public function invoices($includePending = false, $parameters = []) { $invoices = new Collection(); $customer = $this->asBraintreeCustomer(); $parameters = array_merge([TransactionSearch::customerId()->is($customer->id)], $parameters); $braintreeTransactions = Transaction::search($parameters); $subscriptionIds = []; foreach ($braintreeTransactions as $braintreeTransaction) { $subscriptionIds[] = $braintreeTransaction->subscriptionId; } $braintreeSubscriptions = BraintreeSubscription::fetch([], array_unique($subscriptionIds)); // Here we will loop through the Braintree invoices and create our own custom Invoice // instances that have more helper methods and are generally more convenient to // work with than the plain Braintree objects are. Then, we'll return the array. if (!is_null($braintreeSubscriptions)) { foreach ($braintreeSubscriptions as $subscription) { if ($subscription->status == BraintreeSubscription::ACTIVE || $includePending) { foreach ($subscription->transactions as $transaction) { $invoices->push(new Invoice($this, $subscription, $transaction)); } } } } return $invoices->sortByDesc(function ($invoice) { return $invoice->date(); }); }