invoice = $invoice; } /** * Execute the job. * * * @return void */ public function handle() { /* Create Payment */ $payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id); $payment->amount = $this->invoice->balance; $payment->status_id = Payment::STATUS_COMPLETED; $payment->client_id = $this->invoice->client_id; /* Create a payment relationship to the invoice entity */ $payment->save(); $payment->invoices()->save($this->invoice); $payment->save(); /* Update Invoice balance */ //$invoice = ApplyPaymentToInvoice::dispatchNow($payment, $this->invoice); event(new PaymentWasCreated($payment)); UpdateCompanyLedgerWithPayment::dispatchNow($payment, $payment->amount); return $invoice; } }