<?php

namespace App\Models;

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

class modelModules extends Model
{
    public static function selectcashbook($code)
    {

        return DB::select("SELECT * FROM `cashbook` where `Code`='$code'");
    }
    public static function selectcashbookByCode($code,$AccCode)
    {

        return DB::select("SELECT * FROM `cashbook` where `Code`='$code' and `AccCode`='$AccCode'");
    }
    public static function selectAccounts($code)
    {

        return DB::select("SELECT * FROM `mainaccounts` where `Code`='$code'");
    }

    public static function selectJournalsAccounts($code)
    {

        return DB::select("SELECT `ID`, `Code`, `AccCode`, `Name` as AccName FROM `journals` where `Code`='$code'");
    }
    public static function savecashbook($code,$acccode,$name)
    {
        return DB::insert("INSERT INTO `cashbook` ( `Code`, `AccCode`, `Name`) VALUES (?, ?,?)", [$code, $acccode,$name] );
    }

    public static function editcashbook($id,$code,$AccCode,$name)
    {
        return DB::insert("UPDATE  `cashbook` set  `AccCode`=? , `Name`=? where Code=? and ID=?", [$AccCode, $name,$code,$id] );
    }

    public static function deletecashbook($id,$code)
    {
        return DB::insert("DELETE FROM   `cashbook`  where Code=? and ID=?", [$code,$id] );
    }


//journals 

public static function selectjournals($code)
{

    return DB::select("SELECT * FROM `journals` where `Code`='$code'");
}
public static function selectjournalsByCode($code,$AccCode)
{

    return DB::select("SELECT * FROM `journals` where `Code`='$code' and `AccCode`='$AccCode'");
}

public static function savejournals($code,$acccode,$name)
{
    return DB::insert("INSERT INTO `journals` ( `Code`, `AccCode`, `Name`) VALUES (?, ?,?)", [$code, $acccode,$name] );
}

public static function editjournals($id,$code,$AccCode,$name)
{
    return DB::insert("UPDATE  `journals` set  `AccCode`=? , `Name`=? where Code=? and ID=?", [$AccCode, $name,$code,$id] );
}

public static function deletejournals($id,$code)
{
    return DB::insert("DELETE FROM   `journals`  where Code=? and ID=?", [$code,$id] );
}


//Other Accounts 

public static function selectotheraccounts($code)
{

    return DB::select("SELECT * FROM `otheraccounts` where `Code`='$code'");
}
public static function selectotheraccountsByCode($code,$AccCode)
{

    return DB::select("SELECT * FROM `otheraccounts` where `Code`='$code' and `Name`='$AccCode'");
}

public static function saveotheraccounts($code,$acccode,$name)
{
    return DB::insert("INSERT INTO `otheraccounts` ( `Code`, `AccCode`, `Name`) VALUES (?, ?,?)", [$code, $acccode,$name] );
}

public static function editotheraccounts($id,$code,$AccCode,$name)
{
    return DB::insert("UPDATE  `otheraccounts` set  `AccCode`=? , `Name`=? where Code=? and ID=?", [$AccCode, $name,$code,$id] );
}

public static function deleteotheraccounts($id,$code)
{
    return DB::insert("DELETE FROM   `otheraccounts`  where Code=? and ID=?", [$code,$id] );
}



}
