KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

FillNull #2417

Closed Ron opened this topic on on Nov 4, 2021 - 12 comments

Ron commented on Nov 4, 2021

I am trying to use FillNull method and I am receiving the following error Class 'FillNull' not found Do I need to include any class in my report?

KoolReport commented on Nov 4, 2021

It could be that you have not specified the full class name for FillNull, please add this line on top of report class:

use \koolreport\cleandata\FillNull;

Let me know if it works.

Ron commented on Nov 4, 2021

I get an error Report cannot use koolreport\cleandata\FillNull - it is not a trait

KoolReport commented on Nov 4, 2021

No, you use on top of report like this

<?php

use \koolreport\cleandata\FillNull;
...
class MyReport extends \koolreport\KoolReport
{
    ...
}
Ron commented on Nov 4, 2021

I have this report

you can see that in each empty cell it becomes a dash (-). I want to remove the dashes and leave it empty.

KoolReport commented on Nov 4, 2021

Is above result is before or after you use FillNull? Does your raw data contain "-" already and you want to remove it?

Ron commented on Nov 4, 2021

No its a numeric column with a null

Ron commented on Nov 4, 2021

The Null value comes from the DB. the report somehow translates it to a dash.

KoolReport commented on Nov 4, 2021

Do you use PivotTable in your report? Would you mind to post your code here.

Ron commented on Nov 4, 2021
<?php
    //MyReport.view.php
    use \koolreport\datagrid\DataTables;
?>
<html>
    <head>
        <title><?php echo lang('tts.report_substitute_teachers'); ?></title>
        <link rel="stylesheet" href="<?php echo site_url('../assets/css/print.css')?>">
    </head>
    <body DIR="RTL">
        <div class="row d-print-none">
            <div class="col text-center">
                <button id="print" class="btn btn-success" href="<?php echo site_url('reports'); ?>" onclick="javascript: window.print()">
                    <?php echo lang('tts.print'); ?>
                </button>
                <a class="btn btn-secondary mr-2" href="<?php echo $_SERVER['HTTP_REFERER']; ?>">
                    <?php echo lang('tts.back'); ?>
                </a>
            </div>
        </div>
        <?php
        echo '<div class="header print-only"><img src="'.site_url('../assets/img/'.(isset($_SESSION['institute_number']) ? $_SESSION['institute_number'].'.png' : "logo.svg")).'" height="38" /></div>';
        ?>
        <h1 class="text-center"><?php echo lang('tts.report_substitute_teachers'); ?></h1>
        <h3 class="text-center"><u><?php echo lang('tts.for_month').' '.lang('tts.'.date('F', mktime(0, 0, 0, $this->month, 10))).' '.$this->year;  ?></u></h3>
        <div class="responsive">
            <?php
            $group_label = lang('tts.totals_for_substitute_teacher');
            DataTables::create(array(
                "name" => "myTable",
                "language" => "he", //use 'DataTables.de.json'
                "dataSource"=>$this->dataStore("st"),
                "options"=>array(
                    'ordering' => false,
                    "searching"=>true,
                    "paging"=>true,
                    'columnDefs' => array(
            			array(
            				//'visible' => false,
            				// 'targets' => [$this->monthDays+6,2,3], //hide the first column
            			)
            		),
            		'rowGroup' => [
                              'endRender' => "function ( rows, group ) {
                                    var totalA = rows
                                        .data()
                                        .pluck($this->monthDays+4)
                                        .reduce( function (a, b) {
                                            return a + b.replace(/[^\d]/g,'')*1;
                                    }, 0);

                                    var totalB = rows
                                        .data()
                                        .pluck($this->monthDays+5)
                                        .reduce( function (a, b) {
                                            return a + b.replace(/[^\d]/g,'')*1;
                                    }, 0);

                                    var totalC = rows
                                        .data()
                                        .pluck($this->monthDays+6)
                                        .reduce( function (a, b) {
                                            return a + b.replace(/[^\d]/g,'')*1;
                                        }, 0);

                                    var totalD = rows
                                        .data()
                                        .pluck($this->monthDays+7)
                                        .reduce( function (a, b) {
                                            return a + b.replace(/[^\d]/g,'')*1;
                                        }, 0);

                                    return $('<tr/>')
                                        .append( '<td colspan='+($this->monthDays+4)+'><b>$group_label '+group+'</b></td>' )
                                        .append( '<td class=text-center><b>'+totalA+'</b></td>' )
                                        .append( '<td class=text-center><b>'+totalB+'</b></td>' )
                                        .append( '<td class=text-center><b>'+totalC+'</b></td>' )
                                        .append( '<td class=text-center><b>'+totalD+'</b></td>' )
                                        .append( '<td></td>' )
                                }",

                    ],
                ),
                "groupCellsInColumns" => [0, 1, 2], // group similar cells in 1st and 3rd columns
                'complexHeaders' => true,
                'headerSeparator' => ' - ',
                'cssClass'=>array(
                    'table'=>'table table-bordered',
                    'tr'=>'cssItem',
                    'td'=>function($row,$colName)
                    {
                        return in_array($colName, array('substitute_teacher_id','id_number','substituted_teacher','group_name')) ? 'text-right' : 'text-center';
                        // if ($colName == 12) {
                        //     return 'table-dark';
                        // }
                    },
                    'th'=>function($colName)
                    {
                        return in_array($colName, array('substitute_teacher_id','id_number','substituted_teacher','group_name')) ? 'table-dark text-right' : 'table-dark text-center';
                    },
                ),
            ));
            ?>
        </div>
        <?php echo '<div class="footer print-only">Footer</div>'; ?>
    </body>
</html>

Ron commented on Nov 4, 2021
function setup()
    {
        $this->month = date('m', strtotime($this->params["date"]));
        $this->year = date('Y', strtotime($this->params["date"]));
        $this->monthDays = cal_days_in_month(CAL_GREGORIAN, $this->month, $this->year);
        $this->src('db')
        ->query('CALL getSubstituteTeacherHourListPerMonth(:year, :date, :substitute_teacher_id)')
        ->params(array(
            ":year"=>$this->params["year"],
            ":date"=>$this->params["date"],
            ":substitute_teacher_id"=>$this->params["substitute_teacher_id"],
        ))
        ->pipe(new \koolreport\processes\Map(array(
            "{value}" => function($row, $metaData, $index, $mapState) {
                $days = lang('tts.days');
                $newRow = [];
                $substituteDays = 0;
                foreach ($row as $k => $v) {
                    if (is_numeric($k))
                        $k = 1*$k;
                        if ($k >= 1 && $k <= 31) { //i.e $k is month day
                            $weekday = date('w', strtotime($this->year.'-'.$this->month.'-'.$k));
            		        $newRow[$k. " - " . $days[$weekday]] = $row[$k];
                            if ( $row[$k] != NULL ) {
                                $substituteDays += 1;
                            }
                        } else {
                            $originalK = $k;
                            if ( in_array($k, array('substitute_teacher_id','id_number','substituted_teacher','hour_group_id', 'total_hours', 'total_days', 'cost', 'total_travel_cost') ) ) {
                                $k = lang('tts.'.$k);
                            }
                            $newRow[$k] = $row[$originalK];
                            //$row[$originalK] = number_format($substituteDays * $row['cost'], 2);
                        }
                    }
                    return $newRow;
                }
        )))
        ->pipe($this->dataStore("st"));
Sebastian Morales commented on Nov 5, 2021

There's a property called emptyValue in DataTables, which is default "-" for empty value:

https://www.koolreport.com/docs/datagrid/datatables/#properties

If you don't like the dash as an empty value fillter you could set it like this:

DataTables::create(array(
    ...
    "emptyValue" => "", // use an empty string as filler for empty values
));
Ron commented on Nov 5, 2021

Thanks, works great!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None