public function store() { $rules = ['name' => 'required', 'vat_number' => 'required', 'address' => 'required', 'postal_code' => 'required', 'email' => 'required|email', 'phone' => 'required', 'category_id' => 'required', 'city_id' => 'required']; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { $password = Input::get('password'); if (Input::has('company_id')) { $id = Input::get('company_id'); $company = CompanyModel::find($id); if ($password !== '') { $company->secure_key = md5($company->salt . $password); } } else { $company = new CompanyModel(); if ($password === '') { $alert['msg'] = 'You have to enter password'; $alert['type'] = 'danger'; return Redirect::route('admin.company.create')->with('alert', $alert); } $company->salt = str_random(8); $company->token = str_random(8); $company->secure_key = md5($company->salt . $password); } $company->name = Input::get('name'); $company->vat_number = Input::get('vat_number'); $company->address = Input::get('address'); $company->postal_code = Input::get('postal_code'); $company->email = Input::get('email'); $company->phone = Input::get('phone'); $company->category_id = Input::get('category_id'); $company->city_id = Input::get('city_id'); $company->save(); if (!Input::has('company_id')) { $setting = new SettingModel(); $setting->company_id = $company->id; $setting->waiting_time = WAITING_TIME; $setting->logo = LOGO; $setting->color = COLOR; $setting->background = BACKGROUND; $setting->start_time = START_TIME; $setting->end_time = END_TIME; $setting->save(); File::makeDirectory(public_path() . "/assets/img/stores/" . $company->id, 0775, true, true); } $alert['msg'] = 'Company has been saved successfully'; $alert['type'] = 'success'; return Redirect::route('admin.company')->with('alert', $alert); } }
public function asyncStatus() { $token = Input::get('token'); $store = StoreModel::where('token', $token)->first(); $agents = AgentModel::where('store_id', $store->id)->where('is_active', true)->get(); $current = $store->status->current_queue_no; $last = $store->status->last_queue_no; $counter = count($agents); if ($counter == 0) { return Response::json(['result' => 'failed', 'msg' => 'There is no active Agent', 'last' => $last]); } else { $companySetting = CompanySettingModel::where('company_id', $store->company_id)->first(); $waitingTime = ceil(($last - $current) / $counter) * $companySetting->waiting_time; return Response::json(['result' => 'success', 'current' => $current, 'last' => $last, 'counter' => $counter, 'waitingTime' => round($waitingTime / 60, 1)]); } }
public function store() { $rules = ['waiting_time' => 'required|numeric', 'color' => 'required', 'background' => 'required', 'start_time' => 'required', 'end_time' => 'required']; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { $setting = SettingModel::find(Input::get('setting_id')); $setting->waiting_time = Input::get('waiting_time'); $setting->color = Input::get('color'); $setting->background = Input::get('background'); $setting->start_time = Input::get('start_time'); $setting->end_time = Input::get('end_time'); if (Input::hasFile('logo')) { $filename = str_random(24) . "." . Input::file('logo')->getClientOriginalExtension(); Input::file('logo')->move(ABS_LOGO_PATH, $filename); $setting->logo = $filename; } $setting->save(); $alert['msg'] = 'Setting has been saved successfully'; $alert['type'] = 'success'; return Redirect::route('company.setting')->with('alert', $alert); } }