Fixes for ledger

This commit is contained in:
David Bomba 2021-01-21 15:42:30 +11:00
parent 05ea7f092a
commit c173fdcc5b
9 changed files with 11 additions and 19 deletions

View File

@ -308,7 +308,7 @@ class SendReminders implements ShouldQueue
$invoice = $invoice->calc()->getInvoice();
$this->invoice->client->service()->updateBalance($this->invoice->balance - $temp_invoice_balance)->save();
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance - $temp_invoice_balance);
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$this->invoice->number}");
return $invoice;
}

View File

@ -264,7 +264,7 @@ class BaseDriver extends AbstractPaymentDriver
if (collect($invoice->line_items)->contains('type_id', '3')) {
$invoice->service()->toggleFeesPaid()->save();
$invoice->client->service()->updateBalance($fee_total)->save();
$invoice->ledger()->updateInvoiceBalance($fee_total, $notes = 'Gateway fee adjustment');
$invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}");
}
});
}

View File

@ -306,7 +306,7 @@ class BasePaymentDriver
if (collect($invoice->line_items)->contains('type_id', '3')) {
$invoice->service()->toggleFeesPaid()->save();
$invoice->client->service()->updateBalance($fee_total)->save();
$invoice->ledger()->updateInvoiceBalance($fee_total, $notes = 'Gateway fee adjustment');
$invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for Invoice {$invoice->number}");
}
});
}

View File

@ -293,7 +293,7 @@ class BaseRepository
if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
$model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount']));
$model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount']), "Update adjustment for invoice {$model->number}");
$model->client->service()->updateBalance(($state['finished_amount'] - $state['starting_amount']))->save();
}

View File

@ -93,10 +93,6 @@ class AddGatewayFee extends AbstractService
/**Refresh Invoice values*/
$this->invoice = $this->invoice->calc()->getInvoice();
/*Update client balance*/ // don't increment until we have process the payment!
//$this->invoice->client->service()->updateBalance($gateway_fee)->save();
//$this->invoice->ledger()->updateInvoiceBalance($gateway_fee, $notes = 'Gateway fee adjustment');
return $this->invoice;
}
@ -122,10 +118,6 @@ class AddGatewayFee extends AbstractService
$this->invoice = $this->invoice->calc()->getInvoice();
// $this->invoice->client->service()->updateBalance($gateway_fee)->save();
// $this->invoice->ledger()->updateInvoiceBalance($gateway_fee, $notes = 'Discount fee adjustment');
return $this->invoice;
}
}

View File

@ -147,8 +147,8 @@ class AutoBillInvoice extends AbstractService
->save();
$this->invoice->ledger()
->updateInvoiceBalance($amount * -1, 'Invoice payment using Credit')
->updateCreditBalance($amount * -1, 'Credits used to pay down Invoice ' . $this->invoice->number)
->updateInvoiceBalance($amount * -1, "Invoice {$this->invoice->number} payment using Credit {$current_credit->number}")
->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}")
->save();
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
@ -325,7 +325,7 @@ class AutoBillInvoice extends AbstractService
if ($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT) {
$this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save();
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, 'Invoice balance updated after stale gateway fee removed')->save();
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, "Invoice {$this->invoice->number} balance updated after stale gateway fee removed")->save();
}
return $this;

View File

@ -42,7 +42,7 @@ class HandleCancellation extends AbstractService
$this->backupCancellation($adjustment);
//set invoice balance to 0
$this->invoice->ledger()->updateInvoiceBalance($adjustment, 'Invoice cancellation');
$this->invoice->ledger()->updateInvoiceBalance($adjustment, "Invoice {$this->invoice->number} cancellation");
$this->invoice->balance = 0;
$this->invoice = $this->invoice->service()->setStatus(Invoice::STATUS_CANCELLED)->save();
@ -63,7 +63,7 @@ class HandleCancellation extends AbstractService
/* Will turn the negative cancellation amount to a positive adjustment*/
$adjustment = $cancellation->adjustment * -1;
$this->invoice->ledger()->updateInvoiceBalance($adjustment, 'Invoice cancellation REVERSAL');
$this->invoice->ledger()->updateInvoiceBalance($adjustment, "Invoice {$this->invoice->number} reversal");
/* Reverse the invoice status and balance */
$this->invoice->balance += $adjustment;

View File

@ -51,7 +51,7 @@ class MarkSent extends AbstractService
$this->client->service()->updateBalance($this->invoice->balance)->save();
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance);
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, "Invoice {$this->invoice->number} marked as sent.");
event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars()));

View File

@ -80,7 +80,7 @@ class DeletePayment
if ($this->payment->invoices()->exists()) {
$this->payment->invoices()->each(function ($paymentable_invoice) {
$paymentable_invoice->service()->updateBalance($paymentable_invoice->pivot->amount)->save();
$paymentable_invoice->ledger()->updateInvoiceBalance($paymentable_invoice->pivot->amount)->save();
$paymentable_invoice->ledger()->updateInvoiceBalance($paymentable_invoice->pivot->amount, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}")->save();
$paymentable_invoice->client->service()->updateBalance($paymentable_invoice->pivot->amount)->save();
if ($paymentable_invoice->balance == $paymentable_invoice->amount) {