-
app/Models/Transaction.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Transaction extends Model { // public function scopeExpenses($query) { return $query->whereHas('brand.category', function ($query) { return $query->where('type', Category::EXPENSES); }); } // }
-
app/GraphQL/Queries/TotalExpensesTrend.php
Open in GitHubuse App\Models\Transaction; use Illuminate\Support\Facades\DB; class TotalExpensesTrend extends TrendMetric { // public function __invoke($_, array $args) { $rangeData = app('findRangeByKey', ["key" => $args['range']]); $query = Transaction::query() ->expenses() ->select(DB::raw("date_format(created_at, '%Y-%m') as label, SUM(transactions.amount) as value")) ->groupBy(DB::raw("label")) ->orderBy("label"); if($rangeData) { $query->whereBetween('transactions.created_at', [$rangeData->start(), $rangeData->end()]); } return $query->get(); } }