Comments

3 comments

  • Official comment
    Avatar
    Chris Muench

    As of now there isn't a way.

  • Avatar
    Martin Roy

    Would a cron job handle something like that?

  • Avatar
    Chris Muench

    You would setup a cron task and use https://wkhtmltopdf.org to generate an email

     

    Here is an example of creating an email controller that can then be run on a cron (php index.php email_reports index)

    <?php
    class Email_reports extends CI_Controller
    {
    function index()
    {
    $exes = array();
    $exes[] = 'c:\PROGRA~1\wkhtmltopdf\bin\wkhtmltopdf.exe';
    $exes[] = '/usr/local/bin/wkhtmltopdf';

    $tmp = APPPATH.'../tmp';

    $reports_username = $this->config->item('reports_username');
    $reports_password = $this->config->item('reports_password');
    $reports_base_url = $this->config->item('reports_base_url');

    foreach($exes as $exe)
    {
    if (is_executable($exe))
    {

    if ($exe == 'c:\PROGRA~1\wkhtmltopdf\bin\wkhtmltopdf.exe')
    {
    $report_url = escapeshellarg($reports_base_url."index.php/reports/generate/closeout?report_type=simple&report_date_range_simple=TODAY&export_excel=0");
    $login_url = escapeshellarg($reports_base_url."index.php/login");
    }
    else
    {
    $report_url = $reports_base_url."index.php/reports/generate/closeout?report_type=simple&report_date_range_simple=TODAY&export_excel=0";
    $login_url = $reports_base_url."index.php/login";

    }
    shell_exec("$exe --post username $reports_username --post password $reports_password --cookie-jar $tmp/reporting.jar $login_url $tmp/dumb.pdf");
    shell_exec("$exe --print-media-type --orientation Portrait --cookie-jar $tmp/reporting.jar '$report_url' $tmp/closeout.pdf");

    //e-mail
    $reports_email = $this->config->item('reports_email');
    $this->load->library('email');
    $config = array();
    $config['mailtype'] = 'text';
    $this->email->initialize($config);
    $this->email->from($reports_email);
    $this->email->to($reports_email);
    $this->email->subject('Daily Reports');
    $this->email->message('Attached are your daily reports');
    $this->email->attach("$tmp/closeout.pdf", 'attachment', 'closeout.pdf');
    $this->email->send();
    unlink($tmp.'/closeout.pdf');
    unlink($tmp.'/dumb.pdf');
    unlink($tmp.'/reporting.jar');
    break;
    }
    }
    }
    }
    ?>

     

Please sign in to leave a comment.