<?php
if(isset($_SERVER["REMOTE_ADDR"]) || isset($_SERVER["SERVER_ADDR"])){
    die("Permission denied");
};

define('SCRIPT_PATH', dirname(__FILE__));
define('CRON_RUN', true);

require_once(SCRIPT_PATH.'/../../../lib/config.inc.php');
require_once(SCRIPT_PATH.'/../../../lib/app.inc.php');

$cron_settings = $app->db->queryOneRecord("SELECT * FROM invoice_settings WHERE invoice_settings_id = 1");

if($cron_settings['recurring_invoices_cron_active'] != 'y') die("Cron job not activated!\n");

$_POST['test'] = ($cron_settings['recurring_invoices_cron_test'] == 'y'? 1 : 0);
$_POST['finalize_invoices'] = ($cron_settings['recurring_invoices_cron_finalize_invoices'] == 'y'? 1 : 0);
$_POST['send_invoices'] = ($cron_settings['recurring_invoices_cron_send_invoices'] == 'y'? 1 : 0);
$_POST['email_template_id'] = $cron_settings['recurring_invoices_cron_email_template_id'];
$_POST['proforma_invoice'] = ($cron_settings['recurring_invoices_cron_proforma_invoice'] == 'y'? 1 : 0);

$_POST['until_date'] = date('d.m.Y');

require(SCRIPT_PATH.'/../create_recurring_invoices.php');
?>