<?php //header('Content-Type: text/html; charset=utf-8'); ?>
<style>
.submit_excel {
    background-image: url(./assets/images/file-icons/xlsx.png);
    border: 0px;
    background-color: #FFFFFF;
    color: transparent;
    /*float: left;*/
    margin: 5px 0 10px 20px;
    height: 25px;
    width: 25px;
}
.submit_pdf {
    background-image: url(./assets/images/file-icons/pdf.png);
    border: 0px;
    background-color: #FFFFFF;
    color: transparent;
    float: initial;
    margin: 5px 0 10px 0;
    height: 25px;
    width: 25px;
}
.print_chart {
    background-image: url(./assets/images/file-icons/chart.png);
    border: 0px;
    background-color: #FFFFFF;
    color: transparent;
    /*float: left;
    margin: 5px 0 10px 20px;*/
    height: 24px;
    width: 24px;
}
.cht-pie{
    width: 75%;
    margin: 0 auto;
    margin-top: 20px;
    margin-bottom: 60px;
    background: #f3f3f3;
    padding: 30px 30px;
    box-shadow: -1px 20px 7px -18px #717171;
}

</style>
<aside class="right-side">
    <section class="content-header">
        <div class="title_bar">
            <h1 class="major_txt_color"><?php echo $title;?></h1>
            <div class="breadcrumb_container"><?php echo breadcrumb_links();?></div>
        </div>
    </section>
    <?php $general = get_general_setting();?>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box box-primary">
                    <div class="box-body table-responsive">
                        <div class="cht-pie">
                            <canvas id="chart-area"></canvas>
                        </div>
                        <form name="get_data_search" action="<?php echo $form_action;?>" method="post" class="search_form validate_form">
                            <input type="hidden" name="hidden_id" class="hidden_id" value="<?php echo (!empty($hidden_id)) ? $hidden_id : '';?>" />
                        
                            <!-- Filtered Columns to send JS - Start -->
                            <input type="hidden" name="hidden_print" class="hidden_print" value="<?php echo (!empty($start_date)) ? 1 : 0 ;?>" />
                            <?php foreach($filters as $key=>$val) : ?>
                                <input type="hidden" name="hidden_filter_array[]" class="hidden_filter_array" value="<?php echo $val;?>" />
                            <?php endforeach;?>
                            <!-- Filtered Columns to send JS - End -->
                            
                            <div class="col-xs-12">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label >Start Date</label>
                                        <div class="input-group">
                                            
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="start_date" placeholder="DD-MM-YYYY" style="padding: 6px 12px;margin-right:5%;width:100%;" id="start_date" name="start_date" value="<?php echo (!empty($start_date)) ? $start_date : date('d-m-Y');?>" autocomplete="off" >
                                            
                                        </div>
                                    </div>
                                    
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label >End Date</label>
                                        <div class="input-group">
                                            
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="end_date" placeholder="DD-MM-YYYY" style="padding: 6px 12px;margin-right:5%;width:100%;"  id="end_date" name="end_date" value="<?php echo (!empty($end_date)) ? $end_date : date('d-m-Y');?>" autocomplete="off" >
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label >Type</label>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-soccer-ball-o"></i>
                                            </div>
                                            <select name="type_id" class="form-control select2">
                                                <option value="">Select Type</option>
                                                <?php foreach($types as $key=>$row) {?>
                                                    <option value="<?php echo $row->id;?>" <?php echo ($row->id == $type_id) ? 'selected' : '';?>><?php echo $row->service_name;?></option>
                                                <?php } ?>
                                            </select>
                                        </div>    
                                    </div>
                                </div>
                            </div>
                            <div class="col-xs-12">
                                <div class="col-md-5">&nbsp;</div>
                                <div class="col-md-4">
                                    <input type="submit" value="Get Data" name="submit" class="btn btn-danger btn-sm" style="background-color: #e33739;
    border-color: #e33739;" />&nbsp;&nbsp;
                                
                                    <input type="submit" value="Print Data" name="submit" class="btn btn-primary btn-sm" />&nbsp;&nbsp;
                                    
                                    <input type="submit" name="submit" value="Excel Data" class="submit_excel" title="Export Excel" />&nbsp;&nbsp;
                                    
                                    <input type="submit" name="submit" value="PDF Data" class="submit_pdf" title="Export PDF" />&nbsp;&nbsp;
                                    
                                    <input type="submit" name="submit" value="Chart Data" class="print_chart" title="PDF Chart" />
                                </div>
                                <div class="col-md-2">&nbsp;</div>
                            </div>
                            
                            <!-- Filtered Columns to send JS - Start -->
                            <div class="col-xs-12" style="margin-bottom:4%;">
                                <div class="col-xs-12 blck" style="margin-bottom: -35px;">
                                    <div class="sub-title" style="color:#0B45B3; background:#f3f3f3 !important;" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Filter Columns</h4><i class="ctrl opener opened fa fa-chevron-up" style="float: right; margin-top: -25px;"></i></div>
                                    <div class="blck-content col-xs-12" style="border-bottom: 1px inset rgba(209, 216, 216, 0.6); background: rgba(3, 12, 11, 0.05); margin-top: -15px;">
                                        <div id="grpChkBox" class="grpChkBox">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- Filtered Columns to send JS - End -->
                            
                        </form>
                    </div>
                    <div class="box-body table-responsive">
                        <table class="table table-bordered table-striped data_table filterTable" id="filterTable">
                            <thead>
                                <tr>
                                    <th width="5%" class="align-center">S.No</th>
                                    <th class="align-center">Receipt No</th>
                                    <th class="align-center">Type</th>
                                    <th class="align-center">Date of Joined</th>
                                    <th class="align-center">Member No</th>
                                    <th class="align-center">Name</th>
                                    <th class="align-center">Tamil Name</th>
                                    <th class="align-center">DOB</th>
                                    <th class="align-center">Sex</th>
                                    <th class="align-center">Maritial Status</th>
                                    <th class="align-center">Contact No</th>
                                    <th class="align-center">Email</th>
                                    <th class="align-center">Address</th>
                                    <th class="align-center">Postal Code</th>
                                    <th width="15%" class="align-center">Desc</th>
                                    <th class="align-center">Entry Fee Amount</th>
                                    <th class="align-center">Amount</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(count($results) > 0) {  $total_amt = 0;?>
                                    <?php foreach($results as $key=>$value) {
											$chartData[$value->service_name] += $value->amount;
                                            $total_amt += $value->amount;
                                        ?>
                                        <tr>
                                            <td class="align-center"><?php echo ++$key;?></td>
                                            <td><?php echo (($general->prefix == 1) ? $value->prefix : '') . $value->receipt_no;?></td>
                                            <td><?php echo text($value->service_name);?></td>
                                            <td><?php echo date('d-m-Y',strtotime($value->date_of_join));?></td>
                                            <td><?php echo text($value->member_no);?></td>
                                            <td><?php echo text($value->member_name);?></td>
                                            <td><?php echo (!empty($value->tamil_name)) ? '<span class="lang-tamil">' . $value->tamil_name . '</span>': 'N/A';?></td>
                                            <td><?php echo date('d-m-Y',strtotime($value->dob));?></td>
                                            <td><?php echo ($value->sex == 1) ? 'Male' : 'Female';?></td>
                                            <td><?php if($value->maritial_status == 1) { echo 'Single'; } elseif($value->maritial_status == 2) { echo 'Married';}?></td>
                                            <td><?php echo text($value->contact_no);?></td>
                                            <td><?php echo text($value->email);?></td>
                                            <td width="15%"><?php echo text(nl2br($value->address));?></td>
                                            <td><?php echo text($value->postal_code);?></td>
                                            <td width="15%"><?php echo text(nl2br($value->desc));?></td>
                                            <td class="align-right"><?php echo $value->entry_fee_amount;?></td>
                                            <td class="align-right"><?php echo $value->amount;?></td>
                                        </tr>
                                    <?php } ?>
                                <?php } ?>
                            </tbody>
                            <tfoot>
                                <?php if(!empty($total_amt)) {?>
                                    <tr>
                                        <td colspan="16" align="right"><b>Total</b></td>
                                        <td align="right"><b><?php echo number_format($total_amt,2,'.','');?></b></td>
                                    </tr>
                                <?php } ?>
                            </tfoot>
                        </table>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div>
        </div>
    </section><!-- /.content -->
</aside><!-- /.right-side -->
<!-- ./wrapper -->

<div class="modal fade" id="pdfModal" role="dialog">
    <div class="modal-dialog modal-lg">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Member Subscription Report PDF</h4>
        </div>
        <div class="modal-body">
         <iframe src="" class="pdf_iframe" width="850" height="600"></iframe>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
</div>

<div class="modal fade" id="pdfchartModal" role="dialog">
    <div class="modal-dialog modal-lg">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Function Hall Booking Chart Report PDF</h4>
        </div>
        <div class="modal-body">
         <iframe src="" class="pdf_iframe" width="850" height="600"></iframe>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
</div>
<?php 
//echo "<pre>"; print_r($chartData); echo "</pre>"; exit;  
$label 		= '';
$dataval 	= '';

if($chartData){
	foreach($chartData as $key => $amount){
		if(empty($label)){
			$label = "'".$key."'";
		}else{
			$label .= ",'".$key."'";
		}
		
		if(empty($dataval)){
			$dataval = "'".number_format($amount,2,".","")."'";
		}else{
			$dataval .= ",'".number_format($amount,2,".","")."'";
		}
	}		
}
?>
<script src="<?php echo base_url().'assets/js/Chart.min.js'?>"></script>
<script type="text/javascript">
window.onload = function() {
var ctx = document.getElementById("chart-area").getContext('2d');
var myChart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: [<?php echo $label; ?>],
    datasets: [{
      backgroundColor: [
        "#ff4700",
        "#FFA07A",
        "#bc00bf",
        "#FA8072",
        "#E9967A",
        "#E74C3C",
        "#34495E",
        "#bf8400",
        "#148F77",
        "#dd0000",
        "#0093f4",
		"#B22222",
		'#FFD700',
		'#FFEFD5',
		'#FFE4B5',
		'#7CFC00',
		'#00FF7F',
		'#98FB98',
		'#808000',
		'#00FFFF',
		'#008B8B'
       
      ],
      //label: '',
      data: [<?php echo $dataval; ?>]
     
    }]
    
  },
  options: {
	  		tooltips: {
			  callbacks: {
					label: function(tooltipItem, data) {
						var value = data.datasets[0].data[tooltipItem.index];
						if(parseInt(value) >= 1000){
						   return 'S$' + value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
						} else {
						   return 'S$' + value;
						}
					}
			  } // end callbacks:
			}, //end tooltips
          responsive: true,
          legend: false,
		  scales: {
				yAxes: [{
					ticks: {
						beginAtZero: true
					}
				}]
			}
        }
});
};
    
$(document).ready(function () {
     <?php if(isset($_SESSION['pdf_member_subscription'])): ?>
        var srcval='<?php echo base_url().'uploads/member_subscription_pdf/'.$_SESSION['pdf_member_subscription_file']; ?>';
        $('.pdf_iframe').attr("src",srcval);
        $('#pdfModal').modal({"show":true}); 
      <?php 
	  $_SESSION['pdf_member_subscription'] = '';
      unset($_SESSION['pdf_member_subscription']);
      endif; ?> 
	  
		<?php if(isset($_SESSION['pdf_chart'])): ?>
		var srcval='<?php echo base_url().'uploads/member_subscription_pdf/'.$_SESSION['pdf_chart_file']; ?>';
		$('.pdf_iframe').attr("src",srcval);
		$('#pdfchartModal').modal({"show":true}); 
		<?php 
		$_SESSION['pdf_chart'] = '';
		unset($_SESSION['pdf_chart']);
		endif; 
		?>

        $('.start_date').bootstrapMaterialDatePicker({ 
            time: false, 
            format: 'DD-MM-YYYY'
        }). on('change', function(e, date) {
            if($('.end_date').val() != '') {
                $('.end_date').val('');
                var cur_date = new Date(date);
                $('.end_date').val(getTwoDigits(cur_date.getDate()) + '-'+ getTwoDigits((cur_date.getMonth() + 1)) + '-'+ cur_date.getFullYear());
                change_todate(getTwoDigits(cur_date.getDate()) + '-'+ getTwoDigits((cur_date.getMonth() + 1)) + '-'+ cur_date.getFullYear());
            }
        });
        
        $('.end_date').bootstrapMaterialDatePicker({ 
            time: false, 
            format: 'DD-MM-YYYY'
        });
        
        var date = $('.start_date').val();
        change_todate(date);
    });
   
    function change_todate(date) {
       $('.end_date').bootstrapMaterialDatePicker('setMinDate', date);
    }
</script>