This is my code, can anyone help me please? Urgent

This is my code, can anyone help me please? Urgent

GenjosanzoGenjosanzo Posts: 6Questions: 1Answers: 0

This is my code, i need help to use "total días" is the days between the 2 date in date range filter, i need to use in a tab footer callback to calculate (page total/that days), then i need to do a row count and on other tab to show on footer callback the count of the rows that table show, and use all of this value between tabs, how can i do?

``

Desde:
Hasta:
Calcular
Total días:
5

<?php $consulta3 = "SELECT * FROM ps_orders WHERE id_shop = '$ids' AND (current_state = 15 OR current_state = 19)"; $resultado3 = mysqli_query($conexion, $consulta3); while($row3 = mysqli_fetch_array($resultado3)){ echo "<tr>"; echo ""; echo "".$row3['id_order'].""; echo "".$row3['id_shop'].""; echo "".$fecha3=date("Y/m/d", strtotime($row3["date_upd"])).""; echo "".round($row3['total_paid_tax_incl'], 2).""; echo ""; } ?>
Actualizar ID Tienda Fecha Media Diaria:
Media Diaria:
<?php $consulta7 = "SELECT * FROM ps_orders WHERE id_shop = '$ids' AND current_state = 7"; $resultado7 = mysqli_query($conexion, $consulta7); while($row7 = mysqli_fetch_array($resultado7)){ echo "<tr>"; echo ""; echo "".$row7['id_order'].""; echo "".$row7['id_shop'].""; echo "".$fecha7=date("Y/m/d", strtotime($row7["date_upd"])).""; echo "".round($row7['total_paid_tax_incl'], 2).""; echo ""; } ?>
Actualizar ID Tienda Fecha Devoluciones:
Devoluciones:

</div>
</div>

```

<script type="text/javascript">
    $(document).ready(function() {
      
      $('a[data-toggle="tab"]').on( 'shown.bs.tab', function (e) {
        $.fn.dataTable.tables( {visible: true, api: true} ).columns.adjust();
      });


    $('.input-daterange').datepicker({
      format:"yyyy/mm/dd",
      autoclose: true
    })

    $.fn.dataTableExt.afnFiltering.push(
      function( oSettings, aData, iDataIndex ) {
      var iFini = document.getElementById('fini').value;
      var iFfin = document.getElementById('ffin').value;
      var iStartDateCol = 3;
      var iEndDateCol = 3;

      iFini=iFini.substring(6,10) + iFini.substring(3,5)+ iFini.substring(0,2);
      iFfin=iFfin.substring(6,10) + iFfin.substring(3,5)+ iFfin.substring(0,2);

      var datofini=aData[iStartDateCol].substring(6,10) + aData[iStartDateCol].substring(3,5)+ aData[iStartDateCol].substring(0,2);
      var datoffin=aData[iEndDateCol].substring(6,10) + aData[iEndDateCol].substring(3,5)+ aData[iEndDateCol].substring(0,2);

      if ( iFini == "" && iFfin == "" )
      {
        return true;
      }
      else if ( iFini <= datofini && iFfin === "")
      {
        return true;
      }
      else if ( iFfin >= datoffin && iFini === "")
      {
        return true;
      }
      else if (iFini <= datofini && iFfin >= datoffin)
      {
        return true;
      }
      return false;
    }
  );

     var table1 = $('#table_id').DataTable( {
        "paging":false,

        "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;
 
            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
   
            // Total over this page
            pageTotal = api
                .column( 4, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
            // Update footer
            $( api.column( 4 ).header() ).html(
                'Total: '+ Math.round(pageTotal) +' €'
            );
            $( api.column( 4 ).footer() ).html(
                + Math.round(pageTotal) +' €'
            );


        }
    } );

  
    var table3 = $('#table_id_3').DataTable({
        "paging":false,


        "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;
            
            var mediadiaria = document.getElementById('dias').value;

            // Remove the formatting to get integer data for summation

            // Total over this page
            pageTotal = api
                .column( 4, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return parseInt(a) + parseInt(b);
                }, 0 );
            

            // Update footer
            $( api.column( 4 ).header() ).html(
                'Media Diaria: '+ Math.round(pageTotal/4) +' €'
            );
            $( api.column( 4 ).footer() ).html(
                + Math.round(pageTotal/4) +' €'
            );
        }
       

    });

    var table7 = $('#table_id_7').DataTable({
      "paging":false,

        "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;

            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
         
            // Total over this page
            pageTotal = api
                .column( 4, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

            // Update footer
            $( api.column( 4 ).header() ).html(
                'Devoluciones: '+ Math.round(pageTotal) +' €'
            );
            $( api.column( 4 ).footer() ).html(
                + Math.round(pageTotal) +' €'
            );
        }

    });

    $('#fini').keyup( function() { table1.draw(); table2.draw(); table3.draw(); table7.draw(); } );
    $('#ffin').keyup( function() { table1.draw(); table2.draw(); table3.draw(); table7.draw(); } );

    function calcularDiasAusencia(fini, ffin) {
      var diaEnMils = 24 * 60 * 60 * 1000,
          desde = new Date(fini.substr(0, 10)),

          hasta = new Date(ffin.substr(0, 10)),
          diff = hasta.getTime() - desde.getTime() + diaEnMils;// +1 incluir el dia de ini
      return diff / diaEnMils;
    }

    document.getElementById('calcular').addEventListener('click', function() {
      document.getElementById('dias').innerHTML = calcularDiasAusencia(
        document.getElementById('fini').value,
        document.getElementById('ffin').value
      );
    });

} );
  </script>
 </body>
</html>
This discussion has been closed.