<?php

namespace App\Models;

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

class modelProcessJournal extends Model
{
    public static function selectTenants($code)
    {

        return DB::select("SELECT  `AccCode`, `TenantCode` as Code, `Name` FROM `tenants` where `Code`='$code'");
    }


    public static function selectcurrency($code)
    {
        return DB::select("SELECT * FROM currencys where Code='$code'");

    }
    public static function selectJournalTransactions($code,$user,$src)
    {

        return DB::select("SELECT  * FROM `transactionsjob` where `Code`='$code' and Addedby='$user' and Source='$src' ");
    }
    public static function selectCustomers($code)
    {

        return DB::select("SELECT  `AccCode`, `CustomeCode` as Code, `Name` FROM `customers` where `Code`='$code'");
    }
    public static function selectSuppliers($code)
    {

        return DB::select("SELECT  `AccCode`, `SupplierCode` as Code, `Name` FROM `suppliers` where `Code`='$code'");
    }
    public static function selectGL($code)
    {

        return DB::select("SELECT  IF(subaccounts.SubCode IS NOT NULL, CONCAT(mainaccounts.AccCode, '/', subaccounts.SubCode), mainaccounts.AccCode) AS Code, IF(subaccounts.SubName IS NOT NULL, CONCAT(mainaccounts.AccName, '/', subaccounts.SubName), mainaccounts.AccName) AS Name FROM mainaccounts LEFT JOIN subaccounts ON mainaccounts.AccCode = subaccounts.AccCode and mainaccounts.Code=subaccounts.Code where mainaccounts.Code='$code'");
    }
    public static function saveJournal($Regno,$AccCode,$AccSubCode,$ContraCode,$ContraSubCode, $date,$narr,$reff, $DR,$CR,$user,$src)
    {
        return DB::insert("
        INSERT INTO `transactionsjob`(`Code`, `EntryDate`, `Narration`, `Refference`, `Accode`, `AccSubCode`, `ContraCode`, `ContraSubCode`, `DR`, `CR`, `Addedby`, `Source`)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [$Regno, $date, $narr, $reff, $AccCode, $AccSubCode, $ContraCode, $ContraSubCode, $DR, $CR, $user, $src] );
    }





}
