Skip to content

Commit

Permalink
ER:Add a sample report that extracts all leave requests without filter
Browse files Browse the repository at this point in the history
  • Loading branch information
bbalet committed Feb 5, 2017
1 parent 3659262 commit 96be382
Show file tree
Hide file tree
Showing 40 changed files with 2,071 additions and 2 deletions.
62 changes: 62 additions & 0 deletions local/pages/de/all-leave-requests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
//This is a sample page showing how to create a custom report
//We can get access to all the framework, so you can do anything with the instance of the current controller ($this)

//You can load a language file so as to translate the report if the strings are available
//It can be useful for date formating
$this->lang->load('requests', $this->language);
$this->lang->load('global', $this->language);
?>

<h2>All Leave Requests</h2>

<?php
//$this is the instance of the current controller, so you can use it for direct access to the database
$this->db->select('users.firstname, users.lastname, leaves.*');
$this->db->select('status.name as status_name, types.name as type_name');
$this->db->from('leaves');
$this->db->join('status', 'leaves.status = status.id');
$this->db->join('types', 'leaves.type = types.id');
$this->db->join('users', 'leaves.employee = users.id');
$this->db->order_by('users.lastname, users.firstname, leaves.startdate', 'desc');
$rows = $this->db->get()->result_array();
?>

<div class="row-fluid">
<div class="span12">
<table class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th><?php echo lang('requests_index_thead_id');?></th>
<th><?php echo lang('requests_index_thead_fullname');?></th>
<th><?php echo lang('requests_index_thead_startdate');?></th>
<th><?php echo lang('requests_index_thead_enddate');?></th>
<th><?php echo lang('requests_index_thead_duration');?></th>
<th><?php echo lang('requests_index_thead_type');?></th>
<th><?php echo lang('requests_index_thead_status');?></th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $row) {
$date = new DateTime($row['startdate']);
$startdate = $date->format(lang('global_date_format'));
$date = new DateTime($row['enddate']);
$enddate = $date->format(lang('global_date_format'));?>
<tr>
<td><a href="leaves/edit/<?php echo $row['id'];?>?source=hr%2Fleaves%2F1" target="_blank"><?php echo $row['id'];?></a></td>
<td><a href="hr/counters/employees/<?php echo $row['employee'];?>" target="_blank"><?php echo $row['firstname'] . ' ' . $row['lastname']; ?></a></td>
<td><?php echo $startdate . ' (' . lang($row['startdatetype']). ')'; ?></td>
<td><?php echo $enddate . ' (' . lang($row['enddatetype']) . ')'; ?></td>
<td><?php echo $row['duration']; ?></td>
<td><?php echo $row['type_name']; ?></td>
<td><?php echo lang($row['status_name']); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>

<a href="<?php echo base_url() . 'excel-export-all-leave-requests'; ?>" class="btn btn-primary"><i class="fa fa-file-excel-o"></i>&nbsp; <?php echo lang('requests_index_button_export');?></a>

<div class="row-fluid"><div class="span12">&nbsp;</div></div>
62 changes: 62 additions & 0 deletions local/pages/de/excel-export-all-leave-requests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
//This is a sample page showing how to export a custom report to Excel
//If your custom page is making an export to a file (Excel, etc.) simply include 'export' into its name
//http://localhost/jorani/excel-export

//Excel Header
$title = 'All Leave Requests';
$this->lang->load('requests', $this->language);
$this->lang->load('global', $this->language);
$ci = get_instance();
$ci->load->library('excel');
$sheet = $ci->excel->setActiveSheetIndex(0);
$sheet->setTitle($title);
$sheet->setCellValue('A1', lang('requests_index_thead_id'));
$sheet->setCellValue('B1', lang('requests_index_thead_fullname'));
$sheet->setCellValue('C1', lang('requests_index_thead_startdate'));
$sheet->setCellValue('D1', lang('requests_index_thead_enddate'));
$sheet->setCellValue('E1', lang('requests_index_thead_duration'));
$sheet->setCellValue('F1', lang('requests_index_thead_type'));
$sheet->setCellValue('G1', lang('requests_index_thead_status'));
$sheet->getStyle('A1:G1')->getFont()->setBold(true);
$sheet->getStyle('A1:G1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

//Database query
$this->db->select('users.firstname, users.lastname, leaves.*');
$this->db->select('status.name as status_name, types.name as type_name');
$this->db->from('leaves');
$this->db->join('status', 'leaves.status = status.id');
$this->db->join('types', 'leaves.type = types.id');
$this->db->join('users', 'leaves.employee = users.id');
$this->db->order_by('users.lastname, users.firstname, leaves.startdate', 'desc');
$rows = $this->db->get()->result_array();

//Results
$line = 2;
foreach ($rows as $row) {
$date = new DateTime($row['startdate']);
$startdate = $date->format(lang('global_date_format'));
$date = new DateTime($row['enddate']);
$enddate = $date->format(lang('global_date_format'));
$sheet->setCellValue('A' . $line, $row['id']);
$sheet->setCellValue('B' . $line, $row['firstname'] . ' ' . $row['lastname']);
$sheet->setCellValue('C' . $line, $startdate . ' (' . lang($row['startdatetype']). ')');
$sheet->setCellValue('D' . $line, $enddate . ' (' . lang($row['enddatetype']) . ')');
$sheet->setCellValue('E' . $line, $row['duration']);
$sheet->setCellValue('F' . $line, $row['type_name']);
$sheet->setCellValue('G' . $line, lang($row['status_name']));
$line++;
}
//Autofit
foreach(range('A', 'G') as $colD) {
$sheet->getColumnDimension($colD)->setAutoSize(TRUE);
}

//Export Excel file
$filename = 'excel-export.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($ci->excel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
18 changes: 18 additions & 0 deletions local/pages/de/sample-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
//This is a sample page showing how to create a custom content
//As you can see, we can access to loaded helpers as in other view

//If you want to overload the default homepage, simply rename this page "home.php"
//Don't forget to create a page for all the locales you are using into your company
?>
<h2><?php echo lang('Leave Management System');?></h2>

<p>This page is a sample.</p>

<!--We cannot use the POST method, but we can pass parameters by the URL//-->
<form action="<?php echo base_url();?>action" method="GET">
<input type="text" name="txtContent" />
<input type="submit" />
</form>
<br />
<a href="<?php echo base_url();?>custom-report">Try the report</a>
62 changes: 62 additions & 0 deletions local/pages/en-gb/all-leave-requests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
//This is a sample page showing how to create a custom report
//We can get access to all the framework, so you can do anything with the instance of the current controller ($this)

//You can load a language file so as to translate the report if the strings are available
//It can be useful for date formating
$this->lang->load('requests', $this->language);
$this->lang->load('global', $this->language);
?>

<h2>All Leave Requests</h2>

<?php
//$this is the instance of the current controller, so you can use it for direct access to the database
$this->db->select('users.firstname, users.lastname, leaves.*');
$this->db->select('status.name as status_name, types.name as type_name');
$this->db->from('leaves');
$this->db->join('status', 'leaves.status = status.id');
$this->db->join('types', 'leaves.type = types.id');
$this->db->join('users', 'leaves.employee = users.id');
$this->db->order_by('users.lastname, users.firstname, leaves.startdate', 'desc');
$rows = $this->db->get()->result_array();
?>

<div class="row-fluid">
<div class="span12">
<table class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th><?php echo lang('requests_index_thead_id');?></th>
<th><?php echo lang('requests_index_thead_fullname');?></th>
<th><?php echo lang('requests_index_thead_startdate');?></th>
<th><?php echo lang('requests_index_thead_enddate');?></th>
<th><?php echo lang('requests_index_thead_duration');?></th>
<th><?php echo lang('requests_index_thead_type');?></th>
<th><?php echo lang('requests_index_thead_status');?></th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $row) {
$date = new DateTime($row['startdate']);
$startdate = $date->format(lang('global_date_format'));
$date = new DateTime($row['enddate']);
$enddate = $date->format(lang('global_date_format'));?>
<tr>
<td><a href="leaves/edit/<?php echo $row['id'];?>?source=hr%2Fleaves%2F1" target="_blank"><?php echo $row['id'];?></a></td>
<td><a href="hr/counters/employees/<?php echo $row['employee'];?>" target="_blank"><?php echo $row['firstname'] . ' ' . $row['lastname']; ?></a></td>
<td><?php echo $startdate . ' (' . lang($row['startdatetype']). ')'; ?></td>
<td><?php echo $enddate . ' (' . lang($row['enddatetype']) . ')'; ?></td>
<td><?php echo $row['duration']; ?></td>
<td><?php echo $row['type_name']; ?></td>
<td><?php echo lang($row['status_name']); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>

<a href="<?php echo base_url() . 'excel-export-all-leave-requests'; ?>" class="btn btn-primary"><i class="fa fa-file-excel-o"></i>&nbsp; <?php echo lang('requests_index_button_export');?></a>

<div class="row-fluid"><div class="span12">&nbsp;</div></div>
62 changes: 62 additions & 0 deletions local/pages/en-gb/excel-export-all-leave-requests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
//This is a sample page showing how to export a custom report to Excel
//If your custom page is making an export to a file (Excel, etc.) simply include 'export' into its name
//http://localhost/jorani/excel-export

//Excel Header
$title = 'All Leave Requests';
$this->lang->load('requests', $this->language);
$this->lang->load('global', $this->language);
$ci = get_instance();
$ci->load->library('excel');
$sheet = $ci->excel->setActiveSheetIndex(0);
$sheet->setTitle($title);
$sheet->setCellValue('A1', lang('requests_index_thead_id'));
$sheet->setCellValue('B1', lang('requests_index_thead_fullname'));
$sheet->setCellValue('C1', lang('requests_index_thead_startdate'));
$sheet->setCellValue('D1', lang('requests_index_thead_enddate'));
$sheet->setCellValue('E1', lang('requests_index_thead_duration'));
$sheet->setCellValue('F1', lang('requests_index_thead_type'));
$sheet->setCellValue('G1', lang('requests_index_thead_status'));
$sheet->getStyle('A1:G1')->getFont()->setBold(true);
$sheet->getStyle('A1:G1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

//Database query
$this->db->select('users.firstname, users.lastname, leaves.*');
$this->db->select('status.name as status_name, types.name as type_name');
$this->db->from('leaves');
$this->db->join('status', 'leaves.status = status.id');
$this->db->join('types', 'leaves.type = types.id');
$this->db->join('users', 'leaves.employee = users.id');
$this->db->order_by('users.lastname, users.firstname, leaves.startdate', 'desc');
$rows = $this->db->get()->result_array();

//Results
$line = 2;
foreach ($rows as $row) {
$date = new DateTime($row['startdate']);
$startdate = $date->format(lang('global_date_format'));
$date = new DateTime($row['enddate']);
$enddate = $date->format(lang('global_date_format'));
$sheet->setCellValue('A' . $line, $row['id']);
$sheet->setCellValue('B' . $line, $row['firstname'] . ' ' . $row['lastname']);
$sheet->setCellValue('C' . $line, $startdate . ' (' . lang($row['startdatetype']). ')');
$sheet->setCellValue('D' . $line, $enddate . ' (' . lang($row['enddatetype']) . ')');
$sheet->setCellValue('E' . $line, $row['duration']);
$sheet->setCellValue('F' . $line, $row['type_name']);
$sheet->setCellValue('G' . $line, lang($row['status_name']));
$line++;
}
//Autofit
foreach(range('A', 'G') as $colD) {
$sheet->getColumnDimension($colD)->setAutoSize(TRUE);
}

//Export Excel file
$filename = 'excel-export.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($ci->excel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
62 changes: 62 additions & 0 deletions local/pages/en/all-leave-requests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
//This is a sample page showing how to create a custom report
//We can get access to all the framework, so you can do anything with the instance of the current controller ($this)

//You can load a language file so as to translate the report if the strings are available
//It can be useful for date formating
$this->lang->load('requests', $this->language);
$this->lang->load('global', $this->language);
?>

<h2>All Leave Requests</h2>

<?php
//$this is the instance of the current controller, so you can use it for direct access to the database
$this->db->select('users.firstname, users.lastname, leaves.*');
$this->db->select('status.name as status_name, types.name as type_name');
$this->db->from('leaves');
$this->db->join('status', 'leaves.status = status.id');
$this->db->join('types', 'leaves.type = types.id');
$this->db->join('users', 'leaves.employee = users.id');
$this->db->order_by('users.lastname, users.firstname, leaves.startdate', 'desc');
$rows = $this->db->get()->result_array();
?>

<div class="row-fluid">
<div class="span12">
<table class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th><?php echo lang('requests_index_thead_id');?></th>
<th><?php echo lang('requests_index_thead_fullname');?></th>
<th><?php echo lang('requests_index_thead_startdate');?></th>
<th><?php echo lang('requests_index_thead_enddate');?></th>
<th><?php echo lang('requests_index_thead_duration');?></th>
<th><?php echo lang('requests_index_thead_type');?></th>
<th><?php echo lang('requests_index_thead_status');?></th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $row) {
$date = new DateTime($row['startdate']);
$startdate = $date->format(lang('global_date_format'));
$date = new DateTime($row['enddate']);
$enddate = $date->format(lang('global_date_format'));?>
<tr>
<td><a href="leaves/edit/<?php echo $row['id'];?>?source=hr%2Fleaves%2F1" target="_blank"><?php echo $row['id'];?></a></td>
<td><a href="hr/counters/employees/<?php echo $row['employee'];?>" target="_blank"><?php echo $row['firstname'] . ' ' . $row['lastname']; ?></a></td>
<td><?php echo $startdate . ' (' . lang($row['startdatetype']). ')'; ?></td>
<td><?php echo $enddate . ' (' . lang($row['enddatetype']) . ')'; ?></td>
<td><?php echo $row['duration']; ?></td>
<td><?php echo $row['type_name']; ?></td>
<td><?php echo lang($row['status_name']); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>

<a href="<?php echo base_url() . 'excel-export-all-leave-requests'; ?>" class="btn btn-primary"><i class="fa fa-file-excel-o"></i>&nbsp; <?php echo lang('requests_index_button_export');?></a>

<div class="row-fluid"><div class="span12">&nbsp;</div></div>
62 changes: 62 additions & 0 deletions local/pages/en/excel-export-all-leave-requests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
//This is a sample page showing how to export a custom report to Excel
//If your custom page is making an export to a file (Excel, etc.) simply include 'export' into its name
//http://localhost/jorani/excel-export

//Excel Header
$title = 'All Leave Requests';
$this->lang->load('requests', $this->language);
$this->lang->load('global', $this->language);
$ci = get_instance();
$ci->load->library('excel');
$sheet = $ci->excel->setActiveSheetIndex(0);
$sheet->setTitle($title);
$sheet->setCellValue('A1', lang('requests_index_thead_id'));
$sheet->setCellValue('B1', lang('requests_index_thead_fullname'));
$sheet->setCellValue('C1', lang('requests_index_thead_startdate'));
$sheet->setCellValue('D1', lang('requests_index_thead_enddate'));
$sheet->setCellValue('E1', lang('requests_index_thead_duration'));
$sheet->setCellValue('F1', lang('requests_index_thead_type'));
$sheet->setCellValue('G1', lang('requests_index_thead_status'));
$sheet->getStyle('A1:G1')->getFont()->setBold(true);
$sheet->getStyle('A1:G1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

//Database query
$this->db->select('users.firstname, users.lastname, leaves.*');
$this->db->select('status.name as status_name, types.name as type_name');
$this->db->from('leaves');
$this->db->join('status', 'leaves.status = status.id');
$this->db->join('types', 'leaves.type = types.id');
$this->db->join('users', 'leaves.employee = users.id');
$this->db->order_by('users.lastname, users.firstname, leaves.startdate', 'desc');
$rows = $this->db->get()->result_array();

//Results
$line = 2;
foreach ($rows as $row) {
$date = new DateTime($row['startdate']);
$startdate = $date->format(lang('global_date_format'));
$date = new DateTime($row['enddate']);
$enddate = $date->format(lang('global_date_format'));
$sheet->setCellValue('A' . $line, $row['id']);
$sheet->setCellValue('B' . $line, $row['firstname'] . ' ' . $row['lastname']);
$sheet->setCellValue('C' . $line, $startdate . ' (' . lang($row['startdatetype']). ')');
$sheet->setCellValue('D' . $line, $enddate . ' (' . lang($row['enddatetype']) . ')');
$sheet->setCellValue('E' . $line, $row['duration']);
$sheet->setCellValue('F' . $line, $row['type_name']);
$sheet->setCellValue('G' . $line, lang($row['status_name']));
$line++;
}
//Autofit
foreach(range('A', 'G') as $colD) {
$sheet->getColumnDimension($colD)->setAutoSize(TRUE);
}

//Export Excel file
$filename = 'excel-export.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($ci->excel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
Loading

0 comments on commit 96be382

Please sign in to comment.