partial #2969 - some options were missing at the driver schedule page
This commit is contained in:
parent
3b65e94522
commit
bbf2fc48de
@ -40,6 +40,29 @@ class Controller_api_driver_shifts extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
switch ( $action ) {
|
||||
|
||||
case 'shiftsAvailableToWork':
|
||||
$shifts = $this->request()[ 'shifts' ];
|
||||
// Start week on Thursday #3084
|
||||
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
||||
if( $now->format( 'l' ) == 'Thursday' ){
|
||||
$thursday = $now;
|
||||
$thursday->modify( '+ 1 week' );
|
||||
} else {
|
||||
$thursday = new DateTime( 'next thursday', new DateTimeZone( c::config()->timezone ) );
|
||||
}
|
||||
|
||||
$year = $thursday->format( 'Y' );
|
||||
$week = $thursday->format( 'W' );
|
||||
|
||||
$id_admin = c::user()->id_admin;
|
||||
$status = Crunchbutton_Admin_Shift_Status::getByAdminWeekYear( $id_admin, $week, $year );
|
||||
$status->shifts = $shifts;
|
||||
$status->date = date( 'Y-m-d H:i:s' );
|
||||
$status->save();
|
||||
$this->_scheduleList();
|
||||
exit;
|
||||
break;
|
||||
|
||||
case 'rankingChange':
|
||||
$id_community_shift = $this->request()[ 'id_community_shift' ];
|
||||
$id_community_shift_change = $this->request()[ 'id_community_shift_change' ];
|
||||
@ -99,7 +122,7 @@ class Controller_api_driver_shifts extends Crunchbutton_Controller_RestAccount {
|
||||
private function _scheduleList(){
|
||||
|
||||
// Start week on Thursday #3084
|
||||
$now = new DateTime( 'last monday', new DateTimeZone( c::config()->timezone ) );
|
||||
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
||||
if( $now->format( 'l' ) == 'Thursday' ){
|
||||
$thursday = $now;
|
||||
$thursday->modify( '+ 1 week' );
|
||||
@ -166,13 +189,14 @@ class Controller_api_driver_shifts extends Crunchbutton_Controller_RestAccount {
|
||||
}
|
||||
|
||||
$shifts = [];
|
||||
|
||||
$_availableShifts = 0;
|
||||
if( $_shifts && count( $_shifts ) > 0 ){
|
||||
$res_array = [];
|
||||
foreach( $_shifts as $shift ){
|
||||
if( $shift[ 'ranking' ] && $shift[ 'ranking' ] > 0 ){
|
||||
$index = $shift[ 'ranking' ];
|
||||
} else {
|
||||
$_availableShifts++;
|
||||
$index = $ranking;
|
||||
$ranking++;
|
||||
}
|
||||
@ -186,7 +210,15 @@ class Controller_api_driver_shifts extends Crunchbutton_Controller_RestAccount {
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode( [ 'info' => [ 'period' => $shifts_period ], 'results' => $shifts ] );
|
||||
$status = Crunchbutton_Admin_Shift_Status::getByAdminWeekYear( $id_admin, $week, $year );
|
||||
if( $_availableShifts == 0 && $status->shifts > 0 ){
|
||||
$status->completed = 1;
|
||||
} else {
|
||||
$status->completed = 0;
|
||||
}
|
||||
$status->save();
|
||||
|
||||
echo json_encode( [ 'info' => [ 'period' => $shifts_period ], 'completed' => $status->completed, 'shifts' => $status->shifts, 'results' => $shifts ] );
|
||||
}
|
||||
|
||||
private function _list(){
|
||||
|
||||
@ -17,12 +17,20 @@
|
||||
|
||||
<div class="drivers-shift drivers-schedule">
|
||||
|
||||
<div>
|
||||
<ul class="ul-inputs box-content">
|
||||
<li class="li-input">
|
||||
<div class="label">How many shifts would you like to work this week?</div>
|
||||
<select name="shiftsAvailableToWork" ng-model="shiftsAvailableToWork" ng-change="updateShiftsAvailable(this.shiftsAvailableToWork)" ng-options="shift as shift for shift in availableToWork"></select>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div ng-if="available > 0" class="shifts-available">
|
||||
|
||||
<h2 class="title">Available shifts</h2>
|
||||
|
||||
<div class="box-content">
|
||||
|
||||
<table class="tb-grid">
|
||||
<tr ng-repeat="shift in shifts" ng-if="!shift.ranking && shift.ranking != 0">
|
||||
<td>
|
||||
|
||||
@ -154,11 +154,15 @@ NGApp.controller( 'DriversShiftsScheduleCtrl', function ( $scope, DriverShiftSch
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.shiftsAvailableToWork = 0;
|
||||
$scope.availableToWork = [12,11,10,9,8,7,6,5,4,3,2,1];
|
||||
|
||||
var process = function( data ){
|
||||
$scope.available = 0;
|
||||
$scope.yes = 0;
|
||||
$scope.not = 0;
|
||||
$scope.period = data.info.period;
|
||||
$scope.shiftsAvailableToWork = parseInt( data.shifts );
|
||||
$scope.shifts = data.results;
|
||||
count();
|
||||
}
|
||||
@ -187,6 +191,14 @@ NGApp.controller( 'DriversShiftsScheduleCtrl', function ( $scope, DriverShiftSch
|
||||
$scope.nextRanking = ranking;
|
||||
}
|
||||
|
||||
$scope.updateShiftsAvailable = function( shifts ){
|
||||
// $scope.makeBusy();
|
||||
$scope.shiftsAvailableToWork = shifts;
|
||||
DriverShiftScheduleService.shiftsAvailableToWork( shifts, function( data ){
|
||||
process( data );
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.rankingChange = function( id_community_shift, id_community_shift_change ){
|
||||
$scope.makeBusy();
|
||||
DriverShiftScheduleService.rankingChange( id_community_shift, id_community_shift_change, function( data ){
|
||||
|
||||
@ -52,6 +52,7 @@ NGApp.factory( 'DriverShiftScheduleService', function( $rootScope, $resource ) {
|
||||
'dontWantToWork' : { 'method': 'POST', params : {} },
|
||||
'wantToWork' : { 'method': 'POST', params : {} },
|
||||
'rankingChange' : { 'method': 'POST', params : {} },
|
||||
'shiftsAvailableToWork' : { 'method': 'POST', params : {} },
|
||||
} );
|
||||
|
||||
service.list = function( callback ){
|
||||
@ -59,6 +60,12 @@ NGApp.factory( 'DriverShiftScheduleService', function( $rootScope, $resource ) {
|
||||
callback( data ); } );
|
||||
};
|
||||
|
||||
service.shiftsAvailableToWork = function( shifts, callback ){
|
||||
schedules.rankingChange( { 'shifts' : shifts, action: 'shiftsAvailableToWork' }, function( json ){
|
||||
callback( json );
|
||||
} );
|
||||
};
|
||||
|
||||
service.rankingChange = function( id_community_shift, id_community_shift_change, callback ){
|
||||
schedules.rankingChange( { 'id_community_shift' : id_community_shift, 'id_community_shift_change' : id_community_shift_change, action: 'rankingChange' }, function( json ){
|
||||
callback( json );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user