<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class modelProperty extends Model
{
    public static function selectProperty($Regno)
    {

        return DB::select("SELECT * FROM `propertydetails` where `Ownerreg`='$Regno'");
    }
    public static function selectDashboard($code)
    {

        return DB::select("SELECT (select count(*) from tenants where Code='$code'  limit 1) as countTenants,(select propertydetails.Space from propertydetails where Code='$code'  limit 1) as countSpace,(select propertydetails.Floors from propertydetails where Code='$code'  limit 1) as countFloors,(select propertydetails.Rooms from propertydetails where Code='$code'  limit 1) as countRooms");
    }
    public static function saveProperty($Regno,$pcode,$saveProperty ,$address,$type, $floors, $area,$group, $rooms,$space)
    {
        return DB::insert("
        INSERT INTO `propertydetails` (`Ownerreg`, `Code`, `Name`, `Address`, `Type`, `Floors`, `Area`, `Groups`, `Rooms`, `Space`)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [$Regno, $Regno.''.$pcode, $saveProperty, $address, $type, $floors, $area, $group, $rooms, $space] );
    }

    public static function editProperty($id,$Regno,$pcode,$name ,$address,$type, $floors, $area,$group, $rooms,$space)
    {
        
        return DB::update("UPDATE `propertydetails`  SET `Code` = ?, `Name` = ?, `Address` = ?, `Type` = ?, `Floors` = ?, `Area` = ?, `Groups` = ?, `Rooms` = ?, `Space` = ? WHERE `ID` = ? AND `Ownerreg` = ?",  [$Regno.''.$pcode, $name, $address, $type, $floors, $area, $group, $rooms, $space, (int)$id, $Regno] );
    
    }

    public static function DeleteProperty($pcode,$Regno)
    {
        return DB::delete("delete from `propertydetails` where `Code`='$pcode' and `Ownerreg`='$Regno'");
    }
}
