PHP code example of readerstacks / reportmanager
1. Go to this page and download the library: Download readerstacks/reportmanager library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
readerstacks / reportmanager example snippets
return [
// ...
'providers' => [
Aman5537jains\ReportBuilder\ReportBuilderServiceProvider::class,
// ...
],
// ...
];
// ...
$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
// ...
$app->register(Aman5537jains\ReportBuilder\ReportBuilderServiceProvider::class);
// ...
return $app;
(new \Aman5537jains\ReportBuilder\ReportGenerator())->render();
return [
"layouts"=>[
"table"=>["class"=>"\Aman5537jains\ReportBuilder\Layouts\TableLayout\TableLayout"],
"table2"=>["class"=>"\Aman5537jains\ReportBuilder\Layouts\TableLayout\TableLayout"],
"Number"=>["class"=>"\Aman5537jains\ReportBuilder\Layouts\NumberViewLayout"],
'Chart'=>["class"=>"\Aman5537jains\ReportBuilder\Layouts\ChartLayout","settings"=> ["type"=>"pie","chart_label"=>"Users","label_column"=>"labels","data_column"=>"data","colors_column"=>"colors"]],
'CanvasChart'=>["class"=>"\Aman5537jains\ReportBuilder\Layouts\CanvasChartLayout","settings"=>["type"=>"pie","chart_label"=>"Users","label_column"=>"labels","data_column"=>"data","colors_column"=>"colors"]],
],
...
namespace Aman5537jains\ReportBuilder\Layouts\TableLayout;
use Aman5537jains\ReportBuilder\Layouts\BaseLayout;
class TableLayout extends BaseLayout
{
function scripts(){
$script = <<<SCRIPT
new DataTable('.tbl_report');
SCRIPT;
return [
'datatable'=>[
"src"=>'https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js'
],
'script'=>[
'text'=>$script
]
];
}
function styles(){
return [
'datatable'=>[
"src"=>"https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css"
]
];
}
function render(){
if($this->reportBuilder->error==''){
$table=' ';
// foreach($this->reportBuilder->report->variables as $name=>$var){
// $table.=$var['obj']->render();
// }
$table .= '
<style>
.tbl_report{
border-collapse: collapse;
width: 100%;
}
.tbl_report td, .tbl_report th {
border: 1px solid #ddd;
padding: 8px;
}
.tbl_report th {
padding-top: 12px;
padding-bottom: 12px;
text-align: center;
background-color: #000;
color: white;
}
</style>
<table id="tbl_report" class="tbl_report">';
$table .= '<thead><tr>';
foreach($this->reportBuilder->columns as $column){
$table.= '<th>'.$column->render().' </th>';
}
$table .= '</tr><thead><tbody>';
foreach($this->reportBuilder->rows as $row){
$table.= '<tr>';
foreach($this->reportBuilder->columns as $column){
$table.= '<td>'.$row->render($column->name()).' </td>';
}
$table.= '</tr>';
}
$table.= "</tbody></table>";
return $table ;
}
else{
return "<span style='color:red'>".$this->reportBuilder->error."</span>";
}
}
}
return [
"filter_inputs"=>[
"Input"=>["class"=>\Aman5537jains\ReportBuilder\Inputs\TextInput::class,"settings"=>["type"=>"text"]],
"Number"=>["class"=>\Aman5537jains\ReportBuilder\Inputs\TextInput::class,"settings"=>["type"=>"number"]],
"Date Range"=>["class"=>\Aman5537jains\ReportBuilder\Inputs\DateFilterInput::class,"settings"=>["column"=>"created_at"]],
"Select 2 Picker"=>["class"=>\Aman5537jains\ReportBuilder\Inputs\Select2PickerFilterInput::class,"settings"=>["url"=>"https://api.github.com/search/repositories?term=sel&_type=query&q=sel"]]
],
],
...
namespace Aman5537jains\ReportBuilder\Inputs;
use Illuminate\Support\Facades\Log;
class TextInput extends ReportInputs
{
function render(){
return " <span>{$this->config['title']} :</span><input type='{$this->settings['type']}' name='{$this->name}' value='{$this->value}' />";
}
}
namespace Aman5537jains\ReportBuilder\Inputs;
use Illuminate\Support\Facades\Log;
class DateFilterInput extends ReportInputs
{
function queryValue(){
if($this->value!=''){
$value = explode(" - ",$this->value);
$start= trim($value[0])." 00:00:00";
$end= trim($value[1])." 23:59:59";
return "{$this->settings['column']} >= '{$start}' and {$this->settings['column']} <= '{$end}' ";
}
return $this->value;
}
function scripts(){
return [
'moment'=>[
'src'=>'https://cdn.jsdelivr.net/momentjs/latest/moment.min.js'
],
'daterangepicker'=>[
'src'=>'https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js'
],
'daterangepicker'=>[
'src'=>'https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js'
],
'script'=>[
'text'=>"
$('.datefilter_{$this->name}').daterangepicker({
autoUpdateInput: false,
showDropdowns: true,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
locale: {
'format': 'YYYY-MM-DD',
},
opens: 'left'
}, function(start, end, label) {
$('.datefilter_{$this->name}').val(start.format('YYYY-MM-DD')+' - '+ end.format('YYYY-MM-DD'))
console.log( start.format('YYYY-MM-DD') , end.format('YYYY-MM-DD'));
});
"
]
];
}
function styles(){
return [
'daterangepicker'=>[
'src'=>'https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css'
]
];
}
function html(){
$html ="<span>{$this->config['title']} </span>:<input type='text' class='datefilter_{$this->name}' name='{$this->name}' value='{$this->value}' />";
return $html;
}
}
shell
php artisan vendor:publish --provider="Aman5537jains\ReportBuilder\ReportBuilderServiceProvider"
shell
php artisan migrate