Fixes for Client - Paid To Date updating when a payment with no invoices is generated

This commit is contained in:
David Bomba 2021-07-14 12:22:37 +10:00
parent bfd6cf876b
commit e808cc62a8
6 changed files with 20 additions and 16 deletions

View File

@ -77,10 +77,13 @@ class CreateAccount
$sp794f3f->key = Str::random(32);
}
$sp794f3f->trial_started = now();
$sp794f3f->trial_plan = 'pro';
$sp794f3f->save();
if(Ninja::isHosted())
{
$sp794f3f->trial_started = now();
$sp794f3f->trial_plan = 'pro';
$sp794f3f->save();
}
$sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f);
$sp035a66->load('account');
$sp794f3f->default_company_id = $sp035a66->id;

View File

@ -48,7 +48,7 @@ class PaymentUpdatedActivity implements ShouldQueue
$fields = new stdClass;
$user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->payment->user_id;
$fields->payment_id = $payment->id;
$fields->client_id = $payment->client_id;

View File

@ -80,6 +80,11 @@ class PaymentRepository extends BaseRepository {
$client->service()->updatePaidToDate($data['amount'])->save();
}
elseif($data['amount'] >0){
//this fixes an edge case with unapplied payments
$client->service()->updatePaidToDate($data['amount'])->save();
}
if (array_key_exists('credits', $data) && is_array($data['credits']) && count($data['credits']) > 0) {
$_credit_totals = array_sum(array_column($data['credits'], 'amount'));

View File

@ -104,6 +104,8 @@ class ApplyPayment extends AbstractService
->ledger()
->updatePaymentBalance($amount_paid);
nlog("updating client balance by amount {$amount_paid}");
$this->invoice
->client
->service()

View File

@ -33,13 +33,9 @@ class InvoiceService
private $invoice;
protected $client_service;
public function __construct($invoice)
{
$this->invoice = $invoice;
$this->client_service = new ClientService($invoice->client);
}
/**
@ -49,7 +45,7 @@ class InvoiceService
*/
public function markPaid()
{
$this->invoice = (new MarkPaid($this->client_service, $this->invoice))->run();
$this->invoice = (new MarkPaid($this->invoice))->run();
return $this;
}

View File

@ -29,14 +29,10 @@ class MarkPaid extends AbstractService
{
use GeneratesCounter;
private $client_service;
private $invoice;
public function __construct(ClientService $client_service, Invoice $invoice)
public function __construct(Invoice $invoice)
{
$this->client_service = $client_service;
$this->invoice = $invoice;
}
@ -92,7 +88,9 @@ class MarkPaid extends AbstractService
$payment->ledger()
->updatePaymentBalance($payment->amount * -1);
$this->client_service
$this->invoice
->client
->service()
->updateBalance($payment->amount * -1)
->updatePaidToDate($payment->amount)
->save();