diff --git a/app/Services/Report/TaxSummaryReport.php b/app/Services/Report/TaxSummaryReport.php index f0175b6dedc5..5cbb8de0c30b 100644 --- a/app/Services/Report/TaxSummaryReport.php +++ b/app/Services/Report/TaxSummaryReport.php @@ -36,7 +36,6 @@ class TaxSummaryReport extends BaseExport public array $report_keys = [ 'tax_name', - // 'taxable_amount', 'tax_amount', ]; @@ -70,6 +69,7 @@ class TaxSummaryReport extends BaseExport $this->csv->insertOne([]); $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.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) { $this->input['report_keys'] = $this->report_keys; @@ -78,6 +78,8 @@ class TaxSummaryReport extends BaseExport $this->csv->insertOne($this->buildHeader()); $query = Invoice::query() + ->withTrashed() + ->whereIn('status_id', [2,3,4]) ->where('company_id', $this->company->id) ->where('is_deleted', 0) ->orderBy('balance', 'desc'); @@ -85,33 +87,59 @@ class TaxSummaryReport extends BaseExport $query = $this->addDateRange($query); $query = $this->filterByClients($query); - $map = []; + $accrual_map = []; + $cash_map = []; 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) { $key = $tax['name']; - if(!isset($map[$key])) { - $map[$key]['tax_amount'] = 0; - // $map[$key]['taxable_amount'] = 0; + if(!isset($accrual_map[$key])) { + $accrual_map[$key]['tax_amount'] = 0; } - $map[$key]['tax_amount'] += $tax['total']; - // $map[$key]['taxable_amount'] += $invoice->amount; + $accrual_map[$key]['tax_amount'] += $tax['total']; + //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['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)]); } diff --git a/lang/en/texts.php b/lang/en/texts.php index c361561cad38..b97c5cdf20fc 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5159,6 +5159,7 @@ $LANG = array( 'view_dashboard_permission' => 'Allow user to access the dashboard, data is limited to available permissions', 'marked_sent_credits' => 'Successfully marked credits sent', 'show_document_preview' => 'Show Document Preview', + 'cash_accounting' => 'Cash accounting', ); return $LANG; diff --git a/tests/Feature/Export/TaxSummaryReportTest.php b/tests/Feature/Export/TaxSummaryReportTest.php index 251a605b4ef0..e4387f1cca42 100644 --- a/tests/Feature/Export/TaxSummaryReportTest.php +++ b/tests/Feature/Export/TaxSummaryReportTest.php @@ -166,6 +166,8 @@ class TaxSummaryReportTest extends TestCase $pl = new TaxSummaryReport($this->company, $this->payload); $response = $pl->run(); + nlog($response); + $this->assertIsString($response); $this->account->delete();