mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for pivots
This commit is contained in:
parent
89f22dc034
commit
29558dac2c
@ -122,7 +122,7 @@ class PaymentMigrationRepository extends BaseRepository
|
||||
|
||||
$invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->withTrashed()->get();
|
||||
|
||||
$payment->invoices()->saveMany($invoices);
|
||||
$payment->invoices()->saveMany($invoices); // 1:1 relationship so this is ok
|
||||
|
||||
$payment->invoices->each(function ($inv) use ($invoice_totals, $refund_totals, $payment) {
|
||||
if ($payment->status_id != Payment::STATUS_CANCELLED || ! $payment->is_deleted) {
|
||||
|
@ -139,7 +139,7 @@ class PaymentRepository extends BaseRepository
|
||||
|
||||
$invoices = Invoice::withTrashed()->whereIn('id', array_column($data['invoices'], 'invoice_id'))->get();
|
||||
|
||||
// $payment->invoices()->saveMany($invoices);
|
||||
// $payment->invoices()->saveMany($invoices); //25-06-2023
|
||||
|
||||
//todo optimize this into a single query
|
||||
foreach ($data['invoices'] as $paid_invoice) {
|
||||
@ -148,6 +148,8 @@ class PaymentRepository extends BaseRepository
|
||||
|
||||
if ($invoice) {
|
||||
|
||||
//25-06-2023
|
||||
|
||||
$paymentable = new Paymentable();
|
||||
$paymentable->payment_id = $payment->id;
|
||||
$paymentable->paymentable_id = $invoice->id;
|
||||
@ -162,9 +164,7 @@ class PaymentRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//payment is made, but not to any invoice, therefore we are applying the payment to the clients paid_to_date only
|
||||
//01-07-2020 i think we were duplicating the paid to date here.
|
||||
//$payment->client->service()->updatePaidToDate($payment->amount)->save();
|
||||
|
||||
}
|
||||
|
||||
if (array_key_exists('credits', $data) && is_array($data['credits'])) {
|
||||
@ -176,7 +176,7 @@ class PaymentRepository extends BaseRepository
|
||||
|
||||
//todo optimize into a single query
|
||||
foreach ($data['credits'] as $paid_credit) {
|
||||
// $credit = Credit::withTrashed()->find($paid_credit['credit_id']);
|
||||
|
||||
$credit = $credits->firstWhere('id', $paid_credit['credit_id']);
|
||||
|
||||
if ($credit) {
|
||||
|
@ -86,7 +86,7 @@ class ApplyPayment extends AbstractService
|
||||
if ($inv->id == $this->invoice->id) {
|
||||
// $inv->pivot->amount = ($amount_paid * -1);
|
||||
// $inv->pivot->save();
|
||||
|
||||
//25-06-2023
|
||||
$inv->paid_to_date += floatval($amount_paid * -1);
|
||||
$inv->save();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user