<?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">                         
                    <table id="tblresult" class="table table-striped table-bordered">
                        <thead>
                            <tr>
								<th>Sno</th>		
								<th>Company Name</th>						
								<th>Customer Name</th>								
								<th>GSTNo/UIN</th>
								<th>Inv No</th>
								<th>Inv Date</th>
								<th>No.of Sarees</th>
								<th>Amount</th>
								<th>Discount (%)</th>
								<th>After Discount</th>
								<th>GST(2.5 %)</th>
								<th>SGST (2.5 %)</th>
								<th>IGST (5 %)</th>
								<th>Taxable Amount</th>								
								<th>Final Amount</th> 	
                            </tr>
                        </thead>                       
                    </table>
                </div>
            </div>
        </div>		 -->
		
		<style>
    .custom-padding {
        padding-bottom: 10px; 
    }
	.green-color {
        color:green;
		font-size: 18px;
    }
</style>

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

<?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 to get current month in YYYY-MM format
    function getCurrentMonth() {
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth() + 1; // Months are zero indexed
        if (month < 10) {
            month = '0' + month; // Prefix single digit months with 0
        }
        return month + '-' + year;
		
    }
    
    // Function to set start and end month inputs to current month
    function setDefaultMonth() {
        var currentMonth = getCurrentMonth();
        document.getElementById('startDate').value = currentMonth;
        document.getElementById('endDate').value = currentMonth;
			search_result();
    }

    // Call setDefaultMonth function when the page loads
    window.onload = setDefaultMonth;

</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,
		"paging": true,	
		"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: '<"pull-right custom-padding"B>frtip',
		pagingType: "simple_numbers",
        buttons: [
			{
			extend: 'excelHtml5', 
			text:  'Download <i class="fa fa-file-excel-o green-color"></i>',
			 titleAttr: '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>
