<?php
include "header.php";
$today_date = date("Y-m-d");
?>

<?php 
// Today Sales Count - Here
$statement_today_sales = $pdo->prepare("SELECT * FROM `tbl_payments` WHERE date=CURRENT_DATE AND accounts=1");
$statement_today_sales->execute();
$today_sales_results = $statement_today_sales->fetchAll(PDO::FETCH_ASSOC);
$today_sales_totalData = $statement_today_sales->rowCount();



?>















<!--background: #b5dcdd;-->
<div class="content-wrapper" style=" background: #d7d7d7;">
    
    
   
        <section class="content-header">
            <div class="container">
                
                
                
                
            
                
                
                
                
                
                
                
                
                
                
                
                
            <!-- New Counts Starts Here -->
            
<div class="row" style="padding-top: 20px; padding-bottom: 20px;">
    <div class="col-lg-12" style="background-color: #f9f4f4db;padding: 10px;border-radius: 5px;font-size: 16px;color: #0d7c00;font-weight: 700; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.25), inset 0px 0px 0px 1px rgba(255, 255, 255, 0.1);">
        
        <div class="col-md-6 attendance_filter" style="padding-top: 6px;">
            <?=$site_name?>
        </div>
        
        <div class="col-md-2 attendance_filter" style="padding-top: 6px;">
            <input type="date" id="dashboard_start_date" class="form-control" value="<?=date('Y-m-d')?>">
        </div>
        
        <div class="col-md-2 attendance_filter" style="padding-top: 6px;">
            <input type="date" id="dashboard_end_date" class="form-control" value="<?=date('Y-m-d')?>">
        </div>
        
        <div class="col-md-2 attendance_filter" style="padding-top: 6px;">
            <button type="date" id="submit_button" class="btn btn-success" >Submit</button>
        </div>
        
    </div>
</div>





	<div class="row">
		<div class="col-md-12">
		  
		    
				
				<div class="nav-tabs-custom" style="background-color:#3c8dbc;">
					<!--<ul class="nav nav-tabs">
						<li class="active"><a href="#tab_1" data-toggle="tab">Today</a></li>
						<li><a href="#tab_2" data-toggle="tab">This Week</a></li>
						<li><a href="#tab_3" data-toggle="tab">This Month</a></li>
					</ul>-->
					<div class="tab-content">
							
                            <section class="content">
                            <div class="row">
                                <a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
                            		<div class="info-box" style="min-height:70px;width:80%;">
                            			<center><span class="info-box-icon bg-aqua" style="height:70px;"><i class="fa fa-money" style="padding:12px;"></i></span></center>
                            			<div class="info-box-content">
                            				<span class="info-box-text">PURCHASE</span>
                            				<img src="img/loading_small.gif" style="height: 50px; display: none;" class="loading_sections">
                            				<span class="info-box-number values_sections" style=""><i class="fa fa-inr"></i> <span id="total_purchase_amount" class="">0.00</span></span>
                            			</div>
                            		</div>
                            	</div></a>
                            	
                            	<a href="#">
                            	    <div class="col-md-4 col-sm-6 col-xs-12">
                            		<div class="info-box" style="min-height:70px;width:80%;">
                            			<span class="info-box-icon bg-blue" style="height:70px;"><i class="fa fa-shopping-cart" style="padding:12px;"></i></span>
                            			<div class="info-box-content">
                            				<span class="info-box-text">SALES</span>
                            				<img src="img/loading_small.gif" style="height: 50px; display: none;" class="loading_sections">
                            				<span class="info-box-number values_sections"><i class="fa fa-inr"></i> <span id="total_sales_amount" class="">0.00</span></span>
                            			</div>
                            		</div>
                            		</div>
                            	</a>
                            
                            	<a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
                            		<div class="info-box" style="min-height:70px;width:80%;">
                            			<span class="info-box-icon bg-orange" style="height:70px;"><i class="fa fa-exclamation" style="padding:12px;"></i></span>
                            			<div class="info-box-content">
                            				<span class="info-box-text">PURCHASE DEBIT</span>
                            				<img src="img/loading_small.gif" style="height: 50px; display: none;" class="loading_sections">
                            				<span class="info-box-number values_sections"><i class="fa fa-inr"></i> <span id="total_purchase_debit_amount" class="">0.00</span></span>
                            			</div>
                            		</div>
                            		</div>
                            	</a>
                            	
                            	
                            	
                            	<a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
                            		<div class="info-box" style="min-height:70px;width:80%;">
                            			<span class="info-box-icon bg-blue" style="height:70px;"><i class="fa fa-inr" style="padding:12px;"></i></span>
                            			<div class="info-box-content">
                            				<span class="info-box-text">SALES CREDIT</span>
                            				<img src="img/loading_small.gif" style="height: 50px; display: none;" class="loading_sections">
                            				<span class="info-box-number values_sections"><i class="fa fa-inr"></i> <span id="total_sales_credit" class="">0.00</span></span>
                            			</div>
                            		</div>
                            		</div>
                            	</a>
                            	
                            	<a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
                            		<div class="info-box" style="min-height:70px;width:80%;">
                            			<span class="info-box-icon bg-aqua" style="height:70px;"><i class="bi bi-person-lines-fill" style="padding:12px;"></i></span>
                            			<div class="info-box-content">
                            				<span class="info-box-text">SCHEME CREDIT</span>
                            				<img src="img/loading_small.gif" style="height: 50px; display: none;" class="loading_sections">
                            				<span class="info-box-number values_sections"><i class="fa fa-inr"></i> <span id="total_scheme_credit_amount" class="">0.00</span></span>
                            			</div>
                            		</div>
                            		</div>
                            	</a>
                            	
                                <a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
                            		<div class="info-box" style="min-height:70px;width: 80%;">
                            			<span class="info-box-icon bg-aqua" style="height:70px;"><i class="fa fa-inr" style="padding:12px;"></i></span>
                            			<div class="info-box-content">
                            				<span class="info-box-text">ADVANCE CREDIT</span>
                            				<img src="img/loading_small.gif" style="height: 50px; display: none;" class="loading_sections">
                            				<span class="info-box-number values_sections"><i class="fa fa-inr"></i> <span id="total_advance_amount" class="">0.00</span></span>
                            			</div>
                            		</div>
                            		</div>
                            	</a>
                            	
                            	<a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
                            		<div class="info-box" style="min-height:70px;width: 80%;">
                            			<span class="info-box-icon bg-aqua" style="height:70px;"><i class="fa fa-inr" style="padding:12px;"></i></span>
                            			<div class="info-box-content">
                            				<span class="info-box-text">EXPENSES AMOUNT</span>
                            				<img src="img/loading_small.gif" style="height: 50px; display: none;" class="loading_sections">
                            				<span class="info-box-number values_sections"><i class="fa fa-inr"></i> <span id="total_expenses_amount" class="">0.00</span></span>
                            			</div>
                            		</div>
                            		</div>
                            	</a>
                            	
                            	<a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
                            		<div class="info-box" style="min-height:70px;width: 80%;">
                            			<span class="info-box-icon bg-orange" style="height:70px;"><i class="fa fa-file-text" style="padding:12px;"></i></span>
                            			<div class="info-box-content">
                            				<span class="info-box-text">QUOTATIONS</span>
                            				<img src="img/loading_small.gif" style="height: 50px; display: none;" class="loading_sections">
                            				<span class="info-box-number values_sections"><i class="fa fa-inr"></i> <span id="total_quotations" class="">0.00</span></span>
                            			</div>
                            		</div>
                            		</div>
                            	</a>
                            	
                            </div>	
                            </section>
          			</div>
				</div>
				
				
		
				<br>

	
	
	

				
				
				<!-- Sales status Counter starts Here -->
				

					


		</div>
	</div>
            <!-- New Counts Endsss Here -->
                
                
                
                
                
                
<!-- Chart Starts Here -->
<div class="container">
<?php if($today_sales_totalData>0){ ?>

<div id="animation_section">
<div class="row" style="padding-top: 30px;padding-bottom: 30px;" id="animation_section">
    <div class="col-lg-6" style="background: #ffffff; border-radius: 8px; padding-top: 15px; padding-bottom: 15px; box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); margin-left: -2%;">
        <div id="chartDepartmentContainer" style="height: 300px; width: 100%;"></div>
    </div>
    <div class="col-lg-6" style="background: #ffffff; border-radius: 8px; padding-top: 15px; padding-bottom: 15px; box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); margin-left: 2%;">
        <div id="chartContainerAttendance" style="height: 300px; width: 100%;"></div>
    </div>
</div>
</div>

<?php } ?>
</div>
<!-- Chart Endsss Here -->                
                
                
                
                
                
                
                
                
                
                
                
                
<!-- Datatable Starts Here -->
<!-- Form Section Starts Here -->
<div class="row" style="padding-top: 20px;">
    <div class="col-lg-12" style="background-color: #f9f4f4db;padding: 10px;border: 1px solid darkgray;border-radius: 5px;font-size: 16px;color: #0d7c00;font-weight: 700;box-shadow: 1px 1px 1px;">
        <i class="fa fa-inr"></i> Today Price List <span style="float: right;padding-right: 10px;padding-top: 2px;cursor: pointer;" id="filter_button"><i class="fa fa-chevron-circle-down" aria-hidden="true"></i></span>
    </div>
</div>
<div class="row" style="margin-top: 30px;" id="filter_section">
                   
    
    <div class="col-md-12" style="background-color: #f9f4f4db;padding: 20px 20px 20px 20px;border-radius: 11px; border: 1px ridge #80808040;box-shadow: 2px 3px 2px;">
        <div class="table-responsive">
                        <table id="StData" class="table table-striped table-bordered table-condensed table-hover" style="margin-bottom:5px;font-size: 14px;border: 1px solid #77889961;">
                            <thead>
                                <tr>
                                    <td colspan="10" class="p0"><input type="text" class="form-control b0" name="search_table" id="search_table"  placeholder="Search Here" style="width:100%;background-color: <?= $theme_color ?>color: white;"></td>
                                </tr>
                                <tr class="active">
                                    <th style="width:100px;">Actions</th>
                                    <th>S.No</th>
                                    <th>Product Name</th>
                                    <th>Karat</th>
                                    <th>Today Price</th>
                                    <th>Updated Status</th>
                                    <th>Updated By</th>
                                    <th>Updated Date & Time</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="10" class="dataTables_empty"><center> Loading Pls Wait Data</center></td>
                                </tr>
                            </tbody>
                            
                        </table>
                    </div>
    </div>
</div>
<!-- Form Section Endsss Here -->
<!-- Datatable Endsss Here -->
 
                
              
            </div>
        </section>
        
        
        

        
        <br><br><br><br>
        
        
        
        <div class="row">
            <div class="col-md-6">
                   <?php //include "header/index_1.php"; ?>
            </div>
        </div>
        
      
         
         
         
</div>

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

<style>
.demo{ background-color: #EBE8EE; }
.counter{
    font-family: 'Nunito Sans', sans-serif;
    text-align: center;
    height: 210px;
    width: 210px;
    padding: 7px 4px 0;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}
.counter:before{
    content: '';
    background-color: #fff;
    height: 157px;
    width: 157px;
    border-radius: 15px;
    border: 5px solid #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1) inset;
    transform: translateX(-50%) translateY(-50%) rotate(45deg);
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: -1;
}
.counter .counter-icon{
    color: #fff;
    background: linear-gradient(#F83F83,#E2056F);
    line-height: 70px;
    font-size: 35px;
    height: 70px;
    width: 70px;
    margin: 0 auto 8px;
    border-radius: 19px 0 50px;
    transform: rotate(45deg);
}
.counter .counter-icon i{ transform: rotate(-45deg); }
.counter .counter-value{
    font-size: 25px;
    font-weight: 700;
    letter-spacing: 1px;
    margin: 0 0 13px 0;
    display: block;
}
.counter h3{
    color: #fff;
    background: linear-gradient(#F83F83,#E2056F);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: capitalize;
    padding: 10px 5px;
    margin: 0;
    border-radius: 0 0 20px 20px;
    position: relative;
}
.counter h3:before,
.counter h3:after{
    content: "";
    background: linear-gradient(to right bottom, transparent 49%,#c90460 50%);
    width: 20px;
    height: 20px;
    position: absolute;
    top: -20px;
    left: 0;
    z-index: -2;
}
.counter h3:after{
    transform: rotateY(180deg);
    left: auto;
    right: 0;
}
.counter.purple .counter-icon,
.counter.purple h3{
    background: linear-gradient(#B05FDF,#7B26DD);
}
.counter.purple h3:before,
.counter.purple h3:after{
    background: linear-gradient(to right bottom,transparent 49%,#5a07bf 50%);
}
.counter.blue .counter-icon,
.counter.blue h3{
    background: linear-gradient(#00BCF9,#027AF6);
}
.counter.blue h3:before,
.counter.blue h3:after{
    background: linear-gradient(to right bottom,transparent 49%,#0466c9 50%);
}
.counter.green .counter-icon,
.counter.green h3{
    background: linear-gradient(#aff400,#6cc425);
}
.counter.green h3:before,
.counter.green h3:after{
    background: linear-gradient(to right bottom,transparent 49%,#489e03 50%);
}
@media screen and (max-width:990px){
    .counter{ margin-bottom: 40px; }
}
    </style>
<script>
$(document).ready(function(){
    $('.counter-value').each(function(){
        $(this).prop('Counter',0).animate({
            Counter: $(this).text()
        },{
            duration: 3500,
            easing: 'swing',
            step: function (now){
                $(this).text(Math.ceil(now));
            }
        });
    });
});
</script>

<script type="text/javascript">
<?php 
$data_table = " var search_table =$('#search_table').val();
               var table = $('#StData').DataTable({

                    'ajax' : { 
                        url: 'data-tables/dashboard-today-price-data-table.php', 
                        data:{search:search_table}, 
                        type: 'POST'},
                        bFilter: true,
                        bDestroy: true,
                        searching: true,pageLength: 10,
                    'buttons': [
                    { extend: 'copyHtml5', 'footer': false, exportOptions: { columns: [ 0, 1, 2, 3, 4, 5 ] } },
                    { extend: 'excelHtml5', 'footer': false, exportOptions: { columns: [ 0, 1, 2, 3, 4, 5 ] } },
                    { extend: 'csvHtml5', 'footer': false, exportOptions: { columns: [ 0, 1, 2, 3, 4, 5 ] } },
                    { extend: 'pdfHtml5', orientation: 'landscape', pageSize: 'A4', 'footer': false,
                    exportOptions: { columns: [ 0, 1, 2, 3, 4, 5 ] } },
                    { extend: 'colvis', text: 'Columns'},
                    ]

                });";
?>

    $(document).ready(function(){        
        emp_datas();
        
        $('#filter_trip_date').change(function() {
            emp_datas();
        });
        
        $('#search_table').keyup(function() {  
            emp_datas();
            document.getElementById("search_table").focus();
        });
    });
    
        function emp_datas(){
            <?=$data_table?>
        }
</script>
                
                
  
<script>
    $(document).ready(function(){
        
        $('#filter_button').click(function(){
            $("#filter_section").slideToggle();
            return false;
        });
    });
</script>

<style>
    .counter_1{
    color: #f27f21;
    font-family: 'Open Sans', sans-serif;
    text-align: center;
    height: 190px;
    width: 190px;
    padding: 30px 25px 25px;
    margin: 0 auto;
    border: 3px solid #f27f21;
    border-radius: 20px 20px;
    position: relative;
    z-index: 1;
}
.counter_1:before,
.counter_1:after{
    content: "";
    background: #f3f3f3;
    border-radius: 20px;
    box-shadow: 4px 4px 2px rgba(0,0,0,0.2);
    position: absolute;
    left: 15px;
    top: 15px;
    bottom: 15px;
    right: 15px;
    z-index: -1;
}
.counter_1:after{
    background: transparent;
    width: 100px;
    height: 100px;
    border: 15px solid #f27f21;
    border-top: none;
    border-right: none;
    border-radius: 0 0 0 20px;
    box-shadow: none;
    top: auto;
    left: -10px;
    bottom: -10px;
    right: auto;
}
.counter_1 .counter-icon_1{
    font-size: 35px;
    line-height: 35px;
    margin: 0 0 15px;
    transition: all 0.3s ease 0s;
}
.counter_1:hover .counter-icon_1{ transform: rotateY(360deg); }
.counter_1 .counter-value_1{
    color: #555;
    font-size: 30px;
    font-weight: 600;
    line-height: 20px;
    margin: 0 0 20px;
    display: block;
    transition: all 0.3s ease 0s;
}
.counter_1:hover .counter-value_1{ text-shadow: 2px 2px 0 #d1d8e0; }
.counter_1 h3{
    font-size: 17px;
    font-weight: 700;
    text-transform: uppercase;
    margin: 0 0 15px;
}
 .blue{
    color: #4accdb;
    border-color: #4accdb;
}
.blue:after{
    border-bottom-color: #4accdb;
    border-left-color: #4accdb;
}
.pink {
    color: #EE436D;
    border-color: #EE436D;
}
.pink:after {
    color: #EE436D;
    border-color: #EE436D;
}
.purple {
    color: #9C52A1;
    border-color: #9C52A1;
}
.purple:after{
    color: #9C52A1;
    border-color: #9C52A1;
}
@media screen and (max-width:990px){
    .counter_1{ margin-bottom: 40px; }
}
</style>
<script>
    $(document).ready(function(){
    $('.counter-value_1').each(function(){
        $(this).prop('Counter',0).animate({
            Counter: $(this).text()
        },{
            duration: 3500,
            easing: 'swing',
            step: function (now){
                $(this).text(Math.ceil(now));
            }
        });
    });
});
</script>



<style>
.info-box {
    display: block;
    min-height: 90px;
    background: #fff;
    width: 100%;
    box-shadow: 20px 10px 20px rgb(0 0 0 / 10%);
    margin-bottom: 15px;
    border-radius: 15px 15px 15px 15px;
}
.nav-tabs-custom>.tab-content {
    background: #3c8dbc;
}
.info-box-text {
    font-weight: 700;
}
.info-box-text, .progress-description {
    display: block;
    font-size: 14px;
    overflow: hidden;
}
.info-box-number {
    font-size: 25px;
}
.info-box-number {
    font-weight: 700;
}
</style>


<script>
$('#submit_button').click(function() {
            DashboardDetails();
});

$(document).ready(function() { 
    DashboardDetails() 
}); 


function DashboardDetails(){
        $(".loading_sections").show();
        $(".values_sections").hide();
        var start_date = $("#dashboard_start_date").val();
        var end_date = $("#dashboard_end_date").val();
        $.ajax({
                    type: 'POST',
                    dataType : 'json',
                    url: 'api/dashboard-api.php',
                    data: {start_date:start_date,end_date:end_date},                  
                    success: function(response) {
                        console.log(response);
                        $(".loading_sections").hide();
                        $(".values_sections").show();
                        $("#total_purchase_amount").text(response['purchase_total_amt']);
                        $("#total_sales_amount").text(response['sales_total_amount']);
                        $("#total_purchase_debit_amount").text(response['purchase_debit_amt']);
                        $("#total_sales_credit").text(response['sales_credit_amount']);
                        $("#total_scheme_credit_amount").text(response['scheme_credit_amt']);
                        
                        
                        $("#total_advance_amount").text(response['total_advance_voucher_amt']);
                        $("#total_expenses_amount").text(response['total_expenses_amt']);
                        
                        $("#total_quotations").text(response['quoatation_total_amount']);
                        
                    }
            });
    }
</script>




<?php
$dataPointsDepartment = [];
try {

    $handle2 = $pdo->prepare("SELECT id, name FROM `tbl_payment_type` WHERE status=1");
    $handle2->execute();
    $result2 = $handle2->fetchAll(\PDO::FETCH_OBJ);
    $total_follow_Count2 = $handle2->rowCount();
    foreach ($result2 as $row2) {
        $department_name = $row2->name;
       


        $handle1 = $pdo->prepare("SELECT COALESCE(SUM(amount), 0) AS total_amount FROM `tbl_payments` WHERE payment_type=".$row2->id." and accounts=1 and date=CURRENT_DATE");
        $handle1->execute();
        $result1 = $handle1->fetchAll(\PDO::FETCH_OBJ);
        $total_follow_Count1 = $handle1->rowCount();
        
        foreach ($result1 as $row1) {
            $total_amount = $row1->total_amount;
            array_push($dataPointsDepartment, [
                "label" => $department_name,
                "y" => $total_amount,
            ]);
        }
    }

    $link = null;
} catch (\PDOException $ex) {
    print $ex->getMessage();
}
?>
<?php
$dataPoints1 = array();
try{
                            
$attendance_type = array('Sales' => 1, 'Purchase' => 2, 'Scheme' => 3, 'Advance Voucher' => 4, 'Expenses' => 5);

foreach ($attendance_type as $type_name => $type_value) {
    
    if($type_value==1){
        $conditions = "tbl_payments.accounts=1";
    }
    if($type_value==2){
        $conditions = "tbl_payments.accounts=2";
    }
    if($type_value==3){
        $conditions = "tbl_payments.accounts=3";
    }
    if($type_value==4){
        $conditions = "tbl_payments.accounts=4";
    }
    if($type_value==5){
        $conditions = "tbl_payments.accounts=5";
    }
    
    
                        $handle1 = $pdo->prepare("SELECT SUM(amount) as amount FROM `tbl_payments` WHERE ".$conditions." and date=CURDATE()");
                        $handle1->execute(); 
                        $result1 = $handle1->fetchAll(\PDO::FETCH_OBJ);
                        $total_follow_Count1 = $handle1->rowCount();
                        foreach($result1 as $row1){
                            $count = $row1->amount;
                            array_push($dataPoints1, array("label"=> $type_name , "y"=> $count)); 
                        }
                        
                        
                        }
                        
}catch(\PDOException $ex){
    print($ex->getMessage());
}
?>


<script>

<?php if($today_sales_totalData>0){ ?>
    window.onload = function () {

 var chartDepartment = new CanvasJS.Chart("chartDepartmentContainer", {
	animationEnabled: true,
	exportEnabled: true,
	theme: "light1", // "light1", "light2", "dark1", "dark2"
	title:{
		text: "Payment Types With Today Sales"
	},

	data: [{
		type: "pie",
		legendText: "{label}",
		indexLabelFontSize: 16,
		indexLabel: "{label} - #percent%",
		yValueFormatString: "Amount: #,##0",
		dataPoints: <?php echo json_encode($dataPointsDepartment,JSON_NUMERIC_CHECK); ?>
	}]
});
chartDepartment.render();


        
        
    var charttAtt = new CanvasJS.Chart("chartContainerAttendance", {
	animationEnabled: true,
	theme: "light1", // "light1", "light2", "dark1", "dark2"
	title:{
		text: "Today Credit & Debit"
	},
	/*axisY: {
		title: "Employee Count"
	},*/
	data: [{        
	    yValueFormatString: "₹ #,##0\"\"",
	    indexLabel: "{y}",
		indexLabelPlacement: "outside",
		indexLabelFontColor: "black",
		dataPoints: <?php echo json_encode($dataPoints1,JSON_NUMERIC_CHECK); ?>
	}]
});

charttAtt.render();



    }
    
<?php } ?>
</script>