<?php 
$menudisp = "dashboard";

include "includes/header.php"; 

$rslt_supplier = $db->get_a_line("select count(*) as disp_cnt from m_supplier where 1=1 and IsActive=1 ");
$rslt_customer = $db->get_a_line("select count(*) as disp_cnt from m_customer where 1=1 and IsActive=1 ");
$rslt_purchase = $db->get_a_line("select count(*) as disp_cnt from t_purchase_entry_main where 1=1 and IsActive=1 ");
$rslt_sales = $db->get_a_line("select count(*) as disp_cnt from t_sales_entry_main where 1=1 and IsActive=1 ");

$available = $rslt_purchase['disp_cnt']- $rslt_sales['disp_cnt']
?> 
 <div class="wrapper">
            <div class="container">

                <!-- Page-Title - START -->
                <div class="row">
                    <div class="col-sm-12">   
</br>                     
                        <!-- <h4 class="page-title">Dashboard</h4> -->
                    </div>
                </div>				
				<!-- Page-Title - END -->


                <div class="row">
                    <div class="col-xs-12 col-md-6 col-lg-6 col-xl-3">
                        <div class="card-box tilebox-one">
                            <i class="icon-layers pull-xs-right text-muted"></i>
                            <h6 class="text-muted text-uppercase ">Suppliers</h6>
                            <h2 class="" data-plugin="counterup"><?php echo $rslt_supplier['disp_cnt']; ?></h2>                            
                        </div>
                    </div>

                    <div class="col-xs-12 col-md-6 col-lg-6 col-xl-3">
                        <div class="card-box tilebox-one">
                            <i class="icon-paypal pull-xs-right text-muted"></i>
                            <h6 class="text-muted text-uppercase ">Customers</h6>
                            <h2 class=""><span data-plugin="counterup"><?php echo $rslt_customer['disp_cnt']; ?></span></h2>                           
                        </div>
                    </div>

                    <div class="col-xs-12 col-md-6 col-lg-6 col-xl-3">
                        <div class="card-box tilebox-one">
                            <i class="icon-chart pull-xs-right text-muted"></i>
                            <h6 class="text-muted text-uppercase ">Total Stocks</h6>
                            <h2 class=""><span data-plugin="counterup"><?php echo $rslt_purchase['disp_cnt']; ?></span></h2>                           
                        </div>
                    </div>

                    <div class="col-xs-12 col-md-6 col-lg-6 col-xl-3">
                        <div class="card-box tilebox-one">
                            <i class="icon-rocket pull-xs-right text-muted"></i>
                            <h6 class="text-muted text-uppercase ">Available Stocks</h6>
                            <h2 class="" data-plugin="counterup"><?php echo $available; ?></h2>                            
                        </div>
                    </div>
                </div>
                <!-- end row -->
				
				<!-- <div class="row">					
					<div class="col-sm-6">
						<div class="card-box">                         
							<div class="row">
								<h3 class="panel-title">Supplier Payment</h3>
								
							</div>
							<br/>
							<div class="row">								
								<div class="col-md-6">
									<select name="srch_sup_company" id="srch_sup_company" class="form-control select2 jsrequired">
										<option value="">Select Company</option>
										<?php 
										$rslt_list = $db->get_rsltset("select company_id AS Id,company_name AS Name from m_company where IsActive = '1' order by company_name asc");
										foreach($rslt_list as $r){											
										?>
										<option value="<?php echo $r['Id']; ?>"><?php echo $r['Name']; ?></option>
										<?php	
										}
										?>
									</select>
								</div>
								<div class="col-md-6">
									<select name="srch_sup_supplier" id="srch_sup_supplier" class="form-control select2 jsrequired">
										<option value="">Select Supplier</option>
										<?php 
										$rslt_list = $db->get_rsltset("select sup_id AS Id,sup_name AS Name from m_supplier where IsActive = '1' order by sup_name asc");
										foreach($rslt_list as $r){											
										?>
										<option value="<?php echo $r['Id']; ?>" ><?php echo $r['Name']; ?></option>
										<?php	
										}
										?>
									</select>
								</div>								
							</div>
							<br/>
							<div class="row">
								<div class="col-md-8">
									&nbsp;
								</div>
								<div class="col-md-4">
									<button onclick="supplier_payment();" type="button" class="btn btn-warning pull-right">Add Payment</button>
								</div>
							</div>
							
						</div>
					</div>
					
					
					<div class="col-sm-6">
						<div class="card-box">                         
							<div class="row">
								<h3 class="panel-title">Customer Payment</h3>								
							</div>
							
							<br/>
							<div class="row">								
								<div class="col-md-6">
									<select name="srch_cus_company" id="srch_cus_company" class="form-control select2 jsrequired">
										<option value="">Select Company</option>
										<?php 
										$rslt_list = $db->get_rsltset("select company_id AS Id,company_name AS Name from m_company where IsActive = '1' order by company_name asc");
										foreach($rslt_list as $r){											
										?>
										<option value="<?php echo $r['Id']; ?>" ><?php echo $r['Name']; ?></option>
										<?php	
										}
										?>
									</select>
								</div>
								<div class="col-md-6">
									<select name="srch_cus_customer" id="srch_cus_customer" class="form-control select2 jsrequired">
										<option value="">Select Customer</option>
										<?php 
										$rslt_list = $db->get_rsltset("select cus_id AS Id,cus_name AS Name from m_customer where IsActive = '1' order by cus_name asc");
										foreach($rslt_list as $r){											
										?>
										<option value="<?php echo $r['Id']; ?>"><?php echo $r['Name']; ?></option>
										<?php	
										}
										?>
									</select>
								</div>								
							</div>
							<br/>
							<div class="row">
								<div class="col-md-8">
									&nbsp;
								</div>
								<div class="col-md-4">
									<button onclick="customer_payment();" type="button" class="btn btn-warning pull-right">Add Payment</button>
								</div>
							</div>
							
						</div>
					</div>
					
				</div>  -->

				 
<div class="row">
	<div class="col-md-8">
        <div class="card-box" style ="padding-bottom :1px;">
            <div class = "row">
            <div class="col-md-3">
    <select onchange="loadData(this.value, 'financial_id', 'financial_data')" name="financial_id" id="financial_id" class="form-control select2 jsrequired">
        <option value="">Financial Year</option>
        <?php
        $rslt_list = $db->get_rsltset("select financial_id,f_start_date,f_end_date from m_financial_year order by f_start_date asc");
        $current_fy_id = '';

        foreach ($rslt_list as $r) {
            $financial_year_label = date('Y', strtotime($r['f_start_date'])) . '-' . date('Y', strtotime($r['f_end_date']));

            $sel = ($current_fy_id == $r['financial_id']) ? ' selected="selected" ' : ' selected="selected"';
        ?>
            <option value="<?php echo $r['financial_id']; ?>" <?php echo $sel; ?>><?php echo $financial_year_label; ?></option>
        <?php
        }
        ?>
    </select>
</div>

<div class="col-md-4">
    <select onchange="loadData(this.value, 'sel_company', 'company_data')" name="sel_company" id="sel_company" class="form-control select2 jsrequired">
        <option value="">All Company</option>
        <?php
        $rslt_list = $db->get_rsltset("select company_id AS Id, company_name AS Name from m_company where IsActive = '1' order by company_name asc");
        foreach ($rslt_list as $r) {
        ?>
            <option value="<?php echo $r['Id']; ?>"><?php echo $r['Name']; ?></option>
        <?php
        }
        ?>
    </select>
</div>

<div class="col-md-4">
    <select onchange="loadData(this.value, 'sel_customer', 'customer_data')" name="sel_customer" id="sel_customer" class="form-control select2 jsrequired">
        <option value="">All Customer</option>
        <?php
        $rslt_list = $db->get_rsltset("select cus_id AS Id, cus_name AS Name from m_customer where IsActive = '1' order by cus_name asc");
        foreach ($rslt_list as $r) {
        ?>
            <option value="<?php echo $r['Id']; ?>"><?php echo $r['Name']; ?></option>
        <?php
        }
        ?>
    </select>
</div>
<a id="download-pdf-chart" href="javascript:void(0)"style="position: relative; top: 8px;left: 8px;"><i class="zmdi zmdi-cloud-download"style="font-size: 20px;"></i></a>
</div>




	<div class="row">
		<div class="col-md-12">
			<div class="card-box" style ="padding-bottom :1px; height: 500px;">
            <div id="loader" style="position: relative; top: 200px; left: 50%; display:none; ">
                <img src="https://i.imgur.com/fXUIBfi.gif" alt="Chart will Render Here..." style="height: 50px; width:6%;" />
            </div>

			<div id="sales_report"  style="height: 456px; width: 100%;"></div>

		    <div id="chartContainer" style="height: 456px; width: 100%; display:none;"></div>
		    <div id="chartCompany" style="height: 456px; width: 100%; display:none;"></div>
           

			</div>
		</div>
	</div>
	</div>
				


	
</div>

<div class="col-md-4">
    <div class="row">
        <div class="col-md-7">
            <div class="card-box" style ="padding :5px;">
            <div class="tilebox-one">
                <div class="row">
                    <div class="col-xs-12" style ="padding-top: 10px;">
                    <i class="icon-tag pull-xs-right text-muted"></i>
                        <h6 class="text-muted text-uppercase">Total Sales</h6>
                    </div>
                    <div class="col-xs-12">
                        <h2 class="">
                        <div id="salesAmt"></div>
                        <div id ="sales_single" style ="display:none;"></div>
                        </h2>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-5">
            <div class="card-box" style ="padding :5px;">
            <div class="tilebox-one">
                <div class="row">
                    <div class="col-xs-12" style ="padding-top: 10px;">
                    <i class="icon-action-undo pull-xs-right text-muted"></i>
                        <h6 class="text-muted text-uppercase">Total Return</h6>
                    </div>
                    <div class="col-xs-12">
                        <h2 class="">
                        <div id="returnAmt"></div>
                        <div id ="return_single" style ="display:none;"></div>
                        </h2>
                    </div>
                </div>
            </div>
        </div>
    </div>
       

    </div>
    <div class="row">
         <div class="col-md-7">
            <div class="card-box" style ="padding :5px;">
            <div class="tilebox-one">
                <div class="row">
                    <div class="col-xs-12" style ="padding-top: 10px;">
                    <i class="icon-fire pull-xs-right text-muted"></i>
                        <h6 class="text-muted text-uppercase">Outstanding Balance</h6>
                    </div>
                    <div class="col-xs-12">
                        <h2 class="">
                        <div id="balanceAmt"></div>
                        <div id ="balance_single" style ="display:none;"></div>
                        </h2>
                    </div>
                </div>
            </div>
        </div>
    </div>
       
        <div class="col-md-5">
            <div class="card-box" style ="padding :5px;">
            <div class="tilebox-one">
                <div class="row">
                    <div class="col-xs-12" style ="padding-top: 10px;">
                    <i class="icon-target pull-xs-right text-muted"></i>
                        <h6 class="text-muted text-uppercase">Pending BIlls</h6>
                    </div>
                    <div class="col-xs-6">
                        <h2 class="">
                        <div id="pending"></div>
                        <div id ="pending_single" style ="display:none;"></div>
                        </h2>
                    </div>
                </div>
            </div>
        </div>
    </div>

    </div>
    
    <div class="row">
            
        <div class ="col-md-12">
        <div class="card-box" style ="height:355px;">
        <div id="loader_pie" style="position: relative; top: 100px; left: 50%; display:none; ">
                <img src="https://i.imgur.com/fXUIBfi.gif" alt="Chart will Render Here..." style="height: 50px; width:11%;" />
            </div>
<a id ="download-pdf-pie" href="#"style="position: relative; bottom: 0px;"><i class="zmdi zmdi-cloud-download"style="font-size: 20px;"></i></a>

            <div id="sales_pie"  style="height: 285px; width: 100%;"></div>
            <div id="chartContainer_pie" style="height: 285px; width: 100%; display:none; "></div>
            <div id ="company_pie" style="height: 285px; width: 100%; display:none; "></div> 

        </div>  
    </div>  
</div>
</div>
   
</div>
</div>

                       





<?php include "includes/footer.php";  ?>             


</div> <!-- container -->

</div> <!-- End wrapper -->

<?php include "includes/footer_script.php";  ?> 

<!-- Counter Up  -->
<!--<script src="assets/plugins/waypoints/lib/jquery.waypoints.js"></script>
<script src="assets/plugins/counterup/jquery.counterup.min.js"></script>-->

<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>


<!-- Page specific js -->
<!--<script src="assets/pages/jquery.dashboard.js"></script> -->
<!-- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> -->
<script>

$(document).ready(function() {
    // Attach a click event handler to the download icon
    $('#download-pdf-chart').click(function() {
        var financial_id = $('#financial_id').val();
        var sel_company = $('#sel_company').val();
        var sel_customer = $('#sel_customer').val();
        var action = 'get_chart';
        // Create a URL with query parameters for the selected values
        var pdfDownloadUrl = "dashboard_ledger_pdf.php?financial_id=" + financial_id +
            "&sel_customer=" + sel_customer + "&sel_company=" + sel_company+ "&action=" + action;
        
        // Redirect to the PDF generation page
        window.location.href = pdfDownloadUrl;
    });
});
$(document).ready(function() {
    // Attach a click event handler to the download icon
    $('#download-pdf-pie').click(function() {
        var financial_id = $('#financial_id').val();
        var sel_company = $('#sel_company').val();
        var sel_customer = $('#sel_customer').val();
        var action = 'get_pie';
        // Create a URL with query parameters for the selected values
        var pdfDownloadUrl = "dashboard_ledger_pdf.php?financial_id=" + financial_id +
            "&sel_customer=" + sel_customer + "&sel_company=" + sel_company + "&action=" + action;
        
        // Redirect to the PDF generation page
        window.location.href = pdfDownloadUrl;
    });
});


</script>
<script>
window.onload = onPageLoad;
function onPageLoad() {
    var financial_id = $('#financial_id').val();
   
    var requestData = {
        action: 'get_sales_report',
        financial_id: financial_id
        
    }; 

    $.ajax({
        url: 'chart.php', // Specify the URL where you want to send the request
        method: 'POST', // Use POST method to send data
        data: requestData, // Send the requestData as JSON
        dataType: 'json', // Expect JSON response from the server
        success: function (responseData) {
            
            var salesData = responseData.salesData;
            var returnData = responseData.returnData;
            var dataPoints_pie = responseData.dataPoints_pie;
            console.log(salesData);

            $('#balanceAmt').text('₹ ' + responseData.balance);
            $('#returnAmt').text('₹ ' +responseData.return_amt);
            $('#salesAmt').text('₹ ' +responseData.sales_amt);
            $('#returnBill').text(responseData.return);
            $('#salesBill').text(responseData.sales);
            $('#pending').text(responseData.pending);

            if(salesData.length == 0){
        var chartData = [ {
            x: new Date(),
            y: 0
        },{
            x: new Date() + 1,
            y: 0
        },{
            x: new Date() + 2,
            y: 0
        }]
    }
    else{
            var chartData = salesData.map(function (item) {
                return {
                    x: new Date(item.month),
                    y: item.total_sales
                };
            });
        }
            var returnChartData = returnData.map(function (item) {
                return {
                    x: new Date(item.month),
                    y: item.total_return
                };
            });
//             var currentYear = new Date().getFullYear(); // Get the current year
// var startMonth = 2; // April (0-indexed month)
// var endMonth = 2; // March (0-indexed month)
// var fiscalYearMonths = [];
// for (var i = startMonth; i <= endMonth; i++) {
//     fiscalYearMonths.push(new Date(currentYear, i, 1));
// }

// var startDate = new Date(currentYear, startMonth, 1); 
// var endDate = new Date(currentYear + 1, endMonth, 31); 

            var sales_report = new CanvasJS.Chart("sales_report", {
                dataPointWidth: 20,
                theme: "light2",
                animationEnabled: true,
                title: {
                    text: "Monthly Sales and Returns",
                    fontSize: 16, 
                    fontFamily: "Arial, sans-serif"
                },
                axisX: {
                        labelAngle: 0, 
                        valueFormatString: "MMM", 
                        intervalType: "month",
                        interval: 1,
                        // minimum: startDate, 
                        // maximum: endDate
                    },
                data: [{
                    type: "column",
                    name: "Sales",
                    showInLegend: true,
                    legendText: "Sales",
                    dataPoints: chartData
                }, {
                    type: "column",
                    name: "Returns",
                    showInLegend: true,
                    legendText: "Returns",
                    dataPoints: returnChartData
                }]
            });

           
    var sales_pie_chart = new CanvasJS.Chart("sales_pie", {
        theme: "light2",
        animationEnabled: true,
        title: {
            text: "Sales outstanding",
            fontSize: 16, 
        },
        data: [{
            type: "pie",
            indexLabel: "{y}",
            yValueFormatString: "#,##0.00\"\"",
            indexLabelPlacement: "inside",
            indexLabelFontColor: "#36454F",
            indexLabelFontSize: 16,
            indexLabelFontWeight: "bolder",
            showInLegend: true,
            legendText: "{label}",
            dataPoints: dataPoints_pie
        }]
    });

    sales_pie_chart.render();


            sales_report.render();
        }
    });
}




function loadData(customer_id) {
	var financial_id = $('#financial_id').val();
        var sel_company = $('#sel_company').val();
        var sel_customer = $('#sel_customer').val();

    // Define the data you want to send to the server
    var requestData = {
        action: 'get_sales_chart',
        financial_id: financial_id,
        company_id: sel_company,
        customer_id: sel_customer
    };

    $.ajax({
        url: 'chart.php', // Specify the URL where you want to send the request
        method: 'POST', // Use POST method to send data
        data: requestData, // Send the requestData as JSON
        dataType: 'json', // Expect JSON response from the server
        success: function (responseData) {
            // debugger
            var dataPoints = responseData.dataPoints;
            var salesData = responseData.salesData;
            var returnData = responseData.returnData;
            

            $('#balance_single').text('₹ ' +responseData.balance);
            $('#return_single').text('₹ ' +responseData.return);
            $('#sales_single').text('₹ ' +responseData.sales);
            $('#pending').text(responseData.pending);

    // console.log(salesData);
   
            if (salesData.length === 1) {
            var item = salesData[0];
            console.log('salesData length is 1');
            
            var initialDate = new Date(item.month);
            var nextMonthDate = new Date(initialDate);
            nextMonthDate.setMonth(initialDate.getMonth() + 1);

            var chartData = [
                {
                    x: initialDate,
                    y: item.total_sales
                },
                {
                    x: nextMonthDate,
                    y: 0
                }
            ];
        }


  else  if(salesData.length == 0){
        console.log('saledata empty');
        var chartData = [ {
            x: new Date(),
            y: 0
        },{
            x: new Date() + 1,
            y: 0
        },{
            x: new Date() + 2,
            y: 0
        }]
    }
    else{
	    var chartData = salesData.map(function (item) {
                return {
                    x: new Date(item.month),
                    y: item.total_sales
                };
            });
        }
            var returnChartData = returnData.map(function (item) {
                return {
                    x: new Date(item.month),
                    y: item.total_return
                };
            });

            // Create and configure the chart
            console.log(chartData);

            var chart_filter = new CanvasJS.Chart("chartContainer", {
                theme: "light2",
				
                animationEnabled: true,
                title: {
                    text: "Monthly Sales and Returns",
                    fontSize: 16, 
                    fontFamily: "Arial, sans-serif"
                },
                axisX: {
                        labelAngle: 0, 
                        valueFormatString: "MMM", 
                        intervalType: "month",
                        interval: 1,
                       
                    },
				dataPointWidth: 20,
                data: [{
                    type: "column",
                    name: "Credit",
					
					showInLegend: true,
					legendText: "Sales",
                    dataPoints: chartData
                },
                {
                    type: "column",
                    name: "Debit",
					showInLegend: true,
					legendText: "Sales Return",
                    dataPoints: returnChartData
                }]
            });
            $('#loader').show();

            setTimeout(function () {
                
                $('#loader').hide();

            
                $('#chartContainer').show();

                
                chart_filter.render();
            }, 500);
                    
            
            $('#chartContainer').show();
            $('#sales_report').hide();
            $('#sales_pie').hide();
            $('#chartContainer_pie').show();
            $('#returnAmt').hide();
            $('#salesAmt').hide();
            $('#balanceAmt').hide();
            $('#return_single').show();
            $('#sales_single').show();
            $('#balance_single').show();
           
            
        },
       
        error: function (error) {
            console.error("Error fetching data: " + error.statusText);
        }
    });
    get_sales_outstanding();
}


function get_sales_outstanding(customer_id) {
	var financial_id = $('#financial_id').val();
        var sel_company = $('#sel_company').val();
        var sel_customer = $('#sel_customer').val();

    // Define the data you want to send to the server
    var requestData = {
        action: 'get_sales_outstanding',
        financial_id: financial_id,
        company_id: sel_company,
        customer_id: sel_customer
    };

    $.ajax({
        url: 'chart.php', // Specify the URL where you want to send the request
        method: 'POST', // Use POST method to send data
        data: requestData, // Send the requestData as JSON
        dataType: 'json', // Expect JSON response from the server
        success: function (responseData) {
            var dataPoints = responseData.dataPoints;
    console.log(dataPoints);

var chart = new CanvasJS.Chart("chartContainer_pie", {
	theme: "light2",
	animationEnabled: true,
	title: {
		text: "Sales outstanding",
        fontSize: 16, 
	},
	data: [{
		type: "pie",
		indexLabel: "{y}",
		yValueFormatString: "#,##0.00\"\"",
		indexLabelPlacement: "inside",
		indexLabelFontColor: "#36454F",
		indexLabelFontSize: 16,
		indexLabelFontWeight: "bolder",
		showInLegend: true,
		legendText: "{label}",
		dataPoints: dataPoints
	}]
});
        $('#loader_pie').show();

        setTimeout(function () {
            
            $('#loader_pie').hide();


            $('#chartContainer_pie').show();

            
            chart.render();
        }, 500);
            
        },
        error: function (error) {
            console.error("Error fetching data: " + error.statusText);
        }
    });
}

// function get_company(company_id){ 
//     var financial_id = $('#financial_id').val();
//     var sel_company = $('#sel_company').val();
//     console.log(sel_company);
//     console.log(financial_id);

//     var requestData = {
//         action: 'get_company_details',
//         financial_id: financial_id,
//         company_id: sel_company,
        
//     };
//     $.ajax({
//         url: 'chart.php', // Specify the URL where you want to send the request
//         method: 'POST', // Use POST method to send data
//         data: requestData, // Send the requestData as JSON
//         dataType: 'json', // Expect JSON response from the server
//         success: function (responseData) {
//             var dataPoints = responseData.dataPoints;
//     // console.log(dataPoints);

//             var chart_pie = new CanvasJS.Chart("company_pie", {
//                 theme: "light2",
//                 animationEnabled: true,
//                 title: {
//                     text: "Sales outstanding"
//                 },
//                 data: [{
//                     type: "pie",
//                     indexLabel: "{y}",
//                     yValueFormatString: "#,##0.00\"\"",
//                     indexLabelPlacement: "inside",
//                     indexLabelFontColor: "#36454F",
//                     indexLabelFontSize: 16,
//                     indexLabelFontWeight: "bolder",
//                     showInLegend: true,
//                     legendText: "{label}",
//                     dataPoints: dataPoints
//                 }]
//             });
//             // Render the chart
//             chart_pie.render();
        

//             var salesData = responseData.salesData;
//             var returnData = responseData.returnData;
           
            

//             $('#balance_single').text('₹ ' +responseData.balance);
//             $('#return_single').text('₹ ' +responseData.return);
//             $('#sales_single').text('₹ ' +responseData.sales);
//             $('#pending').text(responseData.pending);

//     // console.log(dataPoints);

//     if(salesData.length == 0){
//         var chartData = [ {
//             x: new Date(),
//             y: 0
//         },{
//             x: new Date() + 1,
//             y: 0
//         },{
//             x: new Date() + 2,
//             y: 0
//         }]
//     }
//     else{
// 	    var chartData = salesData.map(function (item) {
//                 return {
//                     x: new Date(item.month),
//                     y: item.total_sales
//                 };
//             });
//         }
//             var returnChartData = returnData.map(function (item) {
//                 return {
//                     x: new Date(item.month),
//                     y: item.total_return
//                 };
//             });

//             // Create and configure the chart
//             var currentYear = new Date().getFullYear(); // Get the current year
//             var startMonth = 2; // April (0-indexed month)
//             var endMonth = 2; // March (0-indexed month)
//             var fiscalYearMonths = [];
//                     for (var i = startMonth; i <= endMonth; i++) {
//                         fiscalYearMonths.push(new Date(currentYear, i, 1));
//                     }

//             var startDate = new Date(currentYear, startMonth, 1); 
//             var endDate = new Date(currentYear + 1, endMonth, 31); 

//             var chart = new CanvasJS.Chart("chartCompany", {
//                 theme: "light2",
				
//                 animationEnabled: true,
//                 title: {
//                     text: "Monthly Sales and Returns",
//                     fontSize: 24, 
//                     fontFamily: "Arial, sans-serif"
//                 },
//                 axisX: {
//                         labelAngle: 0, 
//                         valueFormatString: "MMM", 
//                         intervalType: "month",
//                         interval: 1,
//                         minimum: startDate, 
//                         maximum: endDate
//                     },
// 				dataPointWidth: 20,
//                 data: [{
//                     type: "column",
//                     name: "Credit",
					
// 					showInLegend: true,
// 					legendText: "Sales",
//                     dataPoints: chartData
//                 },
//                 {
//                     type: "column",
//                     name: "Debit",
// 					showInLegend: true,
// 					legendText: "Sales Return",
//                     dataPoints: returnChartData
//                 }]
//             });
         
            
//             $('#chartContainer').show();
//             $('#sales_report').hide();
//             $('#sales_pie').hide();
//             $('#company_pie').show();
//             $('#returnAmt').hide();
//             $('#salesAmt').hide();
//             $('#balanceAmt').hide();
//             $('#return_single').show();
//             $('#sales_single').show();
//             $('#balance_single').show();
           

//             chart.render();
//         },
//         error: function (error) {
//             console.error("Error fetching data: " + error.statusText);
//         }
//     });
// }


</script>



<script type="text/javascript">

function supplier_payment(){
	if ($("#srch_sup_company").val() !='' && $("#srch_sup_supplier").val() !='') {	
		$.ajax({		
			url        : 'dashboard_actions.php',
			method     : 'POST',
			dataType   : 'json',
			data       : 'action=supplier_payment_add&srch_company='+$("#srch_sup_company").val()+'&srch_supplier='+$("#srch_sup_supplier").val(),
			beforeSend: function() { loading(); },
			success: function(response){				
				if(response.rslt == '1'){					
					$(location).attr('href', response.redirect_url);
				}
				else if(response.rslt == '-1'){					
					swal("Failure!", "Search data not getting, Please try again once", "warning");
				}
				else if(response.rslt == '-2'){					
					swal("Failure!", "No data mapping this keyword", "warning");
				}
				else{
					swal("Failure!", "Some session data are missing please login once after that try this operation", "warning");
				}
				unloading();
			}		
		});	
	}else{
		swal("Failure!", "Please select company and supplier to add a payment", "warning");
	}
}


function customer_payment(){
	if ($("#srch_cus_company").val() !='' && $("#srch_cus_customer").val() !='') {	
		$.ajax({		
			url        : 'dashboard_actions.php',
			method     : 'POST',
			dataType   : 'json',
			data       : 'action=customer_payment_add&srch_company='+$("#srch_cus_company").val()+'&srch_customer='+$("#srch_cus_customer").val(),
			beforeSend: function() { loading(); },
			success: function(response){				
				if(response.rslt == '1'){					
					$(location).attr('href', response.redirect_url);
				}
				else if(response.rslt == '-1'){					
					swal("Failure!", "Search data not getting, Please try again once", "warning");
				}
				else if(response.rslt == '-2'){					
					swal("Failure!", "No data mapping this keyword", "warning");
				}
				else{
					swal("Failure!", "Some session data are missing please login once after that try this operation", "warning");
				}
				unloading();
			}		
		});	
	}else{
		swal("Failure!", "Please select company and supplier to add a payment", "warning");
	}
}

</script>

  </body>
</html>

