public function getEditCompInfo($id)
 {
     $company = \Company::where('user_id', '=', $id)->first();
     if ($company) {
         return \View::make('admin/user.company_view')->with('company', $company);
     }
 }
 public function all()
 {
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $messages = CannedMessages::where('company_id', $company->id)->where('department_id', $department->id)->orderBy('id', 'desc')->get();
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_admin = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $messages = CannedMessages::where('company_id', $company->id)->where('department_id', $department->id)->where('operator_id', Auth::user()->id)->orderBy('id', 'desc')->get();
     } else {
         $messages = CannedMessages::orderBy('id', 'desc')->get();
     }
     foreach ($messages as $message) {
         $operator = User::find($message->operator_id);
         $department = Department::find($message->department_id);
         $company = Company::find($message->company_id);
         $message->operator = $operator;
         $message->department = $department;
         $message->company = $company;
     }
     $this->data['messages'] = $messages;
     return View::make('canned_messages.all', $this->data);
 }
Esempio n. 3
0
 public function home($id = 0)
 {
     $param['pageNo'] = 0;
     if ($alert = Session::get('alert')) {
         $param['alert'] = $alert;
     }
     $userId = Session::has('user_id') ? Session::get('user_id') : 0;
     $prefix = DB::getTablePrefix();
     $result = DB::table('store')->join('company', 'store.company_id', '=', 'company.id')->leftJoin(DB::raw('(SELECT * FROM ' . $prefix . 'queue WHERE user_id = ' . $userId . ' AND DATE(created_at) = DATE(NOW()) GROUP BY store_id) AS ' . $prefix . 'queues'), 'store.id', '=', 'queues.store_id')->join('status', 'store.id', '=', 'status.store_id')->leftJoin(DB::raw('(SELECT count(*) as cnt, store_id FROM ' . $prefix . 'agent WHERE is_active = 1 GROUP BY store_id) AS ' . $prefix . 'agt'), 'agt.store_id', '=', 'store.id')->join('company_setting', 'company_setting.company_id', '=', 'company.id')->join('category', 'category.id', '=', 'company.category_id')->join('city', 'city.id', '=', 'company.city_id')->select('store.id', 'store.name as store_name', 'store.address as address', 'company.name as company_name', 'company_setting.waiting_time', 'status.current_queue_no', 'status.last_queue_no', 'agt.cnt', 'queues.queue_no');
     if ($id == 0) {
         $param['stores'] = $result->paginate(PAGINATION_SIZE);
     } else {
         $companyIds = array();
         $companyIds[] = 0;
         $companies = CompanyModel::where('category_id', $id)->get();
         foreach ($companies as $company) {
             $companyIds[] = $company->id;
         }
         $param['stores'] = $result->whereIn('store.company_id', $companyIds)->paginate(PAGINATION_SIZE);
     }
     $param['total'] = StoreModel::count();
     $param['category'] = $id;
     $param['categories'] = CategoryModel::all();
     return View::make('user.store.home')->with($param);
 }
 function getCompanies(Cluster $cluster)
 {
     $companies = Company::where('cluster_id', '=', $cluster->id)->get();
     // decode company domains
     foreach ($companies as $company) {
         $company->domains = json_decode($company->domains);
     }
     return $companies;
 }
 public function create()
 {
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_admin->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_operator = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_operator->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
     } else {
         $this->data['companies'] = Company::all();
     }
     $this->data['timezones'] = Config::get("timezones");
     $this->data['countries'] = DB::table('countries')->get();
     return View::make('customers.create', $this->data);
 }
Esempio n. 6
0
 static function getUpdatedFields($is_fake = false, $ticket_id = 0, $msg_id = 0)
 {
     if (!$is_fake) {
         $ticket = Tickets::where('id', $ticket_id)->first();
         $thread_message = ThreadMessages::where('id', $msg_id)->first();
         $ticket_attachment = TicketAttachments::where('message_id', $msg_id)->first();
         $customer = User::where('id', $ticket->customer_id)->first();
         $operator = User::where('id', $ticket->operator_id)->first();
         $company = Company::where('id', $ticket->company_id)->first();
         $department = Department::where('id', $ticket->department_id)->first();
         $receiver = Input::get('user_id') == $ticket->operator_id ? $customer : $operator;
         $mailer_extra = ['ticket_id' => $ticket->id, 'ticket_subject' => $ticket->subject, 'ticket_description' => $ticket->description, 'ticket_status' => $ticket->status, 'ticket_status_txt' => self::resolveStatus($ticket->status), 'ticket_priority' => $ticket->priority, 'ticket_priority_txt' => self::resolveStatus($ticket->priority), 'company_name' => $company->name, 'company_description' => $company->description, 'company_domain' => $company->domain, 'company_logo' => $company->logo, 'department_name' => $department->name, 'has_attachment' => $ticket_attachment->has_attachment, 'attachment_path' => $ticket_attachment->attachment_path, 'updated_message' => $thread_message->message, 'receiver_name' => $receiver->name, 'receiver_email' => $receiver->email];
     } else {
         $mailer_extra = ['ticket_id' => 1, 'ticket_subject' => "How can i use contact us form", 'ticket_description' => "Hi , Sir how can i use contact us form", 'ticket_status' => 1, 'ticket_status_txt' => self::resolveStatus(1), 'ticket_priority' => 1, 'ticket_priority_txt' => self::resolveStatus(1), 'company_name' => "KODEINFO", 'company_description' => "We are a small and dedicated team of designers/developers. This is our web design and development focused blog.We focus on pushing the boundaries of standards based web technologies.", 'company_domain' => "http://www.kodeinfo.com", 'company_logo' => "http://kodeinfo.com/img/shortlogo.png", 'department_name' => "General Queries", 'has_attachment' => false, 'attachment_path' => "", 'updated_message' => "This is a updated message from customer/operator", 'receiver_name' => "Imran", 'receiver_email' => "*****@*****.**"];
     }
     return $mailer_extra;
 }
Esempio n. 7
0
 function get_logged_company()
 {
     if (!$this->is_signed_in()) {
         return NULL;
     } else {
         if ($this->CI->session->userdata('company_id') || $this->CI->session->userdata('institution_id')) {
             $c = new Company();
             $c->where('id', $this->CI->session->userdata('company_id'))->get();
             if ($c->exists()) {
                 return $c;
             } else {
                 $c = new Institution();
                 $c->where('id', $this->CI->session->userdata('institution_id'))->get();
                 if ($c->exists()) {
                     return $c;
                 }
             }
         }
         return NULL;
     }
 }
 public function create()
 {
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_admin->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
         $permissions_keys = explode(",", $this->data['department']);
         $permissions = Permissions::whereIn('key', $permissions_keys)->get();
         $this->data['permissions'] = $permissions;
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_operator = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_operator->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
         $permissions_keys = explode(",", $this->data['department']);
         $permissions = Permissions::whereIn('key', $permissions_keys)->get();
         $this->data['permissions'] = $permissions;
     } else {
         $companies = Company::all();
         $this->data['companies'] = $companies;
         if (sizeof($companies) > 0) {
             $department = Department::where("company_id", $companies[0]->id)->first();
             if (empty($department)) {
                 Session::flash('error_msg', trans('msgs.create_department_before_adding_operators'));
                 return Redirect::back();
             }
             $permissions_keys = explode(",", $department->permissions);
             $permissions = Permissions::whereIn('key', $permissions_keys)->get();
             $this->data['permissions'] = $permissions;
             $this->data['departments'] = Department::where("company_id", $companies[0]->id)->get();
         } else {
             $this->data['permissions'] = [];
             $this->data['departments'] = [];
         }
     }
     $this->data["countries"] = DB::table("countries")->remember(60)->get();
     $this->data['timezones'] = Config::get("timezones");
     return View::make('operators.create', $this->data);
 }
 /**
  * Update the specified resource in storage.
  * PUT /contact/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     Input::merge(array_map('trim', Input::all()));
     $input = Input::all();
     $validation = Validator::make($input, Contact::$rules);
     $gettime = time() - 14400;
     $datetime_now = date("H:i:s", $gettime);
     if (Input::get('fullname') == 'No record found.') {
         return Redirect::route('contact.edit')->withInput()->with('class', 'error')->with('message', 'Input proper fullname.');
     }
     if ($validation->passes()) {
         if (Input::get('category') == '1') {
             $street = Input::get('street_hid');
             $city = Input::get('city_hid');
             $province = Input::get('province_hid');
             $country = Input::get('country_hid');
             $zip_code = Input::get('zip_code_hid');
             $street_2 = Input::get('street_2');
             $city_2 = Input::get('city_2');
             $province_2 = Input::get('province_2');
             $country_2 = Input::get('country_2');
             $zip_code_2 = Input::get('zip_code_2');
         } else {
             $street = Input::get('i_street');
             $city = Input::get('i_city');
             $province = Input::get('i_province');
             $country = Input::get('i_country');
             $zip_code = Input::get('i_zip_code');
             $street_2 = Input::get('street_2');
             $city_2 = Input::get('city_2');
             $province_2 = Input::get('province_2');
             $country_2 = Input::get('country_2');
             $zip_code_2 = Input::get('zip_code_2');
         }
         if ($street == "" || $city == "" || $country == "") {
             return Redirect::route('contact.edit', $id)->withInput()->with('class', 'error')->with('message', 'Make sure to fill-up company address.');
         }
         $contact = Contact::find($id);
         if (is_null($contact)) {
             return Redirect::route('contact.edit', $id)->withInput()->withErrors($validation)->with('class', 'warning')->with('message', 'Contact information not exist.');
         }
         $contact->position = Input::get('profession');
         $contact->fullname = strtoupper(Input::get('fullname'));
         $contact->gender = strtoupper(Input::get('gender'));
         $contact->category = Input::get('category');
         $contact->company = Input::get('company');
         $contact->in_company_position = Input::get('position');
         $contact->street = strtoupper($street);
         $contact->city = strtoupper($city);
         $contact->province = strtoupper($province);
         $contact->country = strtoupper($country);
         $contact->zip_code = strtoupper($zip_code);
         $contact->street_2 = strtoupper($street_2);
         $contact->city_2 = strtoupper($city_2);
         $contact->province_2 = strtoupper($province_2);
         $contact->country_2 = strtoupper($country_2);
         $contact->zip_code_2 = strtoupper($zip_code_2);
         $contact->contact_number = Input::get('contact_number');
         $contact->contact_number2 = Input::get('2nd_contact_number');
         $contact->contact_number3 = Input::get('3rd_contact_number');
         $contact->status = 1;
         // if(Contact::check_ifcontactinfoExist($contact))
         // {
         // 	return Redirect::route('contact.edit', $id)
         // 					->withInput()
         // 					->withErrors($validation)
         // 					->with('class', 'warning')
         // 					->with('message', 'Record was already added by BDO.');
         // }
         $contactinformation = DB::table('contacts')->select('contacts.*', 'positions.position as cp_position')->join('positions', 'positions.id', '=', 'contacts.position')->where('contacts.id', $id)->first();
         $pos = DB::table('positions')->where('id', Input::get('position'))->first();
         if ($contactinformation->company != '0') {
             $comp = Company::where('id', $contactinformation->company)->first();
             $companyname = $comp->company_name;
             $new_comp = Company::where('id', Input::get('company'))->first();
             $new_companyname = $new_comp->company_name;
         } else {
             $companyname = 'N/A';
             $new_companyname = 'N/A';
         }
         if (Contact::where('position', Input::get('position'))->where('id', $id)->count() > 0) {
             $position = "";
         } else {
             $position = "POSITION : " . $contactinformation->cp_position . " INTO " . strtoupper($pos->position) . ", ";
         }
         if (Contact::where('fullname', strtoupper(Input::get('fullname')))->where('id', $id)->count() > 0) {
             $fullname = "";
         } else {
             $fullname = "FULLNAME : " . $contactinformation->fullname . " INTO " . strtoupper(Input::get('fullname')) . ", ";
         }
         if (Contact::where('gender', strtoupper(Input::get('gender')))->where('id', $id)->count() > 0) {
             $gender = "";
         } else {
             $gender = "GENDER : " . $contactinformation->gender . " INTO " . strtoupper(Input::get('gender')) . ", ";
         }
         if (Contact::where('company', Input::get('company'))->where('id', $id)->count() > 0) {
             $company = "";
         } else {
             $company = "COMPANY : " . $companyname . " INTO " . strtoupper($new_companyname) . ", ";
         }
         if (Input::get('category') == '1') {
             if (Contact::where('street', Input::get('street_hid'))->where('city', Input::get('city_hid'))->where('province', Input::get('province_hid'))->where('country', Input::get('country_hid'))->where('zip_code', Input::get('zip_code_hid'))->where('id', $id)->count() > 0) {
                 $address = "";
             } else {
                 $address = "COMPANY ADDRESS : " . $contactinformation->street . " " . $contactinformation->city . ", " . $contactinformation->country . " " . $contactinformation->zip_code . " INTO " . strtoupper(Input::get('street_hid')) . " " . strtoupper(Input::get('city_hid')) . ", " . strtoupper(Input::get('country_hid')) . " " . strtoupper(Input::get('zip_code_hid')) . ", ";
             }
         } else {
             if (Contact::where('street', Input::get('i_street'))->where('city', Input::get('i_city'))->where('province', Input::get('i_province'))->where('country', Input::get('i_country'))->where('zip_code', Input::get('i_zip_code'))->where('id', $id)->count() > 0) {
                 $address = "";
             } else {
                 $address = "PERSONAL ADDRESS : " . $contactinformation->street . " " . $contactinformation->city . ", " . $contactinformation->country . " " . $contactinformation->zip_code . " INTO " . strtoupper(Input::get('i_street')) . " " . strtoupper(Input::get('i_city')) . ", " . strtoupper(Input::get('i_country')) . " " . strtoupper(Input::get('i_zip_code')) . ", ";
             }
         }
         if (Contact::where('contact_number', Input::get('contact_number'))->where('id', $id)->count() > 0) {
             $contact1 = "";
         } else {
             $contact1 = "CONTACT NUMBER : " . $contactinformation->contact_number . " INTO " . strtoupper(Input::get('contact_number')) . ", ";
         }
         if (Contact::where('contact_number2', Input::get('2nd_contact_number'))->where('id', $id)->count() > 0) {
             $contact2 = "";
         } else {
             $contact2 = "2nd CONTACT NUMBER : " . $contactinformation->contact_number2 . " INTO " . strtoupper(Input::get('2nd_contact_number')) . ", ";
         }
         if (Contact::where('contact_number3', Input::get('3rd_contact_number'))->where('id', $id)->count() > 0) {
             $contact3 = "";
         } else {
             $contact3 = "3rd CONTACT NUMBER : " . $contactinformation->contact_number3 . " INTO " . strtoupper(Input::get('3rd_contact_number')) . ", ";
         }
         $contact->save();
         DB::table('contact_status')->insert(array(['contact_id' => $contact->id, 'user_id' => Auth::id(), 'update' => 'CHANGE ' . $contactinformation->fullname . ' IN CONTACT PERSON RECORD ' . ' | ' . $position . $fullname . $gender . $company . $address . $contact1 . $contact2 . $contact3, 'created_by' => Auth::id(), 'created_at' => date('Y-m-d') . ' ' . $datetime_now, 'access' => 1]));
         return Redirect::route('contact.index')->with('class', 'success')->with('message', 'Record successfully updated.');
     } else {
         return Redirect::route('contact.edit', $id)->withInput()->withErrors($validation)->with('class', 'error')->with('message', 'There were validation errors.');
     }
 }
 public function delete($company_id)
 {
     $departments = Department::where('company_id', $company_id)->get();
     if (Config::get('site-config.is_demo') && $company_id == 1) {
         Session::flash('error_msg', 'Demo : Feature is disabled');
         return Redirect::to('/dashboard');
     }
     foreach ($departments as $department) {
         if (!empty($department)) {
             $tickets = Tickets::where('department_id', $department->id)->get();
             //Delete tickets
             foreach ($tickets as $ticket) {
                 TicketAttachments::where('thread_id', $ticket->id)->delete();
                 MessageThread::where('id', $ticket->thread_id)->delete();
                 ThreadMessages::where('thread_id', $ticket->thread_id)->delete();
             }
             Tickets::where('department_id', $department->id)->delete();
             //Delete Chat and Conversations
             $online_users = OnlineUsers::where('department_id', $department->id)->get();
             foreach ($online_users as $online_user) {
                 MessageThread::where('id', $online_user->thread_id)->delete();
                 ThreadMessages::where('thread_id', $online_user->thread_id)->delete();
             }
             OnlineUsers::where('department_id', $department->id)->delete();
             $closed_conversations = ClosedConversations::where('department_id', $department->id)->get();
             foreach ($closed_conversations as $closed_conversation) {
                 MessageThread::where('id', $closed_conversation->thread_id)->delete();
                 ThreadMessages::where('thread_id', $closed_conversation->thread_id)->delete();
             }
             ClosedConversations::where('department_id', $department->id)->delete();
             $operators = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
             if (sizeof($operators) > 0) {
                 User::whereIn('id', $operators)->delete();
                 UsersGroups::whereIn('user_id', $operators)->delete();
             }
             OperatorsDepartment::where('department_id', $department->id)->delete();
             $department_admin = DepartmentAdmins::where('department_id', $department->id)->first();
             if (!empty($department_admin)) {
                 UsersGroups::where('user_id', $department_admin->user_id)->delete();
                 User::where("id", $department_admin->user_id)->delete();
                 CompanyDepartmentAdmins::where("user_id", $department_admin->user_id)->delete();
                 CannedMessages::where('operator_id', $operators)->delete();
             }
         }
         DepartmentAdmins::where('department_id', $department->id)->delete();
         Department::where('id', $department->id)->delete();
     }
     $company = Company::where('id', $company_id)->first();
     RecentActivities::createActivity("Company <a href='/companies/all'>" . $company->name . "</a> deleted by User Name " . Auth::user()->name . " User ID " . Auth::user()->id);
     Company::where('id', $company_id)->delete();
     Session::flash('success_msg', trans('msgs.company_deleted_success'));
     return Redirect::to('/companies/all');
 }
Esempio n. 11
0
    Route::post('admin/companies/add', function () {
        $input = Input::get(array('title', 'slug', 'description'));
        $validator = new validator($input);
        $validator->check('title')->is_max(3, __('companies.title_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/companies/add');
        }
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        $input['slug'] = slug($input['slug']);
        $company = Company::create($input);
        Extend::process('company', $company->id);
        Notify::success(__('companies.created'));
        return Response::redirect('admin/companies');
    });
    Route::get('admin/companies/delete/(:num)', function ($id) {
        $total = Company::count();
        if ($total == 1) {
            Notify::error(__('companies.delete_error'));
            return Response::redirect('admin/companies/edit/' . $id);
        }
        $company = Company::where('id', '<>', $id)->fetch();
        Company::find($id)->delete();
        Post::where('company', '=', $id)->update(array('company' => $company->id));
        Notify::success(__('companies.deleted'));
        return Response::redirect('admin/companies');
    });
});
 public function all()
 {
     $online_users = OnlineUsers::all();
     foreach ($online_users as $user) {
         $user->user = User::find($user->user_id);
         if ($user->operator_id > 0) {
             $user->operator = User::find($user->operator_id);
         }
     }
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_admin->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_operator = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_operator->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
     }
     $this->data['online_users'] = $online_users;
     return View::make('conversations.all', $this->data);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //transaction strats
     \DB::beginTransaction();
     //delete user in user table
     $userDel = \User::find($id);
     if (!$userDel->delete()) {
         \DB::rollback();
         return \Redirect::back()->with('error', 'Failed to delete');
     }
     //delete user from friends table
     $friendDel = \Friends::where('child_id', '=', $id)->first();
     if (!$friendDel->delete()) {
         \DB::rollback();
         return \Redirect::back()->with('error', 'Failed to delete');
     }
     //delete clients company
     $companyDel = \Company::where('user_id', '=', $id)->first();
     if (!$companyDel->delete()) {
         \DB::rollback();
         return \Redirect::back()->with('error', 'Failed to delete');
     } else {
         \DB::commit();
         return \Redirect::back()->with('success', 'Successfully deleted');
     }
 }
 public function edittask_forcompany($id)
 {
     $pagetitle = 'Edit Task for Company';
     $get_company = Company::where('status', '=', 2)->orderBy('company_name', 'asc')->lists('company_name', 'id');
     $get_task = Task::orderBy('task', 'asc')->lists('task', 'id');
     $get_taskforcompany = DB::table('mytask_forcompany')->where('id', $id)->first();
     $getattached = DB::table('attached_forcompany')->where('forcompany_id', $id)->get();
     $my_company = Company::where('id', $get_taskforcompany->company_id)->first();
     $my_task = Task::where('id', $get_taskforcompany->task_id)->first();
     return View::make('task.edit_taskforcompany', compact('pagetitle', 'get_company', 'get_task', 'get_taskforcompany', 'my_company', 'my_task', 'getattached'));
 }
Esempio n. 15
0
 function company_get()
 {
     $filters = $this->get("filter")["filters"];
     $page = $this->get("page");
     $limit = $this->get("limit");
     $sort = $this->get("sort");
     $data["results"] = array();
     $data["count"] = 0;
     $obj = new Company(null, $this->entity);
     //Sort
     if (!empty($sort) && isset($sort)) {
         foreach ($sort as $value) {
             $obj->order_by($value["field"], $value["dir"]);
         }
     }
     //Filter
     if (!empty($filters) && isset($filters)) {
         foreach ($filters as $value) {
             $obj->where($value["field"], $value["value"]);
         }
     }
     if (!empty($limit) && !empty($page)) {
         $obj->include_related('currency', array('locale', 'rate'), FALSE);
         $obj->get_paged_iterated($page, $limit);
         $data["count"] = $obj->paged->total_rows;
     }
     if ($obj->result_count() > 0) {
         foreach ($obj as $value) {
             //Results
             $data["results"][] = array("id" => $value->id, "name" => $value->name, "abbr" => $value->abbr, "currency_id" => $value->currency_id, "locale" => $value->locale, "rate" => $value->rate);
         }
     }
     //Response Data
     $this->response($data, 200);
 }
 public function all()
 {
     $tickets = Tickets::orderBy('priority', 'desc')->where('customer_id', Auth::user()->id)->get();
     foreach ($tickets as $ticket) {
         $ticket->customer = User::where('id', $ticket->customer_id)->first();
         $ticket->company = Company::where('id', $ticket->company_id)->first();
         $ticket->department = Department::where('id', $ticket->department_id)->first();
         if ($ticket->operator_id > 0) {
             $ticket->operator = User::where('id', $ticket->operator_id)->first();
         }
     }
     $this->data['tickets'] = $tickets;
     return View::make('tickets.customers_all', $this->data);
 }
 public function ticketsRefresh()
 {
     if (Input::get('company_id', 0) > 0 && Input::get('department_id', 0) > 0) {
         $tickets = Tickets::orderBy('priority', 'desc')->where('company_id', Input::get('company_id'))->where('department_id', Input::get('department_id'))->get();
     } else {
         $tickets = Tickets::orderBy('priority', 'desc')->get();
     }
     $tickets_arr = [];
     foreach ($tickets as $ticket) {
         $ticket->customer = User::where('id', $ticket->customer_id)->first();
         $ticket->company = Company::where('id', $ticket->company_id)->first();
         $ticket->department = Department::where('id', $ticket->department_id)->first();
         if ($ticket->operator_id > 0) {
             $ticket->operator = User::where('id', $ticket->operator_id)->first();
         }
         $single_ticket = [];
         $single_ticket[] = $ticket->id;
         $single_ticket[] = isset($ticket->company) ? $ticket->company->name : trans('msgs.none');
         $single_ticket[] = isset($ticket->department) ? $ticket->department->name : trans('msgs.none');
         $single_ticket[] = isset($ticket->customer) ? $ticket->customer->name : trans('msgs.none');
         $single_ticket[] = isset($ticket->customer) ? $ticket->customer->email : trans('msgs.none');
         $single_ticket[] = $ticket->subject;
         $single_ticket[] = isset($ticket->operator) ? $ticket->operator->name : trans('msgs.none');
         if ($ticket->priority == Tickets::PRIORITY_LOW) {
             $single_ticket[] = '<td ><label class="label label-primary" > ' . trans("msgs.low") . ' </label ></td >';
         }
         if ($ticket->priority == Tickets::PRIORITY_MEDIUM) {
             $single_ticket[] = '<td><label class="label label-primary">' . trans("msgs.medium") . '</label></td>';
         }
         if ($ticket->priority == Tickets::PRIORITY_HIGH) {
             $single_ticket[] = '<td><label class="label label-warning">' . trans("msgs.high") . '</label></td>';
         }
         if ($ticket->priority == Tickets::PRIORITY_URGENT) {
             $single_ticket[] = '<td><label class="label label-danger">' . trans("msgs.urgent") . '</label></td>';
         }
         if ($ticket->status == Tickets::TICKET_NEW) {
             $single_ticket[] = '<td><label class="label label-warning">' . trans("msgs.new") . '</label></td>';
         }
         if ($ticket->status == Tickets::TICKET_PENDING) {
             $single_ticket[] = '<td><label class="label label-primary">' . trans("msgs.pending") . '</label></td>';
         }
         if ($ticket->status == Tickets::TICKET_RESOLVED) {
             $single_ticket[] = '<td><label class="label label-success">' . trans("msgs.resolved") . '</label></td>';
         }
         if (!isset($ticket->operator)) {
             $single_ticket[] = '<td><a href="/tickets/read/' . $ticket->thread_id . '" class="btn btn-success btn-sm"> <i class="icon-checkmark4"></i> ' . trans("msgs.accept") . ' </a></td>';
         }
         if (isset($ticket->operator) && $ticket->operator->id == Auth::user()->id) {
             $single_ticket[] = '<td><a href="/tickets/read/' . $ticket->thread_id . '" class="btn btn-success btn-sm"> <i class="icon-checkmark4"></i> ' . trans("msgs.reply") . ' </a></td>';
         }
         if (isset($ticket->operator) && $ticket->operator->id != Auth::user()->id) {
             $single_ticket[] = '<td><a disabled class="btn btn-success btn-sm"> <i class="icon-lock3"></i> ' . trans("msgs.accept") . ' </a></td>';
         }
         $single_ticket[] = '<td><a href="/tickets/transfer/' . $ticket->id . '" class="btn btn-warning btn-sm"> <i class="icon-share3"></i> ' . trans("msgs.transfer") . ' </a></td>';
         $single_ticket[] = '<td><a href="/tickets/delete/' . $ticket->thread_id . '" class="btn btn-danger btn-sm"> <i class="icon-remove3"></i> ' . trans("msgs.delete") . ' </a></td>';
         $tickets_arr[] = $single_ticket;
     }
     return json_encode(['aaData' => $tickets_arr]);
 }
 /**
  * Update the specified resource in storage.
  * PUT /company/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     Input::merge(array_map('trim', Input::all()));
     $input = Input::all();
     $validation = Validator::make($input, Company::$update_rules);
     $gettime = time() - 14400;
     $datetime_now = date("H:i:s", $gettime);
     if ($validation->passes()) {
         $company = Company::find($id);
         if (is_null($company)) {
             return Redirect::route('company.index')->withInput()->withErrors($validation)->with('class', 'warning')->with('message', 'Company information not exist.');
         }
         $company->company_name = strtoupper(Input::get('company_name'));
         $company->type_id = Input::get('client_type');
         $company->street = strtoupper(Input::get('street'));
         $company->city_id = Input::get('city');
         $company->province_id = Input::get('province');
         $company->region = Input::get('region');
         $company->country = strtoupper(Input::get('country'));
         $company->zip_code = Input::get('zip_code');
         $company->street2 = strtoupper(Input::get('2nd_street'));
         $company->city_id2 = Input::get('2nd_city');
         $company->province_id2 = Input::get('2nd_province');
         $company->region2 = strtoupper(Input::get('2nd_region'));
         $company->country2 = strtoupper(Input::get('2nd_country'));
         $company->zip_code2 = strtoupper(Input::get('2nd_zip_code'));
         $company->street3 = strtoupper(Input::get('3rd_street'));
         $company->city_id3 = Input::get('3rd_city');
         $company->province_id3 = Input::get('3rd_province');
         $company->region3 = strtoupper(Input::get('3rd_region'));
         $company->country3 = strtoupper(Input::get('3rd_country'));
         $company->zip_code3 = strtoupper(Input::get('3rd_zip_code'));
         $company->telephone_number = Input::get('telephone_number');
         $company->fax_number = strtoupper(Input::get('fax_number'));
         $company->mobile_number = Input::get('mobile_number');
         $company->email = strtoupper(Input::get('email'));
         $company->telephone_number2 = Input::get('2nd_telephone_number');
         $company->fax_number2 = strtoupper(Input::get('2nd_fax_number'));
         $company->mobile_number2 = Input::get('2nd_mobile_number');
         $company->email2 = strtoupper(Input::get('2nd_email'));
         $company->telephone_number3 = Input::get('3rd_telephone_number');
         $company->fax_number3 = strtoupper(Input::get('3rd_fax_number'));
         $company->mobile_number3 = Input::get('3rd_mobile_number');
         $company->email3 = strtoupper(Input::get('3rd_email'));
         $company->status = 1;
         // if(Company::selectinfo_forupdate($company))
         // {
         // 	return Redirect::route('company.edit', $id)
         // 						->withInput()
         // 						->withErrors($validation)
         // 						->with('class', 'warning')
         // 						->with('message', 'Record was already added by Business Development Officer.');
         // }
         $company_information = DB::table('companies')->select('companies.*', 'cities.city', 'provinces.province', 'types.client_type')->join('types', 'types.id', '=', 'companies.type_id')->join('cities', 'cities.id', '=', 'companies.city_id')->join('provinces', 'provinces.id', '=', 'companies.province_id')->where('companies.id', $id)->first();
         $clienttype = DB::table('types')->where('id', Input::get('client_type'))->first();
         if (Company::where('company_name', Input::get('company_name'))->where('id', $id)->count() > 0) {
             $company_name = "";
         } else {
             $company_name = "COMPANY NAME : " . $company_information->company_name . " INTO " . strtoupper(Input::get('company_name')) . ", ";
         }
         if (Company::where('type_id', Input::get('client_type'))->where('id', $id)->count() > 0) {
             $client_type = "";
         } else {
             $client_type = "CLIENT TYPE : " . $company_information->client_type . " INTO " . strtoupper($clienttype->client_type) . ", ";
         }
         if (Company::where('street', Input::get('street'))->where('city_id', Input::get('city'))->where('province_id', Input::get('province'))->where('region', Input::get('region'))->where('country', Input::get('country'))->where('zip_code', Input::get('zip_code'))->where('id', $id)->count() > 0) {
             $company_address1 = "";
         } else {
             $company_address1 = "COMPANY ADDRESS : " . $company_information->street . " " . $company_information->city . ", " . $company_information->country . " " . $company_information->zip_code . " INTO " . strtoupper(Input::get('street')) . " " . strtoupper(Input::get('city')) . ", " . strtoupper(Input::get('country')) . " " . strtoupper(Input::get('zip_code')) . ", ";
         }
         if (Company::where('street2', Input::get('2nd_street'))->where('city_id2', Input::get('2nd_city'))->where('province_id2', Input::get('2nd_province'))->where('region2', Input::get('2nd_region'))->where('country2', Input::get('2nd_country'))->where('zip_code2', Input::get('2nd_zip_code'))->where('id', $id)->count() > 0) {
             $company_address2 = "";
         } else {
             $company_address2 = "2nd COMPANY ADDRESS : " . $company_information->street2 . " " . $company_information->city2 . ", " . $company_information->country2 . " " . $company_information->zip_code2 . " INTO " . strtoupper(Input::get('2nd_street')) . " " . strtoupper(Input::get('2nd_city')) . ", " . strtoupper(Input::get('2nd_country')) . " " . strtoupper(Input::get('2nd_zip_code')) . ", ";
         }
         if (Company::where('street3', Input::get('3rd_street'))->where('city_id3', Input::get('3rd_city'))->where('province_id3', Input::get('3rd_province'))->where('region3', Input::get('3rd_region'))->where('country3', Input::get('3rd_country'))->where('zip_code3', Input::get('3rd_zip_code'))->where('id', $id)->count() > 0) {
             $company_address3 = "";
         } else {
             $company_address3 = "3rd COMPANY ADDRESS : " . $company_information->street3 . " " . $company_information->city3 . ", " . $company_information->country3 . " " . $company_information->zip_code3 . " INTO " . strtoupper(Input::get('3rd_street')) . " " . strtoupper(Input::get('3rd_city')) . ", " . strtoupper(Input::get('3rd_country')) . " " . strtoupper(Input::get('3rd_zip_code')) . ", ";
         }
         if (Company::where('telephone_number', Input::get('telephone_number'))->where('fax_number', Input::get('fax_number'))->where('mobile_number', Input::get('mobile_number'))->where('email', Input::get('email'))->where('id', $id)->count() > 0) {
             $contact = "";
         } else {
             $contact = "CONTACT INFORMATION : " . $company_information->telephone_number . " / " . $company_information->fax_number . " / " . $company_information->mobile_number . " / " . $company_information->email . " INTO " . strtoupper(Input::get('telephone_number')) . " / " . strtoupper(Input::get('fax_number')) . " / " . strtoupper(Input::get('mobile_number')) . " / " . strtoupper(Input::get('email')) . ", ";
         }
         if (Company::where('telephone_number2', Input::get('2nd_telephone_number'))->where('fax_number2', Input::get('2nd_fax_number'))->where('mobile_number2', Input::get('2nd_mobile_number'))->where('email2', Input::get('2nd_email'))->where('id', $id)->count() > 0) {
             $contact2 = "";
         } else {
             $contact2 = "2nd CONTACT INFORMATION : " . $company_information->telephone_number2 . " / " . $company_information->fax_number2 . " / " . $company_information->mobile_number2 . " / " . $company_information->email2 . " INTO " . strtoupper(Input::get('2nd_telephone_number')) . " / " . strtoupper(Input::get('2nd_fax_number')) . " / " . strtoupper(Input::get('2nd_mobile_number')) . " / " . strtoupper(Input::get('2nd_email')) . ", ";
         }
         if (Company::where('telephone_number3', Input::get('3rd_telephone_number'))->where('fax_number3', Input::get('3rd_fax_number'))->where('mobile_number3', Input::get('3rd_mobile_number'))->where('email3', Input::get('3rd_email'))->where('id', $id)->count() > 0) {
             $contact3 = "";
         } else {
             $contact3 = "3rd CONTACT INFORMATION : " . $company_information->telephone_number3 . " / " . $company_information->fax_number3 . " / " . $company_information->mobile_number3 . " / " . $company_information->email3 . " INTO " . strtoupper(Input::get('3rd_telephone_number')) . " / " . strtoupper(Input::get('3rd_fax_number')) . " / " . strtoupper(Input::get('3rd_mobile_number')) . " / " . strtoupper(Input::get('3rd_email')) . ", ";
         }
         $company->save();
         DB::table('company_status')->insert(array(['company_id' => $company->id, 'user_id' => Auth::id(), 'update' => 'CHANGE ' . $company_information->company_name . ' IN COMPANY RECORD ' . ' | ' . $company_name . $client_type . $company_address1 . $company_address2 . $company_address3 . $contact . $contact2 . $contact3, 'created_by' => Auth::id(), 'created_at' => date('Y-m-d') . ' ' . $datetime_now, 'access' => 1]));
         return Redirect::route('company.index')->with('class', 'success')->with('message', 'Record successfully updated.');
     } else {
         return Redirect::route('company.edit', $id)->withInput()->withErrors($validation)->with('class', 'error')->with('message', 'There were validation errors.');
     }
 }
 public function delete($admin_id)
 {
     $department_admin = DepartmentAdmins::where("user_id", $admin_id)->first();
     if (Config::get('site-config.is_demo') && $admin_id == 2) {
         Session::flash('error_msg', 'Demo : Feature is disabled');
         return Redirect::to('/dashboard');
     }
     if (!empty($department_admin)) {
         $department = Department::where('id', $department_admin->department_id)->first();
         if (!empty($department)) {
             $company = Company::where('id', $department->company_id)->first();
             //Change all conversations , tickets , threads , thread_messages operator_id
             OnlineUsers::where('operator_id', $admin_id)->update(['operator_id' => $company->user_id]);
             ClosedConversations::where('operator_id', $admin_id)->update(['operator_id' => $company->user_id]);
             MessageThread::where('operator_id', $admin_id)->update(['operator_id' => $company->user_id]);
             Tickets::where('operator_id', $admin_id)->update(['operator_id' => $company->user_id]);
             ThreadMessages::where('sender_id', $admin_id)->update(['sender_id' => $company->user_id]);
         }
     }
     CompanyDepartmentAdmins::where("user_id", $admin_id)->delete();
     DepartmentAdmins::where('user_id', $admin_id)->delete();
     UsersGroups::where('user_id', $admin_id)->delete();
     User::where('id', $admin_id)->delete();
     RecentActivities::createActivity("Department admin deleted by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name);
     Session::flash('success_msg', trans('msgs.department_admin_deleted_success'));
     return Redirect::to('/departments/admins/all');
 }
Esempio n. 20
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     if (!$this->option('testrun') == 'true') {
         $this->comment('======= Importing Assets from ' . $filename . ' =========');
     } else {
         $this->comment('====== TEST ONLY Asset Import for ' . $filename . ' ====');
         $this->comment('============== NO DATA WILL BE WRITTEN ==============');
     }
     if (!ini_get("auto_detect_line_endings")) {
         ini_set("auto_detect_line_endings", '1');
     }
     $csv = Reader::createFromPath($this->argument('filename'));
     $csv->setNewline("\r\n");
     $csv->setOffset(1);
     $duplicates = '';
     // Loop through the records
     $nbInsert = $csv->each(function ($row) use($duplicates) {
         $status_id = 1;
         // Let's just map some of these entries to more user friendly words
         // User's name
         if (array_key_exists('0', $row)) {
             $user_name = trim($row[0]);
         } else {
             $user_name = '';
         }
         // User's email
         if (array_key_exists('1', $row)) {
             $user_email = trim($row[1]);
         } else {
             $user_email = '';
         }
         // User's email
         if (array_key_exists('2', $row)) {
             $user_username = trim($row[2]);
         } else {
             $user_username = '';
         }
         // Asset Name
         if (array_key_exists('3', $row)) {
             $user_asset_asset_name = trim($row[3]);
         } else {
             $user_asset_asset_name = '';
         }
         // Asset Category
         if (array_key_exists('4', $row)) {
             $user_asset_category = trim($row[4]);
         } else {
             $user_asset_category = '';
         }
         // Asset Name
         if (array_key_exists('5', $row)) {
             $user_asset_name = trim($row[5]);
         } else {
             $user_asset_name = '';
         }
         // Asset Manufacturer
         if (array_key_exists('6', $row)) {
             $user_asset_mfgr = trim($row[6]);
         } else {
             $user_asset_mfgr = '';
         }
         // Asset model number
         if (array_key_exists('7', $row)) {
             $user_asset_modelno = trim($row[7]);
         } else {
             $user_asset_modelno = '';
         }
         // Asset serial number
         if (array_key_exists('8', $row)) {
             $user_asset_serial = trim($row[8]);
         } else {
             $user_asset_serial = '';
         }
         // Asset tag
         if (array_key_exists('9', $row)) {
             $user_asset_tag = trim($row[9]);
         } else {
             $user_asset_tag = '';
         }
         // Asset location
         if (array_key_exists('10', $row)) {
             $user_asset_location = trim($row[10]);
         } else {
             $user_asset_location = '';
         }
         // Asset notes
         if (array_key_exists('11', $row)) {
             $user_asset_notes = trim($row[11]);
         } else {
             $user_asset_notes = '';
         }
         // Asset purchase date
         if (array_key_exists('12', $row)) {
             if ($row[12] != '') {
                 $user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12]));
             } else {
                 $user_asset_purchase_date = '';
             }
         } else {
             $user_asset_purchase_date = '';
         }
         // Asset purchase cost
         if (array_key_exists('13', $row)) {
             if ($row[13] != '') {
                 $user_asset_purchase_cost = trim($row[13]);
             } else {
                 $user_asset_purchase_cost = '';
             }
         } else {
             $user_asset_purchase_cost = '';
         }
         // Asset Company Name
         if (array_key_exists('14', $row)) {
             if ($row[14] != '') {
                 $user_asset_company_name = trim($row[14]);
             } else {
                 $user_asset_company_name = '';
             }
         } else {
             $user_asset_company_name = '';
         }
         // A number was given instead of a name
         if (is_numeric($user_name)) {
             $this->comment('User ' . $user_name . ' is not a name - assume this user already exists');
             $user_username = '';
             // No name was given
         } elseif ($user_name == '') {
             $this->comment('No user data provided - skipping user creation, just adding asset');
             $first_name = '';
             $last_name = '';
             //$user_username = '';
         } else {
             $user_email_array = User::generateFormattedNameFromFullName($this->option('email_format'), $user_name);
             $first_name = $user_email_array['first_name'];
             $last_name = $user_email_array['last_name'];
             if ($user_email == '') {
                 $user_email = $user_email_array['username'] . '@' . Config::get('app.domain');
             }
             if ($user_username == '') {
                 if ($this->option('username_format') == 'email') {
                     $user_username = $user_email;
                 } else {
                     $user_name_array = User::generateFormattedNameFromFullName($this->option('username_format'), $user_name);
                     $user_username = $user_name_array['username'];
                 }
             }
         }
         $this->comment('Full Name: ' . $user_name);
         $this->comment('First Name: ' . $first_name);
         $this->comment('Last Name: ' . $last_name);
         $this->comment('Username: '******'Email: ' . $user_email);
         $this->comment('Category Name: ' . $user_asset_category);
         $this->comment('Item: ' . $user_asset_name);
         $this->comment('Manufacturer ID: ' . $user_asset_mfgr);
         $this->comment('Model No: ' . $user_asset_modelno);
         $this->comment('Serial No: ' . $user_asset_serial);
         $this->comment('Asset Tag: ' . $user_asset_tag);
         $this->comment('Location: ' . $user_asset_location);
         $this->comment('Purchase Date: ' . $user_asset_purchase_date);
         $this->comment('Purchase Cost: ' . $user_asset_purchase_cost);
         $this->comment('Notes: ' . $user_asset_notes);
         $this->comment('Company Name: ' . $user_asset_company_name);
         $this->comment('------------- Action Summary ----------------');
         if ($user_username != '') {
             if ($user = User::MatchEmailOrUsername($user_username, $user_email)->whereNotNull('username')->first()) {
                 $this->comment('User ' . $user_username . ' already exists');
             } else {
                 // Create the user
                 $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $user_email, 'username' => $user_username, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 12), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'User imported through asset importer'));
                 // Find the group using the group id
                 $userGroup = Sentry::findGroupById(3);
                 // Assign the group to the user
                 $user->addGroup($userGroup);
                 $this->comment('User ' . $first_name . ' created');
             }
         } else {
             $user = new User();
         }
         // Check for the location match and create it if it doesn't exist
         if ($location = Location::where('name', e($user_asset_location))->first()) {
             $this->comment('Location ' . $user_asset_location . ' already exists');
         } else {
             $location = new Location();
             if ($user_asset_location != '') {
                 $location->name = e($user_asset_location);
                 $location->address = '';
                 $location->city = '';
                 $location->state = '';
                 $location->country = '';
                 $location->user_id = 1;
                 if (!$this->option('testrun') == 'true') {
                     if ($location->save()) {
                         $this->comment('Location ' . $user_asset_location . ' was created');
                     } else {
                         $this->comment('Something went wrong! Location ' . $user_asset_location . ' was NOT created');
                     }
                 } else {
                     $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only');
                 }
             } else {
                 $this->comment('No location given, so none created.');
             }
         }
         if (e($user_asset_category) == '') {
             $category_name = 'Unnamed Category';
         } else {
             $category_name = e($user_asset_category);
         }
         // Check for the category match and create it if it doesn't exist
         if ($category = Category::where('name', e($category_name))->where('category_type', 'asset')->first()) {
             $this->comment('Category ' . $category_name . ' already exists');
         } else {
             $category = new Category();
             $category->name = e($category_name);
             $category->category_type = 'asset';
             $category->user_id = 1;
             if ($category->save()) {
                 $this->comment('Category ' . $user_asset_category . ' was created');
             } else {
                 $this->comment('Something went wrong! Category ' . $user_asset_category . ' was NOT created');
             }
         }
         // Check for the manufacturer match and create it if it doesn't exist
         if ($manufacturer = Manufacturer::where('name', e($user_asset_mfgr))->first()) {
             $this->comment('Manufacturer ' . $user_asset_mfgr . ' already exists');
         } else {
             $manufacturer = new Manufacturer();
             $manufacturer->name = e($user_asset_mfgr);
             $manufacturer->user_id = 1;
             if ($manufacturer->save()) {
                 $this->comment('Manufacturer ' . $user_asset_mfgr . ' was created');
             } else {
                 $this->comment('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created');
             }
         }
         // Check for the asset model match and create it if it doesn't exist
         if ($asset_model = Model::where('name', e($user_asset_name))->where('modelno', e($user_asset_modelno))->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) {
             $this->comment('The Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' already exists');
         } else {
             $asset_model = new Model();
             $asset_model->name = e($user_asset_name);
             $asset_model->manufacturer_id = $manufacturer->id;
             $asset_model->modelno = e($user_asset_modelno);
             $asset_model->category_id = $category->id;
             $asset_model->user_id = 1;
             if ($asset_model->save()) {
                 $this->comment('Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' was created');
             } else {
                 $this->comment('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created');
             }
         }
         // Check for the asset company match and create it if it doesn't exist
         if ($user_asset_company_name != '') {
             if ($company = Company::where('name', e($user_asset_company_name))->first()) {
                 $this->comment('Company ' . $user_asset_company_name . ' already exists');
             } else {
                 $company = new Company();
                 $company->name = e($user_asset_company_name);
                 if ($company->save()) {
                     $this->comment('Company ' . $user_asset_company_name . ' was created');
                 } else {
                     $this->comment('Something went wrong! Company ' . $user_asset_company_name . ' was NOT created');
                 }
             }
         } else {
             $company = new Company();
         }
         // Check for the asset match and create it if it doesn't exist
         if ($asset = Asset::where('asset_tag', e($user_asset_tag))->first()) {
             $this->comment('The Asset with asset tag ' . $user_asset_tag . ' already exists');
         } else {
             $asset = new Asset();
             $asset->name = e($user_asset_asset_name);
             if ($user_asset_purchase_date != '') {
                 $asset->purchase_date = $user_asset_purchase_date;
             } else {
                 $asset->purchase_date = NULL;
             }
             if ($user_asset_purchase_cost != '') {
                 $asset->purchase_cost = ParseFloat(e($user_asset_purchase_cost));
             } else {
                 $asset->purchase_cost = 0.0;
             }
             $asset->serial = e($user_asset_serial);
             $asset->asset_tag = e($user_asset_tag);
             $asset->model_id = $asset_model->id;
             $asset->assigned_to = $user->id;
             $asset->rtd_location_id = $location->id;
             $asset->user_id = 1;
             $asset->status_id = $status_id;
             $asset->company_id = $company->id;
             if ($user_asset_purchase_date != '') {
                 $asset->purchase_date = $user_asset_purchase_date;
             } else {
                 $asset->purchase_date = NULL;
             }
             $asset->notes = e($user_asset_notes);
             if ($asset->save()) {
                 $this->comment('Asset ' . $user_asset_name . ' with serial number ' . $user_asset_serial . ' was created');
             } else {
                 $this->comment('Something went wrong! Asset ' . $user_asset_name . ' was NOT created');
             }
         }
         $this->comment('=====================================');
         return true;
     });
 }
Esempio n. 21
0
 static function getActivateFields($is_fake = false, $user_id = 0, $company_id = 0)
 {
     if (!$is_fake) {
         $user = User::find($user_id);
         $company = Company::where('id', $company_id)->first();
         $mailer_extra = ['name' => $user->name, 'email' => $user->email, 'user_id' => $user->id, 'activation_code' => $user->activation_code, 'activation_url' => URL::to('/') . "/activate/" . $user->id . "/" . $user->activation_code, 'company_name' => $company->name, 'company_description' => $company->description, 'company_domain' => $company->domain, 'company_logo' => $company->logo];
     } else {
         $mailer_extra = ['name' => "Imran", 'email' => "*****@*****.**", 'user_id' => 1, 'activation_code' => "some-fake-activation-code", 'activation_url' => URL::to('/') . "/activate/1/some-fake-activation-code", 'company_name' => "KODEINFO", 'company_description' => "We are a small and dedicated team of designers/developers. This is our web design and development focused blog.We focus on pushing the boundaries of standards based web technologies.", 'company_domain' => "http://www.kodeinfo.com", 'company_logo' => "http://kodeinfo.com/img/shortlogo.png"];
     }
     return $mailer_extra;
 }
 public function start()
 {
     $response = [];
     $response['token'] = 0;
     if (Input::has('ip')) {
         //check ip_address in blocking table
         $blocking = Blocking::where('ip_address', Input::get('ip'))->first();
         if (!empty($blocking)) {
             if ($blocking->should_block_chat || $blocking->should_block_web_access) {
                 $response['blocked'] = 1;
                 $response['errors'] = trans('msgs.your_ip_blocked_by_admin_contact_support');
             }
         }
     } else {
         $response['blocked'] = 1;
         $response['errors'] = trans('msgs.your_ip_blocked_by_admin_contact_support');
     }
     $response['blocked'] = 0;
     $v_data = ["email" => Input::get('email'), "name" => Input::get('name'), "company_id" => Input::get('company_id'), "domain" => Input::get('domain'), "department" => Input::get('department'), "message" => Input::get('message')];
     $v_rules = ["email" => 'required|email', "name" => 'required', "company_id" => 'required', "domain" => 'required', "department" => 'required', "message" => 'required'];
     $v = Validator::make($v_data, $v_rules);
     if ($v->passes()) {
         $request_check = Company::where('id', Input::get('company_id'))->where('domain', Input::get('domain'))->get();
         if (sizeof($request_check) <= 0) {
             return $this->send(['result' => 0, 'errors' => trans('msgs.invalid_request_check_id_and_domain')]);
         }
         $company_customers = CompanyCustomers::where('company_id', Input::get('company_id'))->lists('customer_id');
         $user = null;
         if (sizeof($company_customers)) {
             $user = User::whereIn('id', $company_customers)->where('email', Input::get('email'))->first();
         }
         $operator_online = Company::operatorsOnline(Input::get('company_id'));
         $success_msg = trans('msgs.thanks_for_contacting_will_get_back');
         $response['is_online'] = $operator_online;
         $repo = new KodeInfo\Repo\MessageRepo();
         if (!empty($user) && !is_null($user)) {
             //user exists
             $count = OnlineUsers::where('user_id', $user->id)->first();
             if (sizeof($count) > 0) {
                 //user already online
                 $token = OnlineUsers::getToken();
                 if ($operator_online > 0) {
                     $response['token'] = $token;
                 }
                 $response['result'] = 1;
                 $response['user_id'] = $user->id;
                 $response['thread_id'] = $count->thread_id;
                 $response['success_msg'] = $success_msg;
                 return $this->send($response);
             } else {
                 $token = OnlineUsers::getToken();
                 $thread = $repo->createNewThread($user->id, Input::get("message"), true);
                 if ($response['is_online']) {
                     $online_user = new OnlineUsers();
                     $online_user->user_id = $user->id;
                     $online_user->thread_id = $thread['thread_id'];
                     $online_user->operator_id = 0;
                     $online_user->company_id = Input::get('company_id');
                     $online_user->department_id = Input::get('department');
                     $online_user->locked_by_operator = 0;
                     $online_user->requested_on = \Carbon\Carbon::now();
                     $online_user->token = $token;
                     $online_user->save();
                 }
                 $country = DB::table('countries')->where('countryCode', Input::get('country'))->first();
                 $geo_info = new ThreadGeoInfo();
                 $geo_info->thread_id = $thread['thread_id'];
                 $geo_info->ip_address = Input::get('ip');
                 $geo_info->country_code = Input::get('country');
                 $geo_info->country = !empty($country) ? $country->countryName : "";
                 $geo_info->provider = Input::get('provider');
                 $geo_info->current_page = Input::get('page');
                 $geo_info->all_pages = json_encode(['pages' => [Input::get('page')]]);
                 $geo_info->save();
                 if (!$response['is_online']) {
                     $this->convertToTicket($thread['thread_id'], $thread['msg_id'], $user, "", Input::get('message'), Input::get('department'), Input::get('company_id'));
                 }
                 if ($operator_online > 0) {
                     $response['token'] = $token;
                 }
                 $response['result'] = 1;
                 $response['user_id'] = $user->id;
                 $response['thread_id'] = $thread['thread_id'];
                 $response['success_msg'] = $success_msg;
                 return $this->send($response);
             }
         } else {
             $password = Str::random();
             //Is user in users table then get id and put in company-customers table
             $user = User::where('email', Input::get('email'))->first();
             if (!empty($user)) {
                 $company_customer = new CompanyCustomers();
                 $company_customer->company_id = Input::get('company_id');
                 $company_customer->customer_id = $user->id;
                 $company_customer->save();
             } else {
                 $user = $this->userManager->createUser(["name" => Input::get('name'), "email" => Input::get('email'), "password" => $password, "password_confirmation" => $password], 'customer', false);
                 $user->avatar = "/assets/images/default-avatar.jpg";
                 $user->save();
                 $user->getActivationCode();
                 $company_customer = new CompanyCustomers();
                 $company_customer->company_id = Input::get('company_id');
                 $company_customer->customer_id = $user->id;
                 $company_customer->save();
                 $this->mailer->welcome($user->email, $user->name, User::getWelcomeFields(false, $user->id, $password, $company_customer->company_id));
                 $this->mailer->activate($user->email, $user->name, User::getActivateFields(false, $user->id, $company_customer->company_id));
             }
             $token = OnlineUsers::getToken();
             $thread = $repo->createNewThread($user->id, Input::get("message"), true);
             if ($response['is_online']) {
                 $online_user = new OnlineUsers();
                 $online_user->user_id = $user->id;
                 $online_user->thread_id = $thread['thread_id'];
                 $online_user->operator_id = 0;
                 $online_user->company_id = Input::get('company_id');
                 $online_user->department_id = Input::get('department');
                 $online_user->locked_by_operator = 0;
                 $online_user->requested_on = \Carbon\Carbon::now();
                 $online_user->token = $token;
                 $online_user->save();
             }
             $country = DB::table('countries')->where('countryCode', Input::get('country'))->first();
             $geo_info = new ThreadGeoInfo();
             $geo_info->thread_id = $thread['thread_id'];
             $geo_info->ip_address = Input::get('ip');
             $geo_info->country_code = Input::get('country');
             $geo_info->country = !empty($country) ? $country->countryName : "";
             $geo_info->provider = Input::get('provider');
             $geo_info->current_page = Input::get('page');
             $geo_info->all_pages = json_encode(['pages' => [Input::get('page')]]);
             $geo_info->save();
             if (!$response['is_online']) {
                 $this->convertToTicket($thread['thread_id'], $thread['msg_id'], $user, "", Input::get('message'), Input::get('department'), Input::get('company_id'));
             }
             if ($operator_online > 0) {
                 $response['token'] = $token;
             }
             $response['result'] = 1;
             $response['user_id'] = $user->id;
             $response['thread_id'] = $thread['thread_id'];
             $response['success_msg'] = $success_msg;
             return $this->send($response);
         }
     } else {
         return $this->send(['result' => 0, 'errors' => Utils::buildMessages($v->messages()->all())]);
     }
 }
 function index()
 {
     if (\KodeInfo\Utilities\Utils::isCustomer(Auth::user()->id)) {
         return Redirect::to('/tickets/customer/all');
     }
     $past_hr = \Carbon\Carbon::now()->subHour();
     $today = \Carbon\Carbon::now()->subDay();
     $this_week = \Carbon\Carbon::now()->subWeek();
     $this_month = \Carbon\Carbon::now()->subMonth();
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
         $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
         $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
         $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
         if (sizeof($operator_ids) > 0) {
             $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
             $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
         } else {
             $department->operators_online = 0;
             $department->operators_offline = 0;
         }
         $this->data['department_stats'] = $department;
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_operator = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_operator->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
         $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
         $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
         $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
         if (sizeof($operator_ids) > 0) {
             $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
             $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
         } else {
             $department->operators_online = 0;
             $department->operators_offline = 0;
         }
         $this->data['department_stats'] = $department;
     } else {
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $companies = Company::all();
         foreach ($companies as $company) {
             $departments = Department::where('company_id', $company->id)->get();
             foreach ($departments as $department) {
                 $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
                 $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
                 $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
                 $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
                 if (sizeof($operator_ids) > 0) {
                     $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
                     $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
                 } else {
                     $department->operators_online = 0;
                     $department->operators_offline = 0;
                 }
             }
             $company->departments = $departments;
         }
         $this->data['department_stats'] = $companies;
     }
     return View::make('index', $this->data);
 }
Esempio n. 24
0
 /**
  * Check company if exist in our system
  *
  * @param  string  $name
  * @return Response
  */
 private static function isExist($name)
 {
     return Company::where('name', '=', $name)->count();
 }