<?php
session_start();
if( $_SESSION["user"] == "" || $_SESSION["passwd"] == "" || $_SESSION["admin"] == false ) {
   mysqli_close($conn);
   header("Location: index.php");
}


include_once('db_config.php');

$Title  = "Impuestos Anual";
$Year   = isset($_POST['dyear']) ? $_POST["dyear"]  : "";
$Month  = isset($_POST['dmonth']) ? $_POST['dmonth'] : "";
$hYear  = isset($_POST['hyear']) ? $_POST["hyear"]  : "";
$hMonth = isset($_POST['hmonth']) ? $_POST['hmonth'] : "";
$Fecha  = "";
$YS2011 = "";
$YS2012 = "";
$YS2013 = "";
$YS2014 = "";
$YS2015 = "";
$YS2016 = "";
$YS2017 = "";
$YS2018 = "";
$YS2019 = "";
$YS2020 = "";

$hYS2011 = "";
$hYS2012 = "";
$hYS2013 = "";
$hYS2014 = "";
$hYS2015 = "";
$hYS2016 = "";
$hYS2017 = "";
$hYS2018 = "";
$hYS2019 = "";
$hYS2020 = "";

if( empty($Year) ) {        
   if( $_SESSION["dYear"] != "" ) $Year = $_SESSION["dYear"];
   else {
      $Year = date("Y");
   }
}

if( empty($Month) ) {       
   if( $_SESSION["dMonth"] != "" ) $Month = $_SESSION["dMonth"];
   else {
     $Month = date("n");
   }
}

if( empty($hYear) ) {        
   if( $_SESSION["hYear"] != "" ) $hYear = $_SESSION["hYear"];
   else {
      $hYear = date("Y");
   }
}

if( empty($hMonth) ) {       
//if( $hMonth == "" ) {       
   if( $_SESSION["hMonth"] != "" ) $hMonth = $_SESSION["hMonth"];
   else {
     $hMonth = date("n");
   }
}

//echo $hYear . "<br/>";
//echo $hMonth . "<br/>";

$_SESSION["dYear"]  = $Year;
$_SESSION["dMonth"] = $Month;
$_SESSION["hYear"]  = $hYear;
$_SESSION["hMonth"] = $hMonth;

$sm  = array("", "", "", "", "", "", "", "", "", "", "", "");
$hsm = array("", "", "", "", "", "", "", "", "", "", "", "");
$sm [$Month-1]  = "selected";
$hsm[$hMonth-1] = "selected";

if( $Year == "2011")  $YS2011 = "selected";
if( $Year == "2012")  $YS2012 = "selected";
if( $Year == "2013")  $YS2013 = "selected";
if( $Year == "2014")  $YS2014 = "selected";
if( $Year == "2015")  $YS2015 = "selected";
if( $Year == "2016")  $YS2016 = "selected";
if( $Year == "2017")  $YS2017 = "selected";
if( $Year == "2018")  $YS2018 = "selected";
if( $Year == "2019")  $YS2019 = "selected";
if( $Year == "2020")  $YS2020 = "selected";

if( $hYear == "2011")  $hYS2011 = "selected";
if( $hYear == "2012")  $hYS2012 = "selected";
if( $hYear == "2013")  $hYS2013 = "selected";
if( $hYear == "2014")  $hYS2014 = "selected";
if( $hYear == "2015")  $hYS2015 = "selected";
if( $hYear == "2016")  $hYS2016 = "selected";
if( $hYear == "2017")  $hYS2017 = "selected";
if( $hYear == "2018")  $hYS2018 = "selected";
if( $hYear == "2019")  $hYS2019 = "selected";
if( $hYear == "2020")  $hYS2020 = "selected";

include 'contableHeader.php'; 
?>
  <link type="text/css" rel="stylesheet" href="styles/styles_100.css"  media="screen,projection"/> 
  <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <div id="content">
  <div class="container" style="width:90%" >
    <div style="height: 15px;"></div>
    <div class="col l9 m12 s12">
      <div class="page-content">
        <div style="height:20px;"></div>
        <form id="iva" action="contableImpuestos.php" method="post"> 
        <div class="row">
         <div class="input-field col s2">
            <select name="dmonth">
 <?php
            echo "<option value='' disabled>Seleccione el Mes</option>";        
                echo "<option value='1' " . $sm[0] . ">Enero</option>";
                echo "<option value='2' " . $sm[1] . ">Febrero</option>";
                echo "<option value='3' " . $sm[2] . ">Marzo</option>";
                echo "<option value='4' " . $sm[3] . ">Abril</option>";
                echo "<option value='5' " . $sm[4] . ">Mayo</option>";
                echo "<option value='6' " . $sm[5] . ">Junio</option>";
                echo "<option value='7' " . $sm[6] . ">Julio</option>";
                echo "<option value='8' " . $sm[7] . ">Agosto</option>";
                echo "<option value='9' " . $sm[8] . ">Septiembre</option>";
                echo "<option value='10' " . $sm[9] . ">Octubre</option>";
                echo "<option value='11' " . $sm[10] . ">Noviembre</option>";
                echo "<option value='12' " . $sm[11] . ">Diciembre</option>";
?>                
            </select>
            <label>Desde Mes</label>
         </div>      
         <div class="input-field col s2">
              <select  name="dyear">
              <option value="" disabled selected>Seleccione el A&ntilde;o</option>
<?php
                echo "<option value='2011' " . $YS2011 . ">2011</option>";
                echo "<option value='2012' " . $YS2012 . ">2012</option>";
                echo "<option value='2013' " . $YS2013 . ">2013</option>";
                echo "<option value='2014' " . $YS2014 . ">2014</option>";
                echo "<option value='2015' " . $YS2015 . ">2015</option>";
                echo "<option value='2016' " . $YS2016 . ">2016</option>";
                echo "<option value='2017' " . $YS2017 . ">2017</option>";
                echo "<option value='2018' " . $YS2018 . ">2018</option>";
                echo "<option value='2019' " . $YS2019 . ">2019</option>";
                echo "<option value='2020' " . $YS2020 . ">2020</option>";
?>              
              </select>
              <label>Desde A&ntilde;o</label>
         </div>    


 <?php
         echo "<div class='row'>";
         echo "<div class='input-field col s2'>"; 
            echo "<select name='hmonth'>"; 
            echo "<option value='' disabled>Seleccione el Mes</option>";        
                echo "<option value='1' " . $hsm[0] . ">Enero</option>";
                echo "<option value='2' " . $hsm[1] . ">Febrero</option>";
                echo "<option value='3' " . $hsm[2] . ">Marzo</option>";
                echo "<option value='4' " . $hsm[3] . ">Abril</option>";
                echo "<option value='5' " . $hsm[4] . ">Mayo</option>";
                echo "<option value='6' " . $hsm[5] . ">Junio</option>";
                echo "<option value='7' " . $hsm[6] . ">Julio</option>";
                echo "<option value='8' " . $hsm[7] . ">Agosto</option>";
                echo "<option value='9' " . $hsm[8] . ">Septiembre</option>";
                echo "<option value='10' " . $hsm[9] . ">Octubre</option>";
                echo "<option value='11' " . $hsm[10] . ">Noviembre</option>";
                echo "<option value='12' " . $hsm[11] . ">Diciembre</option>";
            echo "</select>"; 
            echo "<label>Hasta Mes</label>"; 
         echo "</div>";       
         echo "<div class='input-field col s2'>"; 
              echo "<select  name='hyear'>"; 
              echo "<option value='' disabled selected>Seleccione el A&ntilde;o</option>";
                echo "<option value='2011' " . $hYS2011 . ">2011</option>";
                echo "<option value='2012' " . $hYS2012 . ">2012</option>";
                echo "<option value='2013' " . $hYS2013 . ">2013</option>";
                echo "<option value='2014' " . $hYS2014 . ">2014</option>";
                echo "<option value='2015' " . $hYS2015 . ">2015</option>";
                echo "<option value='2016' " . $hYS2016 . ">2016</option>";
                echo "<option value='2017' " . $hYS2017 . ">2017</option>";
                echo "<option value='2018' " . $hYS2018 . ">2018</option>";
                echo "<option value='2019' " . $hYS2019 . ">2019</option>";
                echo "<option value='2020' " . $hYS2020 . ">2020</option>";
              echo "</select>"; 
              echo "<label>Hasta A&ntilde;o</label>"; 
         echo "</div>";     
?>              
         <button class="btn waves-effect waves-light btn col s1" style="margin-top:5px; margin-left:30px;" type="submit" name="action" >Go!</button>
        </row>  
        </form>
        <div style="height:70px;"></div>
      </div>  <!-- page-content --> 
<style>
th {
 font-weight: normal;
 color: black;
}
.row {
   line-height:1em;
}

</style>
<?php
  $isData = false;
  $xor = 0;

   echo "<div style='height:30px;'></div>";
   echo "<table id='detail' class='highlight' style='color:grey; font-weight:normal;'>";
   echo "<thead>";
   echo "<tr>";
     echo "<div class='row data grey lighten-2' style='padding-top:10px; padding-bottom:10px; height:40px;'>";
     echo "<div class='col s1 right-align' style='border-radius:0; text-decoration:underline; width:12%;'>Periodo</div>";
     echo "<div class='col s2 right-align' style='border-radius:0; text-decoration:underline; width:12%;'>Debito IVA</div>";
     echo "<div class='col s2 right-align' style='border-radius:0; text-decoration:underline; width:12%;'>Credito IVA</div>";
     echo "<div class='col s2 right-align' style='border-radius:0; text-decoration:underline; width:12%;'>Saldo IVA</div>";
     echo "<div class='col s2 right-align' style='border-radius:0; text-decoration:underline; width:12%;'>Ret.IIBB</div>";
     echo "<div class='col s2 right-align' style='border-radius:0; text-decoration:underline; width:12%;'>Ret.IVA</div>";
     echo "<div class='col s2 right-align' style='border-radius:0; text-decoration:underline; width:12%;'>Ret.Ganancias</div>";
     echo "<div class='col s2 right-align' style='border-radius:0; text-decoration:underline; width:12%;'>Otras Ret.</div>";
   echo "</div>";
   echo "</tr>"; 
   echo "</thead>"; 
   echo "<tbody />"; 
   echo "</table>"; 

   $T_IMPONIBLE = $T_CIMPONIBLE = $T_RETENCIONES = $T_RET_IVA = $T_RET_GAN = $T_OTRAS = 0;

   /* Debito IVA */
  for( $y = $Year; $y <= $hYear; $y++, $Month = 1 ) {

      if( $y != $hYear ) $mMonth = 12;
      else $mMonth = $hMonth;

     for( $i = $Month; $i <= $mMonth; $i++ ) {
//         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, sum(iva_105) as iva105,sum(iva_21) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum( (iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100) )  as total_iva, sum( iva )   as debito_iva from comprobantes where operacion=1 and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
//         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, sum(iva_105) as iva105,sum(iva_21) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum( (iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100) )  as total_iva, sum( iva   as debito_iva from comprobantes where (operacion=1 or operacion=6) and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
//         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, sum(iva_105) as iva105,sum( case when operacion = 1 then iva_21 else (-iva_21) end ) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum( case when operacion = 1 then (iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100) else ((iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100)) *-1 end )  as total_iva, sum( case when operacion = 1 then iva else (iva*-1) end ) as iva_total, sum(iva-retenciones_iva) as debito_iva from comprobantes where (operacion=1 or operacion=6) and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
          $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, sum(iva_105) as iva105,sum( case when operacion = 1 then iva_21 else (-iva_21) end ) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum( case when operacion = 1 then (iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100) else ((iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100)) *-1 end )  as total_iva, sum( case when operacion = 1 then iva else (iva*-1) end ) as iva_total, sum(iva-retenciones_iva) as debito_iva from comprobantes where (operacion=1 or operacion=7) and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
//         echo $sql . "<br/>";
         $result = $conn->query($sql);
         if ($result->num_rows > 0) {

            console.log( $result->num_rows  );
            while($row = $result->fetch_assoc()) {
               $IVA105 = $row["iva105"];
               $IVA21 = $row["iva21"];
               $IVA27 = $row["iva27"];
               $IVAMT = $row["ivamt"];
               $RET_IVA = $row["ret_iva"];
               $IMPONIBLE = $row["imponible"];
               $TOTAL_IVA = $row["total_iva"];
               $DEBITO_IVA = $row["debito_iva"];
               $RET_GAN = $row["gan"];
               $RETENCIONES = $row["ib"];
               $OTRAS = $row["otras"];
      
               $T_IMPONIBLE += $TOTAL_IVA;
               $T_RET_IVA -= $CRET_IVA;
               $T_RETENCIONES -= $RETENCIONES;
               $T_RET_GAN -= $RET_GAN;
               $T_OTRAS -= $OTRAS;
            }
         }

/*
         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, sum(iva_105) as iva105,sum(iva_21) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum( (iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100) )  as total_iva, sum( iva )   as debito_iva from comprobantes where operacion=6 and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
         $result = $conn->query($sql);
         if ($result->num_rows > 0) {
   
            while($row = $result->fetch_assoc()) {
               $IVA105 -= $row["iva105"];
               $IVA21 -= $row["iva21"];
               $IVA27 -= $row["iva27"];
               $IVAMT -= $row["ivamt"];
               $RET_IVA -= $row["ret_iva"];
               $IMPONIBLE -= $row["imponible"];
               $TOTAL_IVA -= $row["total_iva"];
               $DEBITO_IVA -= $row["debito_iva"];
               $RET_GAN -= $row["gan"];
               $RETENCIONES -= $row["ib"];
               $OTRAS -= $row["otras"];
      
               $T_IMPONIBLE -= $TOTAL_IVA;
               $T_RET_IVA += $CRET_IVA;
               $T_RETENCIONES += $RETENCIONES;
               $T_RET_GAN += $RET_GAN;
               $T_OTRAS += $OTRAS;
            }
         }
         */
   
         /* Credito IVA */
//         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, 0 as iva105,sum(iva_21) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum((iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100)) as total_iva, sum(iva) as iva_total, sum(iva+retenciones_iva) as debito_iva from comprobantes where (operacion=2 or operacion=7 or operacion=5 or operacion = 8 or operacion = 9) and year(fecha)='"  . $Year . "' and month(fecha)='" . $Month . "' and comprobantes.Borrado=0 order by fecha";
         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, 0 as iva105,sum(iva_21) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum((iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100)) as total_iva, sum(iva) as iva_total, sum(iva+retenciones_iva) as debito_iva from comprobantes where (operacion=2 or operacion=7 or operacion=5 or operacion = 8 or operacion = 9) and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, 0 as iva105,sum(iva_21) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum((iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100)) as total_iva, sum(iva) as iva_total, sum(iva+retenciones_iva) as debito_iva from comprobantes where (operacion=2 or operacion=7 or operacion=5 or operacion=6) and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, 0 as iva105,sum(iva_21) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum((iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100)) as total_iva, sum(iva) as iva_total, sum(iva+retenciones_iva) as debito_iva from comprobantes where (operacion=2 or operacion=5 or operacion=6) and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
         $result = $conn->query($sql);
         if ($result->num_rows > 0) {
      
            while($row = $result->fetch_assoc()) {
               $CIVA105 = $row["iva105"];
               $CIVA21 = $row["iva21"];
               $CIVA27 = $row["iva27"];
               $CIVAMT = $row["ivamt"];
               $CRET_IVA = $row["ret_iva"];
               $CIMPONIBLE = $row["imponible"];
               $CTOTAL_IVA = $row["total_iva"];
               $CDEBITO_IVA = $row["debito_iva"];
               $CRETENCIONES = $row["ib"];
               $COTRAS = $row["otras"];
               $CRET_GAN = $row["gan"];
         
               $T_CIMPONIBLE += $CTOTAL_IVA;
               $T_RET_IVA += $CRET_IVA;
               $T_RETENCIONES += $CRETENCIONES;
               $T_RET_GAN += $CRET_GAN;
               $T_OTRAS += $COTRAS;
            }
         }

         /* --- Cobranzas & Pagos --- */
         $sql = "select sum(retenciones) as ib, sum(Retenciones_Ganancias) as gan, sum(op_exentas+otras_retenciones) as otras, 0 as iva105,sum(iva_21) as iva21, sum(iva_27) as iva27,sum(iva_mt) as ivamt,sum(retenciones_iva) as ret_iva,sum(iva_105+iva_21+iva_27+iva_mt) as imponible,sum((iva_105*10.5/100)+(iva_21*21/100)+(iva_27*27/100)) as total_iva, sum(iva) as iva_total, sum(iva+retenciones_iva) as debito_iva from comprobantes where (operacion=8 or operacion=9) and year(fecha)='"  . $y . "' and month(fecha)='" . $i . "' and comprobantes.Borrado=0 order by fecha";
         $result = $conn->query($sql);
         if ($result->num_rows > 0) {
      
            while($row = $result->fetch_assoc()) {
               $CRET_IVA += $row["ret_iva"];
               $CRETENCIONES += $row["ib"];
               $COTRAS += $row["otras"];
               $CRET_GAN += $row["gan"];
         
               $T_RET_IVA += $CRET_IVA;
               $T_RETENCIONES += $CRETENCIONES;
               $T_RET_GAN += $CRET_GAN;
               $T_OTRAS += $COTRAS;
            }
         }


         if( $xor ^= 1 ) 
            echo "<div class='row data blue-grey lighten-5'>";
         else echo "<div class='row data'>";
         echo "<div class='input-field col s1 right-align' style='width:12%;'>" . $i . "/" . $y . "</div>";
         echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $TOTAL_IVA, 2, ',' ,  '.' ) . "</div>";
         echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $CTOTAL_IVA, 2, ',' ,  '.' ) . "</div>";
         echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $TOTAL_IVA - $CTOTAL_IVA, 2, ',' ,  '.' ) . "</div>";
         echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( ($CRETENCIONES - $RETENCIONES), 2, ',' ,  '.' ) . "</div>";
         echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( ($CRET_IVA - $RET_IVA), 2, ',' ,  '.' ) . "</div>";
         echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( ($CRET_GAN - $RET_GAN), 2, ',' ,  '.' ) . "</div>";
         echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( ($COTRAS - $OTRAS), 2, ',' ,  '.' ) . "</div>";
         echo "</div>";
      }
      $Month = 1;
   }

   echo "<div class='row data blue-grey white-text'>";
   echo "<div class='input-field col s1 right-align' style='width:12%;'></div>";
   echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $T_IMPONIBLE, 2, ',' ,  '.' ) . "</div>";
   echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $T_CIMPONIBLE, 2, ',' ,  '.' ) . "</div>";
   echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $T_IMPONIBLE - $T_CIMPONIBLE, 2, ',' ,  '.' ) . "</div>";
   echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $T_RETENCIONES, 2, ',' ,  '.' ) . "</div>";
   echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $T_RET_IVA, 2, ',' ,  '.' ) . "</div>";
   echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $T_RET_GAN, 2, ',' ,  '.' ) . "</div>";
   echo "<div class='input-field col s2 right-align' style='width:12%;'>" . number_format( $T_OTRAS, 2, ',' ,  '.' ) . "</div>";
   echo "</div>";

    mysqli_close($conn);
?>        
   </div>   <!-- column --> 
   <div style="height:100px;"></div>
   </div>            <!-- container --> 
   </div>            <!-- content -->

   <script type="text/javascript" src="js/jquery.min.js"></script>
   <script type="text/javascript" src="js/jquery.form.js"></script> 
   <script type="text/javascript" src="materialize/1.0.0/js/materialize.min.js"></script>
   <script src="js/numeral.min.js"></script>
   <script src="js/jquery.maskedinput.min.js" type="text/javascript"></script>
<script>

   $(document).ready(function() {
      $('.dropdown-trigger').dropdown({
         "hover": true,
         "constrainWidth": false,
         "coverTrigger": false
      });
      $('select').formSelect();

      $('.datepicker').datepicker({
         selectMonths: true, // Creates a dropdown to control month
         selectYears: 10, // Creates a dropdown of 15 years to control year
         monthsFull: [ 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre' ],
         monthsShort: [ 'Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic' ],
         weekdaysFull: [ 'Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado' ],
         weekdaysShort: [ 'Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab' ],
         weekdaysLetter: [ 'D', 'L', 'M', 'M', 'J', 'V', 'S' ],
         today: 'Hoy',
         clear: 'Borrar',
         close: 'Cerrar',
         format: 'dd-mm-yyyy',
         formatSubmit: 'yyyy-mm-dd'
       });

      $('#month').on('change', function() {
         Month = this.value;
         console.log( this.value )
      });   
      $('#year').on('change', function() {
         Year = this.value;
         console.log( this.value )
      });   
   });   

   // Post to the provided URL with the specified parameters.
   function post(path, parameters) {
      var form = $('<form></form>');

       form.attr("method", "post");
       form.attr("action", path);

       $.each(parameters, function(key, value) {
           var field = $('<input></input>');
           field.attr("type", "hidden");
           field.attr("name", key);
           field.attr("value", value);
           form.append(field);
       });

       // The form needs to be a part of the document in
       // order for us to be able to submit it.
       $(document.body).append(form);
      form.submit();
   };

</script>
</body>
</html>

