/** * @param $id * @return string * @throws NotFoundHttpException */ public function actionStatuses($id) { $company = Company::findOne(['id' => $id]); if (!$company) { throw new NotFoundHttpException('Invalid company id'); } if (Yii::$app->request->isAjax) { return $this->renderPartial('statuses', ['statusesProvider' => new ActiveDataProvider(['query' => Status::find()->where(['company_id' => $id]), 'sort' => false])]); } }
/** * Parse next unparsed company * @return int */ public function actionNextCompany() { $company = Company::next(); if (!$company) { $this->stdout("No companies found\n", Console::BOLD); return Controller::EXIT_CODE_ERROR; } //TODO: use queries try { $company->status = $company->parseTransactions(); } catch (ParserExceprion $e) { $company->status = ['code' => $company->status == Status::FATAL_ERROR ? Status::FATAL_ERROR : Status::ERROR, 'text' => $e->getMessage()]; } $this->stdout("Parsed {$company->name} with status {$company->status}\n", Console::BOLD); return Controller::EXIT_CODE_NORMAL; }
/** * @inheritdoc * @throws ParserExceprion */ public function parseClients() { $html = $this->getClientsPage(); $js = $html->search_noise('new RichFaces.ui.Select("accountDetailPanel:j_idt'); //get raw html with clients $clients = Parser::getJsonArray($js, 'clientSelectItems'); //debug //$clients = array(0 => array('id' => 'accountDetailPanel:j_idt77:j_idt77Item0', 'label' => '357010219510 (Sight Account - EUR - FEKOTRIS INVESTMENTS LIMITED )', 'value' => 'e0579306-ad71-4997-b9b6-c1dc0d530a96')); if (empty($clients)) { throw new ParserExceprion("Can't find clients"); } $this->status = self::OK; $this->save(); //get ID for linking $transaction = Yii::$app->db->beginTransaction(); try { foreach ($clients as $client) { if (preg_match('/^(\\d+) \\(Sight Account - (\\w+) - (.+) \\)$/', $client['label'], $m)) { $companyName = $m[3]; $currency = $m[2]; $company = new Company(); $company->name = $companyName; $company->currency = $currency; $company->risk = $company->parseRisk(); if ($company->skip) { continue; //do not add } $company->link('bank', $this); $company->params = ['hash' => $client['value'], 'htmlId' => $this->parseHtmlId($client['id']), 'raw' => $client['label']]; $company->save(); } } $transaction->commit(); } catch (ParserExceprion $e) { $transaction->rollBack(); throw $e; } return self::OK; }
/** * @return \yii\db\ActiveQuery */ public function getCompany() { return $this->hasOne(Company::className(), ['id' => 'company_id']); }
/* @var $bankProvider yii\data\ActiveDataProvider */ $this->title = Yii::$app->name; ?> <div class="main-default-index"> <div class="body-content"> <?php echo GridView::widget(['dataProvider' => $bankProvider, 'showHeader' => true, 'summary' => '', 'emptyText' => 'No banks found. Please check the config.', 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'headerOptions' => ['width' => '50']], ['header' => 'Bank', 'content' => function ($row) { $bid = $row['bid']; /* @var $bankModule \app\modules\banks\Module.php */ $bankModule = Yii::$app->getModule('banks'); $bank = $bankModule->getBank($bid); return $bank->name; }], ['header' => 'Run', 'content' => function ($row) { return $row['created_at'] ? Yii::$app->formatter->asDatetime($row['created_at']) : Html::tag('span', '', ['class' => "glyphicon glyphicon-remove text-danger"]); }, 'options' => ['width' => '200']], ['header' => 'Status', 'options' => ['width' => '50'], 'contentOptions' => ['class' => 'text-center'], 'content' => function ($row) { $glyphiconClass = $row['status'] ? 'glyphicon-ok text-success' : 'glyphicon-remove text-danger'; return Html::tag('span', '', ['class' => "glyphicon {$glyphiconClass}", 'title' => $row['status_text']]); }], ['header' => 'Companies', 'options' => ['width' => '50'], 'contentOptions' => ['class' => 'text-center'], 'content' => function ($row) { $count = Company::find()->where(['bank_id' => $row['id']])->count(); if ($count > 0) { $url = Url::toRoute(['/banks/view/companies', 'id' => $row['id']]); $count = Html::a($count, $url); } return $count; }]]]); ?> </div> </div>
/** * @return \yii\db\ActiveQuery */ public function getCompanies() { return $this->hasMany(Company::className(), ['bank_id' => 'id']); }