addressBook()->where('reference_id', $this->id)->where('type', 1) ->where('billing', true)->first(); $reports = \App\Models\Order::select(DB::raw('count(*) total'), DB::raw('SUM(CASE WHEN complete = 0 THEN 0 ELSE 1 END) active'))->where('company_id', $this->id)->first(); return [ 'id' => $this->id, 'name' => $this->name, 'marking' => $this->marking, 'email' => $this->email, 'registration_no' => $this->registration_no, 'tax_no' => $this->tax_no, 'street_one' => $billing ? $billing->street_one : null, 'street_two' => $billing ? $billing->street_two : null, 'city' => $billing ? $billing->city : null, 'state' => $billing ? $billing->state : null, 'post_code' => $billing ? $billing->post_code : null, 'country' => $billing ? $billing->country : null, 'registration_certificate' => (new ListDocuments(Constants::MODULE_TYPES['company'], $this->id, 'registration_certificate'))->execute(), 'logo' => (new ListDocuments(Constants::MODULE_TYPES['company'], $this->id, 'logo'))->execute(), 'order_reports' => [ 'total' => (int) $reports->total, 'active' => (int) $reports->active ] ]; } }