public function postEditJob() { $data = \Input::get('data'); $_hash = new Hash(); $_hash = $_hash->getHasher(); if (!($job = \Job::findJobById(trim(\Input::get('job'))))) { return \Response::json(['type' => 'danger', 'message' => 'Job not found.']); } if (!($company = \Company::findCompanyById($_hash->decode($data['company'])))) { return \Response::json(['type' => 'danger', 'message' => 'Company not found.']); } if (!($agency = \Agency::getAgency())) { return \Response::json(['type' => 'danger', 'message' => 'Not an agency account.']); } if ($data['job_post_duration'] !== '0') { if (!$agency->is_vip) { $value = ['1' => -1, '2' => -3]; $checkValue = abs($value[$data['job_post_duration']]); if ($agency->credit < $checkValue) { return \Response::json(['type' => 'warning', 'message' => 'You have ' . $agency->credit . ' credit. You need at least ' . $checkValue . ' credit(s) to post this job.']); } } } $status = $company->agencies()->wherePivot('company_id', $company->id)->wherePivot('status', 'accept')->first(); if (!$status) { return \Response::json(['type' => 'danger', 'message' => 'You do not have permission from this company to post a job']); } $data['agency_id'] = $agency->id; $data['company_id'] = $company->id; if ($data['job_apply_type'] === 'job_apply_by_email') { if ($data['job_apply_application_email'] === '' && $data['job_apply_direct_email'] === '') { return \Response::json(['type' => 'warning', 'message' => 'Job application by email is chosen, please input at least one email.']); } $data['job_apply_details'] = json_encode(['type' => 'email', 'application_email' => $data['job_apply_application_email'], 'direct_email' => $data['job_apply_direct_email']]); } elseif ($data['job_apply_type'] === 'job_apply_by_url') { if ($data['job_apply_url'] === '') { return \Response::json(['type' => 'warning', 'message' => 'Job application by url is chosen, please input the application url.']); } $data['job_apply_details'] = json_encode(['type' => 'url', 'url' => $data['job_apply_url']]); } try { $job = \Job::updateJob($job, $data); if (!$agency->is_vip && $data['job_post_duration'] !== '0') { \Agency::updateCredit($agency, $value[$data['job_post_duration']]); } return \Response::json(['type' => 'success', 'message' => 'Job updated successfully.']); } catch (\Exception $e) { return \Response::json(['type' => 'danger', 'message' => env('APP_DEBUG') ? $e->getMessage() : 'Error, please contact webmaster.']); } }
public function postRemoveExpense() { if (!($company = \Company::getCompany())) { return \Response::json(['type' => 'danger', 'message' => 'Not a company account']); } $_hash = new Hash(); $_hash = $_hash->getHasher(); $id = $_hash->decode(trim(\Input::get('id'))); try { $model = \Company::updateExpenseStatus($id, $company, false); return \Response::json(['type' => 'success', 'message' => 'Expense de-authorized, page will reload']); } catch (\Exception $e) { return \Response::json(['type' => 'danger', 'message' => $e->getMessage()]); } }
public function getJobListingFrame($id, $type) { $_hash = new Hash(); $_hash = $_hash->getHasher(); switch ($type) { case 'company': if (!($company = \Company::findCompanyById($_hash->decode($id)))) { return view('frame.job')->with('flashMessage', ['class' => 'danger', 'message' => 'Company not found.']); } if (!($jobs = $company->jobs()->get())) { return view('frame.job')->with('flashMessage', ['class' => 'danger', 'message' => 'Jobs not found.']); } return view('frame.job')->with('jobs', $jobs); break; case 'agency': if (!($agency = \Agency::findAgencyById($_hash->decode($id)))) { return view('frame.job')->with('flashMessage', ['class' => 'danger', 'message' => 'Agency not found.']); } if (!($jobs = $agency->jobs()->get())) { return view('frame.job')->with('flashMessage', ['class' => 'danger', 'message' => 'Jobs not found.']); } return view('frame.job')->with('jobs', $jobs); break; default: return view('frame.job')->with('flashMessage', ['class' => 'danger', 'message' => 'Type is incorrectly defined.']); break; } }
public function getCompanyPaymentDone(Request $request) { if (!\Session::has('_temp_payment_sess')) { return redirect(url('company'))->with('flashMessage', ['class' => 'danger', 'message' => 'Your session has expired, please try again.']); } $data = session('_temp_payment_sess'); $id = $request->get('paymentId'); $token = $request->get('token'); $payer_id = $request->get('PayerID'); $payment = PayPal::getById($id, $this->paypalApiContext); $paymentExecution = PayPal::PaymentExecution(); $paymentExecution->setPayerId($payer_id); $executePayment = $payment->execute($paymentExecution, $this->paypalApiContext); $company = \Company::getCompany(); try { switch ($data['type']) { case 'credit': \Company::updateCredit($company, $data['xCreditAmount']); break; case 'contract': \Company::updateVIP($company, true); break; default: break; } session(['_sess_company' => ['model' => $company]]); \Session::forget('_temp_payment_sess'); } catch (\Exception $e) { // TODO: Need better error handler // re-run try with queue? \Session::forget('_temp_payment_sess'); return redirect(url('company'))->with('flashMessage', ['class' => 'danger', 'message' => $e->getMessage()]); } return redirect(url('company'))->with('flashMessage', ['class' => 'success', 'message' => $data['successMessage']]); }
public function postEditJob() { $data = \Input::get('data'); $job = \Job::findJobById(trim(\Input::get('job'))); $company = \Company::getCompany(); if ($job->company_id !== $company->id) { return \Response::json(['type' => 'danger', 'message' => 'You cannot edit the job that does not belong to you.']); } // if company not subscribed to 6 month contract, check the credit // TODO: update this to retrieve from db if ($data['job_post_duration'] !== '0') { if (!$company->is_vip) { $value = ['1' => -1, '2' => -3]; $checkValue = abs($value[$data['job_post_duration']]); if ($company->credit < $checkValue) { return \Response::json(['type' => 'warning', 'message' => 'You have ' . $company->credit . ' credit. You need at least ' . $checkValue . ' credit(s) to post this job.']); } } } $data['company_id'] = $company->id; // WTF? // TODO: move to model if ($data['job_apply_type'] === 'job_apply_by_email') { if ($data['job_apply_application_email'] === '' && $data['job_apply_direct_email'] === '') { return \Response::json(['type' => 'warning', 'message' => 'Job application by email is chosen, please input at least one email.']); } $data['job_apply_details'] = json_encode(['type' => 'email', 'application_email' => $data['job_apply_application_email'], 'direct_email' => $data['job_apply_direct_email']]); } elseif ($data['job_apply_type'] === 'job_apply_by_url') { if ($data['job_apply_url'] === '') { return \Response::json(['type' => 'warning', 'message' => 'Job application by url is chosen, please input the application url.']); } $data['job_apply_details'] = json_encode(['type' => 'url', 'url' => $data['job_apply_url']]); } try { $job = \Job::updateJob($job, $data); // if company not subscribed to 6 month contract, substract the credit if (!$company->is_vip && $data['job_post_duration'] !== '0') { \Company::updateCredit($company, $value[$data['job_post_duration']]); } return \Response::json(['type' => 'success', 'message' => 'Job updated successfully']); } catch (\Exception $e) { return \Response::json(['type' => 'danger', 'message' => env('APP_DEBUG') ? $e->getMessage() : 'Error, please contact webmaster.']); } }
public function postCompanyBan() { if (!($id = \Input::get('i')) || !($ban = \Input::get('ban'))) { return \Response::json(['type' => 'danger', 'message' => 'Data incomplete']); } try { \Company::banCompany($id, $ban); return \Response::json(['type' => 'success', 'message' => $ban === 'true' ? 'Company banned.' : 'Company unbanned.']); } catch (\Exception $e) { return \Response::json(['type' => 'danger', 'message' => $e->getMessage()]); } }
/** * Show the form for deleting the specified resource * * @param $id * @return Response */ public function delete($id) { $company = Company::findOrFail($id); return view('company.delete', compact('company')); }