예제 #1
0
 /**
  * method onPDF()
  * executed whenever the user clicks at the pdf button
  */
 function onPDF($param)
 {
     try {
         TTransaction::open('permission');
         // open transaction
         $conn = TTransaction::get();
         // get PDO connection
         // run query
         $result = $conn->query('SELECT id, name from system_user order by id');
         // get the form data into an active record Customer
         $widths = array(60, 125, 125, 150, 70);
         $tr = new TTableWriterPDF($widths);
         // create the document styles
         $tr->addStyle('title', 'Arial', '12', 'B', '#000000', '#CDCDCD');
         $tr->addStyle('par', 'Arial', '10', '', '#000000', '#CFCFCF');
         $tr->addStyle('impar', 'Arial', '10', '', '#000000', '#FFFFFF');
         $tr->addStyle('header', 'Times', '16', 'B', '#000000', '#CDCDCD');
         $tr->addStyle('footer', 'Times', '12', 'B', '#000000', '#CDCDCD');
         // add a header row
         $tr->addRow();
         $tr->addCell('Employees', 'center', 'header', 5);
         // add titles row
         $tr->addRow();
         $tr->addCell('DNI', 'center', 'title');
         $tr->addCell('Name', 'center', 'title');
         $tr->addCell('Address', 'center', 'title');
         $tr->addCell('Email', 'center', 'title');
         $tr->addCell('Phone', 'center', 'title');
         // controls the background filling
         $colour = FALSE;
         foreach ($result as $row) {
             $style = $colour ? 'par' : 'impar';
             $tr->addRow();
             $tr->addCell('53321548G', 'left', $style);
             $tr->addCell('Jordi Aguilà Cortés', 'left', $style);
             $tr->addCell('Pere Massallach 21 1 2', 'left', $style);
             $tr->addCell('*****@*****.**', 'left', $style);
             $tr->addCell('617186879', 'left', $style);
             $colour = !$colour;
         }
         // footer row
         $tr->addRow();
         $tr->addCell(date('l jS \\of F Y h:i:s A'), 'center', 'footer', 5);
         $tr->Footer('This document contains information about employees of the company.');
         if (!file_exists("app/output/employees_" . date("Ymd") . ".pdf") or is_writable("app/output/employees_" . date("Ymd") . ".pdf")) {
             $tr->save("app/output/employees_" . date("Ymd") . ".pdf");
         } else {
             throw new Exception(_t('Permission denied') . ': ' . "app/output/employees_" . date("Ymd") . ".pdf");
         }
         parent::openFile("app/output/employees_" . date("Ymd") . ".pdf");
         // shows the success message
         new TMessage('info', 'Report generated. Please, enable popups in the browser (just in the web).');
         TTransaction::close();
         // close transaction
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
     }
 }
예제 #2
0
 /**
  * method onPDF()
  * executed whenever the user clicks at the pdf button
  */
 function onPDF($param)
 {
     try {
         TTransaction::open('permission');
         // open transaction
         $conn = TTransaction::get();
         // get PDO connection
         // run query
         $result = $conn->query('SELECT nif, name from system_providers order by id');
         // get the form data into an active record Customer -> tocar las columnas
         $widths = array(270, 270);
         $tr = new TTableWriterPDF($widths);
         // create the document styles
         $tr->addStyle('title', 'Arial', '12', 'B', '#000000', '#A0B2BC');
         $tr->addStyle('par', 'Arial', '10', '', '#000000', '#ECE9E9');
         $tr->addStyle('impar', 'Arial', '10', '', '#000000', '#FFFFFF');
         $tr->addStyle('header', 'Times', '16', 'B', '#FFFFFF', '#4C5976');
         $tr->addStyle('footer', 'Times', '12', 'B', '#000000', '#88BACF');
         // add a header row
         $tr->addRow();
         $tr->addCell('Providers', 'center', 'header', 2);
         // add titles row
         $tr->addRow();
         $tr->addCell('NIF', 'center', 'title');
         $tr->addCell('Name', 'center', 'title');
         // controls the background filling
         $colour = FALSE;
         foreach ($result as $row) {
             $style = $colour ? 'par' : 'impar';
             $tr->addRow();
             $tr->addCell($row['nif'], 'left', $style);
             $tr->addCell($row['name'], 'left', $style);
             $colour = !$colour;
         }
         // footer row
         $tr->addRow();
         $tr->addCell(date('l jS \\of F Y h:i:s A'), 'center', 'footer', 2);
         $tr->Footer('This document contains information about clients of the company.');
         if (!file_exists("app/output/providersList_" . date("Ymd") . "pdf") or is_writable("app/output/providersList_" . date("Ymd") . ".pdf")) {
             $tr->save("app/output/providersList_" . date("Ymd") . ".pdf");
         } else {
             throw new Exception(_t('Permission denied') . ': ' . "app/output/providersList_" . date("Ymd") . ".pdf");
         }
         parent::openFile("app/output/providersList_" . date("Ymd") . ".pdf");
         // shows the success message
         new TMessage('info', 'Report generated. Please, enable popups in the browser (just in the web).');
         TTransaction::close();
         // close transaction
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
     }
 }