diff --git a/app/Http/Controllers/Reports/TaxSummary.php b/app/Http/Controllers/Reports/TaxSummary.php
new file mode 100644
index 000000000..ac81ec6e6
--- /dev/null
+++ b/app/Http/Controllers/Reports/TaxSummary.php
@@ -0,0 +1,139 @@
+where('rate', '<>', '0')->pluck('name')->toArray();
+
+ $taxes = array_combine($t, $t);
+
+ // Get year
+ $year = request('year');
+ if (empty($year)) {
+ $year = Date::now()->year;
+ }
+
+ // Dates
+ for ($j = 1; $j <= 12; $j++) {
+ $dates[$j] = Date::parse($year . '-' . $j)->format('M');
+
+ foreach ($taxes as $tax_name) {
+ $incomes[$tax_name][$dates[$j]] = [
+ 'amount' => 0,
+ 'currency_code' => setting('general.default_currency'),
+ 'currency_rate' => 1,
+ ];
+
+ $expenses[$tax_name][$dates[$j]] = [
+ 'amount' => 0,
+ 'currency_code' => setting('general.default_currency'),
+ 'currency_rate' => 1,
+ ];
+
+ $totals[$tax_name][$dates[$j]] = [
+ 'amount' => 0,
+ 'currency_code' => setting('general.default_currency'),
+ 'currency_rate' => 1,
+ ];
+ }
+ }
+
+ switch ($status) {
+ case 'paid':
+ // Invoices
+ $invoices = InvoicePayment::monthsOfYear('paid_at')->get();
+ $this->setAmount($incomes, $totals, $invoices, 'invoice', 'paid_at');
+ // Bills
+ $bills = BillPayment::monthsOfYear('paid_at')->get();
+ $this->setAmount($expenses, $totals, $bills, 'bill', 'paid_at');
+ break;
+ case 'upcoming':
+ // Invoices
+ $invoices = Invoice::accrued()->monthsOfYear('due_at')->get();
+ $this->setAmount($incomes, $totals, $invoices, 'invoice', 'due_at');
+ // Bills
+ $bills = Bill::accrued()->monthsOfYear('due_at')->get();
+ $this->setAmount($expenses, $totals, $bills, 'bill', 'due_at');
+ break;
+ default:
+ // Invoices
+ $invoices = Invoice::accrued()->monthsOfYear('invoiced_at')->get();
+ $this->setAmount($incomes, $totals, $invoices, 'invoice', 'invoiced_at');
+ // Bills
+ $bills = Bill::accrued()->monthsOfYear('billed_at')->get();
+ $this->setAmount($expenses, $totals, $bills, 'bill', 'billed_at');
+ break;
+ }
+
+ // Check if it's a print or normal request
+ if (request('print')) {
+ $view_template = 'reports.tax_summary.print';
+ } else {
+ $view_template = 'reports.tax_summary.index';
+ }
+
+ return view($view_template, compact('dates', 'taxes', 'incomes', 'expenses', 'totals'));
+ }
+
+ private function setAmount(&$items, &$totals, $rows, $type, $date_field)
+ {
+ foreach ($rows as $row) {
+ $date = Date::parse($row->$date_field)->format('M');
+
+ if ($date_field == 'paid_at') {
+ if (!$row->invoice instanceof Invoice) {
+ continue;
+ }
+
+ $row_totals = $row->invoice->totals;
+ } else {
+ $row_totals = $row->totals;
+ }
+
+ foreach ($row_totals as $row_total) {
+ if ($row_total->code != 'tax') {
+ continue;
+ }
+
+ if (!isset($items[$row_total->name])) {
+ continue;
+ }
+
+ $amount = $this->convert($row_total->amount, $row->currency_code, $row->currency_rate);
+
+ $items[$row_total->name][$date]['amount'] += $amount;
+
+ if ($type == 'invoice') {
+ $totals[$row_total->name][$date]['amount'] += $amount;
+ } else {
+ $totals[$row_total->name][$date]['amount'] -= $amount;
+ }
+ }
+ }
+ }
+}
diff --git a/app/Http/Middleware/AdminMenu.php b/app/Http/Middleware/AdminMenu.php
index 3d58d2516..c16c1ed19 100644
--- a/app/Http/Middleware/AdminMenu.php
+++ b/app/Http/Middleware/AdminMenu.php
@@ -111,7 +111,13 @@ class AdminMenu
}
// Reports
- if ($user->can(['read-reports-income-summary', 'read-reports-expense-summary', 'read-reports-income-expense-summary', 'read-reports-profit-loss'])) {
+ if ($user->can([
+ 'read-reports-income-summary',
+ 'read-reports-expense-summary',
+ 'read-reports-income-expense-summary',
+ 'read-reports-tax-summary',
+ 'read-reports-profit-loss',
+ ])) {
$menu->dropdown(trans_choice('general.reports', 2), function ($sub) use($user, $attr) {
if ($user->can('read-reports-income-summary')) {
$sub->url('reports/income-summary', trans('reports.summary.income'), 1, $attr);
@@ -125,8 +131,12 @@ class AdminMenu
$sub->url('reports/income-expense-summary', trans('reports.summary.income_expense'), 3, $attr);
}
+ if ($user->can('read-reports-tax-summary')) {
+ $sub->url('reports/tax-summary', trans('reports.summary.tax'), 4, $attr);
+ }
+
if ($user->can('read-reports-profit-loss')) {
- $sub->url('reports/profit-loss', trans('reports.profit_loss'), 4, $attr);
+ $sub->url('reports/profit-loss', trans('reports.profit_loss'), 5, $attr);
}
}, 6, [
'title' => trans_choice('general.reports', 2),
diff --git a/app/Listeners/Updates/Version120.php b/app/Listeners/Updates/Version120.php
index 0ef59c704..41ea4942c 100644
--- a/app/Listeners/Updates/Version120.php
+++ b/app/Listeners/Updates/Version120.php
@@ -25,8 +25,17 @@ class Version120 extends Listener
return;
}
- // Create permission
- $permission = Permission::firstOrCreate([
+ $permissions = [];
+
+ // Create tax summary permission
+ $permissions[] = Permission::firstOrCreate([
+ 'name' => 'read-reports-tax-summary',
+ 'display_name' => 'Read Reports Tax Summary',
+ 'description' => 'Read Reports Tax Summary',
+ ]);
+
+ // Create profit loss permission
+ $permissions[] = Permission::firstOrCreate([
'name' => 'read-reports-profit-loss',
'display_name' => 'Read Reports Profit Loss',
'description' => 'Read Reports Profit Loss',
@@ -42,7 +51,9 @@ class Version120 extends Listener
continue;
}
- $role->attachPermission($permission);
+ foreach ($permissions as $permission) {
+ $role->attachPermission($permission);
+ }
}
}
}
diff --git a/database/seeds/Roles.php b/database/seeds/Roles.php
index e1553089f..3e0932bab 100644
--- a/database/seeds/Roles.php
+++ b/database/seeds/Roles.php
@@ -62,6 +62,7 @@ class Roles extends Seeder
'reports-expense-summary' => 'r',
'reports-income-expense-summary' => 'r',
'reports-profit-loss' => 'r',
+ 'reports-tax-summary' => 'r',
],
'manager' => [
'admin-panel' => 'r',
@@ -89,6 +90,7 @@ class Roles extends Seeder
'reports-expense-summary' => 'r',
'reports-income-expense-summary' => 'r',
'reports-profit-loss' => 'r',
+ 'reports-tax-summary' => 'r',
],
'customer' => [
'customer-panel' => 'r',
diff --git a/resources/lang/en-GB/reports.php b/resources/lang/en-GB/reports.php
index a0e8c53e0..a0e1f3a5b 100644
--- a/resources/lang/en-GB/reports.php
+++ b/resources/lang/en-GB/reports.php
@@ -11,11 +11,13 @@ return [
'gross_profit' => 'Gross Profit',
'net_profit' => 'Net Profit',
'total_expenses' => 'Total Expenses',
+ 'net' => 'NET',
'summary' => [
'income' => 'Income Summary',
'expense' => 'Expense Summary',
'income_expense' => 'Income vs Expense',
+ 'tax' => 'Tax Summary',
],
'quarter' => [
diff --git a/resources/views/reports/tax_summary/body.blade.php b/resources/views/reports/tax_summary/body.blade.php
new file mode 100644
index 000000000..59695a1e2
--- /dev/null
+++ b/resources/views/reports/tax_summary/body.blade.php
@@ -0,0 +1,57 @@
+
+
+
+
+
+ |
+ @foreach($dates as $date)
+ {{ $date }} |
+ @endforeach
+
+
+
+ @if ($taxes)
+ @foreach($taxes as $tax_name)
+
+
+
+ {{ $tax_name }} |
+
+
+
+
+ {{ trans_choice('general.incomes', 2) }} |
+ @foreach($incomes[$tax_name] as $tax_date)
+ @money($tax_date['amount'], $tax_date['currency_code'], true) |
+ @endforeach
+
+
+ {{ trans_choice('general.expenses', 2) }} |
+ @foreach($expenses[$tax_name] as $tax_date)
+ @money($tax_date['amount'], $tax_date['currency_code'], true) |
+ @endforeach
+
+
+
+
+ {{ trans('reports.net') }} |
+ @foreach($totals[$tax_name] as $tax_date)
+ @money($tax_date['amount'], $tax_date['currency_code'], true) |
+ @endforeach
+
+
+
+ @endforeach
+ @else
+
+
+
+
+ {{ trans('general.no_records') }}
+ |
+
+
+
+ @endif
+
+
\ No newline at end of file
diff --git a/resources/views/reports/tax_summary/index.blade.php b/resources/views/reports/tax_summary/index.blade.php
new file mode 100644
index 000000000..1cfbbcc09
--- /dev/null
+++ b/resources/views/reports/tax_summary/index.blade.php
@@ -0,0 +1,28 @@
+@extends('layouts.admin')
+
+@section('title', trans('reports.summary.tax'))
+
+@section('new_button')
+ {{ trans('general.print') }}
+@endsection
+
+@section('content')
+
+
+
+
+ @include('reports.tax_summary.body')
+
+
+@endsection
diff --git a/resources/views/reports/tax_summary/print.blade.php b/resources/views/reports/tax_summary/print.blade.php
new file mode 100644
index 000000000..4fc18a5f8
--- /dev/null
+++ b/resources/views/reports/tax_summary/print.blade.php
@@ -0,0 +1,15 @@
+@extends('layouts.print')
+
+@section('title', trans('reports.summary.tax'))
+
+@section('content')
+
+ @include('reports.tax_summary.body')
+@endsection
\ No newline at end of file
diff --git a/routes/web.php b/routes/web.php
index af481a340..8d3d90320 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -96,6 +96,7 @@ Route::group(['middleware' => 'language'], function () {
Route::resource('income-summary', 'Reports\IncomeSummary');
Route::resource('expense-summary', 'Reports\ExpenseSummary');
Route::resource('income-expense-summary', 'Reports\IncomeExpenseSummary');
+ Route::resource('tax-summary', 'Reports\TaxSummary');
Route::resource('profit-loss', 'Reports\ProfitLoss');
});