<?php
if(session_status() !== PHP_SESSION_ACTIVE) session_start();
// if( !isset( $_SESSION["user"] ) || $_SESSION["user"] == "" || !isset($_SESSION["passwd"] ) || $_SESSION["passwd"] == "" || $_SESSION["admin"] == false ) {
if( !isset( $_SESSION["user"] ) || $_SESSION["user"] == "" || !isset($_SESSION["passwd"] ) || $_SESSION["passwd"] == ""  ) {
   header("Location: index.php");
}


include_once('db_config.php');

$Title = "Generaci&oacute;n de Asientos";
$Year     = isset($_POST['year']) ? $_POST["year"]  : "";
$Month  = isset($_POST['month']) ? $_POST['month'] : "";
$Fecha = "";

$Inicio = $_SESSION["inicio"];
$Fin = $_SESSION["fin"];
$I = substr( $Inicio, 6, 4 ) . substr( $Inicio, 3, 2 ) .  substr( $Inicio, 0, 2 );
$F = substr( $Fin, 6, 4 ) . substr( $Fin, 3, 2 ) .  substr( $Fin, 0, 2 );
$Ejercicio = $_SESSION["ID_Ejercicio"];

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

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

$_SESSION["Year"] = $Year;
$_SESSION["Month"] = $Month;

include 'contableHeader.php'; 

$Actual1 = sprintf('%04d', $Year ) . sprintf('%02d', $Month ) . "01";
$Actual2 = sprintf('%04d', $Year ) . sprintf('%02d', $Month ) . sprintf('%02d', cal_days_in_month(CAL_GREGORIAN, $Month, $Year) );
?>

  <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="exportar" action="contableExportarCobranzas.php" method="post"> 
        <div class="row">
<?php
include 'contableSelector.php'; 
        echo "<button class='btn waves-effect waves-light btn col s1' style='margin-top:5px; margin-left:25px;' type='submit' name='action' >Go!</button>";
        echo "</row>";
        echo "</form>"; 
        echo "<div style='height:70px;'></div>"; 
        echo "</div>";   // page-content 
?>              

<style>
th {
 font-weight: normal;
 color: black;
}

.totals {
  color:#0277bd;
  font-weight: bold;
  font-size: 1.1em;
  font-size: 1em;
}
</style>
<?php
  $isData = false;
  $Importe_Total_Retenciones = 0;


   /* ---- Cobranzas ---- */
  $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 iva_total, sum(iva+retenciones_iva) as debito_iva from comprobantes where (operacion=8 or operacion = 116) 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, 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 iva_total, sum(iva-retenciones_iva) as debito_iva from comprobantes where (operacion=1 or operacion=116) and year(fecha)='"  . $Year . "' and month(fecha)='" . $Month . "' and comprobantes.Borrado=0 order by fecha";

//    echo $sql . "</br>";

  $result = $conn->query($sql);
  if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {
      $COIVA105 = $row["iva105"];
      $COIVA21 = $row["iva21"];
      $COIVA27 = $row["iva27"];
      $COIVAMT = $row["ivamt"];
      $CORET_IVA = $row["ret_iva"];
      $COIMPONIBLE = $row["imponible"];
      $COTOTAL_IVA = $row["total_iva"];
      $CODEBITO_IVA = $row["debito_iva"];
      $CORETENCIONES = $row["ib"];
      $CORET_GAN = $row["gan"];
      $COOTRAS = $row["otras"];
    }
    $COIMPORTE_TOTAL = $COIVA105 + $CORET_IVA + $CORETENCIONES + $COOTRAS + $CORET_GAN;
    $COIMPORTE_TOTAL = $COIVAMT + $COIVA105 + $COIVA21 + $COIVA27 + $CORETENCIONES + $COOTRAS + $COTOTAL_IVA;
   }

   /* ---- Pagos ---- */
  $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 iva_total, sum(iva+retenciones_iva) as debito_iva from comprobantes where 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, 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 iva_total, sum(iva+retenciones_iva) as debito_iva from comprobantes where (operacion=2 or operacion=7 or operacion=115) and year(fecha)='"  . $Year . "' and month(fecha)='" . $Month . "' and comprobantes.Borrado=0 order by fecha";

   $result = $conn->query($sql);
   if ($result->num_rows > 0) {

      while($row = $result->fetch_assoc()) {
         $PIVA105 = $row["iva105"];
         $PIVA21 = $row["iva21"];
         $PIVA27 = $row["iva27"];
         $PIVAMT = $row["ivamt"];
         $PRET_IVA = $row["ret_iva"];
         $PIMPONIBLE = $row["imponible"];
         $PTOTAL_IVA = $row["total_iva"];
         $PDEBITO_IVA = $row["debito_iva"];
         $PRETENCIONES = $row["ib"];
         $PRET_GAN = $row["gan"];
         $POTRAS = $row["otras"];
   
      }
      $PIMPORTE_TOTAL = $PIVA105 + $PIVA21 + $PIVA27 + $PIVAMT + $PRET_IVA + $PTOTAL_IVA + $PRETENCIONES + $POTRAS + $PRET_GAN;
      $PIMPORTE_TOTAL = $PIVA105 + $PIVA21 + $PIVA27 + $PIVAMT + $PTOTAL_IVA + $PRETENCIONES + $POTRAS + $PRET_GAN;
      $PIMPORTE_TOTAL = $PIVA105 + $PIVA21 + $PIVA27 + $PIVAMT + $PRETENCIONES + $POTRAS + $PTOTAL_IVA + $PRET_IVA + $PRET_GAN;
   }



      /* --------------------------------------------
         COBRANZAS 
       ------------------------------------------- */
      if( $COIMPORTE_TOTAL > 0 ) {
         echo "<div class='row data'>";
//         echo "<div style='height:20px;'></div>";
         echo "<div class='input-field col s3'>";
         echo "<b>ASIENTO DE COBRANZAS</b>";
         echo "</div>";
         echo "</div>";
         
//         if( ( $COIMPORTE_TOTAL - $CORET_IVA - $CORETENCIONES - $COOTRAS - $CORET_GAN ) > 0 ) {
         if( $COIMPORTE_TOTAL > 0 ) {

            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align '>";
            echo "11310000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Deudores por Ventas";
            echo "</div>";
            echo "<div class='input-field col s2 right-align offset-s2'>";
//            echo number_format ( $COIVA105 + $CORET_IVA + $CORETENCIONES + $COOTRAS + $CORET_GAN, 2, ',' ,  '.' );
            echo number_format ( $COIMPORTE_TOTAL, 2, ',' ,  '.' );
//            echo number_format ( $COIVA105, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }

/*
         if( $CORET_IVA > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11360000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones IVA";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $CORET_IVA, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }
         
         if( $CORETENCIONES > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11341000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones Ingresos Brutos";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $CORETENCIONES, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }

         if( $CORET_GAN > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11340000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones Ganancias";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $CORET_GAN, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         } 
                  
         
         if( $COOTRAS > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11342000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Otras Retenciones";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $COOTRAS, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }
         */
                  
         if( $COIMPORTE_TOTAL > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11120000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Banco";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
//            echo number_format ( $COIMPORTE_TOTAL - $COOTRAS - $CORET_GAN - $CORETENCIONES - $CORET_IVA, 2, ',' ,  '.' );
//          echo number_format ( $COIMPORTE_TOTAL - $COOTRAS - $CORETENCIONES, 2, ',' ,  '.' );
            echo number_format ( $COIMPORTE_TOTAL, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }

         echo "<div class='row data'>";
         echo "<div class='input-field col s2 right-align offset-s4 totals'>";
         echo number_format ( $COIMPORTE_TOTAL, 2, ',' ,  '.' );
         echo "</div>";
         echo "<div class='input-field col s2 right-align totals'>";
//         echo number_format ( $COIVA105 + $CORET_IVA + $CORETENCIONES + $COOTRAS + $CORET_GAN, 2, ',' ,  '.' );
//         echo number_format ( $COIVA105 + $COIVA21 + $COIVA27 + $CORETENCIONES + $COOTRAS, 2, ',' ,  '.' );
         echo number_format ( $COIMPORTE_TOTAL, 2, ',' ,  '.' );
         echo "</div>";
         echo "</div>";
      }

      /* --------------------------------------------
        PAGOS 
       ------------------------------------------- */

      if( $PIMPORTE_TOTAL > 0 ) {
         echo "<div class='row data'>";
         echo "<div class='input-field col s3'>";
         echo "<b>ASIENTO DE PAGOS</b>";
         echo "</div>";
         echo "</div>";
         
         echo "<div class='row data'>";
         echo "<div class='input-field col s1 right-align '>";
         echo "21110000";
         echo "</div>";
         echo "<div class='input-field col s3'>";
         echo "Proveedores";
         echo "</div>";
         echo "<div class='input-field col s2 right-align'>";
//       echo number_format ( $PIMPORTE_TOTAL - $PRETENCIONES - $POTRAS, 2, ',' ,  '.' );
         echo number_format ( $PIMPORTE_TOTAL, 2, ',' ,  '.' );
         echo "</div>";
         echo "</div>";
         
         /*
         if( $PRET_IVA > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11360000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones IVA";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $PRET_IVA, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }

         if( $PRETENCIONES > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11341000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones Ingresos Brutos";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $PRETENCIONES, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }

         if( $PRET_GAN > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11340000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones Ganancias";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $PRET_GAN, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }

         if( $POTRAS > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11342000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Otras Retenciones";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $POTRAS, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }
         */

         echo "<div class='row data'>";
         echo "<div class='input-field col s1 right-align'>";
         echo "11120000";
         echo "</div>";
         echo "<div class='input-field col s3'>";
         echo "Banco";
         echo "</div>";
         echo "<div class='input-field col s2 right-align offset-s2'>";
         echo number_format ( $PIMPORTE_TOTAL, 2, ',' ,  '.' );
         echo "</div>";
         echo "</div>";

         echo "<div class='row data'>";
         echo "<div class='input-field col s2 right-align offset-s4 totals'>";
//         echo number_format ( $COIMPORTE_TOTAL, 2, ',' ,  '.' );
         echo number_format ( $PIMPORTE_TOTAL, 2, ',' ,  '.' );
         echo "</div>";
         echo "<div class='input-field col s2 right-align totals'>";
//         echo number_format ( $PIVA105 + $PIVA21 + $PIVA27 + $PIVAMT + $PRET_IVA + $PTOTAL_IVA + $PRETENCIONES + $POTRAS, 2, ',' ,  '.' );
//         echo number_format ( $PIVA105 + $PIVA21 + $PIVA27 + $PIVAMT + $PRETENCIONES + $POTRAS, 2, ',' ,  '.' );
         echo number_format ( $PIMPORTE_TOTAL, 2, ',' ,  '.' );
         echo "</div>";
         echo "</div>";
      }



    echo "</div>";

    /* --- Preloader --- */
    echo "<div style='position:absolute; top: 48%; left: 46%;'>";
    echo "<div id='preloader' class='preloader-wrapper big'>";
    echo "<div class='spinner-layer spinner-blue-only'>"; 
    echo "<div class='circle-clipper left'>"; 
    echo "<div class='circle'></div>"; 
    echo "</div><div class='gap-patch'>"; 
    echo "<div class='circle'></div>"; 
    echo "</div><div class='circle-clipper right'>"; 
    echo " <div class='circle'></div>"; 
    echo "</div>"; 
    echo "</div>"; 
    echo "</div>"; 
    echo "</div>"; 

    mysqli_close($conn);
?>        
   <div class='row data'>
   <div class='input-field col offset-s5'>
   <button onclick='Generar();' class="btn waves-effect waves-light" style="margin-top:25px; margin-left: 90px; with:300px;">Generar Asientos</button>
   <div style="height:70px;"></div>
   </div>
   </div>   <!-- column --> 
   </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();


      $('#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();
   };

   function Generar() {
      var year = <?php echo json_encode($Year); ?>;
      var month = <?php echo json_encode($Month); ?>;

      if( checkEjercicio() == false ) return;

      $("#preloader").addClass('active');

//      post("contableGenerar.php", {'year': year, 'month': month });

      $.ajax({
          type: "POST",
          url: "contableGenerarCobranzas.php",
          data: {'year': year, 'month': month },
              success: function(data){
                              var msg = JSON.parse(data);
                              if( msg.status.length >= 0 ) {
                                 console.log( msg.status );
                              }    
                              $( "#preloader" ).removeClass( "active" );
                              Materialize.toast('Finalizo la Generaci&oacute;n de Asientos', 3000, 'rounded') 
                       }
      });
   }

   function normalizeDate( fecha ) {
      var normal = fecha.substr(6,4) + fecha.substr(3,2) + fecha.substr(0,2);
      return normal;
   }

   function checkEjercicio() {

      var inicio = <?php echo(json_encode($I)); ?>;
      var fin = <?php echo(json_encode($F)); ?>;
      var actual1 = <?php echo(json_encode($Actual1)); ?>;
      var actual2 = <?php echo(json_encode($Actual2)); ?>;

//      console.log( inicio );
//      console.log( fin );
//      console.log( actual1 );
//      console.log( actual2 );
      if(  actual1 >= inicio && actual1 <= fin && actual2 >= inicio && actual2 <= fin ) {
         return true;
      }
      else {
         Materialize.toast('No es posible generar los asientos.\n Las fechas deben estar comprendidas dentro del ejercicio activo.', 3000, 'rounded') 
         return false;
      }
   }

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




<?php
      /* --- IMPUESTOS ------------------------------------------------------ */
/*

//      if( $COIMPORTE_TOTAL > 0 ) {
         echo "<div class='row data'>";
         echo "<div class='input-field col s3'>";
         echo "<b>ASIENTO DE IMPUESTOS</b>";
         echo "</div>";
         echo "</div>";
         
         if( $TOTAL_IVA > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "21160000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "D&eacute;bito Fiscal";
            echo "</div>";
            echo "<div class='input-field col s2 right-align'>";
            echo number_format ( $TOTAL_IVA, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }

         if( $CTOTAL_IVA > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11361000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Cr&eacute;dito Fiscal";
            echo "</div>";
            echo "<div class='input-field col s2 right-align offset-s2'>";
            echo number_format ( $CTOTAL_IVA, 2, ',' ,  '.' );
            echo "</div>";
            echo "</div>";
         }


         if( $CRET_IVA > 0 || $CORET_IVA > 0 || $RRET_IVA > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11360000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones IVA";
            echo "</div>";
            if( $RRET_IVA > 0 ) {
               echo "<div class='input-field col s2 right-align'>";
               echo number_format ( $RRET_IVA, 2, ',' ,  '.' );
               echo "</div>";
               echo "<div class='input-field col s2 right-align'>";
//               if( $CRET_IVA + $CORET_IVA > 0 ) 
//                  echo number_format ( $CRET_IVA + $CORET_IVA, 2, ',' ,  '.' );
               if( ( $CRET_IVA - $RRET_IVA ) > 0 ) 
                  echo number_format ( $CRET_IVA - $RRET_IVA, 2, ',' ,  '.' );
            }
            else {
               echo "<div class='input-field col s2 right-align offset-s2'>";
//             echo number_format ( $CRET_IVA + $CORET_IVA, 2, ',' ,  '.' );
               echo number_format ( $CRET_IVA, 2, ',' ,  '.' );
            }
            echo "</div>";
            echo "</div>";
         }

         if( $CRET_GAN > 0 || $CORET_GAN > 0 || $RRET_GAN > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11340000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones Ganancias";
            echo "</div>";
            if( $RRET_GAN > 0 ) {
               echo "<div class='input-field col s2 right-align'>";
               echo number_format ( $RRET_GAN, 2, ',' ,  '.' );
               echo "</div>";
               echo "<div class='input-field col s2 right-align'>";
               if( $$CRET_GAN + $CORET_GAN > 0 ) 
                  echo number_format ( $CRET_GAN + $CORET_GAN, 2, ',' ,  '.' );
            }
            else {
               echo "<div class='input-field col s2 right-align offset-s2'>";
               echo number_format ( $CRET_GAN + $CORET_GAN + $RRET_GAN, 2, ',' ,  '.' );
            }
            echo "</div>";
            echo "</div>";
         }


         if( $CRETENCIONES > 0 || $CORETENCIONES > 0 || $RRETENCIONES > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11341000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Retenciones Ingresos Brutos";
            echo "</div>";
            if( $RRETENCIONES > 0 ) {
               echo "<div class='input-field col s2 right-align'>";
               echo number_format ( $RRETENCIONES, 2, ',' ,  '.' );
               echo "</div>";
               echo "<div class='input-field col s2 right-align'>";
//               if( ( $CRETENCIONES + $CORETENCIONES ) > 0 ) 
//                  echo number_format ( $CRETENCIONES + $CORETENCIONES, 2, ',' ,  '.' );
               if( ( $CRETENCIONES ) > 0 ) 
                  echo number_format ( $CRETENCIONES, 2, ',' ,  '.' );
            }
            else {
               echo "<div class='input-field col s2 right-align offset-s2'>";
//               echo number_format ( $CRETENCIONES + $CORETENCIONES, 2, ',' ,  '.' );
               echo number_format ( $CRETENCIONES, 2, ',' ,  '.' );
            }
            echo "</div>";
            echo "</div>";
         }

//       if( $COTRAS > 0 || $COOTRAS > 0 || $ROTRAS > 0 ) {
         if( $COTRAS > 0 || $ROTRAS > 0 ) {
            echo "<div class='row data'>";
            echo "<div class='input-field col s1 right-align'>";
            echo "11342000";
            echo "</div>";
            echo "<div class='input-field col s3'>";
            echo "Otras Retenciones";
            echo "</div>";

            if( $ROTRAS > 0 ) {
               echo "<div class='input-field col s2 right-align'>";
               echo number_format ( $ROTRAS, 2, ',' ,  '.' );
               echo "</div>";
               echo "<div class='input-field col s2 right-align'>";
//             if( ( $COTRAS + $COOTRAS ) > 0 ) 
//                  echo number_format ( $COTRAS + $COOTRAS, 2, ',' ,  '.' );
               if( ( $COTRAS ) > 0 ) 
                  echo number_format ( $COTRAS, 2, ',' ,  '.' );
            }
            else {
               echo "<div class='input-field col s2 right-align offset-s2'>";
//             echo number_format ( $COTRAS + $COOTRAS, 2, ',' ,  '.' );
               echo number_format ( $COTRAS, 2, ',' ,  '.' );
            }
            echo "</div>";
            echo "</div>";
         }

         $TOTAL_DIF = ( $CTOTAL_IVA + $CRET_IVA + $CRETENCIONES + $COTRAS );
         $TOTAL_DIF += ( $CORET_IVA + $CORETENCIONES + $COOTRAS + $CORET_GAN );
         $TOTAL_DIF += ( $PRET_IVA + $PRETENCIONES + $POTRAS + $PRET_GAN );

         $IMPUESTO_DEBE = $TOTAL_IVA + $RRETENCIONES + $RRET_IVA + $ROTRAS + $RRET_GAN;
         $IMPUESTO_HABER = $TOTAL_DIF;


         echo "<div class='row data'>";
         echo "<div class='input-field col s2 right-align offset-s4 totals'>";
//       echo number_format ( $TOTAL_IVA + $RRETENCIONES + $RRET_IVA + $ROTRAS + $RRET_GAN, 2, ',' ,  '.' );
         echo number_format ( $IMPUESTO_DEBE, 2, ',' ,  '.' );
         echo "</div>";
         echo "<div class='input-field col s2 right-align totals'>";
//       echo number_format ( $TOTAL_DIF + ( $TOTAL_IVA + $RRETENCIONES + $RRET_IVA + $ROTRAS + $RRET_GAN- $TOTAL_DIF ), 2, ',' ,  '.' );
         echo number_format( $IMPUESTO_HABER, 2, ',' ,  '.' );
         echo "</div>";
         echo "</div>";
//      }
*/      
?>
