<?php

/**
 * This is the model class for table "{{suppliers}}".
 *
 * The followings are the available columns in table '{{suppliers}}':
 * @property integer $id
 * @property string $supplier_name
 * @property string $phone_no
 * @property string $isActive
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_datetime
 * @property string $updated_datetime
 * @property string $email
 * @property string $Address
 * @property string $img_upload
 * @property integer $location_id
 * @property integer $country_id
 * @property integer $state_id
 */
class Suppliers extends CActiveRecord
{
	public function tableName()
	{
		return '{{suppliers}}';
	}

	public function rules()
	{
		return array(
			array('supplier_name, phone_no, location_id', 'required'),

			array('created_by, updated_by, location_id, country_id, state_id', 'numerical', 'integerOnly'=>true),

			array('supplier_name, email, img_upload', 'length', 'max'=>100),

			array('phone_no', 'length', 'max'=>20),

			array('isActive', 'length', 'max'=>1),

			array('Address', 'length', 'max'=>500),

			array('id, supplier_name, phone_no, isActive, created_by, updated_by, created_datetime, updated_datetime, email, Address, img_upload, location_id, country_id, state_id', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
			'location' => array(self::BELONGS_TO, 'Locations', 'location_id'),
			'country'  => array(self::BELONGS_TO, 'Country', 'country_id'),
			'state'    => array(self::BELONGS_TO, 'States', 'state_id'),
		);
	}

	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'supplier_name' => 'Supplier Name',
			'phone_no' => 'Phone No',
			'isActive' => 'Is Active',
			'created_by' => 'Created By',
			'updated_by' => 'Updated By',
			'created_datetime' => 'Created Datetime',
			'updated_datetime' => 'Updated Datetime',
			'email' => 'Email',
			'Address' => 'Address',
			'img_upload' => 'Img Upload',
			'location_id' => 'Location',
			
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('supplier_name',$this->supplier_name,true);
		$criteria->compare('phone_no',$this->phone_no,true);
		$criteria->compare('isActive',$this->isActive,true);
		$criteria->compare('created_by',$this->created_by);
		$criteria->compare('updated_by',$this->updated_by);
		$criteria->compare('created_datetime',$this->created_datetime,true);
		$criteria->compare('updated_datetime',$this->updated_datetime,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('Address',$this->Address,true);
		$criteria->compare('img_upload',$this->img_upload,true);
		$criteria->compare('location_id',$this->location_id);
		$criteria->compare('country_id',$this->country_id);
		$criteria->compare('state_id',$this->state_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}