KoolReport's Forum

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

Date format (Displaying months in chronological format) #2915

Open Augustine Arthur opened this topic on on Dec 22, 2022 - 1 comments

Augustine Arthur commented on Dec 22, 2022

I want the month to be displayed in order from Jan to Dec in chronological order. This is how my result is showing. I want to show from Jan to Dec.

This is my view file: (MyReportMortgage.view.php) <?php

use \koolreport\widgets\koolphp\Table;
use \koolreport\inputs\Select2;
use \koolreport\widgets\google;
use \koolreport\widgets\google\PieChart;
use \koolreport\clients\bootstrap;
use \koolreport\widgets\google\ColumnChart;
use \koolreport\widgets\google\BarChart;

?> <div class="report-content"> <?php $years = $this->params["years"]; //$years = $_POST["years"]; if (is_array($years)) $years = implode(", ", $years);

$TypeOfApp = $this->params["TypeOfApp"];

if (is_array($TypeOfApp)) $TypeOfApp= implode(", ", $TypeOfApp); $pdfTitle = $TypeOfApp. " in ".$years . " "; ?>

<div class="text-center">
    <h3>Application for Registration - <?php echo $pdfTitle ?></h3>
    
</div>
<form method="post">
    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <b>Select Year</b>
                <?php 
                Select2::create(array(
                    "multiple"=>false,
                    "name"=>"years",
                    "dataSource"=>$this->src("data")->query("
                        select YEAR(RecDate) as Year
                        from landtitlereg                            
						group by Year
                    "),
                    "attributes"=>array(
                        "class"=>"form-control"
						//"size"=>1
                    )
                ));
                ?>
            </div>    

                               
            <div class="form-group">
                <b>Select Type of Application</b>
                <?php 
                Select2::create(array(
                   "multiple"=>false,
                    "name"=>"TypeOfApp",
                    "dataSource"=>$this->src("data")->query("
                        select TypeOfApp
                        from landtitlereg
                        group by TypeOfApp
                    ")->params(
                        $this->params["years"]!=array()?
                        array(":years"=>$this->params["years"]):
                        array()
                    ),
                    "attributes"=>array(
                        "class"=>"form-control"
						//"size"=>1
                    )
                ));
                ?>                
            </div>  
            <div class="form-group">
                <button class="btn btn-primary">Submit</button>
				<button formaction="exportLicensesMortgage.php" class="btn btn-primary">Download PDF</button>
				
			
            </div>    
        </div>
    </div>
    
</form>

<?php
 Table::create(array(
 
    "dataSource"=>$this->dataStore("result"),
	
	"columns"=>array(
			"MONTH"=>array(
			"label"=>"Month",
			"type"=>"Date",
           
			),
			

           "ApplicationsReceived"=>array(
		   "label"=>"Total Received",
            "type"=>"number",
		   ),
			"ApplicationsProcessed"=>array(
			"label"=>"Total Processed",
            "type"=>"number",
			),
			"TotalPending"=>array(
			"label"=>"Total Pending",
			"type"=>"number",
			),
	

    ),			
		"grouping"=>array(
        "Year"=>array(
            "calculate"=>array(
            "{ApplicationsReceived}"=>array("sum","ApplicationsReceived"),
			"{ApplicationsProcessed}"=>array("sum","ApplicationsProcessed"),
			"{TotalPending}"=>array("sum","TotalPending"),
			
		
            ),
            "top"=>"<b>Year {Year}</b>",
            "bottom"=>"<td><b>Total of year {Year}</b></td>
			<td><b>{ApplicationsReceived}</b></td>
			<td><b>{ApplicationsProcessed}</b></td>
			<td><b>{TotalPending}</b></td>
			
			
			",
        ),
		
    ),
	"paging"=>array(
        "pageSize"=>25
    ),
    
	"cssClass"=>array(
        "table"=>"table-bordered table-striped table-hover",
)

) )

?>

<i class="fa fa-arrow-down" style="font-size:24px;"></i> <pre style="font-weight:bold"><code>

</code></pre> <i class="fa fa-arrow-down" style="font-size:24px;"></i>

<div style="margin-top:20px;">
    <div class="row">
        
		<div class="col-md-8">
        <?php 
     google\ColumnChart::create(array(
    "dataStore"=>$this->dataStore('result'),
	"options"=>array(
            'title' => 'Chart Showing Application for Registration',
            'isStacked' => false
            ),		
    "columns"=>array(
        "RecDate"=>array(
            "label"=>"Month",
            "type"=>"Date",
           
        ),
        "ApplicationsReceived"=>array(
            "label"=>"Applications Received",
            "type"=>"number",
           
        ),
		"ApplicationsProcessed"=>array(
            "label"=>"Applications Processed",
            "type"=>"number",
           
        ), 
		"TotalPending"=>array(
            "label"=>"Total Pending",
            "type"=>"number",
           
        ),
		
    ),
    "width"=>"100%",
	
));
        ?>
    </div>
        <div class="col-md-8">
        <?php
        PieChart::create(array(
            "dataSource"=>$this->dataStore("result"),
			"options"=>array(
            'title' => 'Piechart Showing Applications - Mortgage',
            ),
		"columns"=>array(
        "RecDate"=>array(
            "label"=>"Month",
            "type"=>"Date",
           
        ),
        "ApplicationsReceived"=>array(
            "label"=>"Total Received",
            "type"=>"number",
           
        ),
		"ApplicationsProcessed"=>array(
            "label"=>"Total Processed",
            "type"=>"number",
           
        ),
		"TotalPending"=>array(
            "label"=>"Total Pending",
            "type"=>"number",
           
        ),
        ),
        
           
            "options"=>array(
                "legend"=>array(
                    "position"=>"right"
                ),
               
            ) 
        ));
        ?>
        </div>
    </div>


</div>

</div>

This the other file: ((MyReportMortgage.php)

<?php //Step 1: Load KoolReport require_once "../load.koolreport.php"; use \koolreport\processes\ValueMap; use \koolreport\processes\Sort; use \koolreport\clients\Bootstrap; use \koolreport\processes\ColumnMeta; use \koolreport\processes\Transpose; use \koolreport\processes\ColumnRename; use \koolreport\core\src\core\Utility; use \koolreport\cube\processes\Cube; use \koolreport\inputs\Select2; use \koolreport\processes\TimeBucket; use \koolreport\processes\Group; use \koolreport\processes\DateTimeFormat; //Step 2: Creating Report class class MyReportMortgage extends \koolreport\KoolReport

{

use \koolreport\export\Exportable;
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;

use \koolreport\clients\Bootstrap;


protected function defaultParamValues()
{
    return array(
	"years"=>"2019",
     // "Years"=>"",
        "TypeOfApp"=> "",
    
    );
}
 protected function bindParamsToInputs()
{
    return array(
        "years",
        "TypeOfApp",
     
    );
}
protected function settings()
{
    return array(
        "dataSources"=>array(
            "data"=>array(
                "connectionString"=>"mysql:host=localhost;dbname=mlnrgh",
                "username"=>"root",
                "password"=>"",
                "charset"=>"utf8"
            ),
        )
    );
}


protected function setup()
{
	$query_params = array();
    if($this->params["years"]!=array())
    {
        $query_params[":years"] = $this->params["years"];
    }
    if($this->params["TypeOfApp"]!=array())
    {
        $query_params[":TypeOfApp"] = $this->params["TypeOfApp"];
$this->src('data')->query("
        select
            RecDate,
            sum(ApplicationsRcvd) as 'ApplicationsReceived',
			sum(ApplicationProc) as 'ApplicationsProcessed',
			sum(TotalPending)as 'TotalPending',
			
			YEAR(RecDate) as 'Year',
			MONTHNAME(RecDate) as 'MONTH'
			
          
        from landtitlereg
		where 1=1
        ".(($this->params["years"]!=array())?"and YEAR(RecDate) in (:years)":"")."
        ".(($this->params["TypeOfApp"]!=array())?"and TypeOfApp in (:TypeOfApp)":"")."
         
        GROUP BY Year, TypeOfApp, MONTH
    ")->params($query_params)
	//$node->pipe(new Cube(array(
    //    "row" => "MineralRights",
        
   // )))
		
   // ->saveTo($source);

    //Save orginal data
  

))) *///Pipe through process to get result

    ->pipe(new DateTimeFormat(array(
        "RecDate"=>array(
            "from"=>"Y-m-d",
            "to"=>"M",
        )
    )))
	->pipe(new Sort(array(
        'RecDate' => 'asc'
    )))
	
    ->pipe($this->dataStore("result"));
  

}

}

}
Sebastian Morales commented on Dec 26, 2022

Pls try this solution to customize ordering for the month column:

<?php
    DataTables::create(array(
        ...
        "columns" => array(
            "month" => array(
                "type" => "month_name", //set custom column type
                ...
            )
        ),
        "onBeforeInit" => "dtBeforeInit", //call this function to add custom column type
    ));
?>
        <script>
            function dtBeforeInit() {
                jQuery.extend( jQuery.fn.dataTable.ext.type.order, {
                    "month_name-pre": function (a) {
                        var monthArr = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; //Make sure your month column values are exactly like this array case sensitively
                        return monthArr.indexOf(a); 
                    },
                    "month_name-asc": function (a, b) {
                        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
                    },
                    "month_name-desc": function (a, b) {
                        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
                    }
                } );
            }
        </script> 

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