diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index 61c685bc4512..3c03138d04d1 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -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; diff --git a/app/Listeners/Activity/PaymentUpdatedActivity.php b/app/Listeners/Activity/PaymentUpdatedActivity.php index 4ddd72a41ab0..5d4dbe55afd5 100644 --- a/app/Listeners/Activity/PaymentUpdatedActivity.php +++ b/app/Listeners/Activity/PaymentUpdatedActivity.php @@ -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; diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 411a052aab6a..b5913f8b37b3 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -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')); diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index 196fb6e04b9e..da4dbe96449e 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -104,6 +104,8 @@ class ApplyPayment extends AbstractService ->ledger() ->updatePaymentBalance($amount_paid); + nlog("updating client balance by amount {$amount_paid}"); + $this->invoice ->client ->service() diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 2daf4bc074fa..8fa43294be92 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -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; } diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 68563ee5dfc7..7cbd52736242 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -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();