mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Improve tax report #1351
This commit is contained in:
parent
c2bf1b6a04
commit
556a90c8ef
@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Ninja\Reports;
|
namespace App\Ninja\Reports;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use Auth;
|
||||||
|
|
||||||
class TaxRateReport extends AbstractReport
|
class TaxRateReport extends AbstractReport
|
||||||
{
|
{
|
||||||
public $columns = [
|
public $columns = [
|
||||||
|
'invoice',
|
||||||
'tax_name',
|
'tax_name',
|
||||||
'tax_rate',
|
'tax_rate',
|
||||||
'amount',
|
'amount',
|
||||||
@ -21,19 +22,22 @@ class TaxRateReport extends AbstractReport
|
|||||||
$clients = Client::scope()
|
$clients = Client::scope()
|
||||||
->withArchived()
|
->withArchived()
|
||||||
->with('contacts')
|
->with('contacts')
|
||||||
->with(['invoices' => function($query) {
|
->with(['invoices' => function ($query) {
|
||||||
$query->with('invoice_items')->withArchived();
|
$query->with('invoice_items')
|
||||||
|
->withArchived()
|
||||||
|
->invoices()
|
||||||
|
->where('is_public', '=', true);
|
||||||
if ($this->options['date_field'] == FILTER_INVOICE_DATE) {
|
if ($this->options['date_field'] == FILTER_INVOICE_DATE) {
|
||||||
$query->where('invoice_date', '>=', $this->startDate)
|
$query->where('invoice_date', '>=', $this->startDate)
|
||||||
->where('invoice_date', '<=', $this->endDate)
|
->where('invoice_date', '<=', $this->endDate)
|
||||||
->with('payments');
|
->with('payments');
|
||||||
} else {
|
} else {
|
||||||
$query->whereHas('payments', function($query) {
|
$query->whereHas('payments', function ($query) {
|
||||||
$query->where('payment_date', '>=', $this->startDate)
|
$query->where('payment_date', '>=', $this->startDate)
|
||||||
->where('payment_date', '<=', $this->endDate)
|
->where('payment_date', '<=', $this->endDate)
|
||||||
->withArchived();
|
->withArchived();
|
||||||
})
|
})
|
||||||
->with(['payments' => function($query) {
|
->with(['payments' => function ($query) {
|
||||||
$query->where('payment_date', '>=', $this->startDate)
|
$query->where('payment_date', '>=', $this->startDate)
|
||||||
->where('payment_date', '<=', $this->endDate)
|
->where('payment_date', '<=', $this->endDate)
|
||||||
->withArchived();
|
->withArchived();
|
||||||
@ -43,13 +47,12 @@ class TaxRateReport extends AbstractReport
|
|||||||
|
|
||||||
foreach ($clients->get() as $client) {
|
foreach ($clients->get() as $client) {
|
||||||
$currencyId = $client->currency_id ?: Auth::user()->account->getCurrencyId();
|
$currencyId = $client->currency_id ?: Auth::user()->account->getCurrencyId();
|
||||||
$amount = 0;
|
|
||||||
$paid = 0;
|
|
||||||
$taxTotals = [];
|
|
||||||
|
|
||||||
foreach ($client->invoices as $invoice) {
|
foreach ($client->invoices as $invoice) {
|
||||||
|
$taxTotals = [];
|
||||||
|
|
||||||
foreach ($invoice->getTaxes(true) as $key => $tax) {
|
foreach ($invoice->getTaxes(true) as $key => $tax) {
|
||||||
if ( ! isset($taxTotals[$currencyId])) {
|
if (! isset($taxTotals[$currencyId])) {
|
||||||
$taxTotals[$currencyId] = [];
|
$taxTotals[$currencyId] = [];
|
||||||
}
|
}
|
||||||
if (isset($taxTotals[$currencyId][$key])) {
|
if (isset($taxTotals[$currencyId][$key])) {
|
||||||
@ -60,22 +63,20 @@ class TaxRateReport extends AbstractReport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount += $invoice->amount;
|
foreach ($taxTotals as $currencyId => $taxes) {
|
||||||
$paid += $invoice->getAmountPaid();
|
foreach ($taxes as $tax) {
|
||||||
}
|
$this->data[] = [
|
||||||
|
$invoice->present()->link,
|
||||||
|
$tax['name'],
|
||||||
|
$tax['rate'] . '%',
|
||||||
|
$account->formatMoney($tax['amount'], $client),
|
||||||
|
$account->formatMoney($tax['paid'], $client),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($taxTotals as $currencyId => $taxes) {
|
$this->addToTotals($client->currency_id, 'amount', $invoice->amount);
|
||||||
foreach ($taxes as $tax) {
|
$this->addToTotals($client->currency_id, 'paid', $invoice->getAmountPaid());
|
||||||
$this->data[] = [
|
|
||||||
$tax['name'],
|
|
||||||
$tax['rate'] . '%',
|
|
||||||
$account->formatMoney($tax['amount'], $client),
|
|
||||||
$account->formatMoney($tax['paid'], $client)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addToTotals($client->currency_id, 'amount', $tax['amount']);
|
|
||||||
$this->addToTotals($client->currency_id, 'paid', $tax['paid']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user