public function testGenerate() { $xml = simplexml_load_file(Yii::getAlias('@data') . '/mts_report.xml', MTSXML::className()); $report = Report::generate($xml); $this->tester->assertTrue($report instanceof Report); //codecept_debug(ReportSearch::getOperatorItems()); //$report = new Report(); //codecept_debug( Yii::$app->formatter->asDate(mktime(null,null,null,1,1,2015),'LLLL yyyy')); //codecept_debug(); //Report::find(); }
/** * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = ReportItem::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['employee' => SORT_ASC]]]); if (!$this->load($params) || !$this->validate()) { $query->where(['1' => false]); return $dataProvider; } /** @var Report $report */ $report = Report::findOne(['operatorId' => $this->operatorId, 'period' => $this->_period]); $query->andWhere(['reportId' => $report->primaryKey]); $query->andWhere(['or', ['number' => ['$in' => $this->_numbers]], ['employee' => ['$in' => $this->_employees]]]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Report::find(); $query->orderBy(['period.year' => SORT_DESC, 'period.month' => SORT_DESC]); $query->with('operator'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false]); $this->load($params); if (!$this->validate()) { $query->where(['1' => false]); return $dataProvider; } if ($this->year !== self::YEAR_ALL) { $query->andWhere(['period.year' => $this->year]); } if ($this->operator !== self::OPERATOR_ALL) { $query->andWhere(['operatorId' => Operator::findOne($this->operator)->getPrimaryKey()]); } return $dataProvider; }
public function actionNumbers() { if ($this->deleteReports) { $this->cleanCollection(Report::collectionName()); $this->cleanCollection(ReportItem::collectionName()); } $this->actionOperators(); $query = (new Query())->from($this->numberTableName); $this->stdout("Загружаю номера\n", Console::FG_BLUE, Console::BOLD); $this->stdout("Источник: таблица '{$this->numberTableName}' " . $query->count() . " записей.\nЦелевая коллекция: '" . Number::collectionName() . "'\n"); $this->cleanCollection(Number::collectionName()); $count = 0; foreach ($query->all() as $item) { $number = new Number(['number' => $item['number']]); $number->ownerId = (int) $item['owner_id']; $number->operatorId = $this->operatorJunction[$item['operator_id']]; $number->destination = $item['type'] == '1' ? Number::DESTINATION_PHONE : Number::DESTINATION_MODEM; $number->limit = $item['limit'] == '0' || $item['limit'] === null ? null : (int) $item['limit']; $options = []; if ($item['rent_date'] === null && $number->limit === null) { $options[] = Number::OPTION_TRIP; } if ($number->limit !== null && $item['accounting'] == '1') { $options[] = Number::OPTION_ACCOUNTING; } $number->options = $options; $history = []; if ($item['rent_date'] !== null && $item['owner_id'] !== null) { $history[] = ['rentDate' => new MongoDate((int) $item['rent_date']), 'ownerId' => (int) $item['owner_id']]; } $number->history = $history; $number->comment = $item['comment']; if ($number->save(false)) { $count++; } } $this->stdout("Успешно загружено {$count} записей\n", Console::BOLD, Console::FG_GREEN); $this->stdout("\n"); $this->actionDocuments(); return Controller::EXIT_CODE_NORMAL; }
/** * Finds the Report model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Report the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Report::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('Запрашиваемый отчет не найден.'); } }
/** * @param OperatorXML $xml * @return Report|null */ public static function generate(OperatorXML $xml) { $operator = Operator::findOne(['contract' => $xml->getContract()]); $operatorId = $operator !== null ? $operator->getPrimaryKey() : null; $period = ['month' => $xml->getMonth(), 'year' => $xml->getYear()]; $report = self::findOne(['operatorId' => $operatorId, 'period' => $period]); if (!$report instanceof Report) { $report = new Report(); $report['operatorId'] = $operatorId; $report['period'] = $period; } else { $report->outSideDb = []; $report->outSideOperator = []; } if (!$report->save()) { return null; } $report->unlinkAll('items', true); $outSideOperator = Number::find()->where(['operatorId' => $report->operatorId])->indexBy('number')->all(); $outSideDB = []; foreach ($xml->getItems() as $item) { $number = $item['number']; if (array_key_exists($number, $outSideOperator)) { $report->addItem($outSideOperator[$number], $item['expenditure']); unset($outSideOperator[$number]); } else { $outSideDB[] = $item; } } $report->outSideOperator = array_map(function ($item) { return ['number' => $item->number, 'id' => $item->getPrimaryKey()]; }, array_values($outSideOperator)); $report->outSideDb = $outSideDB; $report->save(false); return $report; }
public function getReport() { return $this->hasOne(Report::className(), ['_id' => 'reportId']); }