invoice = $invoice; $this->adjustment = $adjustment; } /** * Execute the job. * * @return void */ public function handle() { $balance = 0; $ledger = CompanyLedger::whereClientId($this->invoice->client_id) ->whereCompanyId($this->invoice->company_id) ->orderBy('id', 'DESC') ->first(); if($ledger) $balance = $ledger->balance; $company_ledger = CompanyLedgerFactory::create($this->invoice->company_id, $this->invoice->user_id); $company_ledger->client_id = $this->invoice->client_id; $company_ledger->adjustment = $this->adjustment; $company_ledger->balance = $balance + $this->adjustment; $company_ledger->save(); $this->invoice->company_ledger()->save($company_ledger); } }