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\TaxSummary;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Tax report object for InvoiceSync - tracks incremental tax history
|
||||
|
|
@ -23,7 +24,7 @@ class TaxReport
|
|||
public ?TaxSummary $tax_summary; // Summary totals
|
||||
public ?array $tax_details; // Array of TaxDetail objects (includes adjustments)
|
||||
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 = [])
|
||||
{
|
||||
|
|
@ -34,7 +35,7 @@ class TaxReport
|
|||
? array_map(fn ($detail) => new TaxDetail($detail), $attributes['tax_details'])
|
||||
: null;
|
||||
$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;
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ class TaxReport
|
|||
return [
|
||||
'tax_summary' => $this->tax_summary?->toArray(),
|
||||
'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([
|
||||
'tax_report' => [
|
||||
'tax_details' => $details,
|
||||
'payment_history' => $this->payments->toArray(),
|
||||
'payment_history' => $this->payments->toArray() ?? [],
|
||||
'tax_summary' => [
|
||||
'total_taxes' => $invoice->total_taxes,
|
||||
'total_paid' => $this->getTotalTaxPaid($invoice),
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class InvoiceTransactionEventEntryAccrual
|
|||
{
|
||||
|
||||
$this->setPaidRatio($invoice);
|
||||
|
||||
|
||||
$this->payments = $invoice->payments->flatMap(function ($payment) use ($start_date, $end_date) {
|
||||
return $payment->invoices()->get()->map(function ($invoice) use ($payment) {
|
||||
return [
|
||||
|
|
@ -173,11 +173,11 @@ class InvoiceTransactionEventEntryAccrual
|
|||
private function getMetadata($invoice)
|
||||
{
|
||||
|
||||
if ($invoice->status_id == Invoice::STATUS_CANCELLED) {
|
||||
return $this->getCancelledMetaData($invoice);
|
||||
} elseif ($invoice->is_deleted) {
|
||||
return $this->getDeletedMetaData($invoice);
|
||||
}
|
||||
// if ($invoice->status_id == Invoice::STATUS_CANCELLED) {
|
||||
// return $this->getCancelledMetaData($invoice);
|
||||
// } elseif ($invoice->is_deleted) {
|
||||
// return $this->getDeletedMetaData($invoice);
|
||||
// }
|
||||
|
||||
$calc = $invoice->calc();
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ class InvoiceTransactionEventEntryAccrual
|
|||
];
|
||||
$details[] = $tax_detail;
|
||||
}
|
||||
|
||||
|
||||
return new TransactionEventMetadata([
|
||||
'tax_report' => [
|
||||
'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();
|
||||
$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){
|
||||
$this->data['accrual']['invoices'][] = [
|
||||
$invoice->number,
|
||||
$invoice->date,
|
||||
$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_paid,
|
||||
'payable',
|
||||
|
|
@ -230,7 +230,8 @@ class TaxReport
|
|||
$invoice->number,
|
||||
$invoice->date,
|
||||
$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_paid,
|
||||
'payable',
|
||||
|
|
|
|||
|
|
@ -218,6 +218,10 @@ class TaxSummaryReportTest extends TestCase
|
|||
|
||||
$i3 = $i3->calc()->getInvoice();
|
||||
|
||||
$i3 = $i3->service()->markSent()->save();
|
||||
|
||||
(new InvoiceTransactionEventEntry())->run($i3);
|
||||
|
||||
$i3 = $i3->service()->markPaid()->save();
|
||||
|
||||
$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');
|
||||
$response = $pl->run()->getXlsFile();
|
||||
|
||||
$this->assertIsString($response);
|
||||
|
||||
|
||||
try{
|
||||
file_put_contents('/home/david/ttx.xlsx', $response);
|
||||
}
|
||||
catch(\Throwable $e){
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
|
||||
$this->account->delete();
|
||||
|
||||
}
|
||||
|
|
@ -298,7 +312,7 @@ class TaxSummaryReportTest extends TestCase
|
|||
$i2 = $i2->calc()->getInvoice();
|
||||
$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);
|
||||
$response = $pl->run();
|
||||
|
|
|
|||
Loading…
Reference in New Issue