<?php

namespace Predial;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class FacturaPredial extends Model{

    public    $table      = "gr_factura_predial";
    protected $primaryKey = "id_unico";
    public    $timestamps = false;

    public static function obtner_factura_anterior($predio){
        try {
            $data = DB::table('gr_factura_predial')
                    ->where('predio', '=', $predio)
                    ->orderBy('id_unico', 'desc')
                    ->offset(1)
                    ->limit(1)
                    ->first();
            return $data;
        } catch (Exception $e) {
            return $e->getMessage();
        }
    }


    public static function obtnerFacturaAnterior($numero){
        try {
            $n    = $numero - 1;
            $data = DB::table('gr_factura_predial')
                        ->select('*')
                        ->where('numero', '=', $n)
                        ->firts();
            return $data;
        } catch (Exception $e) {
            return $e->getMessage();
        }
    }

    /**
     * validar_pago_factura
     *
     * Función para verificar si existen pagos con la factura
     * @author Alexander Numpaque
     * @param int $factura Id de factura
     * @return bool $xxx Variable booleana
     */
    public static function validar_pago_factura($factura){
        try {

        } catch (Exception $e) {
            return $e->getMessage();
        }
    }
}