/** * AbstractDepartment constructor. */ public function __construct() { $this->data['current_shift'] = Shift::current(); $this->data['current_shift_produced_meters'] = $this->getCurrentShiftProducedMeters(); $this->data['current_shift_set_up_minutes'] = $this->getCurrentShiftSetUpMinutes(); $this->data['current_shift_up_time_minutes'] = $this->getCurrentShiftUpTimeMinutes(); $this->data['current_shift_target_meters'] = $this->getCurrentShiftTargetMeters(); }
public static function setTimes($input) { $start = Shift::getTime($input['start_time']); $end = Shift::getTime($input['end_time']); // Return original input if there was an error parsing timestamps if (!$start || !$end) { return $input; } $input['start_time'] = $start['hour'] . ":" . str_pad($start['minute'], 2, 0, STR_PAD_LEFT); // Convert end time to 24 if "12:00 AM" is used if ($end['hour'] === 0 && $end['minute'] === 0) { $input['end_time'] == "24:00"; } else { $input['end_time'] = $end['hour'] . ":" . str_pad($end['minute'], 2, 0, STR_PAD_LEFT); } return $input; }
public static function processAtShift($shiftCode) { $findShift = Md\Shift::find($shiftCode); $timeSend = (new \DateTime($findShift->shift_to))->modify("+1 hours")->format('H:i'); return $timeSend; }
public static function shiftFilter() { $data = \App\Models\Shift::all(); $selecttop = '<select name="shift_id" id="shift_id" class="form-control select2">'; $option = '<option value="">- Pilih Shift -</option>'; foreach ($data as $key => $value) { $option = $option . "<option value='{$value->code}'>{$value->code} - {$value->shift_name}</option>"; } $selectbottom = '</select>'; $list = $selecttop . $option . $selectbottom; return $list; }
public function cloneEvent(Request $request, Event $event) { $this->authorize('create-event'); $this->validate($request, ['start_date' => 'required|date_format:Y-m-d']); // Set up event information $startDate = new Carbon($event->start_date); $endDate = new Carbon($event->end_date); $newStartDate = new Carbon($request->input('start_date')); $departments = $event->departments; // Find the difference of the start dates $difference = $startDate->diffInSeconds($newStartDate); // Create new event from old event data $newEvent = Event::create(['name' => $event->name, 'description' => $event->description, 'start_date' => $startDate->addSeconds($difference)->format('Y-m-d'), 'end_date' => $endDate->addSeconds($difference)->format('Y-m-d')]); // Add the image manually because it's not automatically fillable if ($event->image) { $newEvent->image = $event->image; $newEvent->save(); } // Loop through event departments foreach ($departments as $department) { // Create new department $newDepartment = new Department(); $newDepartment->event_id = $newEvent->id; $newDepartment->save(); // Because the event_id isn't fillable, we have to define it first and then update $newDepartment->update(['name' => $department->name, 'description' => $department->description, 'roles' => $department->roles]); // Loop through shifts $shifts = $department->shifts; foreach ($shifts as $shift) { // Adjust shift dates $shift->start_date = new Carbon($shift->start_date); $shift->end_date = new Carbon($shift->end_date); $shift->start_date = $shift->start_date->addSeconds($difference)->format('Y-m-d'); $shift->end_date = $shift->end_date->addSeconds($difference)->format('Y-m-d'); // Update the department ID $shift->department_id = $newDepartment->id; $newShift = Shift::create(['department_id' => $newDepartment->id, 'name' => $shift->name, 'start_date' => $shift->start_date, 'end_date' => $shift->end_date, 'start_time' => $shift->start_time, 'end_time' => $shift->end_time, 'duration' => $shift->duration, 'roles' => $shift->roles]); Slot::generate($newShift); } } $request->session()->flash('success', 'Event has been cloned.'); return redirect('/event/' . $newEvent->id); }
/** * @test */ public function it_has_a_previous_shift() { $this->createShiftStartingAt(6, 720); $this->createShiftStartingAt(18, 720); $shift = App\Models\Shift::current(); $shift->setRelativeTime(Carbon::now()->setTime(8, 0)); $previousShift = $shift->previous_shift; $this->assertInstanceOf(App\Models\Shift::class, $previousShift); $this->assertEquals(Carbon::now()->subDay()->setTime(18, 0), $previousShift->starting_time); $this->assertEquals(Carbon::now()->setTime(6, 0), $previousShift->ending_time); }
function getXoa($id) { $data['list_shifts'] = Shift::findOrFail($id); $data['list_shifts']->delete(); return redirect()->route('cahoc'); }
public function delete(Request $request, Shift $shift) { $this->authorize('delete-shift'); $event = $shift->department->event; $shift->delete(); event(new EventChanged($event, ['type' => 'shift', 'status' => 'deleted'])); $request->session()->flash('success', 'Shift has been deleted.'); return redirect('/event/' . $event->id); }
/** * Return shift model representing shift after this * @return Carbon */ public function getNextShiftAttribute() { $check_time = $this->starting_time->copy()->addHour(); $shift = Shift::shiftStartingAt($check_time)->get()->first(); for ($i = 0; $i < 24; $i++) { if ($shift instanceof Shift) { return $shift->setRelativeTime($check_time); } $check_time->addHour(); $shift = Shift::shiftStartingAt($check_time)->get()->first(); } return null; }