mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Updates for cancelled invoice presentation
This commit is contained in:
parent
aa649ac625
commit
086e82649b
@ -245,12 +245,11 @@ class InvoiceSum
|
|||||||
*/
|
*/
|
||||||
private function setCalculatedAttributes(): self
|
private function setCalculatedAttributes(): self
|
||||||
{
|
{
|
||||||
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
|
if($this->invoice->status_id == Invoice::STATUS_CANCELLED){
|
||||||
|
$this->invoice->balance = 0;
|
||||||
if ($this->invoice->status_id != Invoice::STATUS_DRAFT) {
|
}
|
||||||
|
elseif ($this->invoice->status_id != Invoice::STATUS_DRAFT) {
|
||||||
if ($this->invoice->amount != $this->invoice->balance) {
|
if ($this->invoice->amount != $this->invoice->balance) {
|
||||||
// $paid_to_date = $this->invoice->amount - $this->invoice->balance;
|
|
||||||
|
|
||||||
$this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision) - $this->invoice->paid_to_date; //21-02-2024 cannot use the calculated $paid_to_date here as it could send the balance backward.
|
$this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision) - $this->invoice->paid_to_date; //21-02-2024 cannot use the calculated $paid_to_date here as it could send the balance backward.
|
||||||
} else {
|
} else {
|
||||||
$this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision);
|
$this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision);
|
||||||
|
@ -279,10 +279,11 @@ class InvoiceSumInclusive
|
|||||||
private function setCalculatedAttributes()
|
private function setCalculatedAttributes()
|
||||||
{
|
{
|
||||||
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
|
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
|
||||||
if ($this->invoice->status_id != Invoice::STATUS_DRAFT) {
|
if($this->invoice->status_id == Invoice::STATUS_CANCELLED){
|
||||||
|
$this->invoice->balance = 0;
|
||||||
|
}
|
||||||
|
elseif ($this->invoice->status_id != Invoice::STATUS_DRAFT) {
|
||||||
if ($this->invoice->amount != $this->invoice->balance) {
|
if ($this->invoice->amount != $this->invoice->balance) {
|
||||||
// $paid_to_date = $this->invoice->amount - $this->invoice->balance;
|
|
||||||
|
|
||||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision) - $this->invoice->paid_to_date;
|
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision) - $this->invoice->paid_to_date;
|
||||||
} else {
|
} else {
|
||||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision);
|
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision);
|
||||||
|
@ -720,7 +720,7 @@ class HtmlEngine
|
|||||||
$data['$payment.date'] = ['value' => '', 'label' => ctrans('texts.payment_date')];
|
$data['$payment.date'] = ['value' => '', 'label' => ctrans('texts.payment_date')];
|
||||||
$data['$payment.number'] = ['value' => '', 'label' => ctrans('texts.payment_number')];
|
$data['$payment.number'] = ['value' => '', 'label' => ctrans('texts.payment_number')];
|
||||||
$data['$payment.transaction_reference'] = ['value' => '', 'label' => ctrans('texts.transaction_reference')];
|
$data['$payment.transaction_reference'] = ['value' => '', 'label' => ctrans('texts.transaction_reference')];
|
||||||
|
$data['$payment.refunded'] = ['value' => '', 'label' => ctrans('texts.refund')];
|
||||||
|
|
||||||
if ($this->entity_string == 'invoice' && $this->entity->net_payments()->exists()) {
|
if ($this->entity_string == 'invoice' && $this->entity->net_payments()->exists()) {
|
||||||
$payment_list = '<br><br>';
|
$payment_list = '<br><br>';
|
||||||
@ -742,6 +742,7 @@ class HtmlEngine
|
|||||||
$data['$payment.date'] = ['value' => $this->formatDate($payment->date, $this->client->date_format()), 'label' => ctrans('texts.payment_date')];
|
$data['$payment.date'] = ['value' => $this->formatDate($payment->date, $this->client->date_format()), 'label' => ctrans('texts.payment_date')];
|
||||||
$data['$payment.number'] = ['value' => $payment->number, 'label' => ctrans('texts.payment_number')];
|
$data['$payment.number'] = ['value' => $payment->number, 'label' => ctrans('texts.payment_number')];
|
||||||
$data['$payment.transaction_reference'] = ['value' => $payment->transaction_reference, 'label' => ctrans('texts.transaction_reference')];
|
$data['$payment.transaction_reference'] = ['value' => $payment->transaction_reference, 'label' => ctrans('texts.transaction_reference')];
|
||||||
|
$data['$payment.refunded'] = ['value' => $this->getPaymentMeta($payment), 'label' => ctrans('texts.refund')];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,6 +756,35 @@ class HtmlEngine
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getPaymentMeta(\App\Models\Payment $payment) {
|
||||||
|
|
||||||
|
if(!is_array($payment->refund_meta))
|
||||||
|
return '';
|
||||||
|
|
||||||
|
return
|
||||||
|
collect($payment->refund_meta)
|
||||||
|
->map(function ($refund) use ($payment) {
|
||||||
|
|
||||||
|
$date = \Carbon\Carbon::parse($refund['date'] ?? $payment->date)->addSeconds($payment->client->timezone_offset());
|
||||||
|
$date = $this->translateDate($date, $payment->client->date_format(), $payment->client->locale());
|
||||||
|
$entity = ctrans('texts.invoice');
|
||||||
|
|
||||||
|
$map = [];
|
||||||
|
|
||||||
|
foreach($refund['invoices'] as $refunded_invoice) {
|
||||||
|
$invoice = \App\Models\Invoice::withTrashed()->find($refunded_invoice['invoice_id']);
|
||||||
|
$amount = Number::formatMoney($refunded_invoice['amount'], $payment->client);
|
||||||
|
$notes = ctrans('texts.status_partially_refunded_amount', ['amount' => $amount]);
|
||||||
|
|
||||||
|
array_push($map, "{$date} {$entity} #{$invoice->number} {$notes}\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $map;
|
||||||
|
|
||||||
|
})->flatten()->implode("\n");
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a localized string for tax compliance purposes
|
* Returns a localized string for tax compliance purposes
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user