Browse Source

history action file downloads

Oleg K 2 years ago
parent
commit
a2726deb90

+ 45 - 1
controllers/HistoryController.php

@@ -2,11 +2,55 @@
 
 namespace app\controllers;
 
+use yii\data\ArrayDataProvider;
+
 class HistoryController extends \yii\web\Controller
 {
+    private static $schet_path = '';
+    private static $act_path = '';
+
+    public function init()
+    {
+        self::$schet_path  = \Yii::getAlias('@webroot') . '/invoices/' . \Yii::$app->user->identity->uuid . '/schet';
+        self::$act_path  = \Yii::getAlias('@webroot') . '/invoices/' . \Yii::$app->user->identity->uuid . '/act';
+
+        parent::init(); // TODO: Change the autogenerated stub
+    }
+
     public function actionIndex()
     {
-        return $this->render('index');
+        $scheta = new ArrayDataProvider([
+            'allModels' => \yii\helpers\FileHelper::findFiles(self::$schet_path)
+        ]);
+        $actu = new ArrayDataProvider([
+            'allModels' => \yii\helpers\FileHelper::findFiles(self::$act_path)
+        ]);
+
+/*        $files = array();
+
+        if (file_exists($schet_path)) {
+
+            $fileNames = array_diff(scandir($schet_path), array('..', '.'));
+
+            foreach ($fileNames as $fileName) {
+
+                //echo Html::img($webPath . '/' . $fileName);
+                $files[] = $fileName;
+
+            }
+
+        }*/
+
+        return $this->render('index', [
+            'scheta' => $scheta,
+            'actu' => $actu
+        ]);
+    }
+
+    public function actionDownload($type, $file)
+    {
+        $schet_path = \Yii::getAlias('@webroot') . '/invoices/' . \Yii::$app->user->identity->uuid . '/'.$type.'/';
+        return \Yii::$app->response->sendFile($schet_path. $file);
     }
 
 }

+ 2 - 2
models/user/User.php

@@ -51,7 +51,7 @@ class User extends BaseUser
     {
         $scenarios = parent::scenarios();
         return ArrayHelper::merge($scenarios, [
-            'api' => ['username', 'password'],
+            'api' => ['uuid', 'password'],
         ]);
     }
 
@@ -90,7 +90,7 @@ class User extends BaseUser
             'roleIsEmpty' => ['type', 'default', 'value' => function($model){return empty($model->type) ? 'client': '';}],
 
             // email rules
-            'emailIsEmpty' => ['email', 'default', 'value' => function($model){return empty($model->email) ? $model->username . '@example.com': $model->email;}],
+            'emailIsEmpty' => ['email', 'default', 'value' => function($model){return empty($model->email) ? $model->uuid . '@example.com': $model->email;}],
             'emailTrim'     => ['email', 'trim'],
             'emailRequired' => ['email', 'required', 'on' => ['register', 'connect', 'create', 'update']],
             'emailPattern'  => ['email', 'email'],

+ 1 - 1
modules/api/controllers/UserController.php

@@ -29,7 +29,7 @@ class UserController extends ActiveController
             \yii\helpers\FileHelper::createDirectory($userFolderPath . '/schet', $mode = 0775, $recursive = true);
             \yii\helpers\FileHelper::createDirectory($userFolderPath . '/act', $mode = 0775, $recursive = true);
 
-            //$model->setScenario('api');
+            $model->setScenario('api');
             $model->attributes = $param;
             if (!$model->save()) {
                 $errs['err'][$param['uuid']] = $model->getErrors();

+ 24 - 51
views/history/index.php

@@ -1,6 +1,9 @@
 <?php
 /* @var $this yii\web\View */
 
+use yii\grid\GridView;
+use yii\widgets\ListView;
+
 $this->title = 'Історія платежів';
 $this->params['breadcrumbs'][] = $this->title;
 ?>
@@ -17,36 +20,21 @@ $this->params['breadcrumbs'][] = $this->title;
                     <thead>
                     <tr>
                         <th style="width: 10px">#</th>
-                        <th>Дата</th>
+                        <th>Назва</th>
                         <th></th>
                     </tr>
                     </thead>
                     <tbody>
-                    <tr>
-                        <td>1</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
-                    <tr>
-                        <td>2</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
-                    <tr>
-                        <td>3</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
-                    <tr>
-                        <td>4</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
-                    <tr>
-                        <td>5</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
+                    <?= ListView::widget([
+                         'dataProvider' => $scheta,
+                         'layout' => "{items}",
+                         //'itemOptions' => ['class' => 'item', 'style' => 'margin-bottom: 5px;'],
+                         'itemView' => function ($model, $key, $index, $widget) {
+                            $link = \yii\bootstrap4\Html::a(\rmrevin\yii\fontawesome\FAS::icon('download', ['class'=>'text-warning']), \yii\helpers\Url::to(['history/download', 'type'=>'act', 'file' => basename($model)]), ['class'=>'text-muted','data-toggle'=>'tooltip', 'title'=>'Завантажити', 'target'=>'_blank']);
+                            //return '<tr><td>' . ($key+1) . '</td><td>' . basename($model) . '</td><td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>';
+                            return '<tr><td>' . ($key+1) . '</td><td>' . basename($model) . '</td><td class="w-25 text-right" width="30%">'.$link.'</td>';
+                         },
+                     ]) ?>
                     </tbody>
                 </table>
             </div>
@@ -69,31 +57,16 @@ $this->params['breadcrumbs'][] = $this->title;
                     </tr>
                     </thead>
                     <tbody>
-                    <tr>
-                        <td>1</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
-                    <tr>
-                        <td>2</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
-                    <tr>
-                        <td>3</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
-                    <tr>
-                        <td>4</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
-                    <tr>
-                        <td>5</td>
-                        <td>10.10.2021</td>
-                        <td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>
-                    </tr>
+                    <?= ListView::widget([
+                         'dataProvider' => $actu,
+                         'layout' => "{items}",
+                         //'itemOptions' => ['class' => 'item', 'style' => 'margin-bottom: 5px;'],
+                         'itemView' => function ($model, $key, $index, $widget) {
+                             $link = \yii\bootstrap4\Html::a(\rmrevin\yii\fontawesome\FAS::icon('download', ['class'=>'text-warning']), \yii\helpers\Url::to(['history/download', 'type'=>'act', 'file' => basename($model)]), ['class'=>'text-muted','data-toggle'=>'tooltip', 'title'=>'Завантажити', 'target'=>'_blank']);
+                             //return '<tr><td>' . ($key+1) . '</td><td>' . basename($model) . '</td><td class="w-25 text-right" width="30%"><a class="text-muted" href="#" data-toggle="tooltip" title="Завантажити"><i class="fas fa-download text-warning"></i></a></td>';
+                             return '<tr><td>' . ($key+1) . '</td><td>' . basename($model) . '</td><td class="w-25 text-right" width="30%">'.$link.'</td>';
+                         },
+                     ]) ?>
                     </tbody>
                 </table>
             </div>

BIN
web/invoices/1111/act/03.07.2021.pdf


BIN
web/invoices/1111/act/05.08.2021.pdf


BIN
web/invoices/1111/act/07.06.2021.pdf


BIN
web/invoices/1111/schet/01.06.2021.pdf


BIN
web/invoices/1111/schet/03.08.2021.pdf


BIN
web/invoices/1111/schet/05.07.2021.pdf