Resolve "Rider optimization improvements" #1430
9 changed files with 1007 additions and 94 deletions
|
|
@ -430,6 +430,14 @@ access_keys:
|
|||
label: Menu
|
||||
- id: analytics.forecast
|
||||
label: Forecasting
|
||||
- id: shift_schedule.list
|
||||
label: List
|
||||
- id: shift_schedule.add
|
||||
label: Add
|
||||
- id: shift_schedule.update
|
||||
label: Update
|
||||
- id: shift_schedule.delete
|
||||
label: Delete
|
||||
|
||||
- id: sap_battery
|
||||
label: SAP Battery Access
|
||||
|
|
|
|||
|
|
@ -216,3 +216,7 @@ main_menu:
|
|||
acl: analytics.forecast
|
||||
label: Forecasting
|
||||
parent: analytics
|
||||
- id: shift_schedule_list
|
||||
acl: shift_schedule.list
|
||||
label: Shift Schedule
|
||||
parent: analytics
|
||||
|
|
|
|||
33
config/routes/shift_schedule.yaml
Normal file
33
config/routes/shift_schedule.yaml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
shift_schedule_list:
|
||||
path: /shift_schedules
|
||||
controller: App\Controller\ShiftScheduleController::index
|
||||
|
||||
shift_schedule_rows:
|
||||
path: /shift_schedules/rows
|
||||
controller: App\Controller\ShiftScheduleController::rows
|
||||
methods: [POST]
|
||||
|
||||
shift_schedule_create:
|
||||
path: /shift_schedules/create
|
||||
controller: App\Controller\ShiftScheduleController::addForm
|
||||
methods: [GET]
|
||||
|
||||
shift_schedule_create_submit:
|
||||
path: /shift_schedules/create
|
||||
controller: App\Controller\ShiftScheduleController::addSubmit
|
||||
methods: [POST]
|
||||
|
||||
shift_schedule_update:
|
||||
path: /shift_schedules/{id}
|
||||
controller: App\Controller\ShiftScheduleController::updateForm
|
||||
methods: [GET]
|
||||
|
||||
shift_schedule_update_submit:
|
||||
path: /shift_schedules/{id}
|
||||
controller: App\Controller\ShiftScheduleController::updateSubmit
|
||||
methods: [POST]
|
||||
|
||||
shift_schedule_delete:
|
||||
path: /shift_schedules/{id}
|
||||
controller: App\Controller\ShiftScheduleController::destroy
|
||||
methods: [DELETE]
|
||||
|
|
@ -21,8 +21,7 @@ use DateInterval;
|
|||
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\Hub;
|
||||
|
||||
use App\Ramcar\ShiftSchedule;
|
||||
use App\Entity\ShiftSchedule;
|
||||
|
||||
class AnalyticsController extends Controller
|
||||
{
|
||||
|
|
@ -93,10 +92,19 @@ class AnalyticsController extends Controller
|
|||
$hub_list[$hub->getID()] = $hub->getName() . ' - ' . $hub->getBranch();
|
||||
}
|
||||
|
||||
// get saved shift schedules
|
||||
$all_shift_schedules = $em->getRepository(ShiftSchedule::class)->findAll();
|
||||
|
||||
$shift_sched_list = [];
|
||||
foreach ($all_shift_schedules as $sched)
|
||||
{
|
||||
$shift_sched_list[$sched->getID()] = $sched->getName();
|
||||
}
|
||||
|
||||
$params = [
|
||||
'hub_list' => $hub_list,
|
||||
'default_hubs' => $hub_ids,
|
||||
'shift_schedules' => ShiftSchedule::getCollection(),
|
||||
'shift_schedules' => $shift_sched_list,
|
||||
];
|
||||
|
||||
return $this->render('analytics/forecast_form.html.twig', $params);
|
||||
|
|
@ -123,8 +131,9 @@ class AnalyticsController extends Controller
|
|||
$shift = $req->request->get('shift_schedule');
|
||||
|
||||
// TODO: populate the hour_shift array, depending on the shift selected
|
||||
$hour_shifts = $this->populateHourShift($shift);
|
||||
$hour_shifts = $this->populateHourShift($em, $shift);
|
||||
|
||||
error_log('reference');
|
||||
error_log(print_r($hour_shifts, true));
|
||||
// error_log(print_r($hub_list, true));
|
||||
|
||||
|
|
@ -177,7 +186,7 @@ class AnalyticsController extends Controller
|
|||
// error_log(print_r($scheduler_data, true));
|
||||
|
||||
// run scheduler
|
||||
$sched_res = $this->runScheduler($scheduler_data, $hour_shifts, $shift);
|
||||
$sched_res = $this->runScheduler($scheduler_data, $hour_shifts);
|
||||
|
||||
// tally total JOs for the month
|
||||
foreach ($scheduler_data as $sday_data)
|
||||
|
|
@ -252,7 +261,7 @@ class AnalyticsController extends Controller
|
|||
return $day_data;
|
||||
}
|
||||
|
||||
protected function runScheduler($scheduler_data, $hour_shifts, $shift)
|
||||
protected function runScheduler($scheduler_data, $hour_shifts)
|
||||
{
|
||||
// run python script to solve scheduling for riders
|
||||
|
||||
|
|
@ -267,8 +276,37 @@ class AnalyticsController extends Controller
|
|||
foreach ($scheduler_data as $weekday_data)
|
||||
$args[] = implode('-', $weekday_data);
|
||||
|
||||
// add shift
|
||||
$args[] = $shift;
|
||||
// add length of hour_shifts
|
||||
$args[] = count($hour_shifts);
|
||||
|
||||
// form hour_shifts argument for the python script
|
||||
foreach ($hour_shifts as $hour_shift)
|
||||
{
|
||||
$shift = '';
|
||||
foreach ($hour_shift as $entry)
|
||||
{
|
||||
// check if entry has format '00:00 - 00:00'
|
||||
if (strpos($entry, ':'))
|
||||
{
|
||||
// need to modify to 00 - 00
|
||||
$hours = explode('-', $entry);
|
||||
$start = trim($hours[0]);
|
||||
$end = trim($hours[1]);
|
||||
|
||||
// get the hour only
|
||||
$s_parts = explode(':', $start);
|
||||
$e_parts = explode(':', $end);
|
||||
$start_hour = trim($s_parts[0]);
|
||||
$end_hour = trim($s_parts[1]);
|
||||
|
||||
$shift = '\'' . $start_hour . ' - ' . $end_hour . '\'';
|
||||
}
|
||||
else
|
||||
$shift = $shift . ',' . $entry;
|
||||
}
|
||||
|
||||
$args[] = $shift;
|
||||
}
|
||||
|
||||
//error_log(print_r($args, true));
|
||||
|
||||
|
|
@ -676,55 +714,51 @@ class AnalyticsController extends Controller
|
|||
{
|
||||
}
|
||||
|
||||
protected function populateHourShift($shift)
|
||||
protected function populateHourShift(EntityManagerInterface $em, $id)
|
||||
{
|
||||
$hour_shift = [];
|
||||
|
||||
if ($shift == '24_7') {
|
||||
$hour_shift = [
|
||||
['00:00 - 09:00', 0, 1, 2, 3, 4, 5, 6, 7, 8],
|
||||
['01:00 - 10:00', 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
['02:00 - 11:00', 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
['03:00 - 12:00', 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
||||
['04:00 - 13:00', 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
||||
['05:00 - 14:00', 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||||
['06:00 - 15:00', 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
||||
['07:00 - 16:00', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08:00 - 17:00', 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
['09:00 - 18:00', 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
||||
['10:00 - 19:00', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
||||
['11:00 - 20:00', 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||
['12:00 - 21:00', 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
||||
['13:00 - 22:00', 13, 14, 15, 16, 17, 18, 19, 20, 21],
|
||||
['14:00 - 23:00', 14, 15, 16, 17, 18, 19, 20, 21, 22],
|
||||
['15:00 - 00:00', 15, 16, 17, 18, 19, 20, 21, 22, 23],
|
||||
['16:00 - 01:00', 16, 17, 18, 19, 20, 21, 22, 23, 0],
|
||||
['17:00 - 02:00', 17, 18, 19, 20, 21, 22, 23, 0, 1],
|
||||
['18:00 - 03:00', 18, 19, 20, 21, 22, 23, 0, 1, 2],
|
||||
['19:00 - 04:00', 19, 20, 21, 22, 23, 0, 1, 2, 3],
|
||||
['20:00 - 05:00', 20, 21, 22, 23, 0, 1, 2, 3, 4],
|
||||
['21:00 - 06:00', 21, 22, 23, 0, 1, 2, 3, 4, 5],
|
||||
['22:00 - 07:00', 22, 23, 0, 1, 2, 3, 4, 5, 6],
|
||||
['23:00 - 08:00', 23, 0, 1, 2, 3, 4, 5, 6, 7],
|
||||
];
|
||||
}
|
||||
if ($shift == '8AM_5PM') {
|
||||
$hour_shift = [
|
||||
['07:00 - 16:00', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08:00 - 17:00', 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
];
|
||||
}
|
||||
// get the hour shifts for the selected shift scheduled
|
||||
$shift = $em->getRepository(ShiftSchedule::class)->find($id);
|
||||
|
||||
if ($shift == '7AM_10PM') {
|
||||
$hour_shift = [
|
||||
['07:00 - 16:00', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08:00 - 17:00', 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
['09:00 - 18:00', 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
||||
['10:00 - 19:00', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
||||
['11:00 - 20:00', 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||
['12:00 - 21:00', 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
||||
['13:00 - 22:00', 13, 14, 15, 16, 17, 18, 19, 20, 21]
|
||||
];
|
||||
if (empty($shift))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
$shifts = $shift->getHourShifts();
|
||||
|
||||
foreach ($shifts as $shift)
|
||||
{
|
||||
$shift_entry = [];
|
||||
// format of hour_shift: [['start time - end time', start time, ... , end time - 1]]
|
||||
// first hour of hour shift is the start time
|
||||
// form the first entry of the hour shift
|
||||
$shift_time = $shift['start'] . ' - ' . $shift['end'];
|
||||
|
||||
$shift_entry[] = $shift_time;
|
||||
|
||||
$s_times = explode(':', $shift['start']);
|
||||
$e_times = explode(':', $shift['end']);
|
||||
|
||||
$shift_start = intval($s_times[0]);
|
||||
$shift_end = intval($e_times[0]);
|
||||
|
||||
if ($shift_start == 23)
|
||||
{
|
||||
$shift_entry[] = 23;
|
||||
for ($hour = 0; $hour < $shift_end; $hour++)
|
||||
{
|
||||
$shift_entry[] = $hour;
|
||||
}
|
||||
}
|
||||
for($hour = $shift_start; $hour < $shift_end; $hour++)
|
||||
{
|
||||
$shift_entry[] = $hour;
|
||||
|
||||
if ($hour == 23)
|
||||
$hour = 0;
|
||||
}
|
||||
|
||||
$hour_shift[] = $shift_entry;
|
||||
}
|
||||
|
||||
return $hour_shift;
|
||||
|
|
|
|||
329
src/Controller/ShiftScheduleController.php
Normal file
329
src/Controller/ShiftScheduleController.php
Normal file
|
|
@ -0,0 +1,329 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\ShiftSchedule;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class ShiftScheduleController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Menu(selected="shift_schedule_list")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('shift_schedule.list', null, 'No access.');
|
||||
|
||||
return $this->render('shift-schedule/list.html.twig');
|
||||
}
|
||||
|
||||
public function rows(Request $req)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('shift_schedule.list', null, 'No access.');
|
||||
|
||||
// get query builder
|
||||
$qb = $this->getDoctrine()
|
||||
->getRepository(ShiftSchedule::class)
|
||||
->createQueryBuilder('q');
|
||||
|
||||
// get datatable params
|
||||
$datatable = $req->request->get('datatable');
|
||||
|
||||
// count total records
|
||||
$tquery = $qb->select('COUNT(q)');
|
||||
$this->setQueryFilters($datatable, $tquery);
|
||||
$total = $tquery->getQuery()
|
||||
->getSingleScalarResult();
|
||||
|
||||
// get current page number
|
||||
$page = $datatable['pagination']['page'] ?? 1;
|
||||
|
||||
$perpage = $datatable['pagination']['perpage'];
|
||||
$offset = ($page - 1) * $perpage;
|
||||
|
||||
// add metadata
|
||||
$meta = [
|
||||
'page' => $page,
|
||||
'perpage' => $perpage,
|
||||
'pages' => ceil($total / $perpage),
|
||||
'total' => $total,
|
||||
'sort' => 'asc',
|
||||
'field' => 'id'
|
||||
];
|
||||
|
||||
// build query
|
||||
$query = $qb->select('q');
|
||||
$this->setQueryFilters($datatable, $query);
|
||||
|
||||
// check if sorting is present, otherwise use default
|
||||
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||
} else {
|
||||
$query->orderBy('q.id', 'asc');
|
||||
}
|
||||
|
||||
// get rows for this page
|
||||
$obj_rows = $query->setFirstResult($offset)
|
||||
->setMaxResults($perpage)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
// process rows
|
||||
$rows = [];
|
||||
foreach ($obj_rows as $orow) {
|
||||
// add row data
|
||||
$shifts = $orow->getHourShifts();
|
||||
$hour_shifts = [];
|
||||
foreach ($shifts as $shift)
|
||||
{
|
||||
// convert to DateTime then format
|
||||
$shift_start = DateTime::createFromFormat('H:i', $shift['start']);
|
||||
$shift_end = DateTime::createFromFormat('H:i', $shift['end']);
|
||||
|
||||
$hour_shifts[] = [
|
||||
$shift_start->format('g:i A') . ' - ' . $shift_end->format('g:i A')
|
||||
];
|
||||
}
|
||||
|
||||
$row['id'] = $orow->getID();
|
||||
$row['name'] = $orow->getName();
|
||||
$row['start_time'] = $orow->getStartTime()->format('g:i A');
|
||||
$row['end_time'] = $orow->getEndtime()->format('g:i A');
|
||||
$row['hour_shifts'] = $hour_shifts;
|
||||
|
||||
// add row metadata
|
||||
$row['meta'] = [
|
||||
'update_url' => '',
|
||||
'delete_url' => ''
|
||||
];
|
||||
|
||||
// add crud urls
|
||||
if ($this->isGranted('shift_schedule.update'))
|
||||
$row['meta']['update_url'] = $this->generateUrl('shift_schedule_update', ['id' => $row['id']]);
|
||||
if ($this->isGranted('shift_schedule.delete'))
|
||||
$row['meta']['delete_url'] = $this->generateUrl('shift_schedule_delete', ['id' => $row['id']]);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
// response
|
||||
return $this->json([
|
||||
'meta' => $meta,
|
||||
'data' => $rows
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="shift_schedule_list")
|
||||
*/
|
||||
public function addForm()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('shift_schedule.add', null, 'No access.');
|
||||
|
||||
$params = [];
|
||||
$params['obj'] = new ShiftSchedule();
|
||||
$params['mode'] = 'create';
|
||||
$params['shift_entries'] = [];
|
||||
|
||||
// response
|
||||
return $this->render('shift-schedule/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('shift_schedule.add', null, 'No access.');
|
||||
|
||||
$obj = new ShiftSchedule();
|
||||
|
||||
// set and save values
|
||||
$this->setObject($obj, $em, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||
}
|
||||
|
||||
// check if any errors were found
|
||||
if (!empty($error_array)) {
|
||||
// return validation failure response
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => $error_array
|
||||
], 422);
|
||||
}
|
||||
|
||||
// validated! save the entity
|
||||
$em->persist($obj);
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="shift_schedule_list")
|
||||
*/
|
||||
public function updateForm($id, EntityManagerInterface $em)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('shift_schedule.update', null, 'No access.');
|
||||
|
||||
$params = [];
|
||||
|
||||
// find shift schedule
|
||||
$obj = $em->getRepository(ShiftSchedule::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// get the shift entries
|
||||
$shifts = $obj->getHourShifts();
|
||||
$hour_shifts = [];
|
||||
foreach ($shifts as $shift)
|
||||
{
|
||||
// convert to DateTime then format
|
||||
$shift_start = DateTime::createFromFormat('H:i', $shift['start']);
|
||||
$shift_end = DateTime::createFromFormat('H:i', $shift['end']);
|
||||
|
||||
$hour_shifts[] = [
|
||||
'start' => $shift_start,
|
||||
'end' => $shift_end
|
||||
];
|
||||
}
|
||||
|
||||
$params['obj'] = $obj;
|
||||
$params['mode'] = 'update';
|
||||
$params['shift_entries'] = $hour_shifts;
|
||||
|
||||
// response
|
||||
return $this->render('shift-schedule/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('shift_schedule.update', null, 'No access.');
|
||||
|
||||
// get object
|
||||
$obj = $em->getRepository(ShiftSchedule::class)->find($id);
|
||||
|
||||
// make sure this object exists
|
||||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
$this->setObject($obj, $em, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||
}
|
||||
|
||||
// check if any errors were found
|
||||
if (!empty($error_array)) {
|
||||
// return validation failure response
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => $error_array
|
||||
], 422);
|
||||
}
|
||||
|
||||
// validated! save the entity
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy($id, EntityManagerInterface $em)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('shift_schedule.delete', null, 'No access.');
|
||||
|
||||
// get object data
|
||||
$obj = $em->getRepository(ShiftSchedule::class)->find($id);
|
||||
|
||||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// delete this object
|
||||
$em->remove($obj);
|
||||
$em->flush();
|
||||
|
||||
// response
|
||||
$response = new Response();
|
||||
$response->setStatusCode(Response::HTTP_OK);
|
||||
$response->send();
|
||||
}
|
||||
|
||||
protected function setQueryFilters($datatable, QueryBuilder $query)
|
||||
{
|
||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||
$query->where('q.name LIKE :filter')
|
||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||
}
|
||||
}
|
||||
|
||||
protected function setObject(ShiftSchedule $obj, EntityManagerInterface $em, Request $req)
|
||||
{
|
||||
$name = $req->request->get('name');
|
||||
|
||||
// times
|
||||
$format = 'h:i A';
|
||||
$start_time = DateTime::createFromFormat($format, $req->request->get('start_time'));
|
||||
$end_time = DateTime::createFromFormat($format, $req->request->get('end_time'));
|
||||
|
||||
// get the shift entries
|
||||
$shift_start = $req->request->get('shift_start_time');
|
||||
$shift_end = $req->request->get('shift_end_time');
|
||||
|
||||
$shifts = [];
|
||||
for ($i = 0; $i < count($shift_start); $i++)
|
||||
{
|
||||
// convert to DateTime so that we can reformat to 00-23 format
|
||||
$s_start = DateTime::createFromFormat($format, $shift_start[$i]);
|
||||
$e_start = DateTime::createFromFormat($format, $shift_end[$i]);
|
||||
|
||||
$start = $s_start->format('H:00');
|
||||
$end = $e_start->format('H:00');
|
||||
|
||||
$shifts[] = [
|
||||
'start' => $start,
|
||||
'end' => $end
|
||||
];
|
||||
}
|
||||
|
||||
$obj->setName($name)
|
||||
->setStartTime($start_time)
|
||||
->setEndTime($end_time)
|
||||
->setHourShifts($shifts);
|
||||
}
|
||||
|
||||
}
|
||||
121
src/Entity/ShiftSchedule.php
Normal file
121
src/Entity/ShiftSchedule.php
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="shift_schedule")
|
||||
*/
|
||||
class ShiftSchedule
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// shift name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=50, nullable=true)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
// start time
|
||||
/**
|
||||
* @ORM\Column(type="time")
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $start_time;
|
||||
|
||||
// end time
|
||||
/**
|
||||
* @ORM\Column(type="time")
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $end_time;
|
||||
|
||||
// hour shifts
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
*/
|
||||
protected $hour_shifts;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->start_time = new DateTime();
|
||||
$this->end_time = new DateTime();
|
||||
$this->hour_shifts = [];
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStartTime()
|
||||
{
|
||||
return $this->start_time;
|
||||
}
|
||||
|
||||
public function setStartTime(DateTime $start_time)
|
||||
{
|
||||
$this->start_time = $start_time;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEndTime()
|
||||
{
|
||||
return $this->end_time;
|
||||
}
|
||||
|
||||
public function setEndTime(DateTime $end_time)
|
||||
{
|
||||
$this->end_time = $end_time;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addHourShift($id, $value)
|
||||
{
|
||||
$this->hour_shifts[$id] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHourShiftsById($id)
|
||||
{
|
||||
// return null if we don't have it
|
||||
if (!isset($this->hour_shifts[$id]))
|
||||
return null;
|
||||
|
||||
return $this->hour_shifts[$id];
|
||||
}
|
||||
|
||||
public function getHourShifts()
|
||||
{
|
||||
return $this->hour_shifts;
|
||||
}
|
||||
|
||||
public function setHourShifts(array $hour_shifts)
|
||||
{
|
||||
$this->hour_shifts = $hour_shifts;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
254
templates/shift-schedule/form.html.twig
Normal file
254
templates/shift-schedule/form.html.twig
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">Shift Schedules</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="fa fa-building"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit Shift Schedule
|
||||
<small>{{ obj.getName() }}</small>
|
||||
{% else %}
|
||||
New Shift Schedule
|
||||
{% endif %}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="row-form" class="m-form m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('shift_schedule_update_submit', {'id': obj.getId()}) : url('shift_schedule_create_submit') }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-6">
|
||||
<label for="name" data-field="name">
|
||||
Name
|
||||
</label>
|
||||
<input type="text" name="name" class="form-control m-input" value="{{ obj.getName()|default('') }}">
|
||||
<div class="form-control-feedback hide" data-field="name"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-3">
|
||||
<label for="start_time">
|
||||
Start Time
|
||||
</label>
|
||||
<div class="input-group timepicker">
|
||||
<input id="timepicker_start" type="text" name="start_time" class="form-control m-input tp-start" readonly placeholder="Select time" type="text" value="{{ obj.getStartTime.format('g:i A') }}" />
|
||||
<span class="input-group-addon">
|
||||
<i class="la la-clock-o"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-control-feedback hide" data-field="start_time"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="end_time">
|
||||
End Time
|
||||
</label>
|
||||
<div class="input-group timepicker">
|
||||
<input id="timepicker_end" type="text" name="end_time" class="form-control m-input tp-end" readonly placeholder="Select time" type="text" value="{{ obj.getEndTime.format('g:i A') }}" />
|
||||
<span class="input-group-addon">
|
||||
<i class="la la-clock-o"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-control-feedback hide" data-field="end_time"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-form__seperator m-form__seperator--dashed"></div>
|
||||
<div class="m-form__section" id="shift-entry-section">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Breakdown of Shift Schedule
|
||||
</h3>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<button type="button" class="btn btn-primary" id="btn-add-shift-entry">Add Shift Entry</button>
|
||||
</div>
|
||||
<!-- loop through the existing shift entries -->
|
||||
{% for shift_entry in shift_entries %}
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-3">
|
||||
<div class="input-group timepicker">
|
||||
<input id="timepicker_start_entry" type="text" name="shift_start_time[]" class="form-control m-input tp-start-shift-entry" readonly placeholder="Select time" type="text" value="{{ shift_entry.start.format('g:i A') }}" />
|
||||
<span class="input-group-addon">
|
||||
<i class="la la-clock-o"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<div class="input-group timepicker">
|
||||
<input id="timepicker_end_entry" type="text" name="shift_end_time[]" class="form-control m-input tp-end-shift-entry" readonly placeholder="Select time" type="text" value="{{ shift_entry.end.format('g:i A') }}" />
|
||||
<span class="input-group-addon">
|
||||
<i class="la la-clock-o"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-1">
|
||||
<button class="btn btn-danger btn-shift-entry-remove">X</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
<a href="{{ url('shift_schedule_list') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
|
||||
var timepicker_options = {
|
||||
format: "HH:ii P",
|
||||
minuteStep: 1,
|
||||
showMeridian: true,
|
||||
snapToStep: true,
|
||||
bootcssVer: 3,
|
||||
todayHighlight: true,
|
||||
autoclose: true
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
// timepickers
|
||||
$(".tp-start, .tp-end, .tp-start-shift-entry, .tp-end-shift-entry").timepicker(timepicker_options);
|
||||
});
|
||||
|
||||
|
||||
// add shift entry
|
||||
$("#btn-add-shift-entry").click(function() {
|
||||
console.log('adding shift entry');
|
||||
|
||||
var html = '<div class="form-group m-form__group row">';
|
||||
html += '<div class="col-lg-3">';
|
||||
html += '<div class="input-group timepicker">';
|
||||
html += '<input id="timepicker_start_entry" type="text" name="shift_start_time[]" class="form-control m-input tp-start-shift-entry" readonly placeholder="Select time" type="text" value="{{ obj.getStartTime.format('g:i A') }}" />';
|
||||
html += '<span class="input-group-addon">';
|
||||
html += '<i class="la la-clock-o"></i>';
|
||||
html += '</span></div></div>';
|
||||
|
||||
html += '<div class="col-lg-3">';
|
||||
html += '<div class="input-group timepicker">';
|
||||
html += '<input id="timepicker_end_entry" type="text" name="shift_end_time[]" class="form-control m-input tp-end-shift-entry" readonly placeholder="Select time" type="text" value="{{ obj.getEndTime.format('g:i A') }}" />';
|
||||
html += '<span class="input-group-addon">';
|
||||
html += '<i class="la la-clock-o"></i>';
|
||||
html += '</span></div></div>';
|
||||
|
||||
html += '<div class="col-lg-1">';
|
||||
html += '<button class="btn btn-danger btn-shift-entry-remove">X</button>';
|
||||
html += '</div>';
|
||||
|
||||
$('#shift-entry-section').append(html);
|
||||
|
||||
// add timepicker functionality to just added timepickers
|
||||
$(".tp-start-shift-entry, .tp-end-shift-entry").timepicker(timepicker_options);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// remove shift entry
|
||||
$('body').on('click', '.btn-shift-entry-remove', function(e) {
|
||||
console.log('removing service charge');
|
||||
|
||||
$(this).closest('.row').remove();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$(function() {
|
||||
$("#row-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: form.prop('action'),
|
||||
data: form.serialize()
|
||||
}).done(function(response) {
|
||||
// remove all error classes
|
||||
removeErrors();
|
||||
swal({
|
||||
title: 'Done!',
|
||||
text: 'Your changes have been saved!',
|
||||
type: 'success',
|
||||
onClose: function() {
|
||||
window.location.href = "{{ url('shift_schedule_list') }}";
|
||||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var firstfield = false;
|
||||
|
||||
// remove all error classes first
|
||||
removeErrors();
|
||||
|
||||
// display errors contextually
|
||||
$.each(errors, function(field, msg) {
|
||||
var formfield = $("[name='" + field + "']");
|
||||
var label = $("label[data-field='" + field + "']");
|
||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||
|
||||
// add error classes to bad fields
|
||||
formfield.addClass('form-control-danger');
|
||||
label.addClass('has-danger');
|
||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||
|
||||
// check if this field comes first in DOM
|
||||
var domfield = formfield.get(0);
|
||||
|
||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
});
|
||||
|
||||
// focus on first bad field
|
||||
firstfield.focus();
|
||||
|
||||
// scroll to above that field to make it visible
|
||||
$('html, body').animate({
|
||||
scrollTop: $(firstfield).offset().top - 200
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// remove all error classes
|
||||
function removeErrors() {
|
||||
$(".form-control-danger").removeClass('form-control-danger');
|
||||
$("[data-field]").removeClass('has-danger');
|
||||
$(".form-control-feedback[data-field]").addClass('hide');
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
155
templates/shift-schedule/list.html.twig
Normal file
155
templates/shift-schedule/list.html.twig
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">
|
||||
Shift Schedules
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__body">
|
||||
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-xl-8 order-2 order-xl-1">
|
||||
<div class="form-group m-form__group row align-items-center">
|
||||
<div class="col-md-4">
|
||||
<div class="m-input-icon m-input-icon--left">
|
||||
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||
<span><i class="la la-search"></i></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||
<a href="{{ url('shift_schedule_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||
<span>
|
||||
<i class="fa fa-building"></i>
|
||||
<span>New Shift Schedule</span>
|
||||
</span>
|
||||
</a>
|
||||
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--begin: Datatable -->
|
||||
<div id="data-rows"></div>
|
||||
<!--end: Datatable -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
var options = {
|
||||
data: {
|
||||
type: 'remote',
|
||||
source: {
|
||||
read: {
|
||||
url: '{{ url("shift_schedule_rows") }}',
|
||||
method: 'POST',
|
||||
}
|
||||
},
|
||||
saveState: {
|
||||
cookie: false,
|
||||
webstorage: false
|
||||
},
|
||||
pageSize: 10,
|
||||
serverPaging: true,
|
||||
serverFiltering: true,
|
||||
serverSorting: true
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'ID',
|
||||
width: 30
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: 'Name'
|
||||
},
|
||||
{
|
||||
field: 'start_time',
|
||||
title: 'Start Time'
|
||||
},
|
||||
{
|
||||
field: 'end_time',
|
||||
title: 'End Time'
|
||||
},
|
||||
{
|
||||
field: 'hour_shifts',
|
||||
title: 'Hour Shifts'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 110,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
var actions = '';
|
||||
|
||||
if (row.meta.update_url != '') {
|
||||
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||
}
|
||||
|
||||
if (row.meta.delete_url != '') {
|
||||
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||
}
|
||||
|
||||
return actions;
|
||||
},
|
||||
}
|
||||
],
|
||||
search: {
|
||||
onEnter: false,
|
||||
input: $('#data-rows-search'),
|
||||
delay: 400
|
||||
}
|
||||
};
|
||||
|
||||
var table = $("#data-rows").mDatatable(options);
|
||||
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
var url = $(this).prop('href');
|
||||
var id = $(this).data('id');
|
||||
var btn = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
swal({
|
||||
title: 'Confirmation',
|
||||
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||
type: 'warning',
|
||||
showCancelButton: true
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
method: "DELETE",
|
||||
url: url
|
||||
}).done(function(response) {
|
||||
table.row(btn.parents('tr')).remove();
|
||||
table.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -47,48 +47,23 @@ def main():
|
|||
for hour_index in range(0, len(hours)):
|
||||
req_hours[day_index][hour_index] = int(hours_data[hour_index])
|
||||
|
||||
# index of shift selected is 8
|
||||
shift = sys.argv[8]
|
||||
argv_index = day_index + 2
|
||||
# number of days is fixed at 7 so the number of shifts will be in index 8
|
||||
num_shifts = sys.argv[argv_index]
|
||||
|
||||
hour_shifts = []
|
||||
if shift == "24_7":
|
||||
hour_shifts = [
|
||||
['00 - 09', 0, 1, 2, 3, 4, 5, 6, 7, 8],
|
||||
['01 - 10', 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
['02 - 11', 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
['03 - 12', 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
||||
['04 - 13', 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
||||
['05 - 14', 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||||
['06 - 15', 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
||||
['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
['09 - 18', 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
||||
['10 - 19', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
||||
['11 - 20', 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||
['12 - 21', 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
||||
['13 - 22', 13, 14, 15, 16, 17, 18, 19, 20, 21],
|
||||
['14 - 23', 14, 15, 16, 17, 18, 19, 20, 21, 22],
|
||||
['15 - 00', 15, 16, 17, 18, 19, 20, 21, 22, 23],
|
||||
['16 - 01', 16, 17, 18, 19, 20, 21, 22, 23, 0],
|
||||
['17 - 02', 17, 18, 19, 20, 21, 22, 23, 0, 1],
|
||||
['18 - 03', 18, 19, 20, 21, 22, 23, 0, 1, 2],
|
||||
['19 - 04', 19, 20, 21, 22, 23, 0, 1, 2, 3],
|
||||
['20 - 05', 20, 21, 22, 23, 0, 1, 2, 3, 4],
|
||||
['21 - 06', 21, 22, 23, 0, 1, 2, 3, 4, 5],
|
||||
['22 - 07', 22, 23, 0, 1, 2, 3, 4, 5, 6],
|
||||
['23 - 08', 23, 0, 1, 2, 3, 4, 5, 6, 7]]
|
||||
if shift == "8AM_5PM":
|
||||
hour_shifts = [
|
||||
['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16]]
|
||||
if shift == "7AM_10PM":
|
||||
hour_shifts = [
|
||||
['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
['09 - 18', 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
||||
['10 - 19', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
||||
['11 - 20', 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||
['12 - 21', 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
||||
['13 - 22', 13, 14, 15, 16, 17, 18, 19, 20, 21]]
|
||||
for shift_ctr in range(0, int(num_shifts)):
|
||||
# form list within the list
|
||||
hour_shift_item = []
|
||||
|
||||
shift = sys.argv[argv_index+1]
|
||||
|
||||
# append to list
|
||||
hour_shift_item.append(shift)
|
||||
|
||||
# append the list to the list
|
||||
hour_shifts.append(hour_shift_item)
|
||||
argv_index+=1
|
||||
|
||||
# all possible days riders come in
|
||||
day_shifts = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue