<?php

/**
 * This is the model class for table "{{invoice}}".
 *
 * The followings are the available columns in table '{{invoice}}':
 * @property integer $id
 * @property integer $customer_id
 * @property string $customer_name
 * @property string $status
 * @property integer $invoice_number
 * @property string $reference_number
 * @property string $invoice_date
 * @property string $invoice_due_date
 * @property string $billing_address
 * @property string $shipping_address
 * @property string $created_by
 * @property string $total_amount
 * @property string $balance_amount
 * @property string $grand_total
 * @property string $salesperson_name
 * @property string $currency_code
 * @property string $currency_symbol
 * @property integer $salesperson_id
 * @property string $created_time
 * @property string $updated_time
 */
class Invoice extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{invoice}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id, customer_id, customer_name, status, invoice_number, reference_number, invoice_date, invoice_due_date, billing_address, shipping_address, created_by, total_amount, balance_amount, grand_total, salesperson_name, currency_code, currency_symbol, salesperson_id, created_time, updated_time', 'required'),
			array('id, customer_id, invoice_number, salesperson_id', 'numerical', 'integerOnly'=>true),
			array('customer_name, status, reference_number, created_by, salesperson_name, created_time, updated_time', 'length', 'max'=>255),
			array('billing_address, shipping_address', 'length', 'max'=>500),
			array('total_amount, balance_amount, grand_total', 'length', 'max'=>15),
			array('currency_code, currency_symbol', 'length', 'max'=>10),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, customer_id, customer_name, status, invoice_number, reference_number, invoice_date, invoice_due_date, billing_address, shipping_address, created_by, total_amount, balance_amount, grand_total, salesperson_name, currency_code, currency_symbol, salesperson_id, created_time, updated_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'customer_id' => 'Customer',
			'customer_name' => 'Customer Name',
			'status' => 'Status',
			'invoice_number' => 'Invoice Number',
			'reference_number' => 'Reference Number',
			'invoice_date' => 'Invoice Date',
			'invoice_due_date' => 'Invoice Due Date',
			'billing_address' => 'Billing Address',
			'shipping_address' => 'Shipping Address',
			'created_by' => 'Created By',
			'total_amount' => 'Total Amount',
			'balance_amount' => 'Balance Amount',
			'grand_total' => 'Grand Total',
			'salesperson_name' => 'Salesperson Name',
			'currency_code' => 'Currency Code',
			'currency_symbol' => 'Currency Symbol',
			'salesperson_id' => 'Salesperson',
			'created_time' => 'Created Time',
			'updated_time' => 'Updated Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('customer_id',$this->customer_id);
		$criteria->compare('customer_name',$this->customer_name,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('invoice_number',$this->invoice_number);
		$criteria->compare('reference_number',$this->reference_number,true);
		$criteria->compare('invoice_date',$this->invoice_date,true);
		$criteria->compare('invoice_due_date',$this->invoice_due_date,true);
		$criteria->compare('billing_address',$this->billing_address,true);
		$criteria->compare('shipping_address',$this->shipping_address,true);
		$criteria->compare('created_by',$this->created_by,true);
		$criteria->compare('total_amount',$this->total_amount,true);
		$criteria->compare('balance_amount',$this->balance_amount,true);
		$criteria->compare('grand_total',$this->grand_total,true);
		$criteria->compare('salesperson_name',$this->salesperson_name,true);
		$criteria->compare('currency_code',$this->currency_code,true);
		$criteria->compare('currency_symbol',$this->currency_symbol,true);
		$criteria->compare('salesperson_id',$this->salesperson_id);
		$criteria->compare('created_time',$this->created_time,true);
		$criteria->compare('updated_time',$this->updated_time,true);

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

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Invoice the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
