partial #2494 - drivers shift preferences
This commit is contained in:
parent
ef48be631d
commit
6c3ad48f33
@ -96,15 +96,24 @@ class Controller_api_drivers_shift extends Crunchbutton_Controller_RestAccount {
|
||||
$year = $this->request()[ 'year' ];
|
||||
$week = $this->request()[ 'week' ];
|
||||
$id_community = $this->request()[ 'id_community' ];
|
||||
|
||||
|
||||
// Start week at monday #2666
|
||||
$firstDay = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 1 ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
|
||||
$days = [];
|
||||
for( $i = 0; $i <= 6; $i++ ){
|
||||
$dateFrom = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . $i ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
$days[] = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
|
||||
$firstDay->modify( '+ 1 day' );
|
||||
}
|
||||
|
||||
foreach( $days as $day ){
|
||||
$dateFrom = new DateTime( $day->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
|
||||
$dateFrom->modify( '- 7 day' );
|
||||
$dateTo = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . $i ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
$dateTo = new DateTime( $day->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
|
||||
Crunchbutton_Community_Shift::removeHoursFromDay( $id_community, $dateTo->format( 'Y-m-d' ) );
|
||||
Crunchbutton_Community_Shift::copyHoursFromTo( $id_community, $dateFrom->format( 'Y-m-d' ), $dateTo->format( 'Y-m-d' ) );
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode( array( 'success' => true ) );
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -40,13 +40,21 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
|
||||
|
||||
public function scheduleDriver(){
|
||||
$admin = Admin::o( c::admin()->id_admin );
|
||||
$week = c::getPagePiece( 8 ) ? c::getPagePiece( 8 ) : date( 'W' );
|
||||
$year = date( 'Y' );
|
||||
$week = date( 'W' );
|
||||
|
||||
// Start week at monday #2666
|
||||
$firstDay = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 1 ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
|
||||
// Get next week
|
||||
$firstDay->modify( '+ 1 week' );
|
||||
|
||||
$days = [];
|
||||
for( $i = 0; $i <= 6; $i++ ){
|
||||
$day = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . $i ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
$day->modify( '+ 7 day' );
|
||||
$days[] = $day;
|
||||
$days[] = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
|
||||
$firstDay->modify( '+ 1 day' );
|
||||
}
|
||||
c::view()->days = $days;
|
||||
c::view()->communities = $admin->communitiesHeDeliveriesFor();
|
||||
c::view()->display( 'drivers/shift/schedule/driver' );
|
||||
}
|
||||
@ -68,9 +76,13 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
|
||||
$day = c::getPagePiece( 7 ) ? c::getPagePiece( 7 ) : date( 'd' );
|
||||
$week = c::getPagePiece( 8 ) ? c::getPagePiece( 8 ) : date( 'W' );
|
||||
|
||||
// Start week at monday #2666
|
||||
$firstDay = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 1 ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
|
||||
$days = [];
|
||||
for( $i = 0; $i <= 6; $i++ ){
|
||||
$days[] = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . $i ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
$days[] = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
|
||||
$firstDay->modify( '+ 1 day' );
|
||||
}
|
||||
|
||||
if( $id_community ){
|
||||
@ -97,9 +109,13 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
|
||||
$week = '0' . intval( $week );
|
||||
}
|
||||
|
||||
// Start week at monday #2666
|
||||
$firstDay = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 1 ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
|
||||
$days = [];
|
||||
for( $i = 0; $i <= 6; $i++ ){
|
||||
$days[] = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . $i ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
$days[] = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
|
||||
$firstDay->modify( '+ 1 day' );
|
||||
}
|
||||
|
||||
if( $week <= 1 ){
|
||||
@ -118,25 +134,10 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
|
||||
c::view()->week = $week;
|
||||
c::view()->year = $year;
|
||||
c::view()->days = $days;
|
||||
c::view()->from = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . '0' ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
c::view()->to = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . '6' ) ), new DateTimeZone( c::config()->timezone ) );
|
||||
|
||||
|
||||
/*$year = c::getPagePiece( 4 );
|
||||
$week = c::getPagePiece( 5 );
|
||||
$today = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
||||
if( !$year ){
|
||||
$year = $today->format( 'Y' );
|
||||
}
|
||||
if( !$week ){
|
||||
$week = $today->format( 'W' );
|
||||
}
|
||||
$week = ( intval( $week ) < 10 ) ? '0' . $week : $week;
|
||||
c::view()->week = $week;
|
||||
c::view()->year = $year;
|
||||
c::view()->days = $days;
|
||||
// c::view()->segments = Crunchbutton_Community_Shift::shiftByCommunity( $id_community );
|
||||
*/
|
||||
$firstDay->modify( '-1 day' );
|
||||
c::view()->to = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
|
||||
$firstDay->modify( '-6 day' );
|
||||
c::view()->from = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
|
||||
}
|
||||
c::view()->id_community = $id_community;
|
||||
c::view()->display( 'drivers/shift/community/index' );
|
||||
|
||||
@ -9,6 +9,10 @@ class Crunchbutton_Community_Shift extends Cana_Table {
|
||||
->load($id);
|
||||
}
|
||||
|
||||
public function autoCopyLastWeek(){
|
||||
|
||||
}
|
||||
|
||||
public function shiftByCommunityDay( $id_community, $date ){
|
||||
return Crunchbutton_Community_Shift::q( 'SELECT * FROM community_shift WHERE id_community = "' . $id_community . '" AND DATE_FORMAT( date_start, "%Y-%m-%d" ) = "' . $date . '" ORDER BY id_community_shift ASC' );
|
||||
}
|
||||
|
||||
@ -61,13 +61,13 @@
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<?php foreach( $this->days as $day ) {
|
||||
$dark = ( $day->format( 'N' ) == 7 || $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
|
||||
$dark = ( $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
|
||||
?>
|
||||
<th width="14%" style="background:<?php echo $dark; ?>">
|
||||
<div class="row-fluid padded">
|
||||
<div class="span12">
|
||||
<strong style="font-size:16px;color:#666;">
|
||||
<?php echo $day->format( 'D' ); ?>
|
||||
<?php echo $day->format( 'l' ); ?>
|
||||
<div style="font-size:10px;font-weight:normal;color:#CCC;"><?php echo $day->format( 'M' ); ?> <?php echo $day->format( 'd' ); ?></div>
|
||||
</strong>
|
||||
</div>
|
||||
@ -77,12 +77,11 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<?php foreach( $this->days as $day ) {
|
||||
$dark = ( $day->format( 'N' ) == 7 || $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
|
||||
$dark = ( $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
|
||||
$segments = Crunchbutton_Community_Shift::shiftByCommunityDay( $id_community, $day->format( 'Y-m-d' ) );
|
||||
?>
|
||||
<td width="14%" style="background:<?php echo $dark; ?>" valign="top">
|
||||
<div class="row-fluid padded">
|
||||
|
||||
<?php
|
||||
foreach( $segments as $segment ) {
|
||||
?><div class="row-fluid">
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
$this->titleLink = '/drivers';
|
||||
$this->title2 = 'Shift';
|
||||
$this->title2icon = 'clock';
|
||||
|
||||
$communities = $this->communities;
|
||||
?>
|
||||
<div class="container-fluid padded">
|
||||
@ -19,38 +18,36 @@
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<?php
|
||||
$days = [ 'sun', 'mon','tue','wed','thu','fri','sat' ];
|
||||
foreach( $days as $day ){ ?>
|
||||
foreach( $this->days as $day ){
|
||||
$dark = ( $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
|
||||
?>
|
||||
<th width="14%" style="background:<?php echo $dark; ?>">
|
||||
<div class="row-fluid padded">
|
||||
<div class="span12">
|
||||
<strong style="font-size:15px;color:#666;">
|
||||
<?php echo ucfirst( $day ); ?>
|
||||
</strong>
|
||||
</div>
|
||||
<strong style="font-size:15px;color:#666;">
|
||||
<?php echo ucfirst( $day->format( l ) ); ?>
|
||||
<div style="font-size:10px;font-weight:normal;color:#CCC;"><?php echo $day->format( 'M' ); ?> <?php echo $day->format( 'd' ); ?></div>
|
||||
</strong>
|
||||
</div>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<?php
|
||||
$days = $this->days;
|
||||
foreach( $days as $day ){
|
||||
$hasShift = false;
|
||||
foreach( $this->days as $day ){
|
||||
$dark = ( $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
|
||||
$segments = Crunchbutton_Community_Shift::shiftByCommunityDay( $community->id_community, $day->format( 'Y-m-d' ) );
|
||||
?>
|
||||
<td style="background:<?php echo $dark; ?>">
|
||||
<div class="row-fluid padded">
|
||||
<?php
|
||||
foreach( $segments as $segment ) {
|
||||
?> <div class="span12"><?php
|
||||
echo trim( Crunchbutton_Community_Shift::startEndToSegment( $segment->start, $segment->end ) );
|
||||
?></div><?php
|
||||
} ?>
|
||||
</div>
|
||||
<td style="background:<?php echo $dark; ?>">
|
||||
<?php
|
||||
foreach( $segments as $segment ) {
|
||||
$hasShift = true;
|
||||
?><div class="row-fluid padded"><?php echo $segment->startEndToString(); ?></div><?php
|
||||
} ?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php if( !$hasShift ){ ?><i><?php echo $community->name; ?> has no shift for this period!</i><?php } ?>
|
||||
<hr />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user