<?php

namespace App\Http\Controllers\HistorialPagos;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\View\View;
use Auth;
use App\Model\Prestamo;
use App\Model\TramiteUsuarioDeuda;
use App\Model\Recibo;
use Yajra\Datatables\Datatables;
use Illuminate\Support\Facades\DB;

class HistorialPagosController extends Controller
{
    public function getIndex(){
        return view('pages.historial.index');
    }

    public function getHistorialPagosTramite()
    {

        $pagos = DB::table('recibo')
            ->join('tramite_usuario','tramite_usuario.id_recibo','=','recibo.id')
            ->join('numeroserie','numeroserie.id','=','recibo.id_numeroserie')
            ->where('tramite_usuario.id_usuario','=',Auth::user()->id)
            ->select('recibo.id as id',
                     'recibo.fecha as fecha',
                     'numeroserie.serie as numeroserieN',
                     'recibo.turno as turno',
                     'recibo.monto as monto',
                     'recibo.semestre as semestre');
        return Datatables::of($pagos)->make(true);
    }

    public function getHistorialPagosBiblioteca()
    {
        $pagos = DB::table('recibo')
            ->join('mora','mora.id_recibo','=','recibo.id')
            ->join('prestamo','prestamo.id','mora.id_prestamo')
            ->join('numeroserie','numeroserie.id','recibo.id_numeroserie')
            ->where('prestamo.id_usuario','=',Auth::user()->id)
            ->select(
                'recibo.id as id',
                'recibo.fecha as fecha',
                'numeroserie.serie as numeroserieN',
                'recibo.turno as turno',
                'recibo.monto as monto',
                'recibo.semestre as semestre');

        return Datatables::of($pagos)->make(true);
    }
}
