/**
  * Constructor
  *
  * @return void
  */
 public function construct()
 {
     if ($this->isNew()) {
         $this->setType('rtShopVoucher');
         $this->setCode(rtShopVoucherToolkit::generateVoucherCode());
     }
 }
 /**
  * Execute function
  *
  * @param array $arguments Arguments
  * @param array $options  Options
  */
 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', false);
     sfContext::createInstance($configuration);
     $configuration->loadHelpers('Partial');
     $this->configuration->loadHelpers('Number', 'I18N', 'Partial');
     // If no day/month set use current date
     $day = is_null($arguments['day']) ? date("j", strtotime(date("Y-m-d H:i:s"))) : $arguments['day'];
     $month = is_null($arguments['month']) ? date("n", strtotime(date("Y-m-d H:i:s"))) : $arguments['month'];
     if (!sfConfig::has('app_rt_shop_birthday_voucher')) {
         throw new sfCommandException('app_rt_shop_birthday_voucher has to be set');
     }
     $config = sfConfig::get('app_rt_shop_birthday_voucher');
     $config['title'] = isset($config['title']) ? $config['title'] : 'Birthday Voucher';
     $config['reduction_type'] = isset($config['reduction_type']) ? $config['reduction_type'] : 'percentageOff';
     $config['reduction_value'] = isset($config['reduction_value']) ? $config['reduction_value'] : '0';
     // Database actions
     $databaseManager = new sfDatabaseManager($this->configuration);
     $q = Doctrine_Query::create()->from('rtGuardUser u')->andWhere('DAY(u.date_of_birth) = ?', $day)->andWhere('MONTH(u.date_of_birth) = ?', $month);
     $users = $q->fetchArray();
     // Set expiry date for vouchers
     if (isset($config['expires_in'])) {
         $expiry_date = date('Y-m-d H:i:s', strtotime(sprintf("+%s days", $config['expires_in'])));
     } else {
         $expiry_date = isset($config['date_to']) ? $config['date_to'] : NULL;
     }
     $this->_batch_reference = rtShopVoucherToolkit::generateVoucherCode();
     $voucher_details = array('date_from' => NULL, 'date_to' => $expiry_date, 'reduction_type' => $config['reduction_type'], 'reduction_value' => $config['reduction_value'], 'title' => $config['title'], 'type' => 'rtShopVoucher', 'batch_reference' => $this->_batch_reference, 'count' => 1, 'mode' => 'Single', 'total_from' => isset($config['total_from']) ? $config['total_from'] : NULL, 'total_to' => isset($config['total_to']) ? $config['total_to'] : NULL, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"), 'code' => '');
     $this->createBatchVouchers($voucher_details, count($users));
     $q = Doctrine_Query::create()->from('rtShopVoucher v')->andWhere('v.batch_reference = ?', $this->_batch_reference);
     $voucher = $q->fetchArray();
     if (count($users) > 0) {
         $this->log('--------------------------------');
         $this->log('--- Create birthday vouchers ---');
         $this->log('--------------------------------');
         $i = 0;
         foreach ($users as $user) {
             $this->logSection('shop-create-birthday-voucher', sprintf('Date of birth: [%s] // Code: [%s] // Last_name: [%s]', $user['date_of_birth'], $voucher[$i]['code'], $user['last_name']));
             if ($user['email_address'] != '') {
                 $this->notifyUser($user, $voucher[$i]['code'], $config);
             }
             $i++;
         }
         $this->logSection('shop-create-birthday-voucher', sprintf('Total created birthday vouchers: [%s]', count($users)));
     } else {
         $this->logSection('shop-create-birthday-voucher', 'No users in chosen birthday range');
     }
     $this->notifyAdministrator($users, $config);
 }
$i5->delete();
$i6->delete();
unset($i3, $i4, $i5, $i6);
unset($o2, $o3, $o4, $o5);
$t->diag('*******************************************************');
$t->diag('*** Combination: date_from/date_to and voucher code ***');
$t->diag('*******************************************************');
// Generate voucher codes
$code1 = rtShopVoucherToolkit::generateVoucherCode();
$code2 = rtShopVoucherToolkit::generateVoucherCode();
$code3 = rtShopVoucherToolkit::generateVoucherCode();
$code4 = rtShopVoucherToolkit::generateVoucherCode();
$code5 = rtShopVoucherToolkit::generateVoucherCode();
$code6 = rtShopVoucherToolkit::generateVoucherCode();
$code7 = rtShopVoucherToolkit::generateVoucherCode();
$code8 = rtShopVoucherToolkit::generateVoucherCode();
// Add vouchers data
$set_date_from = date("Y-m-d H:i:s");
$set_date_to = sprintf("+%s months", 3);
// Add vouchers data
try {
    rtShopVoucherTestTools::clean();
    // Add 3 vouchers
    $i3 = new rtShopVoucher();
    $i3->setTitle('Voucher');
    $i3->setCode($code1);
    $i3->setReductionValue(10);
    $i3->save();
    $i4 = new rtShopVoucher();
    $i4->setTitle('Voucher');
    $i4->setCode($code2);