/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Customers::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['customer_id' => $this->customer_id]); $query->andFilterWhere(['like', 'customer_name', $this->customer_name])->andFilterWhere(['like', 'zip_code', $this->zip_code])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'province', $this->province]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Customers::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['customer_id' => $this->customer_id]); $query->andFilterWhere(['like', 'customer_name', $this->customer_name])->andFilterWhere(['like', 'zip_code', $this->zip_code])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'province', $this->province]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { //каждому пользователю соответствуют его контрагенты if (Yii::$app->user->can('admin')) { $query = Customers::find(); } else { $query = Customers::find()->where(['user_id' => Yii::$app->user->id]); } $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->joinWith('usersUser'); $query->joinWith('typePrices'); $query->andFilterWhere(['customer_id' => $this->customer_id]); $query->andFilterWhere(['like', 'customer_name', $this->customer_name])->andFilterWhere(['like', 'user.fullname', $this->user_id])->andFilterWhere(['like', 'type_price.type_price_name', $this->typeprices_id])->andFilterWhere(['like', 'customer_email', $this->customer_email]); return $dataProvider; }
public function getCustomerList() { $customers = Customers::find()->where(['user_id' => Yii::$app->user->id])->all(); return ArrayHelper::map($customers, 'id', 'name'); }
use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model backend\models\Orders */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="orders-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'customers_customer_id')->dropDownList(ArrayHelper::map(Customers::find()->where(['user_id' => Yii::$app->user->id])->all(), 'customer_id', 'customer_name'), ['prompt' => 'Выберите контрагента...']); ?> <?php //$form->field($model, 'order_amount')->textInput(['value' => $model->order_amount / 100]) ?> <?php if (isset($amount)) { echo 'Сумма заказа: ' . $amount; } else { echo 'Сумма заказа: ' . $model->order_amount; } ?>