<?php

namespace App\Models;

use CodeIgniter\Model;

class HorasModel extends Model
{
    protected $table = 'horasprestador';
    protected $primaryKey = 'id';
    protected $useTimestamps = false;


    function getHorasRealizadas($idPrestador = null)
    {
        return $this
            ->selectSum('total_horas_truncadas', 'horas')
            ->where('idprestador', $idPrestador)
            ->first();
    }

    function getHoras($idPrestador = null)
    {
        return $this
            ->select(['dia', 'mes', 'ano', 'total_horas_truncadas'])
            ->where('idprestador', $idPrestador)
            ->where('total_horas_truncadas >', 0)
            ->orderBy('ano DESC, mes DESC, dia DESC')
            ->findAll();
    }

    function getSegundosMensuales($idPrestador = null)
    {
        return $this
            ->select(['mes', 'ano'])
            ->selectSum('total_horas_truncadas', 'segundos')
            ->where('idprestador', $idPrestador)
            ->groupby(['mes', 'ano'])
            ->findAll();
    }
}