Skip to content

Instantly share code, notes, and snippets.

@mirzaawais
Last active February 13, 2020 17:15
Show Gist options
  • Save mirzaawais/876a9a93e1194cc7528177e32d9d90df to your computer and use it in GitHub Desktop.
Save mirzaawais/876a9a93e1194cc7528177e32d9d90df to your computer and use it in GitHub Desktop.
Laravel Code Snippet
<?php
namespace App\Models;
use App\Traits\Auditable;
use Illuminate\Database\Eloquent\Model;
class Employee extends Model
{
use Auditable;
/**
* @var array
*/
public static $STATUS = ['Inactive','Active','Travelling','Voluntary Terminated' ,'Involuntary Terminated'];
/**
* @var array
*/
public static $MARITAL_STATUS = ['' => '-', 0 => 'Single', 1 => 'Married'];
/**
* @var array
*/
public static $BOOL = [
'' => '-', 0 => 'No', 1 => 'Yes'
];
/**
* @var array
*/
public static $Voluntary_Reasons = [
'Schedule', 'No Call/No Show', 'School', 'New Job', 'Compensation',
'Personal Reasons', 'Transferred'
];
/**
* @var array
*/
public static $Involuntary_Reasons = [
'Attendance Issues', 'Personality', 'Not following company policies',
'Unsatisfactory performance', 'E-verify process', 'Gross Misconduct', 'Lay-off '
];
/**
* @var array
*/
public static $rules = [
'first_name' => 'required',
'last_name' => 'required',
'display_name' => 'required',
'payroll_id' => 'required|regex:/^[0-9]{3}-[0-9]{2}-[0-9]{4}$/',
'email' => 'required|email',
'ssn' => 'required|digits:9',
'mobile' => 'required',
'job' => 'required',
'security_level_id' => 'required',
'pay_rate' => 'required'
];
/**
* @var array
*/
protected $fillable = [
'id',
'brink_id',
'location_id',
'alternate_id',
'payroll_id',
'first_name',
'last_name',
'display_name',
'status',
'email',
'address_1',
'address_2',
'birth_date',
'pin',
'ssn',
'city',
'home_location_id',
'zip',
'state',
'mobile',
'home_phone',
'hire_date',
'card_number',
'notes',
'can_login_with_card',
'can_login_with_finger',
'can_login_with_pin',
'clocked_in_disconnected_id',
'clocked_out_disconnected_id',
'export_to_pay_roll',
'health_card_expiration_date',
'identification_verified',
'is_exempt',
'is_salaried',
'limit_locations',
'marital_status',
'maximum_daily_discount_amount',
'maximum_daily_discount_count',
'tax_withhold_allowance',
'terminated',
'terminated_date',
'employee_photo',
'is_removed_from_brink',
'terminated_reason',
'terminated_type',
'is_locally_changed',
'inactive_date',
're_hireable',
//'transfer_location_date',
'fast_track',
'is_foodie_level_three_enable',
'status_effective_date',
'status_effective',
'transfer_location_id',
'stop_training',
'pay_rate',
'is_borrowed',
'borrowed_location_id',
'borrowed_date',
'is_transfered',
'transfered_date',
'transfered_location_id',
'min_shifts',
'max_shifts'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function jobs()
{
$jobs = $this->belongsToMany('App\Models\Job','employee_job')->withPivot('security_level_id');
$jobs->where('is_active','=', 1);
return $jobs;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function jobsAll()
{
return $this->belongsToMany('App\Models\Job','employee_job');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function jobsWithSecurityLevelId()
{
return $this->belongsToMany('App\Models\Job','employee_job')
->withPivot('security_level_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function availabilities()
{
return $this->hasMany('App\Models\EmployeeAvailability',
'employee_id', 'id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function timeOffs()
{
return $this->hasMany('App\Models\EmployeeTimeoff', 'brink_employee_id', 'brink_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function empTimeOffs()
{
return $this->hasMany('App\Models\EmployeeTimeoff', 'employee_id', 'id');
}
/**
* @param $date
* @param $shift
* @return bool|int
*/
public function hasTimeoffValue($date,$shift)
{
if($this->timeOffs->count() > 0) {
foreach ($this->timeOffs as $timeOff) {
$sqlDate = date('Y-m-d',strtotime($date));
if($timeOff->for_date == $sqlDate && 1 == $timeOff->{$shift.'_off'}){
return 1;
}
}
}
return false;
}
/**
* @param $week
* @return bool|int
*/
public function hasTimeoffValueForWeek($week)
{
if ($this->timeOffs->count() > 0) {
foreach ($this->timeOffs as $timeOff) {
if ($timeOff->week_off == intval($week)) {
return 1;
}
}
}
return false;
}
/**
*
* @return \BrinkSettings\StructType\Employee
*/
public function getBrinkAttributes()
{
$brinkObj = [
'address1' => (string)$this->address_1,
'address2' => (string)$this->address_2,
'alternateId' => (string)$this->alternate_id,
'birthDate' => (string)$this->birth_date,
'canLoginWithCard' => boolval($this->can_login_with_card),
'canLoginWithFinger' => boolval($this->can_login_with_finger),
'canLoginWithPin' => boolval($this->can_login_with_pin),
'cardNumber' => (string)$this->card_number,
'cellPhone' => (string)$this->mobile,
'city' => (string)$this->city,
'clockedInDiscountId' => intval($this->clocked_in_disconnected_id),
'clockedOutDiscountId' => intval($this->clocked_out_disconnected_id),
'displayName' => (string)$this->display_name,
'emailAddress' => (string)$this->email,
'exportToPayroll' => boolval($this->export_to_pay_roll),
'firstName' => (string)$this->first_name,
'healthCardExpirationDate' => $this->health_card_expiration_date,
'hireDate' => $this->hire_date,
'homeLocationId' => $this->home_location_id,
'homePhone' => (string)$this->home_phone,
'identificationVerified' => boolval($this->identification_verified),
'isExempt' => boolval($this->is_exempt),
'isSalaried' => boolval($this->is_salaried),
'lastName' => (string)$this->last_name,
'limitLocations' => boolval($this->limit_location),
'maritalStatus' => (string)$this->marital_status,
'maximumDailyDiscountAmount' => floatval($this->maximum_daily_discount_amount),
'maximumDailyDiscountCount' => intval($this->maximum_daily_discount_count),
'notes' => (string)$this->notes,
'payrollId' => (string)$this->payroll_id,
'pin' => (string)$this->pin,
'ssn' => (string)$this->ssn,
'state' => (string)$this->state,
'taxWithholdingAllowance' => intval($this->tax_withhold_allowance),
'terminated' => boolval($this->terminated),
'terminationDate' => $this->terminated_date,
'zip' => (string) $this->zip
];
$brinkEmployee = new \BrinkSettings\StructType\Employee();
$brinkEmployee->setId($this->brink_id);
foreach ($brinkObj as $key => $val) {
if(empty($val) && $key != 'terminated')
$val = null;
$func = 'set'.ucfirst($key);
$brinkEmployee->$func($val);
}
return $brinkEmployee;
}
/**
* @param $job
* @return \BrinkSettings\StructType\EmployeeJob
*/
public function getBrinkJobAttributes($job)
{
$brinkJob = new \BrinkSettings\StructType\EmployeeJob();
if(!empty($job)) {
$brinkJob->setJobId(intval($job->brink_job_id));
$brinkJob->setPayRate(floatval($job->pay_rate));
$brinkJob->setSecurityLevelId(intval($job->security_level_id));
$job->brink_id = $job->brink_id == 0 ? -1 : $job->brink_id;
$brinkJob->setId(intval($job->brink_id));
}
return $brinkJob;
}
/**
* @param $value
*/
public function setTransferLocationIdAttribute($value)
{
$this->attributes['transfer_location_id'] = empty($value) ? 0 : $value;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function trainings()
{
return $this->hasMany('App\Models\EmployeeTraining');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function location()
{
return $this->belongsTo('App\Models\MarketLocation','location_id', 'location_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function transferLocation()
{
return $this->belongsTo('App\Models\MarketLocation','transfer_location_id', 'location_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function fromTransferLocation()
{
return $this->belongsTo('App\Models\MarketLocation','transfered_location_id', 'location_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function fromBorrowLocation()
{
return $this->belongsTo('App\Models\MarketLocation','borrowed_location_id', 'location_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function employeeFoodieLevel()
{
return $this->hasMany('App\Models\EmployeeFoodieLevel','employee_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function involuntaryReasons()
{
return $this->hasOne(EmployeeInvoluntaryReason::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function employeeScheduleShifts()
{
return $this->hasMany('App\Models\SchedulerShift','employee_id', 'id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function allAvailabilities() // created this because of need all availabilities on timeoff page
{
return $this->hasMany('App\Models\EmployeeAvailability',
'employee_id', 'id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function employeeJob()
{
return $this->hasMany('App\Models\EmployeeJob','employee_id', 'id');
}
/**
* @return array
*/
public function getFillableAttributes()
{
return $this->fillable;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function audits()
{
return $this->morphMany(Audit::class, 'auditable');
}
}
<?php
namespace App\Repositories;
use App\Models\Area;
use App\Models\AreaStationJob;
use App\Models\AreaStationStack;
use App\Models\Employee;
use App\Models\EmployeeAvailability;
use App\Models\EmployeeFoodieLevel;
use App\Models\EmployeeTimeoff;
use App\Models\EmployeeTraining;
use App\Models\LocationProjection;
use App\Models\LocationTier;
use App\Models\MarketLocation;
use App\Models\ScheduleAssignedTraining;
use App\Models\Scheduler;
use App\Models\SecurityLevel;
use App\Models\TierDetail;
use App\Models\TierRevenue;
use App\Models\Training;
use App\Models\TrainingSchedule;
use DateInterval;
use DateTime;
use App\Services\JobService;
use App\Services\SecurityLevelService;
use DB;
use App\Models\EmployeeInvoluntaryReason;
use App\Models\EmployeeJob;
use App\Models\Job as JobLocals;
use App\Repositories\EmployeeFoodieLevelRepository;
use Illuminate\Support\Facades\Log;
class EmployeeRepository
{
/**
* @var null
*/
private $securityLevelService = null;
/**
* @var null
*/
private $jobRepository = null;
/**
* @var null
*/
public $employeeFoodieLevelRepo = null;
public $gameNewUsersRepository = null;
/**
* EmployeeRepository constructor.
* @param SecurityLevelService $securityLevelService
* @param JobRepository $jobRepository
*/
public function __construct(
SecurityLevelService $securityLevelService,
JobRepository $jobRepository,
GameNewUsersRepository $gameNewUsersRepository)
{
$this->db = DB::connection("manageDB");
$this->systemsDB = DB::connection("systemsDB");
$this->employeeFoodieLevelRepo = new EmployeeFoodieLevelRepository();
$this->securityLevelService = $securityLevelService;
$this->jobRepository = $jobRepository;
$this->gameNewUsersRepository = $gameNewUsersRepository;
}
/**
* @param $request
* @return array
* @throws \Exception
*/
public function storeEmployee($request)
{
try {
$employee = Employee::where('payroll_id', $request['payroll_id'])
->where('payroll_id', '!=', '000-00-0000')
->where('location_id', $request['location_id'])
->first();
if (!empty($employee))
return ['status' => 201];
$employee = new Employee();
$request['brink_id'] = -1;
$request['status'] = 'Active';
$request['terminated_type'] = '';
$request['is_foodie_level_three_enable'] = 0;
$request['transfer_location_id'] = 0;
$request['stop_training'] = 0;
$request['is_removed_from_brink'] = 0;
$request['is_borrowed'] = 0;
$request['is_transfered'] = 0;
$request['is_locally_changed'] = 1;
$request['min_shifts'] = 0;
$request['max_shifts'] = 0;
$employee->fill($request->only($employee->getFillableAttributes()));
if ($employee->save()) {
return [
'employee' => $employee,
'status' => 200
];
}
return [];
} catch (\PDOException $PDOException) {
throw new \PDOException($PDOException->getMessage());
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
}
<?php
namespace App\Services;
use App\Helpers\ViewHelper;
use App\Models\MarketLocation;
use App\Repositories\EmployeeAvailabilityRepository;
use App\Repositories\EmployeeFoodieLevelRepository;
use App\Repositories\EmployeeRepository;
use App\Repositories\EmployeeTimeoffRepository;
use App\Repositories\FoodieLevelRepository;
use App\Repositories\GameNewUsersRepository;
use App\Repositories\JobRepository;
use App\ZupasLibrary\ApiBaseClass;
use BrinkSettings\ArrayType\ArrayOfEmployeeJob;
use BrinkSettings\StructType\Employee;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Input;
use App\Repositories\LocationRepository;
use Illuminate\Support\Facades\Log;
class EmployeeService
{
/**
* @var null
*/
private $employeeAvailabilityRepository = null;
/**
* @var null
*/
private $employeeTimeoffRepository = null;
/**
* @var null
*/
private $employeeTrainingService = null;
/**
* @var null
*/
private $foodieLevelService = null;
/**
* @var null
*/
private $employeeFoodieLevelRepository = null;
/**
* @var null
*/
private $jobRepository = null;
private $gameNewUsersRepository = null;
/**
* EmployeeService constructor.
* @param EmployeeRepository $employeeRepository
* @param LocationRepository $locationRepository
* @param EmployeeAvailabilityRepository $employeeAvailabilityRepository
* @param EmployeeTimeoffRepository $employeeTimeoffRepository
* @param EmployeeTrainingService $employeeTrainingService
* @param FoodieLevelService $foodieLevelService
* @param EmployeeFoodieLevelRepository $employeeFoodieLevelRepository
* @param JobRepository $jobRepository
*/
public function __construct(
EmployeeRepository $employeeRepository,
LocationRepository $locationRepository,
EmployeeAvailabilityRepository $employeeAvailabilityRepository,
EmployeeTimeoffRepository $employeeTimeoffRepository,
EmployeeTrainingService $employeeTrainingService,
FoodieLevelService $foodieLevelService,
EmployeeFoodieLevelRepository $employeeFoodieLevelRepository,
JobRepository $jobRepository,
GameNewUsersRepository $gameNewUsersRepository
)
{
$this->employeeRepo = $employeeRepository;
$this->locationRepo = $locationRepository;
$this->employeeAvailabilityRepository = $employeeAvailabilityRepository;
$this->employeeTimeoffRepository = $employeeTimeoffRepository;
$this->employeeTrainingService = $employeeTrainingService;
$this->foodieLevelService = $foodieLevelService;
$this->employeeFoodieLevelRepository = $employeeFoodieLevelRepository;
$this->jobRepository = $jobRepository;
$this->gameNewUsersRepository = $gameNewUsersRepository;
}
/**
* @param $request
* @return array
* @throws \Exception
*/
public function storeEmployee($request)
{
try {
$employee = $this->employeeRepo->storeEmployee($request);
if (!empty($employee) && $employee['status'] == 200) {
if (!empty($request['job'])) {
$job = $this->jobRepository->fetchById($request['job']);
if (!empty($job)) {
$employeejob['pay_rate'] = $request['pay_rate'];
$employeejob['brink_id'] = (int)$request['job'] * -1;
$employeejob['brink_job_id'] = $job->brink_id;
$employeejob['security_level_id'] = $request['security_level_id'];
$employeejob['is_active'] = 1;
$employee['employee']->jobs()->attach($request['job'], $employeejob);
}
}
if (!empty($request['foodieLevel'])) {
foreach ($request['foodieLevel'] as $key => $foodieLevel) {
if (!empty($request['scheduleTraining'][$key])) {
$data = [
'employee_id' => $employee['employee']->id,
'foodie_level_id' => $foodieLevel,
'training_schedule_id' => $request['scheduleTraining'][$key],
'status' => 0
];
$this->employeeFoodieLevelRepository->saveEmployeeFoodieLevel($data);
}
}
}
$employeeCreated = $this->createNewEmployeeOnBrink($request['location_id'], $employee['employee']->id);
if (!empty($employeeCreated)) {
$employeeData['brink_id'] = $brinkId = $employeeCreated[array_keys($employeeCreated)[0]]->Id;
$employeeData['is_locally_changed'] = 0;
$employee['employee']->fill($employeeData);
$employee['employee']->save();
// saving user brink id for game DB
$this->gameNewUsersRepository->saveUserData($brinkId);
}
}
return $employee;
} catch (\PDOException $PDOException) {
throw new \PDOException($PDOException->getTraceAsString());
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
/**
* @param $locationId
* @param $employeeId
* @param int $flag
* @return array|bool|\BrinkSettings\StructType\KeyedSettingsObjectSaveResult[]|null
* @throws \Exception
*/
public function createNewEmployeeOnBrink($locationId, $employeeId, $flag = 1)
{
try {
$apiBaseClass = new ApiBaseClass();
$location = MarketLocation::where('location_id', '=', $locationId)->first();
$header = $apiBaseClass->createHeader($location->location_token, 'Settings2.svc?singleWsdl',
'Settings2.svc', \BrinkSettings\ClassMap::get());
$save = new \BrinkSettings\ServiceType\Save($header);
$arrEmp = $this->createCommandRequestParamsForEmployee($employeeId);
$request = new \BrinkSettings\StructType\SaveEmployeesRequest($arrEmp);
$employeeCreated = $save->SaveEmployees(new \BrinkSettings\StructType\SaveEmployees($request));
if ($employeeCreated->getSaveEmployeesResult()->getResultCode() == 0 && $flag == 1) { // create case
return $employeeCreated->getSaveEmployeesResult()->SaveResults->getKeyedSettingsObjectSaveResult();
}else if ($employeeCreated->getSaveEmployeesResult()->getResultCode() == 0 && $flag == 2) { // update case
return true;
}
return [];
} catch (\PDOException $PDOException) {
$log = Log::getMonoLog();
$log->alert("Creating employee on brink PDO Failed: " . $PDOException->getTraceAsString());
throw new \PDOException($PDOException->getMessage());
} catch (\Exception $exception) {
$log = Log::getMonoLog();
$log->alert("Creating employee on brink Failed: " . $exception->getTraceAsString());
throw new \Exception($exception->getMessage());
}
}
}
<?php
/**
* Created by PhpStorm.
* User: TK-LPT-0046
* Date: 26/12/2019
* Time: 4:34 PM
*/
namespace App\Traits;
use App\Repositories\BelongsToManyCustom;
trait ExtendBelongsToManyTrait
{
/**
* @param $related
* @param null $table
* @param null $foreignKey
* @param null $otherKey
* @param null $relation
* @return BelongsToManyCustom
*/
public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
{
if (is_null($relation)) {
$relation = $this->getBelongsToManyCaller();
}
$foreignKey = $foreignKey ?: $this->getForeignKey();
$instance = new $related;
$otherKey = $otherKey ?: $instance->getForeignKey();
if (is_null($table)) {
$table = $this->joiningTable($related);
}
$query = $instance->newQuery();
return new BelongsToManyCustom($query, $this, $table, $foreignKey, $otherKey, $relation);
}
}
<?php
/**
* Created by PhpStorm.
* User: TK-LPT-0046
* Date: 26/12/2019
* Time: 4:34 PM
*/
namespace App\Traits;
trait ExtendFireModelEventTrait
{
/**
* @param $event
* @param bool $halt
* @param null $relationName
* @param array $ids
* @param array $idsAttributes
* @return bool
*/
public function fireModelEvent($event, $halt = true, $relationName = null, $ids = [], $idsAttributes = [])
{
if (! isset(static::$dispatcher)) {
return true;
}
$event = "eloquent.{$event}: ".static::class;
$method = $halt ? 'until' : 'fire';
$payload = ['model' => $this, 'relation' => $relationName, 'pivotIds' => $ids, 'pivotIdsAttributes' => $idsAttributes];
return static::$dispatcher->$method($event, $payload);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Job extends Model
{
protected $fillable = [
'name',
"brink_id",
"allow_add_item",
'job_code_rule',
"alternate_id",
"cannot_close",
"can_open_any_order",
"cash_drawer",
"checkout_requires_approval",
"clock_in_requires_approval",
"clock_out_requires_approval",
"delcare_tipes",
"default_screen_id",
"display_color",
"exclude_on_sales_and_labor_reports",
"exempt_from_labor_schedule",
"export_code",
"group_items_by_seat",
"is_bartender",
"is_delivery_dispatcher",
"is_delivery_driver",
"item_lookup",
"is_hostess",
"lane_id",
"limited_destination_id",
"location_type",
"no_cash_transactions",
"order_entry",
"order_screen_id",
"section_id",
"self_banking",
"tabs",
"training"
];
/**
* @var array
* Allowed job codes to be assigned in the scheduler
*/
public static $allowedJobCodes = [
'Line Server AM',
'Training Cashier',
'Operating Partner',
'Catering Coordinator',
'Prep Cook',
'Soup Maker',
'Travel Trainer',
'AM Dish',
'PM Dish',
'Hospitality Manager',
'Culinary Manager',
'Catering Driver',
'Line Server PM',
'Training Catering Coordinator',
'Shift Lead AM',
'Shift Lead PM',
'Catering Trainee',
'Catering Apprentice',
'Catering Specialist',
'Catering Consultant',
'Catering Professional',
'Catering Certified Trainer',
'Training Manager',
'Lobby'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function employees()
{
return $this->belongsToMany('App\Models\Employee','employee_job',
'brink_job_id','brink_employee_id' ,'brink_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function area()
{
return $this->belongsTo('App\Models\Area');
}
/**
* @return array
*/
public static function getAllJobs()
{
$jobs = Job::orderBy('name', 'ASC')->get();
$out = array();
foreach ($jobs as $job) {
if (in_array($job->name, self::$allowedJobCodes)) {
$out[$job->id] = $job->name;
}
}
return $out;
}
}
<?php
namespace App\Http\Controllers\OperatingPartner;
use App\Services\EmployeeAvailabilityService;
use App\Services\EmployeeFoodieLevel;
use App\Services\EmployeeService;
use App\Models\Employee;
use App\Services\JobService;
use App\Services\PrivacyService;
use App\Services\SchedulerService;
use App\Services\SecurityLevelService;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Log;
use App\Services\FoodieLevelService;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Validator;
use Session;
use View;
class ProfileController extends OperatingPartnerBaseController
{
/**
* @var
*/
private $locationId;
/**
* @var EmployeeService|null
*/
private $empService = null;
/**
* HomeController constructor.
* @param EmployeeService $employeeService
*/
public function __construct(EmployeeService $employeeService)
{
parent::__construct();
$this->locationId = $this->location->getId();
$this->empService = $employeeService;
}
/**
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function store(Request $request)
{
try {
$validator = Validator::make($request->all(), Employee::$rules);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator->errors())->withInput();
}
$request['location_id'] = $this->locationId;
$employee = $this->empService->storeEmployee($request);
if (!empty($employee)) {
if ($employee['status'] == 200) {
Session::flash('msg', "Team member created successfully.");
} else if ($employee['status'] == 201) {
Session::flash('error_msg', "Team member with same payroll id already exists.");
} else {
Session::flash('error_msg', "Something went wrong please try again.");
}
}
return redirect()->route('schedule');
} catch (\PDOException $PDOException) {
throw new \PDOException($PDOException->getMessage());
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function updateProfile()
{
try {
$data = Input::all();
$this->empService->updateEmployee($data);
Session::flash('msg', "Successfully Updated");
} catch (\PDOException $e) {
$log = Log::getMonoLog();
$log->alert("Update Profile Failed: " . $e->getMessage());
return view('errors.error');
} catch (\Exception $e) {
$log = Log::getMonoLog();
$log->alert("Update Profile Failed: " . $e->getMessage());
return view('errors.error');
}
return \Redirect::route('profile', $data['id']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment