<?php

namespace App\Models;

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

class modelCustomer extends Model
{
    public static function selectCustomers($code)
{

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

public static function selectAccounts($code)
{

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

public static function saveCustomer($Regno,$Pno,$AccCode, $code,$name,$contactperson, $contact1, $contact2,$email, $Address)
{
    return DB::insert("
    INSERT INTO `customers` (`Code`, `AccCode`, `CustomeCode`, `Name`, `ContactPerson`, `Contact1`, `Contact2`, `Email`, `Address`)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", [$Pno,$AccCode, $Regno.$code,$name,$contactperson, $contact1, $contact2,$email, $Address] );
}

public static function updateCustomer($id, $Regno, $Pno, $AccCode, $code, $name, $contactperson, $contact1, $contact2, $email, $Address)
{
    return DB::update("
        UPDATE `customers`
        SET  `CustomeCode` = ?, `Name` = ?, `ContactPerson` = ?, `Contact1` = ?, `Contact2` = ?, `Email` = ?, `Address` = ?
        WHERE `ID` = ? and `Code` = ?", [ $Regno . $code, $name, $contactperson, $contact1, $contact2, $email, $Address, $id,$Pno]
    );
}

public static function DeleteCustomer($id,$code)
{
    return DB::delete("delete from `customers` where `Code`='$code' and `ID`='$id'");
}


}
