mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Updates for tax summary reports
This commit is contained in:
parent
9f1a035704
commit
283c3d4ead
@ -36,7 +36,6 @@ class TaxSummaryReport extends BaseExport
|
|||||||
|
|
||||||
public array $report_keys = [
|
public array $report_keys = [
|
||||||
'tax_name',
|
'tax_name',
|
||||||
// 'taxable_amount',
|
|
||||||
'tax_amount',
|
'tax_amount',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -70,6 +69,7 @@ class TaxSummaryReport extends BaseExport
|
|||||||
$this->csv->insertOne([]);
|
$this->csv->insertOne([]);
|
||||||
$this->csv->insertOne([ctrans('texts.tax_summary')]);
|
$this->csv->insertOne([ctrans('texts.tax_summary')]);
|
||||||
$this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]);
|
$this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]);
|
||||||
|
$this->csv->insertOne([ctrans('texts.date_range'),' ',$this->translateDate($this->input['start_date'], $this->company->date_format(), $this->company->locale()),' - ',$this->translateDate($this->input['end_date'], $this->company->date_format(), $this->company->locale())]);
|
||||||
|
|
||||||
if (count($this->input['report_keys']) == 0) {
|
if (count($this->input['report_keys']) == 0) {
|
||||||
$this->input['report_keys'] = $this->report_keys;
|
$this->input['report_keys'] = $this->report_keys;
|
||||||
@ -78,6 +78,8 @@ class TaxSummaryReport extends BaseExport
|
|||||||
$this->csv->insertOne($this->buildHeader());
|
$this->csv->insertOne($this->buildHeader());
|
||||||
|
|
||||||
$query = Invoice::query()
|
$query = Invoice::query()
|
||||||
|
->withTrashed()
|
||||||
|
->whereIn('status_id', [2,3,4])
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->orderBy('balance', 'desc');
|
->orderBy('balance', 'desc');
|
||||||
@ -85,33 +87,59 @@ class TaxSummaryReport extends BaseExport
|
|||||||
$query = $this->addDateRange($query);
|
$query = $this->addDateRange($query);
|
||||||
|
|
||||||
$query = $this->filterByClients($query);
|
$query = $this->filterByClients($query);
|
||||||
$map = [];
|
$accrual_map = [];
|
||||||
|
$cash_map = [];
|
||||||
|
|
||||||
foreach($query->cursor() as $invoice)
|
foreach($query->cursor() as $invoice)
|
||||||
{
|
{
|
||||||
|
$calc = $invoice->calc();
|
||||||
|
|
||||||
|
//Combine the line taxes with invoice taxes here to get a total tax amount
|
||||||
|
$taxes = array_merge($calc->getTaxMap()->merge($calc->getTotalTaxMap())->toArray());
|
||||||
|
|
||||||
$taxes = $invoice->calc()->getTaxMap();
|
//filter into two arrays for accrual + cash
|
||||||
|
|
||||||
foreach($taxes as $tax)
|
foreach($taxes as $tax)
|
||||||
{
|
{
|
||||||
$key = $tax['name'];
|
$key = $tax['name'];
|
||||||
|
|
||||||
if(!isset($map[$key])) {
|
if(!isset($accrual_map[$key])) {
|
||||||
$map[$key]['tax_amount'] = 0;
|
$accrual_map[$key]['tax_amount'] = 0;
|
||||||
// $map[$key]['taxable_amount'] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$map[$key]['tax_amount'] += $tax['total'];
|
$accrual_map[$key]['tax_amount'] += $tax['total'];
|
||||||
// $map[$key]['taxable_amount'] += $invoice->amount;
|
|
||||||
|
|
||||||
|
//cash
|
||||||
|
if(in_array($invoice->status_id, [Invoice::STATUS_PARTIAL,Invoice::STATUS_PAID])){
|
||||||
|
|
||||||
|
$key = $tax['name'];
|
||||||
|
|
||||||
|
if(!isset($cash_map[$key])) {
|
||||||
|
$cash_map[$key]['tax_amount'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($invoice->status_id == Invoice::STATUS_PAID)
|
||||||
|
$cash_map[$key]['tax_amount'] += $tax['total'];
|
||||||
|
else
|
||||||
|
$cash_map[$key]['tax_amount'] += (($invoice->amount - $invoice->balance) / $invoice->balance) * $tax['total'] ?? 0;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($map as $key => $value)
|
$this->csv->insertOne([]);
|
||||||
|
$this->csv->insertOne([ctrans('texts.cash_vs_accrual')]);
|
||||||
|
|
||||||
|
foreach($accrual_map as $key => $value)
|
||||||
{
|
{
|
||||||
$this->csv->insertOne([$key, Number::formatMoney($value['tax_amount'], $this->company)]);
|
$this->csv->insertOne([$key, Number::formatMoney($value['tax_amount'], $this->company)]);
|
||||||
// $this->csv->insertOne([$key, Number::formatMoney($value['taxable_amount'], $this->company), Number::formatMoney($value['tax_amount'], $this->company)]);
|
}
|
||||||
|
|
||||||
|
$this->csv->insertOne([]);
|
||||||
|
$this->csv->insertOne([ctrans('texts.cash_accounting')]);
|
||||||
|
|
||||||
|
foreach($cash_map as $key => $value) {
|
||||||
|
$this->csv->insertOne([$key, Number::formatMoney($value['tax_amount'], $this->company)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5159,6 +5159,7 @@ $LANG = array(
|
|||||||
'view_dashboard_permission' => 'Allow user to access the dashboard, data is limited to available permissions',
|
'view_dashboard_permission' => 'Allow user to access the dashboard, data is limited to available permissions',
|
||||||
'marked_sent_credits' => 'Successfully marked credits sent',
|
'marked_sent_credits' => 'Successfully marked credits sent',
|
||||||
'show_document_preview' => 'Show Document Preview',
|
'show_document_preview' => 'Show Document Preview',
|
||||||
|
'cash_accounting' => 'Cash accounting',
|
||||||
);
|
);
|
||||||
|
|
||||||
return $LANG;
|
return $LANG;
|
||||||
|
@ -166,6 +166,8 @@ class TaxSummaryReportTest extends TestCase
|
|||||||
$pl = new TaxSummaryReport($this->company, $this->payload);
|
$pl = new TaxSummaryReport($this->company, $this->payload);
|
||||||
$response = $pl->run();
|
$response = $pl->run();
|
||||||
|
|
||||||
|
nlog($response);
|
||||||
|
|
||||||
$this->assertIsString($response);
|
$this->assertIsString($response);
|
||||||
|
|
||||||
$this->account->delete();
|
$this->account->delete();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user