diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 653e5d9b6739..40ef4bba2344 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -1279,7 +1279,7 @@ class Utils $tax1 = round($amount * $taxRate1 / 100, 2); $tax2 = round($amount * $taxRate2 / 100, 2); - return round($amount + $tax1 + $tax2, 2); + return round($tax1 + $tax2, 2); } public static function roundSignificant($value, $precision = 2) { diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 1dc81d2c381e..395a81cfae20 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -253,6 +253,11 @@ class Expense extends EntityModel } public function amountWithTax() + { + return $this->amount + $this->taxAmount(); + } + + public function taxAmount() { return Utils::calculateTaxes($this->amount, $this->tax_rate1, $this->tax_rate2); } diff --git a/app/Models/RecurringExpense.php b/app/Models/RecurringExpense.php index 04703e916104..8eb8b6c6f374 100644 --- a/app/Models/RecurringExpense.php +++ b/app/Models/RecurringExpense.php @@ -129,7 +129,7 @@ class RecurringExpense extends EntityModel public function amountWithTax() { - return Utils::calculateTaxes($this->amount, $this->tax_rate1, $this->tax_rate2); + return $this->amount + Utils::calculateTaxes($this->amount, $this->tax_rate1, $this->tax_rate2); } } diff --git a/app/Ninja/Datatables/ExpenseDatatable.php b/app/Ninja/Datatables/ExpenseDatatable.php index 620366c21ccc..45e277e15455 100644 --- a/app/Ninja/Datatables/ExpenseDatatable.php +++ b/app/Ninja/Datatables/ExpenseDatatable.php @@ -59,7 +59,7 @@ class ExpenseDatatable extends EntityDatatable [ 'amount', function ($model) { - $amount = Utils::calculateTaxes($model->amount, $model->tax_rate1, $model->tax_rate2); + $amount = $model->amount + Utils::calculateTaxes($model->amount, $model->tax_rate1, $model->tax_rate2); $str = Utils::formatMoney($amount, $model->expense_currency_id); // show both the amount and the converted amount diff --git a/app/Ninja/Datatables/RecurringExpenseDatatable.php b/app/Ninja/Datatables/RecurringExpenseDatatable.php index e8a1311595d2..3117e1cec558 100644 --- a/app/Ninja/Datatables/RecurringExpenseDatatable.php +++ b/app/Ninja/Datatables/RecurringExpenseDatatable.php @@ -70,7 +70,7 @@ class RecurringExpenseDatatable extends EntityDatatable [ 'amount', function ($model) { - $amount = Utils::calculateTaxes($model->amount, $model->tax_rate1, $model->tax_rate2); + $amount = $model->amount + Utils::calculateTaxes($model->amount, $model->tax_rate1, $model->tax_rate2); $str = Utils::formatMoney($amount, $model->expense_currency_id); /* diff --git a/app/Ninja/Presenters/ExpensePresenter.php b/app/Ninja/Presenters/ExpensePresenter.php index fda0104bf3c7..2cac47973ddd 100644 --- a/app/Ninja/Presenters/ExpensePresenter.php +++ b/app/Ninja/Presenters/ExpensePresenter.php @@ -41,7 +41,12 @@ class ExpensePresenter extends EntityPresenter public function amount() { - return Utils::formatMoney($this->entity->amount, $this->entity->expense_currency_id); + return Utils::formatMoney($this->entity->amountWithTax(), $this->entity->expense_currency_id); + } + + public function taxAmount() + { + return Utils::formatMoney($this->entity->taxAmount(), $this->entity->expense_currency_id); } public function category() diff --git a/app/Ninja/Reports/ActivityReport.php b/app/Ninja/Reports/ActivityReport.php index 3ad95f292545..cf4e9dce9359 100644 --- a/app/Ninja/Reports/ActivityReport.php +++ b/app/Ninja/Reports/ActivityReport.php @@ -10,10 +10,10 @@ class ActivityReport extends AbstractReport public function getColumns() { return [ - 'date', - 'client', - 'user', - 'activity', + 'date' => [], + 'client' => [], + 'user' => [], + 'activity' => [], ]; } diff --git a/app/Ninja/Reports/AgingReport.php b/app/Ninja/Reports/AgingReport.php index 1b82cceaaf31..0b4a3ada5881 100644 --- a/app/Ninja/Reports/AgingReport.php +++ b/app/Ninja/Reports/AgingReport.php @@ -10,13 +10,13 @@ class AgingReport extends AbstractReport public function getColumns() { return [ - 'client', - 'invoice_number', - 'invoice_date', - 'due_date', - 'age', - 'amount', - 'balance', + 'client' => [], + 'invoice_number' => [], + 'invoice_date' => [], + 'due_date' => [], + 'age' => [], + 'amount' => [], + 'balance' => [], ]; } diff --git a/app/Ninja/Reports/ClientReport.php b/app/Ninja/Reports/ClientReport.php index f3e5b9be07f0..08e8f71d6c8d 100644 --- a/app/Ninja/Reports/ClientReport.php +++ b/app/Ninja/Reports/ClientReport.php @@ -10,10 +10,10 @@ class ClientReport extends AbstractReport public function getColumns() { $columns = [ - 'client', - 'amount', - 'paid', - 'balance', + 'client' => [], + 'amount' => [], + 'paid' => [], + 'balance' => [], 'public_notes' => ['columnSelector-false'], 'private_notes' => ['columnSelector-false'], ]; diff --git a/app/Ninja/Reports/DocumentReport.php b/app/Ninja/Reports/DocumentReport.php index c131ae73f8ab..cbdbb426b663 100644 --- a/app/Ninja/Reports/DocumentReport.php +++ b/app/Ninja/Reports/DocumentReport.php @@ -11,10 +11,10 @@ class DocumentReport extends AbstractReport public function getColumns() { return [ - 'document', - 'client', - 'invoice_or_expense', - 'date', + 'document' => [], + 'client' => [], + 'invoice_or_expense' => [], + 'date' => [], ]; } diff --git a/app/Ninja/Reports/ExpenseReport.php b/app/Ninja/Reports/ExpenseReport.php index 30888c64019b..9a46f9cd8831 100644 --- a/app/Ninja/Reports/ExpenseReport.php +++ b/app/Ninja/Reports/ExpenseReport.php @@ -12,11 +12,12 @@ class ExpenseReport extends AbstractReport public function getColumns() { return [ - 'vendor', - 'client', - 'date', - 'category', - 'amount', + 'vendor' => [], + 'client' => [], + 'date' => [], + 'category' => [], + 'amount' => [], + 'tax' => ['columnSelector-false'], 'public_notes' => ['columnSelector-false'], 'private_notes' => ['columnSelector-false'], ]; @@ -35,7 +36,7 @@ class ExpenseReport extends AbstractReport $expenses = Expense::scope() ->orderBy('expense_date', 'desc') ->withArchived() - ->with('client.contacts', 'vendor') + ->with('client.contacts', 'vendor', 'expense_category') ->where('expense_date', '>=', $this->startDate) ->where('expense_date', '<=', $this->endDate); @@ -62,6 +63,7 @@ class ExpenseReport extends AbstractReport $this->isExport ? $expense->present()->expense_date : link_to($expense->present()->url, $expense->present()->expense_date), $expense->present()->category, Utils::formatMoney($amount, $expense->currency_id), + $expense->present()->taxAmount, $expense->public_notes, $expense->private_notes, ]; diff --git a/app/Ninja/Reports/InvoiceReport.php b/app/Ninja/Reports/InvoiceReport.php index a7a2aac79610..fbc0ae7d522e 100644 --- a/app/Ninja/Reports/InvoiceReport.php +++ b/app/Ninja/Reports/InvoiceReport.php @@ -11,14 +11,14 @@ class InvoiceReport extends AbstractReport public function getColumns() { $columns = [ - 'client', - 'invoice_number', - 'invoice_date', - 'amount', - 'status', - 'payment_date', - 'paid', - 'method', + 'client' => [], + 'invoice_number' => [], + 'invoice_date' => [], + 'amount' => [], + 'status' => [], + 'payment_date' => [], + 'paid' => [], + 'method' => [], 'private_notes' => ['columnSelector-false'], ]; diff --git a/app/Ninja/Reports/PaymentReport.php b/app/Ninja/Reports/PaymentReport.php index dab9f779d094..19eb19072f02 100644 --- a/app/Ninja/Reports/PaymentReport.php +++ b/app/Ninja/Reports/PaymentReport.php @@ -11,13 +11,13 @@ class PaymentReport extends AbstractReport public function getColumns() { return [ - 'client', - 'invoice_number', - 'invoice_date', - 'amount', - 'payment_date', - 'paid', - 'method', + 'client' => [], + 'invoice_number' => [], + 'invoice_date' => [], + 'amount' => [], + 'payment_date' => [], + 'paid' => [], + 'method' => [], 'private_notes' => ['columnSelector-false'], ]; } diff --git a/app/Ninja/Reports/ProductReport.php b/app/Ninja/Reports/ProductReport.php index da6ea7e8deec..cc18997cc735 100644 --- a/app/Ninja/Reports/ProductReport.php +++ b/app/Ninja/Reports/ProductReport.php @@ -11,13 +11,13 @@ class ProductReport extends AbstractReport public function getColumns() { $columns = [ - 'client', - 'invoice_number', - 'invoice_date', - 'product', - 'description', - 'qty', - 'cost', + 'client' => [], + 'invoice_number' => [], + 'invoice_date' => [], + 'product' => [], + 'description' => [], + 'qty' => [], + 'cost' => [], //'tax_rate1', //'tax_rate2', ]; diff --git a/app/Ninja/Reports/ProfitAndLossReport.php b/app/Ninja/Reports/ProfitAndLossReport.php index 14f1b97b2721..fd2372d96531 100644 --- a/app/Ninja/Reports/ProfitAndLossReport.php +++ b/app/Ninja/Reports/ProfitAndLossReport.php @@ -11,11 +11,11 @@ class ProfitAndLossReport extends AbstractReport public function getColumns() { return [ - 'type', - 'client', - 'amount', - 'date', - 'notes', + 'type' => [], + 'client' => [], + 'amount' => [], + 'date' => [], + 'notes' => [], ]; } @@ -68,8 +68,8 @@ class ProfitAndLossReport extends AbstractReport ]; $this->addToTotals($expense->expense_currency_id, 'revenue', 0, $expense->present()->month); - $this->addToTotals($expense->expense_currency_id, 'expenses', $expense->amount, $expense->present()->month); - $this->addToTotals($expense->expense_currency_id, 'profit', $expense->amount * -1, $expense->present()->month); + $this->addToTotals($expense->expense_currency_id, 'expenses', $expense->amountWithTax(), $expense->present()->month); + $this->addToTotals($expense->expense_currency_id, 'profit', $expense->amountWithTax() * -1, $expense->present()->month); } //$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0); diff --git a/app/Ninja/Reports/QuoteReport.php b/app/Ninja/Reports/QuoteReport.php index 64f300bd8335..b19479c46f56 100644 --- a/app/Ninja/Reports/QuoteReport.php +++ b/app/Ninja/Reports/QuoteReport.php @@ -11,11 +11,11 @@ class QuoteReport extends AbstractReport public function getColumns() { $columns = [ - 'client', - 'quote_number', - 'quote_date', - 'amount', - 'status', + 'client' => [], + 'quote_number' => [], + 'quote_date' => [], + 'amount' => [], + 'status' => [], 'private_notes' => ['columnSelector-false'], ]; diff --git a/app/Ninja/Reports/TaskReport.php b/app/Ninja/Reports/TaskReport.php index 4c5e2faf142b..37c364cd1cff 100644 --- a/app/Ninja/Reports/TaskReport.php +++ b/app/Ninja/Reports/TaskReport.php @@ -10,12 +10,12 @@ class TaskReport extends AbstractReport public function getColumns() { return [ - 'client', - 'date', - 'project', - 'description', - 'duration', - 'amount', + 'client' => [], + 'date' => [], + 'project' => [], + 'description' => [], + 'duration' => [], + 'amount' => [], ]; } diff --git a/app/Ninja/Reports/TaxRateReport.php b/app/Ninja/Reports/TaxRateReport.php index ff1d05a56599..f4005134091b 100644 --- a/app/Ninja/Reports/TaxRateReport.php +++ b/app/Ninja/Reports/TaxRateReport.php @@ -10,12 +10,12 @@ class TaxRateReport extends AbstractReport public function getColumns() { return [ - 'client', - 'invoice', - 'tax_name', - 'tax_rate', - 'tax_amount', - 'tax_paid', + 'client' => [], + 'invoice' => [], + 'tax_name' => [], + 'tax_rate' => [], + 'tax_amount' => [], + 'tax_paid' => [], 'invoice_amount' => ['columnSelector-false'], 'payment_amount' => ['columnSelector-false'], ]; diff --git a/resources/views/reports/report_builder.blade.php b/resources/views/reports/report_builder.blade.php index 7df0c1b8bf8a..e985535f89f6 100644 --- a/resources/views/reports/report_builder.blade.php +++ b/resources/views/reports/report_builder.blade.php @@ -445,10 +445,10 @@ } var sumColumns = []; - @foreach ($columns as $column) - sumColumns.push("{{ in_array($column, ['amount', 'paid', 'balance', 'cost', 'duration']) ? trans("texts.{$column}") : false }}"); + @foreach ($columns as $column => $class) + sumColumns.push("{{ in_array($column, ['amount', 'paid', 'balance', 'cost', 'duration', 'tax']) ? trans("texts.{$column}") : false }}"); @endforeach - + console.log(sumColumns); $(function() { $('.start_date .input-group-addon').click(function() { toggleDatePicker('start_date');