<?php
session_start();
 include 'header.php' ?>

 

<!--<script type="text/javascript" src="../js/loader.js"></script>-->
<script src="../js/highcharts.src.js"></script>
<script src="../js/exporting.js"></script>
<script src="../js/export-data.js"></script>


<div class="page-wrapper">

            <!-- Bread crumb -->
            <div class="row page-titles" style="height:50px">
                <div class="col-md-5 align-self-center">
                    <h3 class="text-primary">Dashboard <?php //echo $_SESSION["state_code"];?></h3> </div>
                
            </div>
            <!-- End Bread crumb -->
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
               
				<div class="row">
                    
                   
                    <div class="col-lg-7">
                         <div class="card" >
						<div id="bar_chart" style=" width:100%;  height: 350px; margin: 0 auto"></div>
                            
                       </div>
                    </div>
                  
				  <div class="col-lg-5">
                        <div class="card" >
						<div id="piechart" style="width:480px; height: 350px;"></div>
                            
                        </div>
                    </div>
                </div>
				
				<div class="row">
                    
                   
                   
                  
				   <div class="col-lg-6">
                        <div class="card" >
						<div id="piechart2" style="height: 300px;"></div>
                        </div>
                    </div>
                   	 
					 <div class="col-lg-6">
					
                      <div class="card" >
						<div id="donutchart" style="height: 300px;"></div>
                        </div>
                  
                  </div>
                </div>
				
				
				
				     <!--<div class="row">         
                    <div class="col-lg-12">
                        <div class="card" >
						<div id="linechart" ></div>
                            
                        </div>
                    </div>
                  
				 
                </div>-->
				
				
				
				<!--<div class="row">
                    
                   
                    <div class="col-lg-12">
                        <div class="card" >
						<div id="linechart2" ></div>
                            
                        </div>
                    </div>
                  
				 
                </div>-->
                
                
                

            
        </div>
		
		
		
		<?php
   $cur_fy = '01-04-'.date('Y');
 $next_fy ='31-03-'.(date('Y')+1);
 

$start    = new DateTime($cur_fy);
$start->modify('first day of this month');
$end      = new DateTime($next_fy);
$end->modify('first day of next month');
$interval = DateInterval::createFromDateString('1 month');
$period   = new DatePeriod($start, $interval, $end);
$cd_amt_t=0;
$credit_t=0;
$i=0;
foreach ($period as $dt) {
$i++;

     $dateString= $dt->format("d-m-Y");
	$mn = explode('-',$dateString );
	 $lastDateOfMonth = date("t-m-Y", strtotime($dateString));
	$month_name = date('F', mktime(0, 0, 0, $mn[1], 1));
	
 $menu[$i] =  $month_name;
     $startdate=$dateString;
    $enddate=$lastDateOfMonth;
	
  $sdt = date('d-m-Y', strtotime("$startdate"));
  $s_date=$objIms->DateToInt($sdt);
  $edt = date('d-m-Y', strtotime("$enddate"));
  $end_date=$objIms->DateToInt($edt);

   $sql_pur = "SELECT sum(round_off) as pur_price FROM `view_pur_masdet`
WHERE session_login_id = '".$_SESSION['login_id']."'  and purchase_date>='$s_date' and purchase_date<='$end_date';
";
$res_pur = mysql_query($sql_pur);
$row_pur = mysql_fetch_assoc($res_pur);
  $purchase = $row_pur["pur_price"];
  if($purchase==''){$purchase=0;}
$pur_price[$i]=$purchase;

   
      $sql_sl = "select sum((unit_price*qty)-((unit_price*qty)*discount/100)+(((unit_price*qty)-((unit_price*qty)*discount/100))*cgst/100)+(((unit_price*qty)-((unit_price*qty)*discount/100))*sgst/100)+(((unit_price*qty)-((unit_price*qty)*discount/100))*igst/100))  as sale_price FROM `view_sales_mstrdet` WHERE session_login_id = '".$_SESSION['login_id']."'  and stampdate>='$s_date' and stampdate<='$end_date';
";
$res_sl = mysql_query($sql_sl);
$row_sl = mysql_fetch_assoc($res_sl);
  $sale =  number_format((float)$row_sl["sale_price"], 2, '.', '');
  if($sale==''){$sale=0;}
 $sale_price[$i]=$sale;

           
$sql_ex = "SELECT sum(Dr_Amt) as expance FROM tbl_account where sales_type= 'Expance' and session_login_id = '".$_SESSION['login_id']."'  and trans_date>='$s_date' and trans_date<='$end_date';
";
$res_ex = mysql_query($sql_ex);
$row_ex = mysql_fetch_assoc($res_ex);
  $exp_amt =  number_format((float)$row_ex["expance"], 2, '.', '');
  if($exp_amt==''){$exp_amt=0;}
  $expance[$i]=$exp_amt;
 

}
?>
		
		
		
		
		<script>
	Highcharts.chart('bar_chart', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Monthly Report '
    },
    subtitle: {
        text: '<?php echo date('Y');?>'
    },
    xAxis: {
        categories: [
            '<?php echo $menu[1];?>',
            '<?php echo $menu[2];?>',
            '<?php echo $menu[3];?>',
            '<?php echo $menu[4];?>',
            '<?php echo $menu[5];?>',
            '<?php echo $menu[6];?>',
            '<?php echo $menu[7];?>',
            '<?php echo $menu[8];?>',
            '<?php echo $menu[9];?>',
            '<?php echo $menu[10];?>',
            '<?php echo $menu[11];?>',
            '<?php echo $menu[12];?>'
        ],
        crosshair: true
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Amount (INR)'
        }
    },
    tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            '<td style="padding:0"><b>Rs : {point.y:.1f} </b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
    },
    plotOptions: {
        column: {
            pointPadding: 0.2,
            borderWidth: 0
        }
    },
    series: [{
        name: 'Purchase',
        data: [<?php echo $pur_price[1];?>, <?php echo $pur_price[2];?>, <?php echo $pur_price[3];?>, <?php echo $pur_price[4];?>, <?php echo $pur_price[5];?>, <?php echo $pur_price[6];?>, <?php echo $pur_price[7];?>, <?php echo $pur_price[8];?>, <?php echo $pur_price[9];?>, <?php echo $pur_price[10];?>, <?php echo $pur_price[11];?>, <?php echo $pur_price[12];?>]

    }, {
        name: 'Expances',
        data: [<?php echo $expance[1];?>, <?php echo $expance[2];?>, <?php echo $expance[3];?>, <?php echo $expance[4];?>, <?php echo $expance[5];?>, <?php echo $expance[6];?>, <?php echo $expance[7];?>, <?php echo $expance[8];?>, <?php echo $expance[9];?>, <?php echo $expance[10];?>, <?php echo $expance[11];?>, <?php echo $expance[12];?>]

    }, {
        name: 'Sales',
        data: [<?php echo $sale_price[1];?>, <?php echo $sale_price[2];?>, <?php echo $sale_price[3];?>, <?php echo $sale_price[4];?>, <?php echo $sale_price[5];?>, <?php echo $sale_price[6];?>, <?php echo $sale_price[7];?>, <?php echo $sale_price[8];?>, <?php echo $sale_price[9];?>, <?php echo $sale_price[10];?>, <?php echo $sale_price[11];?>, <?php echo $sale_price[12];?>]

    }]
});
	</script>
	
	
	
	<?php
	  $sql_tri="SELECT sum(actual_amt) as pur_amt FROM `tbl_account` where session_login_id = '".$_SESSION['login_id']."' and sales_type = 'Purchase' and cancel_status ='0'";
    $res_tri=mysql_query($sql_tri);
    $rows=mysql_fetch_assoc($res_tri);
    $pur_amt=$rows["pur_amt"];
	if($pur_amt==''){
	$pur_amt=0;
	}
	 $sql_tri2="SELECT sum(Dr_Amt) as paid_amt FROM `tbl_account` where session_login_id = '".$_SESSION['login_id']."' and sales_type in ('Purchase','Purchase Paid') and cancel_status ='0' and clear = '1'";
    $res_tri2=mysql_query($sql_tri2);
    $rows2=mysql_fetch_assoc($res_tri2);
    $paid_amt=$rows2["paid_amt"];
	if($paid_amt==''){
	$paid_amt=0;
	}
	$pur_due = $pur_amt - $paid_amt;
	?>
	
	
	<script>
	Highcharts.chart('piechart', {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
    title: {
        text: 'Purchase Summary <br> Total Amt: <?php echo $pur_amt;?>'
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>',
                style: {
                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                }
            }
        }
    },
    series: [{
        name: 'Amount',
        colorByPoint: true,
        data: [{
            name: 'Paid Amt : <br><?php echo $paid_amt;?> <br>',
            y: <?php echo $paid_amt;?>,
            sliced: true,
            selected: true
        }, {
            name: 'Due Amt : <br> <?php echo $pur_due;?> <br>',
            y: <?php echo $pur_due;?>
        }]
    }]
});
	</script>
	<?php
	 $sql_tri3="SELECT sum(actual_amt) as sale_amt FROM `tbl_account` where session_login_id = '".$_SESSION['login_id']."' and sales_type in ('Sales','Sales_Due' ) and cancel_status ='0'";
    $res_tri3=mysql_query($sql_tri3);
    $rows3=mysql_fetch_assoc($res_tri3);
    $sale_amt=$rows3["sale_amt"];
	if($sale_amt==''){
	$sale_amt=0;
	}
	 $sql_tri4="SELECT sum(Cr_Amt) as sale_paid_amt FROM `tbl_account` where session_login_id = '".$_SESSION['login_id']."' and sales_type in ('Sales','Sale Paid') and cancel_status ='0' and clear = '1'";
    $res_tri4=mysql_query($sql_tri4);
    $rows4=mysql_fetch_assoc($res_tri4);
    $sale_paid_amt=$rows4["sale_paid_amt"];
	if($sale_paid_amt==''){
	$sale_paid_amt=0;
	}
	$sale_pur_due = $sale_amt - $sale_paid_amt;
	?>
	<script>
	Highcharts.chart('piechart2', {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
    title: {
        text: 'Sales Summary <br> Total Amt: <?php echo $sale_amt;?>'
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>',
                style: {
                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                }
            }
        }
    },
    series: [{
        name: 'Amount',
        colorByPoint: true,
        data: [{
            name: 'Recieve Amount :<br> <?php echo $sale_paid_amt;?>',
            y: <?php echo $sale_paid_amt;?>,
            sliced: true,
            selected: true
        }, {
            name: 'Due Amount : <br> <?php echo $sale_pur_due;?>',
            y: <?php echo $sale_pur_due;?>
        }]
    }]
});
	</script>
	
	<script>
	Highcharts.chart('linechart', {

    title: {
        text: 'Monthly Sale Report'
    },

    subtitle: {
        text: '2018'
    },
	 xAxis: {
        categories: [
            'Jan',
            'Feb',
            'Mar',
            'Apr',
            'May',
            'Jun',
            'Jul',
            'Aug',
            'Sep',
            'Oct',
            'Nov',
            'Dec'
        ],
        crosshair: true
    },

    yAxis: {
        title: {
            text: 'Amount'
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

   

    series: [{
        name: 'Amount',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175, 97031, 119931, 137133, 154175]
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});
	</script>
	
	<script>
	Highcharts.chart('linechart2', {

    title: {
        text: 'Solar Employment Growth by Sector, 2010-2016'
    },

    subtitle: {
        text: 'Source: thesolarfoundation.com'
    },

    yAxis: {
        title: {
            text: 'Number of Employees'
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            label: {
                connectorAllowed: false
            },
            pointStart: 2010
        }
    },

    series: [{
        name: 'Installation',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }, {
        name: 'Project Development',
        data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});
	</script>
	
	<?php
	$sql_pq="select sum(pur_qty) as pur_qty  from view_purchase_det where  session_login_id = '".$_SESSION['login_id']."' ";
				$res_pq=mysql_query($sql_pq);
				
				$row_pq=mysql_fetch_assoc($res_pq);
				$pur_qty=$row_pq['pur_qty'];
				if($pur_qty==''){$pur_qty=0;}
				$sqlret="select sum(ret_qty) as purret_qty from view_purchasereturn_det where session_login_id = '".$_SESSION['login_id']."' ";
					$exeret=mysql_query($sqlret);
					$rowsret=mysql_fetch_assoc($exeret);
					$purret_qty=$rowsret["purret_qty"];
					if($purret_qty==''){$purret_qty=0;}
					$sqlsel="select sum(qty) as sale_qty from view_sales_mstrdet where session_login_id = '".$_SESSION['login_id']."' and cancel_status=0";
					$exesel=mysql_query($sqlsel);
					$rowssel=mysql_fetch_assoc($exesel);
					$sale_qty=$rowssel["sale_qty"];
					if($sale_qty==''){$sale_qty=0;}
					$sqlselret="select sum(ret_qty) as saleret_qty from view_saleret_masdet where session_login_id = '".$_SESSION['login_id']."' ";
					$exeselret=mysql_query($sqlselret);
					$rowsselret=mysql_fetch_assoc($exeselret);
					$saleret_qty=$rowsselret["saleret_qty"];
					if($saleret_qty==''){$saleret_qty=0;}
					$sqldem="select sum(dem_qty) as dem_qty from tbl_itemdamage_details	 where session_login_id = '".$_SESSION['login_id']."' ";
					$exedem=mysql_query($sqldem);
					$rowsdem=mysql_fetch_assoc($exedem);
					$dem_qty=$rowsdem["dem_qty"];
					if($dem_qty==''){$dem_qty=0;}
					$stock=$pur_qty-$purret_qty-$sale_qty-$dem_qty+$saleret_qty;
					if($stock==''){$stock=0;}
	?>
	
	
	
	<script>
	Highcharts.chart('donutchart', {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
    title: {
        text: 'Stock Summary'
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>',
                style: {
                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                }
            }
        }
    },
    series: [{
        name: 'Qty',
        colorByPoint: true,
        data: [{
            name: 'Stock Qty :<?php echo $stock;?>',
            y: <?php echo $stock;?>,
            sliced: true,
            selected: true
        }, {
            name: 'Pur Return Qty : <?php echo $purret_qty;?>',
            y: <?php echo $purret_qty;?>
        }, {
            name: 'Sale Qty :<?php echo $sale_qty;?>',
            y: <?php echo $sale_qty;?>
        }, {
            name: 'Sale Ret Qty : <?php echo $saleret_qty;?>',
            y: <?php echo $saleret_qty;?>
        }, {
            name: 'Damage Qty : <?php echo $dem_qty;?>',
            y: <?php echo $dem_qty;?>
        }]
    }]
});
	</script>
<?php include 'footer.php' ?>
<!--<script src="../js/loader.js"></script>-->