|
@@ -113,6 +113,16 @@ class TransactionObserver
|
113
|
113
|
->when($excludedTransaction, fn (Builder $query) => $query->whereKeyNot($excludedTransaction->getKey()))
|
114
|
114
|
->get()
|
115
|
115
|
->sum(function (Transaction $transaction) use ($invoiceCurrency) {
|
|
116
|
+ // If the transaction has stored the original invoice amount in metadata, use that
|
|
117
|
+ if (! empty($transaction->meta) &&
|
|
118
|
+ isset($transaction->meta['original_document_currency']) &&
|
|
119
|
+ $transaction->meta['original_document_currency'] === $invoiceCurrency &&
|
|
120
|
+ isset($transaction->meta['amount_in_document_currency_cents'])) {
|
|
121
|
+
|
|
122
|
+ return (int) $transaction->meta['amount_in_document_currency_cents'];
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ // Fall back to conversion if metadata is not available
|
116
|
126
|
$bankAccountCurrency = $transaction->bankAccount->account->currency_code;
|
117
|
127
|
$amountCents = (int) $transaction->getRawOriginal('amount');
|
118
|
128
|
|
|
@@ -123,6 +133,16 @@ class TransactionObserver
|
123
|
133
|
->when($excludedTransaction, fn (Builder $query) => $query->whereKeyNot($excludedTransaction->getKey()))
|
124
|
134
|
->get()
|
125
|
135
|
->sum(function (Transaction $transaction) use ($invoiceCurrency) {
|
|
136
|
+ // If the transaction has stored the original invoice amount in metadata, use that
|
|
137
|
+ if (! empty($transaction->meta) &&
|
|
138
|
+ isset($transaction->meta['original_document_currency']) &&
|
|
139
|
+ $transaction->meta['original_document_currency'] === $invoiceCurrency &&
|
|
140
|
+ isset($transaction->meta['amount_in_document_currency_cents'])) {
|
|
141
|
+
|
|
142
|
+ return (int) $transaction->meta['amount_in_document_currency_cents'];
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ // Fall back to conversion if metadata is not available
|
126
|
146
|
$bankAccountCurrency = $transaction->bankAccount->account->currency_code;
|
127
|
147
|
$amountCents = (int) $transaction->getRawOriginal('amount');
|
128
|
148
|
|
|
@@ -136,6 +156,7 @@ class TransactionObserver
|
136
|
156
|
$newStatus = match (true) {
|
137
|
157
|
$totalPaidInInvoiceCurrencyCents > $invoiceTotalInInvoiceCurrencyCents => InvoiceStatus::Overpaid,
|
138
|
158
|
$totalPaidInInvoiceCurrencyCents === $invoiceTotalInInvoiceCurrencyCents => InvoiceStatus::Paid,
|
|
159
|
+ $totalPaidInInvoiceCurrencyCents === 0 => $invoice->last_sent_at ? InvoiceStatus::Sent : InvoiceStatus::Unsent,
|
139
|
160
|
default => InvoiceStatus::Partial,
|
140
|
161
|
};
|
141
|
162
|
|
|
@@ -168,11 +189,11 @@ class TransactionObserver
|
168
|
189
|
->sum(function (Transaction $transaction) use ($billCurrency) {
|
169
|
190
|
// If the transaction has stored the original bill amount in metadata, use that
|
170
|
191
|
if (! empty($transaction->meta) &&
|
171
|
|
- isset($transaction->meta['original_bill_currency']) &&
|
172
|
|
- $transaction->meta['original_bill_currency'] === $billCurrency &&
|
173
|
|
- isset($transaction->meta['amount_in_bill_currency_cents'])) {
|
|
192
|
+ isset($transaction->meta['original_document_currency']) &&
|
|
193
|
+ $transaction->meta['original_document_currency'] === $billCurrency &&
|
|
194
|
+ isset($transaction->meta['amount_in_document_currency_cents'])) {
|
174
|
195
|
|
175
|
|
- return (int) $transaction->meta['amount_in_bill_currency_cents'];
|
|
196
|
+ return (int) $transaction->meta['amount_in_document_currency_cents'];
|
176
|
197
|
}
|
177
|
198
|
|
178
|
199
|
// Fall back to conversion if metadata is not available
|
|
@@ -188,6 +209,7 @@ class TransactionObserver
|
188
|
209
|
|
189
|
210
|
$newStatus = match (true) {
|
190
|
211
|
$totalPaidInBillCurrencyCents >= $billTotalInBillCurrencyCents => BillStatus::Paid,
|
|
212
|
+ $totalPaidInBillCurrencyCents === 0 => BillStatus::Open,
|
191
|
213
|
default => BillStatus::Partial,
|
192
|
214
|
};
|
193
|
215
|
|