<?php 
include "includes/header.php"; 
include "includes/Mdme-functions.php";
$mdme = getMdme_salesreport($db,'');
include_once "includes/pagepermission.php";

include_once "common/dpselect-functions.php";

//check permission - START
if(!($res_modm_prm)){
	header("Location:".admin_public_url."error.php");
}
else if(trim($res_modm_prm['ViewPrm'])=="0") {
	header("Location:".admin_public_url."error.php");
}
//check permission - END
?> 


<div class="wrapper">
    <div class="container">
        <!-- Page-Title - START -->
        <div class="row">
            <div class="col-sm-12">  
				<h4 class="page-title">Monthly Sales Report</h4>
							
            </div>
        </div>
		<!-- Page-Title - END -->	
			
		<form class="form-horizontal" id="jvalidate" action="#" method="post" >
		<input type="hidden" name="action" id="action" value="<?php echo "rpt_sales_report"; ?>" />	
		<div class="row">
            <div class="col-sm-12">
                <div class="card-box">                         
                    <div class="row">
						
						<div class="col-md-3">
							<?php 
							echo getSelectBox_companylist($db, 'srch_sup_company', 'jsrequired');
							?>							
						</div>
						
						<div class="col-md-3">
							<input type="text" name="startDate" id="startDate" placeholder="Start Month" class="date-picker-month form-control" />						
						</div>
						
						<div class="col-md-3">
							<input type="text" name="endDate" id="endDate" placeholder="End Month" class="date-picker-month form-control" />						
						</div>
						
						<div class="col-md-1">
							<button onclick="fn_pu_payment_pending();" type="button" class="btn btn-warning pull-right">Search</button>
						</div>
						
					</div>
                </div>
            </div>
        </div>
		</form>
		
		
		<div class="row">
            <div class="col-sm-12">
                <div class="card-box table-responsive" id="dv_rpt_results">                         
                   <center>No Record Found</center>
                </div>
            </div>
        </div> <!-- end row -->		

<?php include "includes/footer.php";  ?> 
	</div> <!-- container -->
</div> <!-- End wrapper -->  

<?php include "includes/footer_script.php";  ?> 
 
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.4/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.4/js/buttons.html5.min.js"></script>
<script>
$(function () {   		
	//datatblCal();		
	search_result();
});


function search_result(){
	$("#dv_rpt_results").html('');	
	
	$.ajax({
		url        : 'bind_reports_html.php',
		method     : 'POST',
		dataType   : 'json',
		data       : $("#jvalidate").serialize(),
		//beforeSend: function() { loading(); },
		success: function(response){ 	
			if(response.rslt == "1"){
				$("#dv_rpt_results").html(response.reports_rslt);
				
				//$("#dv_rpt_results_foot").html(response.rslt_html_data_foot);	
				re_intialize_data_tbl();
			}					
			else{
				swal("Failure!", "Some data are missing please login once after that try this operation", "warning");
			}
			//unloading();
		}
	});	
	
}


function re_intialize_data_tbl(){
	$('#rslt_tbl').DataTable({
		initComplete: function () 
			{	
				unloading(); 
				
			},
		"lengthMenu": [[-1], ["All"]],
		"bFilter": false,
		"bPaginate": false,	
		"ordering": false,		        
		"scrollX":  true,
        "scrollCollapse":true,       
       // "columnDefs": [ { width: 250, targets: 14 } ],	
		"footerCallback": function (row, data, start, end, display) {
            var api = this.api(), data;
            var colNumber = [6,7,9,10,11,12,13,14];
            for (i = 0; i < colNumber.length; i++) {
                var colNo = colNumber[i];
                var total2 = api
                        .column(colNo,{ page: 'current'})
                        .data()
                        .reduce(function (a, b) {
                            return parseFloat(a) + parseFloat(b);
                        }, 0);
												
						//alert('Total:  ' + total2.toFixed(2));
						if(colNo == 5){
							$(api.column(colNo).footer()).html("<b>"+total2+"</b>");
						}else{
						$(api.column(colNo).footer()).html("<b>"+total2.toFixed(2)+"</b>");
						}
            }
        },
			
		dom: 'Bfrtip',
        buttons: [
			{
			extend: 'excelHtml5', 
			text: 'Export to Excel',
			footer: true,
			filename: function(){
					var d = new Date();
					var n = d.getTime();
					return 'sales_report_'+n;
				}
			}
		]
	});
	

} 


function fn_pu_payment_pending(){	
	search_result();
}

</script>	

</body>
</html>
