<?php
if(isset ($_POST['report'])){
$dy = $_POST['dys'];
} else { 
$dy = date('Y');
}

$report1 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '01' AND status = 'confirmed' AND ano = '$dy'");
$report1s = mysql_fetch_array($report1);
$january = number_format($report1s["total"],2,'.','');

$report2 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '02' AND status = 'confirmed' AND ano = '$dy'");
$report2s = mysql_fetch_array($report2);
$february = number_format($report2s["total"],2,'.','');
	
$report3 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '03' AND status = 'confirmed' AND ano = '$dy'");
$report3s = mysql_fetch_array($report3);
$march = number_format($report3s["total"],2,'.','');	

$report4 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '04' AND status = 'confirmed' AND ano = '$dy'");
$report4s = mysql_fetch_array($report4);
$april = number_format($report4s["total"],2,'.','');	

$report5 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '05' AND status = 'confirmed' AND ano = '$dy'");
$report5s = mysql_fetch_array($report5);
$may = number_format($report5s["total"],2,'.','');	

$report6 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '06' AND status = 'confirmed' AND ano = '$dy'");
$report6s = mysql_fetch_array($report6);
$june = number_format($report6s["total"],2,'.','');	

$report7 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '07' AND status = 'confirmed' AND ano = '$dy'");
$report7s = mysql_fetch_array($report7);
$july = number_format($report7s["total"],2,'.','');	

$report8 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '08' AND status = 'confirmed' AND ano = '$dy'");
$report8s = mysql_fetch_array($report8);
$august = number_format($report8s["total"],2,'.','');	

$report9 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '09' AND status = 'confirmed' AND ano = '$dy'");
$report9s = mysql_fetch_array($report9);
$september = number_format($report9s["total"],2,'.','');

$report10 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '10' AND status = 'confirmed' AND ano = '$dy'");
$report10s = mysql_fetch_array($report10);
$october = number_format($report10s["total"],2,'.','');

$report11 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '11' AND status = 'confirmed' AND ano = '$dy'");
$report11s = mysql_fetch_array($report11);
$november = number_format($report11s["total"],2,'.','');

$report12 = mysql_query("SELECT SUM(total) as total FROM invoices WHERE mes = '12' AND status = 'confirmed' AND ano = '$dy'");
$report12s = mysql_fetch_array($report12);
$december = number_format($report12s["total"],2,'.','');

$report = mysql_query("SELECT SUM(total) as total FROM invoices WHERE status = 'confirmed' AND ano = '$dy'");
$reports = mysql_fetch_array($report);
$totalyear = number_format($reports["total"],2,'.','');

?>

    <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            <?php echo $lang['TITLE_REPORT_INVOICE']; ?> - Total Revenue <?php if(isset ($_POST['report'])){ echo $_POST['dys']; } else { echo date('Y'); } ?>
          </h1>
          
        </section>

       
       <section class="content">
          <div class="row">
            <div class="col-xs-12">
			
              <div class="box">
				  
                <div class="box-header">
					<form method="POST">
						<div class="input-group">
      <input type="number" min="2016" name="dys" value="<?php if(isset ($_POST['report'])){ echo $_POST['dys']; } else { echo date('Y'); } ?>" class="form-control" placeholder="Year">
      <span class="input-group-btn">
     <input type="submit" name="report" class="btn btn-info" value="Filter">
      </span>
    </div>
					</form>
                
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped ">
                    
					<tr>
		            <td><b>Month</b></td>
		            <td><b>Total</b></td>
		            </tr>
		            
		            <tr>
		            <td>January</td>
		            <td>$ <?php echo $january; ?> <?php echo $config['moeda']; ?> </td>
		            </tr>
					<tr>
		            <td>February</td>
		            <td>$ <?php echo $february; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>March</td>
		            <td>$ <?php echo $march; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>April</td>
		            <td>$ <?php echo $april; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>May</td>
		            <td>$ <?php echo $may; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>June</td>
		            <td>$ <?php echo $june; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>July</td>
		            <td>$ <?php echo $july; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>August</td>
		            <td>$ <?php echo $august; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>September</td>
		            <td>$ <?php echo $september; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>October</td>
		            <td>$ <?php echo $october; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>November</td>
		            <td>$ <?php echo $november; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr>
		            <td>December</td>
		            <td>$ <?php echo $december; ?> <?php echo $config['moeda']; ?>  </td>
		            </tr>
		            <tr class="info">
		            <td><strong>Total Year</strong></td>
		            <td><strong>$ <?php echo $totalyear; ?> <?php echo $config['moeda']; ?> </strong> </td>
		            </tr>
					
                  </table>
                  
                  <hr>
                  
                  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Month', 'Total'],
          ['Jan',  <?php echo $january; ?>],
          ['Feb',  <?php echo $february; ?>],
          ['Mar',  <?php echo $march; ?>],
          ['Apr',  <?php echo $april; ?>],
          ['May',  <?php echo $may; ?>],
          ['Jun',  <?php echo $june; ?>],
          ['Jul',  <?php echo $july; ?>],
          ['Ago',  <?php echo $august; ?>],
          ['Sep',  <?php echo $september; ?>],
          ['Oct',  <?php echo $october; ?>],
          ['Nov',  <?php echo $november; ?>],
          ['Dec',  <?php echo $december; ?>]
        ]);

        var options = {
          title: 'Invoice Performance',
          curveType: 'function',
          legend: { position: 'bottom' }
        };

        var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="curve_chart" style="width: 100%; height: 500px"></div>
  </body>
                  
                  
                </div><!-- /.box-body -->
              </div><!-- /.box -->
       
           </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
       
       
        
        
      </div><!-- /.content-wrapper -->
   
   
   
   
