public function search()
{
$criteria = new CDbCriteria();
$criteria->with = ['delivery', 'payment', 'client', 'status'];
$criteria->compare('t.id', $this->id);
$criteria->compare('t.name', $this->name, true);
$criteria->compare('delivery_id', $this->delivery_id);
$criteria->compare('delivery_price', $this->delivery_price);
$criteria->compare('payment_method_id', $this->payment_method_id);
$criteria->compare('paid', $this->paid);
$criteria->compare('payment_time', $this->payment_time);
$criteria->compare('payment_details', $this->payment_details, true);
$criteria->compare('total_price', $this->total_price);
$criteria->compare('total_price', $this->total_price);
$criteria->compare('discount', $this->discount);
$criteria->compare('coupon_discount', $this->coupon_discount);
$criteria->compare('separate_delivery', $this->separate_delivery);
$criteria->compare('t.status_id', $this->status_id);
$criteria->compare('date', $this->date, true);
$criteria->compare('t.user_id', $this->user_id);
$criteria->compare('phone', $this->phone, true);
$criteria->compare('email', $this->email, true);
$criteria->compare('comment', $this->comment, true);
$criteria->compare('ip', $this->ip, true);
$criteria->compare('url', $this->url, true);
$criteria->compare('note', $this->note, true);
$criteria->compare('modified', $this->modified, true);
$criteria->compare('t.manager_id', $this->manager_id);
if (null !== $this->couponId) {
$criteria->with['couponsIds'] = ['together' => true];
$criteria->addCondition('couponsIds.coupon_id = :id');
$criteria->params = CMap::mergeArray($criteria->params, [':id' => $this->couponId]);
}
if (null !== $this->name) {
$clientCriteria = new CDbCriteria();
$clientCriteria->with['client'] = ['together' => true];
$clientCriteria->addSearchCondition('client.last_name', $this->name, true, 'OR');
$clientCriteria->addSearchCondition('client.first_name', $this->name, true, 'OR');
$clientCriteria->addSearchCondition('client.middle_name', $this->name, true, 'OR');
$clientCriteria->addSearchCondition('client.nick_name', $this->name, true, 'OR');
$criteria->mergeWith($clientCriteria, 'OR');
}
return new CActiveDataProvider(__CLASS__, ['criteria' => $criteria, 'sort' => ['defaultOrder' => $this->getTableAlias() . '.id DESC']]);
}