KoolReport's Forum

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

How to pass datetime picker value into sub report ListOrders.php file #2060

Open Abhishek opened this topic on on May 7, 2021 - 3 comments

Abhishek commented on May 7, 2021

Dear Team,I have problem with the code of sub report i.e i am using ajax loading concept sub report.when i am selecting date time picker value i am unable to pass that value into the query of ListOrders file.so could you please help me on how to pass that value and below is the code which i am using.

This is the view code of selecting options

<?php
    use \koolreport\inputs\Select;
	 use \koolreport\inputs\BSelect;
	  use \koolreport\inputs\DateTimePicker;
	  use \koolreport\inputs\DateRangePicker;
?>
<div class="row" style="text-align:center;">
<div class="col-sm-2"></div>
<div class="col-sm-3 form-group">
    <label>Select State:</label>
    <?php
    Select::create(array(
        "name"=>"statename",
        "dataStore"=>$this->dataStore("result1"),
        "defaultOption"=>array("--"=>null),
        "dataBind"=>"statename",
        "clientEvents"=>array(
            "change"=>"function(){
                subReport.update('srcreportselect',{
                    statename:$('#statename').val(),
                });
                subReport.update('srcreportOrders');
            }",
        ),
        "attributes"=>array(
            "class"=>"form-control",
        )
    ));
    ?>                
</div>
<?php
if($this->params["statename"])
{
?>
    <div class="col-sm-4 form-group">
    <label>Select Branch<?php //echo $this->params["statename"]; ?>:</label>
        <?php
         BSelect::create(array(
			"name"=>"brnchName",
			"multiple"=>true,
			"dataStore"=>$this->dataStore("result2"),
			"dataBind"=>"brnchName",
			"options"=>array(
			'numberDisplayed' => 5,
			'includeSelectAllOption' => true,
			),			
            "clientEvents"=>array(
                "change"=>"function(){
                    subReport.update('srcreportselect',{
                        statename:$('#statename').val(),
                        brnchName:$('#brnchName').val(),
                    });                     
                }",
            ),
            "attributes"=>array(
                "class"=>"form-control",
            )
        ));    
        ?>
    </div>
	    <div class="col-sm-4 form-group">
    <label>Select Source<?php //echo $this->params["statename"]; ?>:</label>
        <?php
         BSelect::create(array(
			"name"=>"srcName",
			"multiple"=>true,
			"dataStore"=>$this->dataStore("result3"),
			"dataBind"=>"srcName",
			"options"=>array(
			'numberDisplayed' => 5,
			'includeSelectAllOption' => true,
			),			
             "clientEvents"=>array(
              "change"=>"function(){
                    subReport.update('srcreportselect',{
                       statename:$('#statename').val(),
                        brnchName:$('#brnchName').val(),
                        srcName:$('#srcName').val(),
                    });                     
                }",
            ),
            "attributes"=>array(
                "class"=>"form-control",
            )
        ));    
        ?>
    </div>
	  <div class="col-md-12 form-group">
                <strong>DateTimePicker</strong>
                
                        From Date:
                        <?php
                        DateTimePicker::create(array(
                            "name"=>"startDatePicker",
                           // "maxDate"=>"@endDatePicker",
                            "format"=>"DD-MM-YYYY",

"clientEvents"=>array(
              "change"=>"function(){
                    subReport.update('srcreportselect',{
                       statename:$('#statename').val(),
                        brnchName:$('#brnchName').val(),
                        srcName:$('#srcName').val(),
						startDatePicker:$('#startDatePicker').val(),
						
                    });                     
                }",
            ),
            "attributes"=>array(
                "class"=>"form-control",
            )                ));
                ?>
            </div>
	
					  <div class="form-group" style="margin-top:20px;">
        <button onclick="srcreportorders()" class="btn btn-success">submit</button>
    </div>
					
<?php    
}
?>
<div class="col-sm-1">
<?php
if(isset($this->params["brnchName"]) && $this->params["brnchName"]!=null)
{
?>
     <!--<div class="form-group" style="margin-top:20px;">
        <button onclick="srcreportorders()" class="btn btn-success">submit</button>
    </div>-->
<?php    
}
?>
</div>
<div class="col-sm-2"></div>
</div>
<script type="text/javascript">
    function srcreportorders()
    {
        subReport.update("srcreportorders",{
            
			"brnchName":$('#brnchName').val(),
			//"dateRange":$('#dateRange').val(),
			//"end":$('#end').val(),
			startDatePicker:$('#startDatePicker').val(),
		    endDatePicker:$('#endDatePicker').val(),
			"srcName":$('#srcName').val(),
			 
        });
    }
</script>

ListOrders.php

 if(isset($this->params["brnchName"]))
       {
            $this->src("db name")
            ->query("
SELECT *
 FROM tblname 
 WHERE brnchName=:brnchName AND custCreatedDate>=:startDatePicker AND custCreatedDate<=:endDatePickerAND srcName=:srcName

            ")
            ->params(array(
                ":brnchName"=>$this->params["brnchName"],
				":startDatePicker"=>$this->params["startDatePicker"],
                ":endDatePicker"=>$this->params["endDatePicker"],
				//":start"=>$this->params["dateRange"][0],
                //":end"=>$this->params["dateRange"][1],
				":srcName"=>$this->params["srcName"],
            ))
            ->pipe($this->dataStore("data"));
        }

When i am selecting the date in the date time picker that date is automatically get back to today date and if i am clicking submit button that today date also not passed to query

Abhishek commented on May 7, 2021

Dear Team, I have resolved the above issue now that is i am able to print the selected data range picker values but i need to achieve that by using datatimepicker and now could you please help me on how to pass the value in to the query of the sub report.

Below is the view code of select date range picker:

<?php
                DateRangePicker::create(array(
                    "name"=>"dateRange",

"clientEvents"=>array(
              "change"=>"function(){
                    subReport.update('srcreportselect',{
                       statename:$('#statename').val(),
                        brnchName:$('#brnchName').val(),
                        srcName:$('#srcName').val(),
						dateRange:[$('#dateRange_start').val(),$('#dateRange_end').val()], 
                    });                     
                }",
            ),
            "attributes"=>array(
                "class"=>"form-control",
            )                ));
                ?>

<script type="text/javascript">
    function srcreportorders()
    {
        subReport.update("srcreportorders",{
            
			"brnchName":$('#brnchName').val(),
			//"dateRange":$('#dateRange').val(),
			
			//"start":$('$this->params["dateRange"][0]').val(),
			//"end":$('$this->params["dateRange"][1]').val(),
			//startDatePicker:$('#startDatePicker').val(),
		    //endDatePicker:$('#endDatePicker').val(),
			"srcName":$('#srcName').val(),
				"dateRange":[$('#dateRange_start').val(),$('#dateRange_end').val()], 
        });
    }
</script>

ListOrders.php


            $this->src("dbname")
            ->query("
SELECT  
 FROM tblname
 WHERE brnchName IN (:brnchName) AND srcName IN (:srcName) AND (DATE_FORMAT(custCreatedDate, '%d-%m-%Y')>=:start AND DATE_FORMAT(custCreatedDate, '%d-%m-%Y')<=:end)
GROUP BY employeeId ORDER BY employeeFirstName
            ")
            ->params(array(
                ":brnchName"=>$this->params["brnchName"],
				":srcName"=>$this->params["srcName"],
				//":startDatePicker"=>$this->params["startDatePicker"],
                //":endDatePicker"=>$this->params["endDatePicker"],
				":start"=>$this->params["#dateRange_start"],
                ":end"=>$this->params["#dateRange_end"],
				
            ))
            ->pipe($this->dataStore("data"));
Abhishek commented on May 8, 2021

Dear Team, cloud you please help me how to solve the above problem please.

Abhishek commented on May 8, 2021

Dear Team, I need a small information from you that is could you please help me oh how to pass the datarange picker value from main report to sub report.

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
help needed

Inputs