<?
  include('../functions.php');

  $startDate="2010-02-01";
  $endDate="2010-03-31";
  $u18 = true;
  $wechsler = 1;
  $versand = 1; # 1 = letter, 2 = email, 0 = kein Versand

  # Create Application Object
  $healthmiles = new healthmiles();
 
  # Fetch all users with changes in balance between startDate and endDate
  $userIds = $healthmiles->getUsersWithAccountChanges($startDate,$endDate,$u18,$versand, $wechsler);
#  $userIds = $healthmiles->getUsersWithInvalidations($endDate,$u18,$versand, $wechsler);

  # iterate through result list
  foreach($userIds as $userId) {
      print "--------------------------------------------------------\n";

      # create user object
      $user = new user(0,$userId);
      # read user account
      $konto = new konto($userId);

      # calc points that invalidate during the next two month
      # refence date = now + 1 month (fenced to 1st of next month)
      $invalidpoints = $konto->calcinvalidatenext($endDate);
      print "User: " . $user->vorname . ", " . $user->name;
      print "Geburtsdatum: " . $user->geburtsdatum ;
      print " Next Month: " . $invalidpoints[0]; 
      print " 2nd Next Month: " . $invalidpoints[1]; 
      print " Saldo Start: " . $konto->getSaldo($startDate);
      print " Saldo Ende: " . $konto->getSaldo($endDate);
      print "\n";

      # filter account entries (drop all 0 lines, from start to end)
      # result will be stored in $konto->kontoBewegungen
      $konto->readKontoauszugFiltered($startDate, $endDate);

      foreach ($konto->kontoBewegungen as $kontobewegung) {
          print date("d.m.Y", $kontobewegung->datum);
          print " " . trim($kontobewegung->beschreibung);
          print " " . $kontobewegung->wert;
          print "\n";
      }
  }

  print "Anzahl: " . sizeof($userIds) . "\n";
?>
