two table and display the same days, in different tables

By | July 14, 2018
Questions:

I have 2 tables, one Maintenance and other Activities. I want to make a report according to the day and see the activities and maintenance performed by a worker that day. I have a code where I create a table according to the day and it shows the maintenance made by that work at the same time I estimate 2 hours to get a total of time worked that day.
I want to be able to add the table Activities in this report since I keep the date as in such table Maintenance, but in this table I only keep the total of hours worked.
my javascritps where I calculate the hours

  // We create variables to go through dates and group total x day
        var afecha = new Array(); var fecha = ""; var i = 0; var firsttime = 1;
        var atotal = new Array(); var total = 0; var totaltotal = 0; var contartotal = 0; var multi =0;
      $(".td-calcular").each(function (){
         var HDesde = $(this).data("inicio");
         var HHasta = $(this).data("fin");
        // you collect the value of the day and in the first entry what is assigned to the var date
         var dia = $(this).data("dia");
         if (firsttime==1) { fecha = dia; firsttime = 0; }
         hora1 = (HDesde).split(":");
         hora2 = (HHasta).split(":");
         HoraDesde=(hora1[0]);
         MinutoDesde=(hora1[1]);
         HoraHasta=(hora2[0]);
         MinutoHasta=(hora2[1]);
         TotDesde=parseInt((HoraDesde*60)) + parseInt(MinutoDesde);
         TotHasta=parseInt(HoraHasta*60) + parseInt(MinutoHasta);
         RestaHoras=(TotHasta - TotDesde);
         TotHorasTrab=(RestaHoras / 60).toFixed(2);
         $(this).html(TotHorasTrab);
         // Now at the moment you change the date you save the date and total values in two arrays and you put total to 0
         if (fecha != dia) {
        afecha[i] = fecha;
        atotal[i] = total;
        i++;
        total = 0;
     }
     fecha = dia;
         //Incrementas total
         total = parseFloat(total) + parseFloat(TotHorasTrab);
      });
      // We add the value of the last day and show results stored in the aray
      afecha[i] = fecha;
      atotal[i] = total;
      for (j=0; j<afecha.length; j++) {
         $( ".div-calcular" ).data( "calcular", atotal[j]);
          totaltotal+=atotal[j];
          alert(atotal[j]);
        }
        contartotal = afecha.length;
        multi = parseFloat(afecha.length*9);
        totalResultado = (contartotal* multi)/100;
        $('#totalhrs').html(totaltotal);
        $('#countTotal').html('  ['+contartotal+' dias ]  '+multi);
        $('#totalResultado').html(totalResultado);
          }

here my code where I create a table according to a day

 <?php if ($Maintenances ): ?>
      <?php $dates= array();
            foreach ($Maintenances as $Maintenance ) {
               $dates[$Maintenance -> date][] = $Maintenance;
            }
      ?>
      <?php foreach ($dates $date): ?>
      <table  class="table table-hover dataTable no-footer">
      <thead>
          <tr>
              <th>date</th>
              <th>work</th>
              <th>hrs start</th>
              <th>hrs end</th>
              <th>Total</th>

          </tr>
      </thead>
      <?php $subtotal ?>
      <?php   foreach ($date $Maintenance): ?>
      <tr>
          <td">

              <?php echo  date('j M Y',strtotime($Maintenance-> date)); ?>
          </td>
          <td>
              <?php echo $Maintenance-> work; ?>
          </td>
          <td>
              <?php
              $cadena = strtotime($Maintenance->start);
              $cadena = date("H:i", $cadena);
              echo $cadena;
               ?>

          </td>
          <td>
              <?php
              $cadena2 = strtotime($Maintenance->end);
              $cadena2 = date("H:i", $cadena2);
              echo $cadena2;
               ?>

          </td>
          <td class="td-calcular" data-inicio="<?php echo $Maintenance->start;?>" data-fin="<?php echo $Maintenance->end;?>" data-dia="<?php echo $Maintenance->date;?>" >
        </td>
      </tr>
      <?php endforeach; ?>
          </table>
          <div class="row">
            <div class="col-4 col-sm-9">
            </div>
            <div class="col-4 col-md-2">
              <h5> Total horas por fecha :
              <div class="div-calcular" data-calcular="">  </div> </h5>
                <h5> Horas turno :    9</h5>
                <h5> % Ocupacion por fecha: </h5>
            </div>
          </div>
      <?php endforeach; ?>
      <div class="row">
          <div class="col-4 col-sm-9">
          </div>
          <div class="col-4 col-md-2">
              <h5>Total horas :  <p id="totalhrs" ></p>  </h5>
              <h5>Horas turno : <p id="countTotal"></p> </h5>
              <h5>% Ocupacidad por fecha<p id="totalResultado"></p> </h5>
          </div>
      </div>
<?php endif; ?>

my tables Maintenance

---------------------------------------------------  
|id|work       |start   |end  |worker|date        |  
|--|-----------|--------|-----|------|------------|  
|1 |caja       |8:30    |8:32 |1     |2018-07-13  |  
|2 |baul       |8:35    |8:40 |1     |2018-07-13  |  
|3 |cofre      |8:50    |9:30 |2     |2018-07-14  |  

my tables Activities

----------------------------------------- 
|id|work       |date       |end  |worker| 
|--|-----------|-----------|-----|------|
|1 |meeting    |2018-07-13 |1.5  |1     |
|2 |shop       |2018-07-13 |1.5  |2     | 
|3 |coffee     |2018-07-14 |1    |1     | 
Answers:

Leave a Reply

Your email address will not be published. Required fields are marked *