public static function run() { try { //Create timestamps of start and end of week $fromTimeStamp = strtotime('monday last week ' . GlobalConfig::PHP_TIME_ZONE); $toTimeStamp = strtotime('monday this week ' . GlobalConfig::PHP_TIME_ZONE); //Get all gransactions for this week $transactions = MoneyTransactionDB::getTransactionsBetween($fromTimeStamp, $toTimeStamp); //Get total amount of money in the system right now $totalBalanceAfter = MoneyTransactionDB::getTotalBalance(); //Get total amount of money added and removed during this week. $incrMoneyFromRealMoney = 0; $incrMoneyFromPrize = 0; $decrMoneyWithoutDiscount = 0; $decrMoneyWithDiscount = 0; foreach ($transactions as $transaction) { if ($transaction->isFromPrize()) { $incrMoneyFromPrize += $transaction->getIncrMoney(); } else { $incrMoneyFromRealMoney += $transaction->getIncrMoney(); } $decrMoneyWithoutDiscount += $transaction->getDecrMoney(); $decrMoneyWithDiscount += $transaction->getDecrMoneyWithDiscount(); } //Get total amount of money in the system before this week $totalBalanceBefore = $totalBalanceAfter - $incrMoneyFromRealMoney - $incrMoneyFromPrize + $decrMoneyWithDiscount; //Create from and to time strings $fromTime = new DateTime(); $fromTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE)); $fromTime->setTimeStamp($fromTimeStamp); $fromTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE)); $fromDateString = $fromTime->format('d/m/y'); $fromTimeString = $fromTime->format('d/m/y H:i:s'); $toTime = new DateTime(); $toTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE)); $toTime->setTimeStamp($toTimeStamp); //Subtract 1 second to display the correct date. $toTime = date_sub($toTime, new DateInterval('PT1S')); $toDateString = $toTime->format('d/m/y'); $toTimeString = $toTime->format('d/m/y H:i:s'); //Create array with date to show in the email $emailExtras['common']['fromDate'] = $fromDateString; $emailExtras['common']['toDate'] = $toDateString; $emailExtras['common']['fromTime'] = $fromTimeString; $emailExtras['common']['toTime'] = $toTimeString; $emailExtras['common']['totalBalanceBefore'] = $totalBalanceBefore / 100; $emailExtras['common']['incrMoneyFromRealMoney'] = $incrMoneyFromRealMoney / 100; $emailExtras['common']['incrMoneyFromPrize'] = $incrMoneyFromPrize / 100; $emailExtras['common']['decrMoneyWithoutDiscount'] = $decrMoneyWithoutDiscount / 100; $emailExtras['common']['decrMoneyWithDiscount'] = $decrMoneyWithDiscount / 100; $emailExtras['common']['totalBalanceAfter'] = $totalBalanceAfter / 100; //Create fake users to send email to addresses $users = array(); foreach (BalandeSummaryEmailSenderConfig::EMAIL_ADDRESSES as $emailAddress) { $user = new User(); $user->email = $emailAddress; array_push($users, $user); } //Send email Email::sendEmails('MoneyOverview.html', 'Saldo lidkaarten ' . $fromDateString . ' - ' . $toDateString, '*****@*****.**', $users, $emailExtras); } catch (Exception $ex) { var_dump($ex); } }