<?php

namespace App\Models;

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

class modelSuppliers extends Model
{
    public static function selectsuppliers($code)
    {
    
        return DB::select("SELECT * FROM `suppliers` where `Code`='$code'");
    }
    
    public static function selectAccounts($code)
    {
    
        return DB::select("SELECT * FROM `otheraccounts` where `Code`='$code' and  `Name`='suppliers' ");
    }
    
    public static function savesuppliers($Regno,$Pno,$AccCode, $code,$name,$contactperson, $contact1, $contact2,$email, $Address)
    {
        return DB::insert("
        INSERT INTO `suppliers` (`Code`, `AccCode`, `SupplierCode`, `Name`, `ContactPerson`, `Contact1`, `Contact2`, `Email`, `Address`)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", [$Pno,$AccCode, $Regno.$code,$name,$contactperson, $contact1, $contact2,$email, $Address] );
    }
    
    public static function updatesuppliers($id, $Regno, $Pno, $AccCode, $code, $name, $contactperson, $contact1, $contact2, $email, $Address)
    {
        return DB::update("
            UPDATE `suppliers`
            SET  `SupplierCode` = ?, `Name` = ?, `ContactPerson` = ?, `Contact1` = ?, `Contact2` = ?, `Email` = ?, `Address` = ?
            WHERE `ID` = ? and `Code` = ?", [ $Regno . $code, $name, $contactperson, $contact1, $contact2, $email, $Address, $id,$Pno]
        );
    }
    
    public static function Deletesuppliers($id,$code)
    {
        return DB::delete("delete from `suppliers` where `Code`='$code' and `ID`='$id'");
    }
}
