Fixes for statements

This commit is contained in:
David Bomba 2024-09-10 14:29:01 +10:00
parent 2c6c7cc3b8
commit 4d72a312d6
3 changed files with 67 additions and 1 deletions

View File

@ -103,6 +103,7 @@ class RefundPayment
//block prevents the edge case where a partial refund was attempted.
$this->refund_data['invoices'] = $this->payment->invoices->map(function ($invoice) {
return [
'date' => now()->addSeconds($invoice->client->timezone_offset())->format('Y-m-d'),
'invoice_id' => $invoice->id,
'amount' => $invoice->pivot->amount,
];

View File

@ -356,6 +356,37 @@ class PdfBuilder
$tbody[] = $element;
$this->payment_amount_total += $payment->pivot->amount;
if($payment->pivot->refunded > 0){
$refund_date = $payment->date;
if($payment->refund_meta && is_array($payment->refund_meta)){
$refund_array = collect($payment->refund_meta)->first(function ($meta) use($invoice){
foreach($meta['invoices'] as $refunded_invoice){
if ($refunded_invoice['invoice_id'] == $invoice->id) {
return true;
}
}
});
$refund_date = $refund_array['date'];
}
$element = ['element' => 'tr', 'elements' => []];
$element['elements'][] = ['element' => 'td', 'content' => $invoice->number];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($refund_date, $this->service->config->date_format, $this->service->config->locale) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => ctrans('texts.refund')];
$element['elements'][] = ['element' => 'td', 'content' => $this->service->config->formatMoney($payment->pivot->refunded) ?: ' '];
$tbody[] = $element;
$this->payment_amount_total -= $payment->pivot->refunded;
}
}
}

View File

@ -561,7 +561,41 @@ class Design extends BaseDesign
$tbody[] = $element;
$this->payment_amount_total += $payment->pivot->amount;
}
if ($payment->pivot->refunded > 0) {
$refund_date = $payment->date;
if($payment->refund_meta && is_array($payment->refund_meta)){
$refund_array = collect($payment->refund_meta)->first(function ($meta) use($invoice){
foreach($meta['invoices'] as $refunded_invoice){
if ($refunded_invoice['invoice_id'] == $invoice->id) {
return true;
}
}
});
$refund_date = $refund_array['date'];
}
$element = ['element' => 'tr', 'elements' => []];
$element['elements'][] = ['element' => 'td', 'content' => $invoice->number];
$element['elements'][] = ['element' => 'td', 'content' => $this->translateDate($refund_date, $this->client->date_format(), $this->client->locale()) ?: ' '];
$element['elements'][] = ['element' => 'td', 'content' => ctrans('texts.refund')];
$element['elements'][] = ['element' => 'td', 'content' => Number::formatMoney($payment->pivot->refunded, $this->client) ?: ' '];
$tbody[] = $element;
$this->payment_amount_total -= $payment->pivot->refunded;
}
}
}
return [