From 430c092ebe7d0b0b7f86c9e88ae9ade654fdeb08 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Sun, 3 May 2020 11:15:56 +0300 Subject: [PATCH] added more scopes --- app/Exports/Purchases/Payments.php | 2 +- .../Purchases/Sheets/BillTransactions.php | 2 +- app/Exports/Sales/Revenues.php | 2 +- .../Sales/Sheets/InvoiceTransactions.php | 2 +- app/Http/Controllers/Common/Items.php | 4 +- app/Http/Controllers/Common/Search.php | 4 +- app/Http/Controllers/Modals/Items.php | 2 +- app/Http/Controllers/Portal/Invoices.php | 2 +- app/Http/Controllers/Portal/Payments.php | 2 +- app/Http/Controllers/Purchases/Bills.php | 8 ++-- app/Http/Controllers/Purchases/Payments.php | 8 ++-- app/Http/Controllers/Purchases/Vendors.php | 2 +- app/Http/Controllers/Sales/Customers.php | 2 +- app/Http/Controllers/Sales/Invoices.php | 8 ++-- app/Http/Controllers/Sales/Revenues.php | 8 ++-- app/Models/Banking/Transaction.php | 22 +++++++++ app/Models/Setting/Category.php | 46 ++++++++++++++++++- app/Reports/ExpenseSummary.php | 2 +- app/Reports/IncomeExpenseSummary.php | 4 +- app/Reports/IncomeSummary.php | 2 +- app/Reports/ProfitLoss.php | 4 +- app/Reports/TaxSummary.php | 4 +- app/Widgets/ExpensesByCategory.php | 2 +- app/Widgets/IncomeByCategory.php | 2 +- app/Widgets/LatestExpenses.php | 2 +- app/Widgets/LatestIncome.php | 2 +- app/Widgets/TotalExpenses.php | 2 +- app/Widgets/TotalIncome.php | 2 +- database/factories/Bill.php | 2 +- database/factories/Invoice.php | 2 +- database/factories/Item.php | 2 +- database/factories/Transaction.php | 4 +- 32 files changed, 115 insertions(+), 49 deletions(-) diff --git a/app/Exports/Purchases/Payments.php b/app/Exports/Purchases/Payments.php index 4a903ad17..dba57e593 100644 --- a/app/Exports/Purchases/Payments.php +++ b/app/Exports/Purchases/Payments.php @@ -9,7 +9,7 @@ class Payments extends Export { public function collection() { - $model = Model::with(['account', 'bill', 'category', 'contact'])->type('expense')->usingSearchString(request('search')); + $model = Model::with(['account', 'bill', 'category', 'contact'])->expense()->usingSearchString(request('search')); if (!empty($this->ids)) { $model->whereIn('id', (array) $this->ids); diff --git a/app/Exports/Purchases/Sheets/BillTransactions.php b/app/Exports/Purchases/Sheets/BillTransactions.php index be3eb613e..40af135a9 100644 --- a/app/Exports/Purchases/Sheets/BillTransactions.php +++ b/app/Exports/Purchases/Sheets/BillTransactions.php @@ -9,7 +9,7 @@ class BillTransactions extends Export { public function collection() { - $model = Model::with(['account', 'category', 'contact', 'bill'])->type('expense')->isDocument()->usingSearchString(request('search')); + $model = Model::with(['account', 'category', 'contact', 'bill'])->expense()->isDocument()->usingSearchString(request('search')); if (!empty($this->ids)) { $model->whereIn('document_id', (array) $this->ids); diff --git a/app/Exports/Sales/Revenues.php b/app/Exports/Sales/Revenues.php index 47f9f384f..edf74c71b 100644 --- a/app/Exports/Sales/Revenues.php +++ b/app/Exports/Sales/Revenues.php @@ -9,7 +9,7 @@ class Revenues extends Export { public function collection() { - $model = Model::with(['account', 'category', 'contact', 'invoice'])->type('income')->usingSearchString(request('search')); + $model = Model::with(['account', 'category', 'contact', 'invoice'])->income()->usingSearchString(request('search')); if (!empty($this->ids)) { $model->whereIn('id', (array) $this->ids); diff --git a/app/Exports/Sales/Sheets/InvoiceTransactions.php b/app/Exports/Sales/Sheets/InvoiceTransactions.php index cdb3ab71c..2855d8f06 100644 --- a/app/Exports/Sales/Sheets/InvoiceTransactions.php +++ b/app/Exports/Sales/Sheets/InvoiceTransactions.php @@ -9,7 +9,7 @@ class InvoiceTransactions extends Export { public function collection() { - $model = Model::with(['account', 'category', 'contact', 'invoice'])->type('income')->isDocument()->usingSearchString(request('search')); + $model = Model::with(['account', 'category', 'contact', 'invoice'])->income()->isDocument()->usingSearchString(request('search')); if (!empty($this->ids)) { $model->whereIn('document_id', (array) $this->ids); diff --git a/app/Http/Controllers/Common/Items.php b/app/Http/Controllers/Common/Items.php index 30f5312fd..a33e42bda 100644 --- a/app/Http/Controllers/Common/Items.php +++ b/app/Http/Controllers/Common/Items.php @@ -50,7 +50,7 @@ class Items extends Controller */ public function create() { - $categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id'); $taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id'); @@ -131,7 +131,7 @@ class Items extends Controller */ public function edit(Item $item) { - $categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id'); $taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id'); diff --git a/app/Http/Controllers/Common/Search.php b/app/Http/Controllers/Common/Search.php index 21fb486a5..f8d0040ab 100644 --- a/app/Http/Controllers/Common/Search.php +++ b/app/Http/Controllers/Common/Search.php @@ -65,7 +65,7 @@ class Search extends Controller } }/* - $income_transactions = Transaction::type('income')->usingSearchString($keyword)->get(); + $income_transactions = Transaction::income()->usingSearchString($keyword)->get(); if ($income_transactions->count()) { foreach ($income_transactions as $transaction) { @@ -107,7 +107,7 @@ class Search extends Controller } } /* - $payments = Transaction::type('expense')->usingSearchString($keyword)->get(); + $payments = Transaction::expense()->usingSearchString($keyword)->get(); if ($revenues->count()) { foreach ($revenues as $revenue) { diff --git a/app/Http/Controllers/Modals/Items.php b/app/Http/Controllers/Modals/Items.php index 8eb73ca7c..176d8a743 100644 --- a/app/Http/Controllers/Modals/Items.php +++ b/app/Http/Controllers/Modals/Items.php @@ -30,7 +30,7 @@ class Items extends Controller */ public function create(IRequest $request) { - $categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id'); $taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id'); diff --git a/app/Http/Controllers/Portal/Invoices.php b/app/Http/Controllers/Portal/Invoices.php index 24cb48447..a843bb564 100644 --- a/app/Http/Controllers/Portal/Invoices.php +++ b/app/Http/Controllers/Portal/Invoices.php @@ -27,7 +27,7 @@ class Invoices extends Controller ->accrued()->where('contact_id', user()->contact->id) ->collect(['invoice_number'=> 'desc']); - $categories = collect(Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id')); + $categories = collect(Category::income()->enabled()->orderBy('name')->pluck('name', 'id')); $statuses = $this->getInvoiceStatuses(); diff --git a/app/Http/Controllers/Portal/Payments.php b/app/Http/Controllers/Portal/Payments.php index dc1525473..df42e1a55 100644 --- a/app/Http/Controllers/Portal/Payments.php +++ b/app/Http/Controllers/Portal/Payments.php @@ -16,7 +16,7 @@ class Payments extends Controller */ public function index() { - $payments = Transaction::type('income')->where('contact_id', '=', user()->contact->id)->paginate(); + $payments = Transaction::income()->where('contact_id', '=', user()->contact->id)->paginate(); $payment_methods = Modules::getPaymentMethods('all'); diff --git a/app/Http/Controllers/Purchases/Bills.php b/app/Http/Controllers/Purchases/Bills.php index 4660f5753..bf3061883 100644 --- a/app/Http/Controllers/Purchases/Bills.php +++ b/app/Http/Controllers/Purchases/Bills.php @@ -41,7 +41,7 @@ class Bills extends Controller $vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id'); $statuses = $this->getBillStatuses(); @@ -67,7 +67,7 @@ class Bills extends Controller $vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id'); $payment_methods = Modules::getPaymentMethods(); @@ -106,7 +106,7 @@ class Bills extends Controller $taxes = Tax::enabled()->orderBy('name')->get(); - $categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id'); $number = $this->getNextBillNumber(); @@ -202,7 +202,7 @@ class Bills extends Controller $taxes = Tax::enabled()->orderBy('name')->get(); - $categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id'); return view('purchases.bills.edit', compact('bill', 'vendors', 'currencies', 'currency', 'items', 'taxes', 'categories')); } diff --git a/app/Http/Controllers/Purchases/Payments.php b/app/Http/Controllers/Purchases/Payments.php index cbf50467e..95cdd672a 100644 --- a/app/Http/Controllers/Purchases/Payments.php +++ b/app/Http/Controllers/Purchases/Payments.php @@ -30,11 +30,11 @@ class Payments extends Controller */ public function index() { - $payments = Transaction::type('expense')->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']); + $payments = Transaction::expense()->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']); $vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id'); $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id'); @@ -68,7 +68,7 @@ class Payments extends Controller $vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id'); $payment_methods = Modules::getPaymentMethods(); @@ -156,7 +156,7 @@ class Payments extends Controller $vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id'); $payment_methods = Modules::getPaymentMethods(); diff --git a/app/Http/Controllers/Purchases/Vendors.php b/app/Http/Controllers/Purchases/Vendors.php index 17a0829db..59340a7d3 100644 --- a/app/Http/Controllers/Purchases/Vendors.php +++ b/app/Http/Controllers/Purchases/Vendors.php @@ -78,7 +78,7 @@ class Vendors extends Controller } // Handle payments - $transactions = Transaction::where('contact_id', $vendor->id)->type('expense')->get(); + $transactions = Transaction::where('contact_id', $vendor->id)->expense()->get(); $counts['transactions'] = $transactions->count(); diff --git a/app/Http/Controllers/Sales/Customers.php b/app/Http/Controllers/Sales/Customers.php index f52e241ae..1857b9f30 100644 --- a/app/Http/Controllers/Sales/Customers.php +++ b/app/Http/Controllers/Sales/Customers.php @@ -76,7 +76,7 @@ class Customers extends Controller } // Handle transactions - $transactions = Transaction::where('contact_id', $customer->id)->type('income')->get(); + $transactions = Transaction::where('contact_id', $customer->id)->income()->get(); $counts['transactions'] = $transactions->count(); diff --git a/app/Http/Controllers/Sales/Invoices.php b/app/Http/Controllers/Sales/Invoices.php index aaf7834a0..7af09cee0 100644 --- a/app/Http/Controllers/Sales/Invoices.php +++ b/app/Http/Controllers/Sales/Invoices.php @@ -42,7 +42,7 @@ class Invoices extends Controller $customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id'); $statuses = $this->getInvoiceStatuses(); @@ -68,7 +68,7 @@ class Invoices extends Controller $customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id'); $payment_methods = Modules::getPaymentMethods(); @@ -109,7 +109,7 @@ class Invoices extends Controller $taxes = Tax::enabled()->orderBy('name')->get(); - $categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id'); $number = $this->getNextInvoiceNumber(); @@ -205,7 +205,7 @@ class Invoices extends Controller $taxes = Tax::enabled()->orderBy('name')->get(); - $categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id'); return view('sales.invoices.edit', compact('invoice', 'customers', 'currencies', 'currency', 'items', 'taxes', 'categories')); } diff --git a/app/Http/Controllers/Sales/Revenues.php b/app/Http/Controllers/Sales/Revenues.php index b0146538c..5eed29da2 100644 --- a/app/Http/Controllers/Sales/Revenues.php +++ b/app/Http/Controllers/Sales/Revenues.php @@ -30,11 +30,11 @@ class Revenues extends Controller */ public function index() { - $revenues = Transaction::type('income')->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']); + $revenues = Transaction::income()->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']); $customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id'); $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id'); @@ -68,7 +68,7 @@ class Revenues extends Controller $customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id'); $payment_methods = Modules::getPaymentMethods(); @@ -156,7 +156,7 @@ class Revenues extends Controller $customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id'); - $categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'); + $categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id'); $payment_methods = Modules::getPaymentMethods(); diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 6f85c8255..f82e36f86 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -96,6 +96,28 @@ class Transaction extends Model return $query->whereIn($this->table . '.type', (array) $types); } + /** + * Scope to include only income. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeIncome($query) + { + return $query->where($this->table . '.type', '=', 'income'); + } + + /** + * Scope to include only expense. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeExpense($query) + { + return $query->where($this->table . '.type', '=', 'expense'); + } + /** * Get only transfers. * diff --git a/app/Models/Setting/Category.php b/app/Models/Setting/Category.php index b627a811a..3ad11959b 100644 --- a/app/Models/Setting/Category.php +++ b/app/Models/Setting/Category.php @@ -68,6 +68,50 @@ class Category extends Model return $query->whereIn($this->table . '.type', (array) $types); } + /** + * Scope to include only income. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeIncome($query) + { + return $query->where($this->table . '.type', '=', 'income'); + } + + /** + * Scope to include only expense. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeExpense($query) + { + return $query->where($this->table . '.type', '=', 'expense'); + } + + /** + * Scope to include only item. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeItem($query) + { + return $query->where($this->table . '.type', '=', 'item'); + } + + /** + * Scope to include only other. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeOther($query) + { + return $query->where($this->table . '.type', '=', 'other'); + } + public function scopeName($query, $name) { return $query->where('name', '=', $name); @@ -81,6 +125,6 @@ class Category extends Model */ public function scopeTransfer($query) { - return $query->where('type', 'other')->pluck('id')->first(); + return $query->where($this->table . '.type', '=', 'other')->pluck('id')->first(); } } diff --git a/app/Reports/ExpenseSummary.php b/app/Reports/ExpenseSummary.php index 9335c730a..1c1069e27 100644 --- a/app/Reports/ExpenseSummary.php +++ b/app/Reports/ExpenseSummary.php @@ -30,7 +30,7 @@ class ExpenseSummary extends Report public function setData() { - $transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']); + $transactions = $this->applyFilters(Transaction::expense()->isNotTransfer(), ['date_field' => 'paid_at']); switch ($this->model->settings->basis) { case 'cash': diff --git a/app/Reports/IncomeExpenseSummary.php b/app/Reports/IncomeExpenseSummary.php index 2e74f99c5..19abe176d 100644 --- a/app/Reports/IncomeExpenseSummary.php +++ b/app/Reports/IncomeExpenseSummary.php @@ -16,8 +16,8 @@ class IncomeExpenseSummary extends Report public function setData() { - $income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']); - $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']); + $income_transactions = $this->applyFilters(Transaction::income()->isNotTransfer(), ['date_field' => 'paid_at']); + $expense_transactions = $this->applyFilters(Transaction::expense()->isNotTransfer(), ['date_field' => 'paid_at']); switch ($this->model->settings->basis) { case 'cash': diff --git a/app/Reports/IncomeSummary.php b/app/Reports/IncomeSummary.php index acc6608f7..5bde4b9d8 100644 --- a/app/Reports/IncomeSummary.php +++ b/app/Reports/IncomeSummary.php @@ -30,7 +30,7 @@ class IncomeSummary extends Report public function setData() { - $transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']); + $transactions = $this->applyFilters(Transaction::income()->isNotTransfer(), ['date_field' => 'paid_at']); switch ($this->model->settings->basis) { case 'cash': diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index af944e645..2169a61a6 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -40,8 +40,8 @@ class ProfitLoss extends Report public function setData() { - $income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']); - $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']); + $income_transactions = $this->applyFilters(Transaction::income()->isNotTransfer(), ['date_field' => 'paid_at']); + $expense_transactions = $this->applyFilters(Transaction::expense()->isNotTransfer(), ['date_field' => 'paid_at']); switch ($this->model->settings->basis) { case 'cash': diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index f9abe6b38..007d294e8 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -47,11 +47,11 @@ class TaxSummary extends Report switch ($this->model->settings->basis) { case 'cash': // Invoice Payments - $invoices = $this->applyFilters(Transaction::with(['invoice', 'invoice.totals'])->type('income')->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get(); + $invoices = $this->applyFilters(Transaction::with(['invoice', 'invoice.totals'])->income()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $this->setTotals($invoices, 'paid_at'); // Bill Payments - $bills = $this->applyFilters(Transaction::with(['bill', 'bill.totals'])->type('expense')->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get(); + $bills = $this->applyFilters(Transaction::with(['bill', 'bill.totals'])->expense()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $this->setTotals($bills, 'paid_at'); break; diff --git a/app/Widgets/ExpensesByCategory.php b/app/Widgets/ExpensesByCategory.php index fcf068b05..b44ef7e15 100644 --- a/app/Widgets/ExpensesByCategory.php +++ b/app/Widgets/ExpensesByCategory.php @@ -15,7 +15,7 @@ class ExpensesByCategory extends Widget public function show() { - Category::with('expense_transactions')->type('expense')->each(function ($category) { + Category::with('expense_transactions')->expense()->each(function ($category) { $amount = 0; $this->applyFilters($category->expense_transactions())->each(function ($transaction) use (&$amount) { diff --git a/app/Widgets/IncomeByCategory.php b/app/Widgets/IncomeByCategory.php index ee532420a..8d34286e0 100644 --- a/app/Widgets/IncomeByCategory.php +++ b/app/Widgets/IncomeByCategory.php @@ -15,7 +15,7 @@ class IncomeByCategory extends Widget public function show() { - Category::with('income_transactions')->type('income')->each(function ($category) { + Category::with('income_transactions')->income()->each(function ($category) { $amount = 0; $this->applyFilters($category->income_transactions())->each(function ($transaction) use (&$amount) { diff --git a/app/Widgets/LatestExpenses.php b/app/Widgets/LatestExpenses.php index ffdfb521e..9f5810136 100644 --- a/app/Widgets/LatestExpenses.php +++ b/app/Widgets/LatestExpenses.php @@ -11,7 +11,7 @@ class LatestExpenses extends Widget public function show() { - $transactions = $this->applyFilters(Transaction::with('category')->type('expense')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get(); + $transactions = $this->applyFilters(Transaction::with('category')->expense()->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get(); return $this->view('widgets.latest_expenses', [ 'transactions' => $transactions, diff --git a/app/Widgets/LatestIncome.php b/app/Widgets/LatestIncome.php index 89334b9ee..d883fcdf5 100644 --- a/app/Widgets/LatestIncome.php +++ b/app/Widgets/LatestIncome.php @@ -11,7 +11,7 @@ class LatestIncome extends Widget public function show() { - $transactions = $this->applyFilters(Transaction::with('category')->type('income')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get(); + $transactions = $this->applyFilters(Transaction::with('category')->income()->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get(); return $this->view('widgets.latest_income', [ 'transactions' => $transactions, diff --git a/app/Widgets/TotalExpenses.php b/app/Widgets/TotalExpenses.php index 82014f0d9..90787c309 100644 --- a/app/Widgets/TotalExpenses.php +++ b/app/Widgets/TotalExpenses.php @@ -18,7 +18,7 @@ class TotalExpenses extends Widget { $current = $open = $overdue = 0; - $this->applyFilters(Transaction::type('expense')->isNotTransfer())->each(function ($transaction) use (&$current) { + $this->applyFilters(Transaction::expense()->isNotTransfer())->each(function ($transaction) use (&$current) { $current += $transaction->getAmountConvertedToDefault(); }); diff --git a/app/Widgets/TotalIncome.php b/app/Widgets/TotalIncome.php index e48bd42f8..9f8edcef1 100644 --- a/app/Widgets/TotalIncome.php +++ b/app/Widgets/TotalIncome.php @@ -18,7 +18,7 @@ class TotalIncome extends Widget { $current = $open = $overdue = 0; - $this->applyFilters(Transaction::type('income')->isNotTransfer())->each(function ($transaction) use (&$current) { + $this->applyFilters(Transaction::income()->isNotTransfer())->each(function ($transaction) use (&$current) { $current += $transaction->getAmountConvertedToDefault(); }); diff --git a/database/factories/Bill.php b/database/factories/Bill.php index c63624cfd..3392bdee7 100644 --- a/database/factories/Bill.php +++ b/database/factories/Bill.php @@ -41,7 +41,7 @@ $factory->define(Bill::class, function (Faker $faker) use ($company) { 'currency_code' => setting('default.currency'), 'currency_rate' => '1', 'notes' => $faker->text(5), - 'category_id' => $company->categories()->type('expense')->get()->random(1)->pluck('id')->first(), + 'category_id' => $company->categories()->expense()->get()->random(1)->pluck('id')->first(), 'contact_id' => $contact->id, 'contact_name' => $contact->name, 'contact_email' => $contact->email, diff --git a/database/factories/Invoice.php b/database/factories/Invoice.php index 59c06e806..78e09ad33 100644 --- a/database/factories/Invoice.php +++ b/database/factories/Invoice.php @@ -42,7 +42,7 @@ $factory->define(Invoice::class, function (Faker $faker) use ($company) { 'currency_code' => setting('default.currency'), 'currency_rate' => '1', 'notes' => $faker->text(5), - 'category_id' => $company->categories()->type('income')->get()->random(1)->pluck('id')->first(), + 'category_id' => $company->categories()->income()->get()->random(1)->pluck('id')->first(), 'contact_id' => $contact->id, 'contact_name' => $contact->name, 'contact_email' => $contact->email, diff --git a/database/factories/Item.php b/database/factories/Item.php index d61ccaf77..61664c320 100644 --- a/database/factories/Item.php +++ b/database/factories/Item.php @@ -16,7 +16,7 @@ $factory->define(Item::class, function (Faker $faker) use ($company) { 'description' => $faker->text(100), 'purchase_price' => $faker->randomFloat(2, 10, 20), 'sale_price' => $faker->randomFloat(2, 10, 20), - 'category_id' => $company->categories()->type('item')->get()->random(1)->pluck('id')->first(), + 'category_id' => $company->categories()->item()->get()->random(1)->pluck('id')->first(), 'tax_id' => null, 'enabled' => $faker->boolean ? 1 : 0, ]; diff --git a/database/factories/Transaction.php b/database/factories/Transaction.php index 3a5a85a58..2bdc0c6ff 100644 --- a/database/factories/Transaction.php +++ b/database/factories/Transaction.php @@ -31,13 +31,13 @@ $factory->define(Transaction::class, function (Faker $faker) use ($company) { $factory->state(Transaction::class, 'income', function (Faker $faker) use ($company) { return [ 'type' => 'income', - 'category_id' => $company->categories()->type('income')->get()->random(1)->pluck('id')->first(), + 'category_id' => $company->categories()->income()->get()->random(1)->pluck('id')->first(), ]; }); $factory->state(Transaction::class, 'expense', function (Faker $faker) use ($company) { return [ 'type' => 'expense', - 'category_id' => $company->categories()->type('expense')->get()->random(1)->pluck('id')->first(), + 'category_id' => $company->categories()->expense()->get()->random(1)->pluck('id')->first(), ]; });