public function search($params) { $query = Order::find(); $query->joinWith('elementsRelation'); if ($elementTypes = yii::$app->request->get('element_types')) { $query->andFilterWhere(['order_element.model' => $elementTypes])->groupBy('order.id'); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'status' => $this->status, 'promocode' => $this->promocode, 'seller_user_id' => $this->seller_user_id]); $query->andFilterWhere(['like', 'client_name', $this->client_name])->andFilterWhere(['like', 'shipping_type_id', $this->shipping_type_id])->andFilterWhere(['like', 'payment_type_id', $this->payment_type_id])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'time', $this->time]); if (yii::$app->request->get('promocode')) { $query->andWhere("promocode != ''"); $query->andWhere("promocode IS NOT NULL"); } if ($customField = yii::$app->request->get('order-custom-field')) { $orderIds = []; foreach ($customField as $id => $str) { if (!empty($str)) { if ($values = FieldValue::find()->select('order_id')->where(['field_id' => $id])->andWhere(['LIKE', 'value', $str])->all()) { foreach ($values as $value) { $orderIds[] = $value->order_id; } } } } if ($orderIds) { $query->andWhere(['order.id' => $orderIds]); } } if ($dateStart = yii::$app->request->get('date_start')) { $dateStart = date('Y-m-d', strtotime($dateStart)); if (!yii::$app->request->get('date_stop')) { $query->andWhere('DATE_FORMAT(date, "%Y-%m-%d") = :dateStart', [':dateStart' => $dateStart]); } else { $query->andWhere('date >= :dateStart', [':dateStart' => $dateStart]); } } else { if ($timeStart = yii::$app->request->get('time_start')) { $query->andWhere('date >= :timeStart', [':timeStart' => $timeStart]); } if ($timeStop = yii::$app->request->get('time_stop')) { if (urldecode($timeStop) == '0000-00-00 00:00:00') { $timeStop = date('Y-m-d H:i:s'); } $query->andWhere('date <= :timeStop', [':timeStop' => $timeStop]); } } if ($dateStop = yii::$app->request->get('date_stop')) { $dateStop = date('Y-m-d', strtotime($dateStop)); $query->andWhere('date <= :dateStop', [':dateStop' => $dateStop]); } return $dataProvider; }
public function run() { if ($this->types) { $paymentTypes = ArrayHelper::map(PaymentType::find()->where(['id' => $this->types])->all(), 'id', 'name'); } else { $paymentTypes = ArrayHelper::map(PaymentType::find()->all(), 'id', 'name'); } $report = []; $hasReport = false; foreach ($paymentTypes as $pid => $pname) { $query = Order::find()->where('date >= :dateStart AND date <= :dateStop', [':dateStart' => $this->dateStart, ':dateStop' => $this->dateStop]); $sum = $query->andWhere(['payment_type_id' => $pid])->distinct()->sum('cost'); $report[$pname] = $sum; if ($sum) { $hasReport = true; } } if (!$hasReport) { return ''; } return $this->render('report-payment-types', ['report' => $report, 'dateStart' => $this->dateStart, 'dateStop' => $this->dateStop]); }
public function actionPrintLast() { $this->layout = 'print'; $this->enableCsrfValidation = false; $model = Order::find()->orderBy('id DESC')->limit(1)->one(); $searchModel = new ElementSearch(); $params = yii::$app->request->queryParams; if (empty($params['ElementSearch'])) { $params = ['ElementSearch' => ['order_id' => $model->id]]; } $dataProvider = $searchModel->search($params); $paymentTypes = ArrayHelper::map(PaymentType::find()->all(), 'id', 'name'); $shippingTypes = ArrayHelper::map(ShippingType::find()->all(), 'id', 'name'); $fieldFind = Field::find(); return $this->render('print', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'shippingTypes' => $shippingTypes, 'fieldFind' => $fieldFind, 'paymentTypes' => $paymentTypes, 'module' => $this->module, 'model' => $model]); }
private function orderFinder() { $return = OrderModel::find(); return $this->buildQuery($return); }