Skip to content

Commit

Permalink
Print Applications Admin and User panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaniot committed Oct 19, 2017
1 parent 5056e53 commit 7d31bf3
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 27 deletions.
80 changes: 79 additions & 1 deletion controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
use app\models\Application;
use app\models\Applicant;
use app\models\Choice;
use app\models\Prefecture;
use League\Csv\Writer;
use yii\data\ArrayDataProvider;
use kartik\mpdf\Pdf;

class AdminController extends \yii\web\Controller
{
Expand Down Expand Up @@ -101,7 +104,7 @@ public function actionOverview()

$choices = Choice::find()
->count();

return $this->render('overview', compact(['dataProvider', 'applicants', 'applications', 'choices']));
}

Expand Down Expand Up @@ -152,4 +155,79 @@ public function actionExportCsv()
$csv->output('ΑΙΤΗΣΕΙΣ-' . date('Y-m-d') . '.csv');
\Yii::$app->end();
}

public function actionViewApplications()
{
$dataProvider = new ArrayDataProvider(['allModels' => Applicant::find()->joinWith([
'applications' => function (\yii\db\ActiveQuery $query) {
$query->andWhere(['deleted' => 0])->count() >0;
}
])->all()]);

return $this->render('view-applications', ['users' => $dataProvider,
'pagination' => ['pageSize' => 100],
'sort' => ['attributes' => ['vat', 'identity', 'specialty']],
]);
}

public function actionPrintApplications($applicantId = null)
{
if(isset($applicantId) && is_numeric($applicantId) && intval($applicantId))
$users[0] = Applicant::findOne(['id' => $applicantId]);
else
$users = Applicant::find()->joinWith(['applications' => function (\yii\db\ActiveQuery $query) {
$query->andWhere(['deleted' => 0])->count() >0;}])->all();

for($j = 0; $j < count($users); $j++){
$choices = $users[$j]->applications;

// if no application exists, forward to create
if (count($choices) == 0) {
Yii::$app->session->addFlash('info', "Δεν υπάρχει αποθηκευμένη αίτηση. Μπορείτε να υποβάλλετε νέα αίτηση.");
return $this->redirect(['apply']);
}

$choicesArray = \yii\helpers\ArrayHelper::toArray($choices);

for($i = 0; $i < count($choicesArray); $i++){
$choiceActRec = Choice::findOne(['id' => $choicesArray[$i]['choice_id']]);
$prefectureId = $choiceActRec->prefecture_id;
$choicesArray[$i]['Position'] = $choiceActRec->position;
$choicesArray[$i]['PrefectureName'] = Prefecture::findOne(['id' => $prefectureId])->prefecture;
$choicesArray[$i]['RegionName'] = Prefecture::findOne(['id' => $prefectureId])->region;
}

$provider = new \yii\data\ArrayDataProvider([
'allModels' => $choicesArray
]);


$data[$j]['user'] = $users[$j];
$data[$j]['provider'] = $provider;
}

$content = $this->renderPartial('../application/print', ['data' => $data]);
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'filename' => 'aitisi.pdf',
'destination' => Pdf::DEST_DOWNLOAD,
'content' => $content,
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline' => '.kv-heading-1{font-size:18px}',
'options' => ['title' => 'Περιφερειακή Διεύθυνση Πρωτοβάθμιας και Δευτεροβάθμιας Εκπαίδευσης Κρήτης'],
'methods' => [
'SetHeader'=>['Περιφερειακή Διεύθυνση Πρωτοβάθμιας και Δευτεροβάθμιας Εκπαίδευσης Κρήτης'],
'SetFooter'=>['Σελίδα: {PAGENO} από {nb}'],
]
]);

return $pdf->render();
}

private function printApplications($applicants)
{
}
}
26 changes: 10 additions & 16 deletions controllers/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function behaviors()
[
'actions' => ['my-application'],
'allow' => true,
'roles' => ['@'],
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return false === \Yii::$app->user->identity->isAdmin();
}
Expand Down Expand Up @@ -89,10 +89,9 @@ public function actionIndex()
*/
public function actionMyApplication($printMode = 0)
{
$user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]);
$user = Applicant::findOne(['vat' => \Yii::$app->user->getIdentity()->vat, 'specialty' => \Yii::$app->user->getIdentity()->specialty]);

$choices = $user->applications;
//$prefectrs_prefrnc_model = PrefecturesPreference::find()->where(['applicant_id' => $user->id])->orderBy('order')->all();
//$prefectrs_choices_model = Choice::classname();

// if no application exists, forward to create
if (count($choices) == 0) {
Expand All @@ -109,20 +108,16 @@ public function actionMyApplication($printMode = 0)
$choicesArray[$i]['PrefectureName'] = Prefecture::findOne(['id' => $prefectureId])->prefecture;
$choicesArray[$i]['RegionName'] = Prefecture::findOne(['id' => $prefectureId])->region;
}
//echo "<pre>"; print_r($choicesArray); echo "</pre>"; die();

$provider = new \yii\data\ArrayDataProvider([
'allModels' => $choicesArray,
'pagination' => [
'pageSize' => 100,
],
'allModels' => $choicesArray
]);

if($printMode == 1){
$data[0]['user'] = $user;
$data[0]['provider'] = $provider;
$content = $this->renderPartial('print', [
'user' => $user,
'dataProvider' => $provider,
'enable_applications' => (\app\models\Config::getConfig('enable_applications') === 1)
'data' => $data,
]);

// setup kartik\mpdf\Pdf component
Expand All @@ -141,8 +136,7 @@ public function actionMyApplication($printMode = 0)
'SetFooter'=>['Σελίδα: {PAGENO} από {nb}'],
]
]);

// return the pdf output as per the destination setting

return $pdf->render();
}

Expand Down Expand Up @@ -173,7 +167,7 @@ public function actionApply()
$prefectures_choices = [];
$counter = 1;

if($user->applications){
if($user->applications){ // Edit, if the user has already applied
foreach ($prefectrs_prefrnc_model as $preference) {
$userChoices = $user->getApplications()->all();
$prefectures_choices[$preference->getPrefectureName()] = $preference->prefect_id;
Expand All @@ -186,7 +180,7 @@ public function actionApply()
}
}
}
else{
else{ // Make new application, if the user has not already applied
foreach ($prefectrs_prefrnc_model as $preference) {
$choices = Choice::getChoices($preference->prefect_id, $user->specialty);
$prefectures_choices[$preference->getPrefectureName()] = $preference->prefect_id;
Expand Down
10 changes: 10 additions & 0 deletions views/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
<p class="text-danger">Προσοχή! Η ενέργεια αυτή είναι <strong>μή αναστρέψιμη</strong>!</p>
<p><?= Html::a(Html::icon('trash') . ' Εκκαθάριση', Url::to(['admin/clear-data']), ['class' => 'btn btn-danger', 'data-method' => 'post', 'data-confirm' => 'Η ενέργεια αυτή είναι μη αναστρέψιμη! Είστε βέβαιοι;']) ?></p>
</div>
<div class="col-lg-4">
<h2>Εκτύπωση αιτήσεων</h2>
<p>Η λειτουργία αυτή εκτυπώνει όλες τις υποβληθείσες αιτήσεις.</p>
<p><?= Html::a(Html::icon('print') . ' Εκτύπωση', Url::to(['admin/print-applications']), ['class' => 'btn btn-primary', 'data-method' => 'POST']) ?></p>
</div>
<div class="col-lg-4">
<h2>Προβολή Αιτήσεων</h2>
<p>Προβολή αιτήσεων που έχουν υποβληθεί.</p>
<p><?= Html::a('Προβολή', Url::to(['admin/view-applications']), ['class' => 'btn btn-primary', 'data-method' => 'post']) ?></p>
</div>
</div>

</div>
35 changes: 35 additions & 0 deletions views/admin/view-applications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
use yii\bootstrap\Html;
use yii\grid\GridView;

$this->title = 'Προβολή αιτήσεων';
$this->params['breadcrumbs'][] = ['label' => 'Διαχειριστικές λειτουργίες', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
//echo "<pre>"; print_r($users); echo "</pre>"; die();
echo GridView::widget([
'dataProvider' => $users,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label' => 'Α.Φ.Μ.',
'attribute' => 'vat'
],
[
'label' => 'Α.Δ.Τ.',
'attribute' => 'identity'
],
[
'label' => 'Ειδικότητα',
'attribute' => 'specialty'
],
['class' => 'yii\grid\ActionColumn',
'header' => 'Προβολή',
'template' => '{printButton}',
'buttons' => ['printButton' => function($url, $model, $key){
return Html::a(Html::icon('print'), ['admin/print-applications', 'applicantId' => $model->id]);}
]
]
]
]);

?>
16 changes: 11 additions & 5 deletions views/application/print.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@
$this->params['breadcrumbs'][] = $this->title;

?>
<?php
$putpagebreak = false;
foreach($data as $userdata):
if($putpagebreak === true) echo "<pagebreak />";
$putpagebreak = true;
?>
<h3 style="text-align: center;"><?= Html::encode($this->title) ?></h3>
<table style="border: 1px solid grey; width: 100%;border-spacing: 10px; padding: 5px; background-color: WhiteSmoke;">
<tr>
<td style="border-bottom: 1px solid grey;"><h4>Ονοματεπώνυμο: </h4></td>
<td style="border-bottom: 1px solid grey;"><h4>Ειδικότητα: <?= $user->specialty ?></h4></td>
<td style="border-bottom: 1px solid grey;"><h4>Ειδικότητα: <?= $userdata['user']->specialty ?></h4></td>
</tr>
<tr>
<td style="border-bottom: 1px solid grey;"><h4>Α.Φ.Μ.: <?= $user->vat ?></h4></td>
<td style="border-bottom: 1px solid grey;"><h4>Ταυτότητα: <?= $user->identity ?></h4></td>
<td style="border-bottom: 1px solid grey;"><h4>Α.Φ.Μ.: <?= $userdata['user']->vat ?></h4></td>
<td style="border-bottom: 1px solid grey;"><h4>Ταυτότητα: <?= $userdata['user']->identity ?></h4></td>
</tr>
<tr>
<td style="border-bottom: 1px solid grey;"><h4>Τηλ: </h4></td>
Expand All @@ -28,7 +34,6 @@
<td><h4>..................., .... /.... /<?= date("Y") ?></h4></td>
</tr>
</table>

<?php //echo "<pre>"; var_dump($dataProvider); echo "</pre>"; ?>
<h3 style="text-align: center">Προτιμήσεις</h3>
<table style="border: 1px solid grey;">
Expand All @@ -41,7 +46,7 @@
<tbody>
<?=
ListView::widget([
'dataProvider' => $dataProvider,
'dataProvider' => $userdata['provider'],//$dataProvider,
'itemView' => '_myapplication_item',
'summary' => '<h3>{totalCount} προτιμήσεις</h3>'
]);
Expand All @@ -52,3 +57,4 @@
<table style="width: 100%; border: none; padding: 15px;">
<tr><td style="width: 50%">&nbsp;</td><td style="font-weight:bold; text-align: center; width: 50%;">Ο αιτών / Η αιτούσα<br /><br /><br />(υπογραφή)</td></tr>
</table>
<?php endforeach;?>
13 changes: 8 additions & 5 deletions views/application/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
/* @var $this yii\web\View */
/* @var $model app\models\Application */

$this->title = 'Η αίτηση μου';
$this->title = 'Η αίτησή μου';
$this->params['breadcrumbs'][] = $this->title;

?>
<div class="application-view">

<?php if ($enable_applications === true) : ?>
<?= Html::a('Διαγραφή', ['delete-my-application'], ['class' => 'pull-right btn btn-danger']) ?>
<?= Html::a('Εκτύπωση', ['my-application', 'printMode' => '1'], ['class' => 'pull-right btn btn-primary']) ?>
<?php endif; ?>
<div class="btn-toolbar">
<?php if ($enable_applications === true) : ?>
<?= Html::a('Διαγραφή', ['delete-my-application'], ['class' => 'pull-right btn btn-danger']);?>
<?php endif; ?>
<?= Html::a('Εκτύπωση', ['my-application', 'printMode' => '1', 'userId' => $user->id], ['class' => 'pull-right btn btn-primary']) ?>
</div>


<h1><?= Html::encode($this->title) ?></h1>
<div class="well well-sm">
Expand Down

0 comments on commit 7d31bf3

Please sign in to comment.