Hi, I have a report that is generating dynamically 29-31 columns as days of month depending on the month type. each day has a different number value. I want to add another column that will sum all the numbers in the generated days column.
here is the report code:
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 getTeacherAttendancePerMonth(:year, :date)')
->params(array(
":year"=>$this->params["year"],
":date"=>$this->params["date"]
))
->pipe(new \koolreport\processes\Map(array(
"{value}" => function($row, $metaData, $index, $mapState) {
$days = array('א','ב','ג','ד','ה','ו','ש');
//$month = date('m', strtotime($this->params["date"]));
//$year = date('Y', strtotime($this->params["date"]));
$newRow = [];
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];
} else {
//echo $k."<br>";
$originalK = $k;
if ( in_array($k, array('teacher_id','id_number','hour_group_id', 'total_hours', 'reason_id') ) ) {
$k = lang('tts.'.$k);
}
$newRow[$k] = $row[$originalK];
//$row[$originalK] = number_format($substituteDays * $row['cost'], 2);
}
}
return $newRow;
}
)))
->pipe($this->dataStore("st"));
}
<?php
DataTables::create(array(
"dataSource"=>$this->dataStore("st"),
"removeDuplicate"=>array("id_number","teacher_id","total_hours"),
"options"=>array(
"searching"=>true,
"paging"=>true,
'columnDefs' => array(
array(
'visible' => false,
//'targets' => [$this->monthDays+6], //hide the first column
)
),
),
'complexHeaders' => true,
'headerSeparator' => ' - ',
'cssClass'=>array(
'table'=>'table table-bordered',
'tr'=>'cssItem',
'td'=>function($row,$colName)
{
return in_array($colName, array('teacher_id','id_number', 'reason')) ? 'text-right' : 'text-center';
},
'th'=>function($colName)
{
return in_array($colName, array('teacher_id','id_number','reason')) ? 'table-dark text-right' : 'table-dark text-center';
},
),
));
echo '<div class="footer print-only">Footer</div>';
?>