diff --git a/app/Abstracts/DocumentModel.php b/app/Abstracts/DocumentModel.php index 3fe0a2d78..c23263c11 100644 --- a/app/Abstracts/DocumentModel.php +++ b/app/Abstracts/DocumentModel.php @@ -171,7 +171,7 @@ abstract class DocumentModel extends Model { $amount = $this->amount; - $this->totals()->where('code', 'tax')->each(function ($tax) use(&$amount) { + collect($this->totals)->where('code', 'tax')->each(function ($tax) use(&$amount) { $amount -= $tax->amount; }); diff --git a/app/Http/Controllers/Common/Items.php b/app/Http/Controllers/Common/Items.php index a33e42bda..b08400940 100644 --- a/app/Http/Controllers/Common/Items.php +++ b/app/Http/Controllers/Common/Items.php @@ -28,7 +28,7 @@ class Items extends Controller */ public function index() { - $items = Item::with(['category', 'tax'])->collect(); + $items = Item::with('category')->collect(); return view('common.items.index', compact('items')); } diff --git a/app/Http/Controllers/Purchases/Bills.php b/app/Http/Controllers/Purchases/Bills.php index bf3061883..8683c7f6d 100644 --- a/app/Http/Controllers/Purchases/Bills.php +++ b/app/Http/Controllers/Purchases/Bills.php @@ -37,7 +37,7 @@ class Bills extends Controller */ public function index() { - $bills = Bill::with(['contact', 'items', 'histories', 'transactions'])->collect(['billed_at'=> 'desc']); + $bills = Bill::with('contact')->collect(['billed_at'=> 'desc']); $vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id'); diff --git a/app/Http/Controllers/Purchases/Payments.php b/app/Http/Controllers/Purchases/Payments.php index 95cdd672a..0c8c47783 100644 --- a/app/Http/Controllers/Purchases/Payments.php +++ b/app/Http/Controllers/Purchases/Payments.php @@ -30,7 +30,7 @@ class Payments extends Controller */ public function index() { - $payments = Transaction::expense()->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']); + $payments = Transaction::with(['account', 'category', 'contact'])->expense()->isNotTransfer()->collect(['paid_at'=> 'desc']); $vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id'); diff --git a/app/Http/Controllers/Sales/Invoices.php b/app/Http/Controllers/Sales/Invoices.php index 7af09cee0..02d84a29e 100644 --- a/app/Http/Controllers/Sales/Invoices.php +++ b/app/Http/Controllers/Sales/Invoices.php @@ -38,7 +38,7 @@ class Invoices extends Controller */ public function index() { - $invoices = Invoice::with(['contact', 'items', 'histories', 'transactions'])->collect(['invoice_number'=> 'desc']); + $invoices = Invoice::with('contact')->collect(['invoice_number'=> 'desc']); $customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id'); diff --git a/app/Http/Controllers/Sales/Revenues.php b/app/Http/Controllers/Sales/Revenues.php index 5eed29da2..3a4b5927b 100644 --- a/app/Http/Controllers/Sales/Revenues.php +++ b/app/Http/Controllers/Sales/Revenues.php @@ -30,7 +30,7 @@ class Revenues extends Controller */ public function index() { - $revenues = Transaction::income()->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']); + $revenues = Transaction::with(['account', 'category', 'contact'])->income()->isNotTransfer()->collect(['paid_at'=> 'desc']); $customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id'); diff --git a/app/Reports/ExpenseSummary.php b/app/Reports/ExpenseSummary.php index 1c1069e27..ac1a8e1c2 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::expense()->isNotTransfer(), ['date_field' => 'paid_at']); + $transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']); switch ($this->model->settings->basis) { case 'cash': @@ -41,7 +41,7 @@ class ExpenseSummary extends Report break; default: // Bills - $bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get(); + $bills = $this->applyFilters(Bill::with(['recurring', 'transactions'])->accrued(), ['date_field' => 'billed_at'])->get(); Recurring::reflect($bills, 'billed_at'); $this->setTotals($bills, 'billed_at'); diff --git a/app/Reports/IncomeExpenseSummary.php b/app/Reports/IncomeExpenseSummary.php index 19abe176d..149c2c31a 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::income()->isNotTransfer(), ['date_field' => 'paid_at']); - $expense_transactions = $this->applyFilters(Transaction::expense()->isNotTransfer(), ['date_field' => 'paid_at']); + $income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']); + $expense_transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']); switch ($this->model->settings->basis) { case 'cash': @@ -32,7 +32,7 @@ class IncomeExpenseSummary extends Report break; default: // Invoices - $invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get(); + $invoices = $this->applyFilters(Invoice::with(['recurring', 'transactions'])->accrued(), ['date_field' => 'invoiced_at'])->get(); Recurring::reflect($invoices, 'invoiced_at'); $this->setTotals($invoices, 'invoiced_at', true); @@ -42,7 +42,7 @@ class IncomeExpenseSummary extends Report $this->setTotals($revenues, 'paid_at', true); // Bills - $bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get(); + $bills = $this->applyFilters(Bill::with(['recurring', 'transactions'])->accrued(), ['date_field' => 'billed_at'])->get(); Recurring::reflect($bills, 'bill', 'billed_at'); $this->setTotals($bills, 'billed_at', true); diff --git a/app/Reports/IncomeSummary.php b/app/Reports/IncomeSummary.php index 5bde4b9d8..4f8b2f513 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::income()->isNotTransfer(), ['date_field' => 'paid_at']); + $transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']); switch ($this->model->settings->basis) { case 'cash': @@ -41,7 +41,7 @@ class IncomeSummary extends Report break; default: // Invoices - $invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get(); + $invoices = $this->applyFilters(Invoice::with(['recurring', 'transactions'])->accrued(), ['date_field' => 'invoiced_at'])->get(); Recurring::reflect($invoices, 'invoiced_at'); $this->setTotals($invoices, 'invoiced_at'); diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index cf55d9f27..3365ec3db 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -35,8 +35,8 @@ class ProfitLoss extends Report public function setData() { - $income_transactions = $this->applyFilters(Transaction::income()->isNotTransfer(), ['date_field' => 'paid_at']); - $expense_transactions = $this->applyFilters(Transaction::expense()->isNotTransfer(), ['date_field' => 'paid_at']); + $income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']); + $expense_transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']); switch ($this->model->settings->basis) { case 'cash': @@ -51,7 +51,7 @@ class ProfitLoss extends Report break; default: // Invoices - $invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get(); + $invoices = $this->applyFilters(Invoice::with(['recurring', 'transactions', 'totals'])->accrued(), ['date_field' => 'invoiced_at'])->get(); Recurring::reflect($invoices, 'invoiced_at'); $this->setTotals($invoices, 'invoiced_at', true, $this->tables['income'], false); @@ -61,7 +61,7 @@ class ProfitLoss extends Report $this->setTotals($revenues, 'paid_at', true, $this->tables['income'], false); // Bills - $bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get(); + $bills = $this->applyFilters(Bill::with(['recurring', 'transactions', 'totals'])->accrued(), ['date_field' => 'billed_at'])->get(); Recurring::reflect($bills, 'bill', 'billed_at'); $this->setTotals($bills, 'billed_at', true, $this->tables['expense'], false); diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index f9dc3dca9..f9f62123a 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -42,22 +42,22 @@ class TaxSummary extends Report switch ($this->model->settings->basis) { case 'cash': // Invoice Payments - $invoices = $this->applyFilters(Transaction::with(['invoice', 'invoice.totals'])->income()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get(); + $invoices = $this->applyFilters(Transaction::with(['recurring', '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'])->expense()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get(); + $bills = $this->applyFilters(Transaction::with(['recurring', 'bill', 'bill.totals'])->expense()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get(); $this->setTotals($bills, 'paid_at'); break; default: // Invoices - $invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get(); + $invoices = $this->applyFilters(Invoice::with(['recurring', 'transactions', 'totals'])->accrued(), ['date_field' => 'invoiced_at'])->get(); Recurring::reflect($invoices, 'invoiced_at'); $this->setTotals($invoices, 'invoiced_at'); // Bills - $bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get(); + $bills = $this->applyFilters(Bill::with(['recurring', 'transactions', 'totals'])->accrued(), ['date_field' => 'billed_at'])->get(); Recurring::reflect($bills, 'billed_at'); $this->setTotals($bills, 'billed_at');