Tax Period Tests

This commit is contained in:
David Bomba 2025-11-18 15:50:29 +11:00
parent 0fb63dec60
commit 00e93582ea
5 changed files with 23 additions and 96 deletions

View File

@ -22,6 +22,7 @@ class BlackListRule implements ValidationRule
{
/** Bad domains +/- disposable email domains */
private array $blacklist = [
"moonfee.com",
"edus2.us",
"educj.org",
"edu0.org",

View File

@ -17,6 +17,10 @@ use App\Models\Invoice;
use App\Models\TransactionEvent;
use Illuminate\Support\Collection;
use App\DataMapper\TransactionEventMetadata;
/**
* Handles entries for invoices.
* Used for end of month aggregation of accrual accounting.
*/
class InvoiceTransactionEventEntry
{

View File

@ -13,17 +13,14 @@
namespace App\Listeners\Invoice;
use App\Models\Invoice;
use App\Models\Activity;
use App\Models\TransactionEvent;
use Illuminate\Support\Collection;
use App\DataMapper\TaxReport\TaxDetail;
use App\DataMapper\TaxReport\TaxReport;
use App\DataMapper\TaxReport\TaxSummary;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\DataMapper\TransactionEventMetadata;
use Illuminate\Queue\Middleware\WithoutOverlapping;
/**
* Handles entries for vanilla payments on an invoice.
* Used for end of month aggregation of cash payments.
*/
class InvoiceTransactionEventEntryCash
{
private Collection $payments;
@ -91,95 +88,9 @@ class InvoiceTransactionEventEntryCash
return round($amount * $this->paid_ratio, 2);
}
/**
* Existing tax details are not deleted, but pending taxes are set to 0
*
* @param mixed $invoice
*/
// private function getCancelledMetaData($invoice)
// {
// $calc = $invoice->calc();
// $details = [];
// $taxes = array_merge($calc->getTaxMap()->merge($calc->getTotalTaxMap())->toArray());
// foreach ($taxes as $tax) {
// $tax_detail = [
// 'tax_name' => $tax['name'],
// 'tax_rate' => $tax['tax_rate'],
// 'taxable_amount' => $tax['base_amount'] ?? $calc->getNetSubtotal(),
// 'tax_amount' => $this->calculateRatio($tax['total']),
// 'tax_amount_paid' => $this->calculateRatio($tax['total']),
// 'tax_amount_remaining' => 0,
// ];
// $details[] = $tax_detail;
// }
// return new TransactionEventMetadata([
// 'tax_report' => [
// 'tax_details' => $details,
// 'payment_history' => $this->payments->toArray(),
// 'tax_summary' => [
// 'total_taxes' => $invoice->total_taxes,
// 'total_paid' => $this->getTotalTaxPaid($invoice),
// 'status' => 'cancelled',
// ],
// ],
// ]);
// }
/**
* Set all tax details to 0
*
* @param mixed $invoice
*/
// private function getDeletedMetaData($invoice)
// {
// $calc = $invoice->calc();
// $details = [];
// $taxes = array_merge($calc->getTaxMap()->merge($calc->getTotalTaxMap())->toArray());
// foreach ($taxes as $tax) {
// $tax_detail = [
// 'tax_name' => $tax['name'],
// 'tax_rate' => $tax['tax_rate'],
// 'taxable_amount' => $tax['base_amount'] ?? $calc->getNetSubtotal(),
// 'tax_amount' => $tax['total'],
// 'tax_amount_paid' => $this->calculateRatio($tax['total']),
// 'tax_amount_remaining' => 0,
// ];
// $details[] = $tax_detail;
// }
// return new TransactionEventMetadata([
// 'tax_report' => [
// 'tax_details' => $details,
// 'payment_history' => $this->payments->toArray(),
// 'tax_summary' => [
// 'total_taxes' => $invoice->total_taxes,
// 'total_paid' => $this->getTotalTaxPaid($invoice),0,
// 'status' => 'deleted',
// ],
// ],
// ]);
// }
private function getMetadata($invoice)
{
// if ($invoice->status_id == Invoice::STATUS_CANCELLED) {
// return $this->getCancelledMetaData($invoice);
// } elseif ($invoice->is_deleted) {
// return $this->getDeletedMetaData($invoice);
// }
$calc = $invoice->calc();
$details = [];
@ -206,6 +117,9 @@ class InvoiceTransactionEventEntryCash
'total_taxes' => $invoice->total_taxes,
'total_paid' => $this->getTotalTaxPaid($invoice),
'status' => 'updated',
'taxable_amount' => $calc->getNetSubtotal(),
'adjustment' => 0,
'tax_adjustment' => 0,
],
],
]);

View File

@ -173,8 +173,10 @@ class PaymentTransactionEventEntry implements ShouldQueue
'tax_summary' => [
'total_taxes' => $invoice->total_taxes,
'total_paid' => $this->getTotalTaxPaid($invoice),
'adjustment' => round($invoice->total_taxes - $this->getTotalTaxPaid($invoice), 2) * -1,
'tax_adjustment' => round($invoice->total_taxes - $this->getTotalTaxPaid($invoice), 2) * -1,
'status' => 'adjustment',
'taxable_amount' => $calc->getNetSubtotal(),
'adjustment' => 0,
],
],
]);
@ -197,7 +199,6 @@ class PaymentTransactionEventEntry implements ShouldQueue
foreach ($taxes as $tax) {
$base_amount = $tax['base_amount'] ?? $calc->getNetSubtotal();
if($this->invoice_adjustment > 0)
@ -226,7 +227,9 @@ class PaymentTransactionEventEntry implements ShouldQueue
'tax_summary' => [
'total_taxes' => $invoice->total_taxes,
'total_paid' => $this->getTotalTaxPaid($invoice),
'adjustment' => round($invoice->total_taxes - $this->getTotalTaxPaid($invoice), 2) * -1,
'taxable_amount' => $calc->getNetSubtotal(),
'adjustment' => 0,
'tax_adjustment' => round($invoice->total_taxes - $this->getTotalTaxPaid($invoice), 2) * -1,
'status' => 'adjustment',
],
],

View File

@ -498,4 +498,9 @@ class TaxPeriodReportTest extends TestCase
// Updated invoices with payments in the same period
// Updated invoices with payments in the next period
//cash accounting.
// What happens when a payment is deleted?
// What happens when a paid invoice is deleted?
}