Selaa lähdekoodia

Fixed settle-method in Plugin.php

pull/1/head
DragonSkills99 6 vuotta sitten
vanhempi
commit
3e2456e2d4
1 muutettua tiedostoa jossa 33 lisäystä ja 5 poistoa
  1. 33
    5
      Plugin.php

+ 33
- 5
Plugin.php Näytä tiedosto

@@ -54,11 +54,7 @@ class MinecraftPaymentPlugin extends Plugin {
$this->show_template( 'GrantUser', $params );
}

public function settle_view( string $url ) {
$m = array_key_exists( 'month', $_GET ) ? $_GET[ 'month' ] : date( 'm' ) - 1;
$y = array_key_exists( 'month', $_GET ) ? $_GET[ 'month' ] : date( 'Y' );
if ( $m == '0' ) { $m = '12'; $y--; }

private function settle( $m, $y ) {
$mp = MinecraftMonthPaid::GetByUnique( 0, $m ,$y );
if ( $mp ) {
echo __( [ 'de' => 'Bereits abgerechnet', 'en' => 'Already settled' ] );
@@ -123,6 +119,38 @@ class MinecraftPaymentPlugin extends Plugin {
}
}

public function settle_view( string $url ) {
// ORDER BY Year DESC, Month DESC LIMIT 1

$nwst = MinecraftMonthPaid::GetAll( "1 ORDER BY Year DESC, Month DESC LIMIT 1" )[ 0 ];
if ( !$nwst ) {
$nwst = new MinecraftMonthPaid();
$nwst->SetMonth( date( 'm' ) );
$nwst->SetYear( date( 'Y' ) );
}

$m = array_key_exists( 'month', $_GET ) ? $_GET[ 'month' ] + 1 : date( 'm' );
$y = array_key_exists( 'year', $_GET ) ? $_GET[ 'year' ] : date( 'Y' );
if ( $m == '0' ) { $m = '12'; $y--; }

$start = ( new DateTime( $nwst->GetYear() . '-' . $nwst->GetMonth() . '-' . '01' ) )->modify( 'first day of next month' );
$end = ( new DateTime( date( "$y-$m-01" ) ) )->modify( 'first day of this month' );
$interval = DateInterval::createFromDateString( '1 month' );
$period = new DatePeriod( $start, $interval, $end );

$settled = false;
foreach ($period as $dt) {
$settled = true;
echo 'Settling ' . $dt->format("Y-m") . ': ';
$this->settle( $dt->format( 'm' ), $dt->format( 'Y' ) );
echo "<br>\n";
}

if( !$settled ) {
echo 'Nothing to settle';
}
}

public function acredit_view( string $url ) {
if ( !Permission::PERMITTED( 'Minecraft-Pay-Settings', 1 ) ) return;
$params = null;

Loading…
Peruuta
Tallenna