change payment_history to resolve to a laravel collection
This commit is contained in:
parent
7b1f026c6b
commit
5ae786865b
|
|
@ -14,6 +14,7 @@ namespace App\DataMapper\TaxReport;
|
||||||
|
|
||||||
use App\DataMapper\TaxReport\TaxDetail;
|
use App\DataMapper\TaxReport\TaxDetail;
|
||||||
use App\DataMapper\TaxReport\TaxSummary;
|
use App\DataMapper\TaxReport\TaxSummary;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tax report object for InvoiceSync - tracks incremental tax history
|
* Tax report object for InvoiceSync - tracks incremental tax history
|
||||||
|
|
@ -23,7 +24,7 @@ class TaxReport
|
||||||
public ?TaxSummary $tax_summary; // Summary totals
|
public ?TaxSummary $tax_summary; // Summary totals
|
||||||
public ?array $tax_details; // Array of TaxDetail objects (includes adjustments)
|
public ?array $tax_details; // Array of TaxDetail objects (includes adjustments)
|
||||||
public float $amount; // The total amount of the invoice
|
public float $amount; // The total amount of the invoice
|
||||||
public ?array $payment_history; // Array of PaymentHistory objects
|
public ?Collection $payment_history; // Collection of PaymentHistory objects
|
||||||
|
|
||||||
public function __construct(array $attributes = [])
|
public function __construct(array $attributes = [])
|
||||||
{
|
{
|
||||||
|
|
@ -34,7 +35,7 @@ class TaxReport
|
||||||
? array_map(fn ($detail) => new TaxDetail($detail), $attributes['tax_details'])
|
? array_map(fn ($detail) => new TaxDetail($detail), $attributes['tax_details'])
|
||||||
: null;
|
: null;
|
||||||
$this->payment_history = isset($attributes['payment_history'])
|
$this->payment_history = isset($attributes['payment_history'])
|
||||||
? array_map(fn ($payment) => new PaymentHistory($payment), $attributes['payment_history'])
|
? collect($attributes['payment_history'])->map(fn ($payment) => new PaymentHistory($payment))
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +44,7 @@ class TaxReport
|
||||||
return [
|
return [
|
||||||
'tax_summary' => $this->tax_summary?->toArray(),
|
'tax_summary' => $this->tax_summary?->toArray(),
|
||||||
'tax_details' => $this->tax_details ? array_map(fn ($detail) => $detail->toArray(), $this->tax_details) : null,
|
'tax_details' => $this->tax_details ? array_map(fn ($detail) => $detail->toArray(), $this->tax_details) : null,
|
||||||
'payment_history' => $this->payment_history ? array_map(fn ($payment) => $payment->toArray(), $this->payment_history) : null,
|
'payment_history' => $this->payment_history ? $this->payment_history->map(fn ($payment) => $payment->toArray())->toArray() : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ class InvoiceTransactionEventEntry
|
||||||
return new TransactionEventMetadata([
|
return new TransactionEventMetadata([
|
||||||
'tax_report' => [
|
'tax_report' => [
|
||||||
'tax_details' => $details,
|
'tax_details' => $details,
|
||||||
'payment_history' => $this->payments->toArray(),
|
'payment_history' => $this->payments->toArray() ?? [],
|
||||||
'tax_summary' => [
|
'tax_summary' => [
|
||||||
'total_taxes' => $invoice->total_taxes,
|
'total_taxes' => $invoice->total_taxes,
|
||||||
'total_paid' => $this->getTotalTaxPaid($invoice),
|
'total_paid' => $this->getTotalTaxPaid($invoice),
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class InvoiceTransactionEventEntryAccrual
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->setPaidRatio($invoice);
|
$this->setPaidRatio($invoice);
|
||||||
|
|
||||||
$this->payments = $invoice->payments->flatMap(function ($payment) use ($start_date, $end_date) {
|
$this->payments = $invoice->payments->flatMap(function ($payment) use ($start_date, $end_date) {
|
||||||
return $payment->invoices()->get()->map(function ($invoice) use ($payment) {
|
return $payment->invoices()->get()->map(function ($invoice) use ($payment) {
|
||||||
return [
|
return [
|
||||||
|
|
@ -173,11 +173,11 @@ class InvoiceTransactionEventEntryAccrual
|
||||||
private function getMetadata($invoice)
|
private function getMetadata($invoice)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($invoice->status_id == Invoice::STATUS_CANCELLED) {
|
// if ($invoice->status_id == Invoice::STATUS_CANCELLED) {
|
||||||
return $this->getCancelledMetaData($invoice);
|
// return $this->getCancelledMetaData($invoice);
|
||||||
} elseif ($invoice->is_deleted) {
|
// } elseif ($invoice->is_deleted) {
|
||||||
return $this->getDeletedMetaData($invoice);
|
// return $this->getDeletedMetaData($invoice);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$calc = $invoice->calc();
|
$calc = $invoice->calc();
|
||||||
|
|
||||||
|
|
@ -196,7 +196,7 @@ class InvoiceTransactionEventEntryAccrual
|
||||||
];
|
];
|
||||||
$details[] = $tax_detail;
|
$details[] = $tax_detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TransactionEventMetadata([
|
return new TransactionEventMetadata([
|
||||||
'tax_report' => [
|
'tax_report' => [
|
||||||
'tax_details' => $details,
|
'tax_details' => $details,
|
||||||
|
|
|
||||||
|
|
@ -211,13 +211,13 @@ class TaxReport
|
||||||
$payment_state = $invoice->transaction_events()->where('event_id', TransactionEvent::PAYMENT_CASH)->where('period', now()->endOfMonth()->format('Y-m-d'))->orderBy('timestamp', 'desc')->first();
|
$payment_state = $invoice->transaction_events()->where('event_id', TransactionEvent::PAYMENT_CASH)->where('period', now()->endOfMonth()->format('Y-m-d'))->orderBy('timestamp', 'desc')->first();
|
||||||
$adjustments = $invoice->transaction_events()->whereIn('event_id',[TransactionEvent::PAYMENT_REFUNDED, TransactionEvent::PAYMENT_DELETED])->where('period', now()->endOfMonth()->format('Y-m-d'))->get();
|
$adjustments = $invoice->transaction_events()->whereIn('event_id',[TransactionEvent::PAYMENT_REFUNDED, TransactionEvent::PAYMENT_DELETED])->where('period', now()->endOfMonth()->format('Y-m-d'))->get();
|
||||||
|
|
||||||
|
|
||||||
if($invoice_state && $invoice_state->event_id == TransactionEvent::INVOICE_UPDATED){
|
if($invoice_state && $invoice_state->event_id == TransactionEvent::INVOICE_UPDATED){
|
||||||
$this->data['accrual']['invoices'][] = [
|
$this->data['accrual']['invoices'][] = [
|
||||||
$invoice->number,
|
$invoice->number,
|
||||||
$invoice->date,
|
$invoice->date,
|
||||||
$invoice->amount,
|
$invoice->amount,
|
||||||
$invoice_state->invoice_paid_to_date,
|
|
||||||
|
$invoice_state->metadata->tax_report->payment_history?->sum('amount') ?? 00,
|
||||||
$invoice_state->metadata->tax_report->tax_summary->total_taxes,
|
$invoice_state->metadata->tax_report->tax_summary->total_taxes,
|
||||||
$invoice_state->metadata->tax_report->tax_summary->total_paid,
|
$invoice_state->metadata->tax_report->tax_summary->total_paid,
|
||||||
'payable',
|
'payable',
|
||||||
|
|
@ -230,7 +230,8 @@ class TaxReport
|
||||||
$invoice->number,
|
$invoice->number,
|
||||||
$invoice->date,
|
$invoice->date,
|
||||||
$invoice->amount,
|
$invoice->amount,
|
||||||
$payment_state->invoice_paid_to_date,
|
|
||||||
|
$payment_state->metadata->tax_report->payment_history?->sum('amount') ?? 0,
|
||||||
$payment_state->metadata->tax_report->tax_summary->total_taxes,
|
$payment_state->metadata->tax_report->tax_summary->total_taxes,
|
||||||
$payment_state->metadata->tax_report->tax_summary->total_paid,
|
$payment_state->metadata->tax_report->tax_summary->total_paid,
|
||||||
'payable',
|
'payable',
|
||||||
|
|
|
||||||
|
|
@ -218,6 +218,10 @@ class TaxSummaryReportTest extends TestCase
|
||||||
|
|
||||||
$i3 = $i3->calc()->getInvoice();
|
$i3 = $i3->calc()->getInvoice();
|
||||||
|
|
||||||
|
$i3 = $i3->service()->markSent()->save();
|
||||||
|
|
||||||
|
(new InvoiceTransactionEventEntry())->run($i3);
|
||||||
|
|
||||||
$i3 = $i3->service()->markPaid()->save();
|
$i3 = $i3->service()->markPaid()->save();
|
||||||
|
|
||||||
$this->assertEquals($i3->amount, $i3->paid_to_date);
|
$this->assertEquals($i3->amount, $i3->paid_to_date);
|
||||||
|
|
@ -226,11 +230,21 @@ class TaxSummaryReportTest extends TestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(new InvoiceTransactionEventEntry())->run($i);
|
||||||
|
|
||||||
$pl = new \App\Services\Report\XLS\TaxReport($this->company, '2025-01-01', '2025-12-31');
|
$pl = new \App\Services\Report\XLS\TaxReport($this->company, '2025-01-01', '2025-12-31');
|
||||||
$response = $pl->run()->getXlsFile();
|
$response = $pl->run()->getXlsFile();
|
||||||
|
|
||||||
$this->assertIsString($response);
|
$this->assertIsString($response);
|
||||||
|
|
||||||
|
|
||||||
|
try{
|
||||||
|
file_put_contents('/home/david/ttx.xlsx', $response);
|
||||||
|
}
|
||||||
|
catch(\Throwable $e){
|
||||||
|
nlog($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$this->account->delete();
|
$this->account->delete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -298,7 +312,7 @@ class TaxSummaryReportTest extends TestCase
|
||||||
$i2 = $i2->calc()->getInvoice();
|
$i2 = $i2->calc()->getInvoice();
|
||||||
$i2->service()->markPaid();
|
$i2->service()->markPaid();
|
||||||
|
|
||||||
(new InvoiceTransactionEventEntryAccrual())->run($i2, now()->subDays(30)->format('Y-m-d'), now()->addDays(30)->format('Y-m-d'));
|
(new InvoiceTransactionEventEntryAccrual())->run($i2, now()->subDays(3000)->format('Y-m-d'), now()->addDays(3000)->format('Y-m-d'));
|
||||||
|
|
||||||
$pl = new TaxSummaryReport($this->company, $this->payload);
|
$pl = new TaxSummaryReport($this->company, $this->payload);
|
||||||
$response = $pl->run();
|
$response = $pl->run();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue