<?php


$startDate = date('01-m-Y');
$endDate   = date('d-m-Y');

$cs = Yii::app()->clientScript;

$cs->registerScript("loadMasterReport", "
function loadMasterReport() {
    var from_date = $('#from_date').val();
    var to_date   = $('#to_date').val();

    if(from_date == '' || to_date == ''){
        alert('Please select From Date and To Date');
        return false;
    }

    var url = '" . Yii::app()->createUrl('settlementreport/PrintPurchaseOrderReport') . "';

    // AJAX call to load report inside the div
    $.ajax({
        type: 'GET',
        url: url,
        data: {from_date: from_date, to_date: to_date},
        beforeSend: function() {
            // Optional: show loading text
            $('#master-report-container').html('<p>Loading report...</p>');
        },
        success: function(data){
            $('#master-report-container').html(data);
        },
        error: function(){
            alert('Error loading report. Please try again.');
        }
    });
}
", CClientScript::POS_END);
?>

<section class="panel">
    <header class="panel-heading clearfix panel-theame">
        <i class="fa fa-list"></i> Settlement Report
    </header>

    <div class="panel-body">
        <!-- Date filters -->
        <div id="div_master_report_orderlist">
          <!--   <ul class="clearfix form-ul material" id="orderlist-form-hide"> 
                <li class="col-sm-2">
                    <div class="material">    
                        <?php //echo CHtml::textField('from_date', $startDate, ['class' => 'datepicker','data-label'=>'From Date']); ?>
                    </div>
                </li>
                <li class="col-sm-2">
                    <div class="material">    
                        <?php //echo CHtml::textField('to_date', $endDate, ['class' => 'datepicker','data-label'=>'To Date']); ?>
                    </div>
                </li>                        
            </ul> -->
        </div>

        <!-- Button -->
        <div class='btn-wrap text-center'>
            <button type="button" class="btn btn-theme" onclick="loadMasterReport();return false;" title="HTML">
                <i class="fa fa-file-text"></i> &nbsp;HTML
            </button>
        </div>

        <!-- Container where report will be loaded -->
        <div class="custom-data-table" id="master-report-container"></div>
    </div>
</section>
