<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\TicketInstallmentRequest;

/**
 * TicketInstallmentRequestSearch represents the model behind the search form about `common\models\TicketInstallmentRequest`.
 * 
 * 
 * @property common\models\Contract $contract
 */
class ContractRequestSearch extends TicketInstallmentRequest
{
	
	public $contract;
	
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [[ 'id_contract', 'id_ticket_installment_request', 'id_ticket', 'id_customer',  'status' ,'id_ticket_type','id_ugiro'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
      $query = TicketInstallmentRequest::find();
      
      $query->andWhere( ['ticket_installment_request.id_contract' => $this->contract->id_contract ]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        return $dataProvider;
    }
}
