<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Brand_model extends CI_Model {

    public function getBrands()
    {
        return $this->db
                    ->where('status', '1')
                    ->order_by('brandId', 'DESC')
                    ->get('acc_brand')
                    ->result();
    }

    public function insertBrand($data)
    {
        return $this->db->insert('acc_brand', $data);
    }

    public function updateBrand($brandId, $data)
    {
        return $this->db
                    ->where('brandId', $brandId)
                    ->update('acc_brand', $data);
    }

    // Check brand exists for Add
    public function checkBrandName($brandName)
    {
        return $this->db
                    ->where('brandName', $brandName)
                    ->where('status', '1')
                    ->get('acc_brand')
                    ->num_rows() > 0;
    }
    public function checkBrandCode($brandCode)
{
    return $this->db
                ->where('brandCode', $brandCode)
                ->where('status', '1')
                ->get('acc_brand')
                ->num_rows() > 0;
}

    // Check brand exists for Edit (ignore current brand)
    public function checkBrandNameEdit($brandName, $brandId)
    {
        return $this->db
                    ->where('brandName', $brandName)
                    ->where('status', '1')
                    ->where('brandId !=', $brandId)
                    ->get('acc_brand')
                    ->num_rows() > 0;
    }
    public function checkBrandCodeEdit($brandCode, $brandId)
{
    return $this->db
                ->where('brandCode', $brandCode)
                ->where('status', '1')
                ->where('brandId !=', $brandId)
                ->get('acc_brand')
                ->num_rows() > 0;
}
    // ngk
    // Check brand code exists for Add
// public function checkBrandCode($brandCode)
// {
//     return $this->db
//                 ->where('brandCode', $brandCode)
//                 ->where('status', '1')
//                 ->get('acc_brand')
//                 ->num_rows() > 0;
// }

// Check brand code exists for Edit (ignore current brand)
// public function checkBrandCodeEdit($brandCode, $brandId)
// {
//     return $this->db
//                 ->where('brandCode', $brandCode)
//                 ->where('status', '1')
//                 ->where('brandId !=', $brandId)
//                 ->get('acc_brand')
//                 ->num_rows() > 0;
// }
// ngk
}
?>
