<?
require_once('../functions.php');
$startyear = 2009;
$startmonth = 06;

$endyear = 2010;

/*
for ($year = $startyear; $year++; $year <= $endyear) {
  if ($year != $startyear) {
    $startmonth = 1;
  }
  if ($year != $endyear) {
    $endmonth = 12;
  } else {
    $endmonth = date('m', time());
  }
  for ($month = $startmonth; $month++; $month <= $endmonth) {
    
  }
}
*/

$query = "SELECT *
  FROM kontobewegungen
  WHERE kommentar LIKE 'Punkteverfall nach%'
  AND datum = 1270072800";
$result = mysql_query($query) or die ("Cannot select: " . mysql_error());

print "Anzahl der Verfaller: " . mysql_num_rows($result) . "\n";
$userIds = array();
$werte = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  $userIds[] = $row['userId'];
  $werte[] = $row['wert'];
  $pkeys[] = $row['pkey'];
  $datums[] = $row['datum'];
}

print "Versnummer;Rechtskreis;Verfallen;Berechnet\n";
#$userIds = array(9466);
#$werte = array(-50);
$i = 0;
$now = time();
for ($i=0; $i< count($userIds); $i++) {
// foreach ($userIds as $userId) {
    $user = new user(0,$userIds[$i]);
    $konto = new konto($userIds[$i]);
    $pkey = $pkeys[$i];
    $datum = $datums[$i];
    $wert = $werte[$i];
    $Verfall = $konto->calcinvalidatenext('2010-03-31', false);
    $lastEntry = date("Y-m-d" , $konto->getLastEntryDate($now));
    // if ($Verfall[0] != abs($wert) && $lastEntry <'2010-06-15')  { 
    //if ($Verfall[0] == 0 && $lastEntry < '2010-06-15') {
    /* print "Versnummer: " . $user->versnummer . ", Rechtskreis: " . $user->rechtskreis . ", Verfallen: $wert, Berechnet: " . $Verfall[0] . "\n"; */
        print  "$lastEntry;" . $user->versnummer . ";" . $pkey . ";" . $datum . ";" . $user->rechtskreis . ";$wert;" . (0- $Verfall[0]) . "\n";
        $kontobewegung = new kontoBewegung();
        $kontobewegung->id = $pkey;
 ///       $kontobewegung->deleteEntry();
//    }
}
exit;
?>
