Commit f6c3dc95c84edf2b8edbdce4e9c2a6d2d7eae71c

Authored by Mihail
1 parent 884c04ad

finish with cart functional (admin)

backend/assets/CartAsset.php 0 → 100644
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: Cibermag
  5 + * Date: 28.09.2015
  6 + * Time: 11:40
  7 + */
  8 +
  9 +namespace backend\assets;
  10 +
  11 +use yii\web\AssetBundle;
  12 +
  13 +class CartAsset extends AssetBundle {
  14 + public $basePath = '@webroot';
  15 + public $baseUrl = '@web';
  16 + public $css = [
  17 + 'css/site.css',
  18 + ];
  19 + public $js = [
  20 + 'js/cart.js',
  21 + ];
  22 + public $depends = [
  23 + 'yii\web\YiiAsset',
  24 + 'yii\bootstrap\BootstrapAsset',
  25 + ];
  26 +}
0 \ No newline at end of file 27 \ No newline at end of file
backend/controllers/CartController.php
@@ -2,10 +2,12 @@ @@ -2,10 +2,12 @@
2 2
3 namespace backend\controllers; 3 namespace backend\controllers;
4 4
  5 +use common\models\Cart;
5 use Yii; 6 use Yii;
6 use common\models\CartBillsView; 7 use common\models\CartBillsView;
7 use common\models\CartBillsSearch; 8 use common\models\CartBillsSearch;
8 use backend\components\base\BaseController; 9 use backend\components\base\BaseController;
  10 +use yii\data\ActiveDataProvider;
9 use yii\web\NotFoundHttpException; 11 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter; 12 use yii\filters\VerbFilter;
11 13
@@ -38,8 +40,15 @@ class CartController extends BaseController @@ -38,8 +40,15 @@ class CartController extends BaseController
38 */ 40 */
39 public function actionView($id) 41 public function actionView($id)
40 { 42 {
41 - return $this->render('view', [  
42 - 'model' => $this->findModel($id), 43 + $provider = new ActiveDataProvider([
  44 + 'query' => Cart::find()->where(['bill_id' => $id]),
  45 + 'sort' => false,
  46 +
  47 + ]);
  48 +
  49 + return $this->renderAjax('view', [
  50 + 'id' => $id,
  51 + 'provider' => $provider,
43 ]); 52 ]);
44 } 53 }
45 54
@@ -53,7 +62,7 @@ class CartController extends BaseController @@ -53,7 +62,7 @@ class CartController extends BaseController
53 */ 62 */
54 protected function findModel($id) 63 protected function findModel($id)
55 { 64 {
56 - if (($model = CartBillsView::findById($id)) !== null) { 65 + if (($model = Cart::findOne(['bill_id' => $id])) !== null) {
57 return $model; 66 return $model;
58 } else { 67 } else {
59 throw new NotFoundHttpException('The requested page does not exist.'); 68 throw new NotFoundHttpException('The requested page does not exist.');
backend/views/cart/index.php
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 use yii\helpers\Html; 3 use yii\helpers\Html;
4 use yii\grid\GridView; 4 use yii\grid\GridView;
5 use kartik\date\DatePicker; 5 use kartik\date\DatePicker;
  6 +use \yii\widgets\Pjax;
  7 +use \yii\bootstrap\Modal;
6 8
7 /* @var $this yii\web\View */ 9 /* @var $this yii\web\View */
8 /* @var $searchModel common\models\CartBillsSearch */ 10 /* @var $searchModel common\models\CartBillsSearch */
@@ -11,7 +13,13 @@ use kartik\date\DatePicker; @@ -11,7 +13,13 @@ use kartik\date\DatePicker;
11 $this->title = Yii::t('app', 'Заказы'); 13 $this->title = Yii::t('app', 'Заказы');
12 $this->params['breadcrumbs'][] = $this->title; 14 $this->params['breadcrumbs'][] = $this->title;
13 15
  16 +$safe_bill_img0 = '/storage/checkbox0.gif';
  17 +$safe_bill_img1 = '/storage/checkbox1.gif';
  18 +
  19 +\backend\assets\CartAsset::register($this);
  20 +Pjax::begin(['id' => 'gridViewContent']);
14 ?> 21 ?>
  22 +
15 <div class="cart-bills-index"> 23 <div class="cart-bills-index">
16 24
17 <h1><?= Html::encode($this->title) ?></h1> 25 <h1><?= Html::encode($this->title) ?></h1>
@@ -23,13 +31,32 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -23,13 +31,32 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
23 'filterModel' => $searchModel, 31 'filterModel' => $searchModel,
24 'columns' => [ 32 'columns' => [
25 ['class' => 'yii\grid\SerialColumn'], 33 ['class' => 'yii\grid\SerialColumn'],
26 - 34 + ['content' => function ($model) {
  35 + $url = \yii\helpers\Url::to(['view', 'id' => $model->id]);
  36 + return Html::a('<span class="glyphicon glyphicon-eye-open"> </span>', '#', [
  37 + 'class' => 'cartModalViewButton',
  38 + 'value' => $url,
  39 + ]);
  40 + },
  41 + ],
27 'id', 42 'id',
28 'account_id', 43 'account_id',
29 ['label' =>'Информация', 44 ['label' =>'Информация',
30 - 'value' =>function ($data) {  
31 - $info = $data->scode . ' /n';  
32 - $info .= $data->name; 45 + 'format' => 'raw',
  46 + 'value' =>function( $model ) use ($safe_bill_img0, $safe_bill_img1) {
  47 + $info = '<b> Код 1С:</b>' . ' ' . $model->scode . '<br>';
  48 + $info .= '<b> Имя:</b>' . ' ' .$model->name . '<br>';
  49 + $info .= '<b> Тел.:</b>' . ' ' .$model->phone . '<br>';
  50 + $info .= '<b> Email:</b>' . ' ' .$model->email . '<br>';
  51 + $info .= '<b> Доставка:</b>' . ' ' .$model->delivery . '<br>';
  52 + $info .= '<b> Комментарий:</b>' . ' ' .$model->message . '<br>';
  53 + $info .= '<b> Страховка:</b>';
  54 + if ($model->safe_bill == '1') {
  55 + $info .= " <img src=$safe_bill_img1>";
  56 + }
  57 + else {
  58 + $info .= " <img src=$safe_bill_img0>";
  59 + }
33 return $info; 60 return $info;
34 }, 61 },
35 ], 62 ],
@@ -60,4 +87,16 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -60,4 +87,16 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
60 ], 87 ],
61 ]); ?> 88 ]); ?>
62 89
  90 + <?php
  91 + // сюда будем всавлять контент модального окна
  92 + Modal::begin([
  93 + // 'header'=>'<h4>Прайс</h4>',
  94 + 'id' => 'modal',
  95 + 'size' => 'modal-lg',
  96 + ]);
  97 +
  98 + echo "<div class='modalContent'></div>";
  99 + Modal::end();
  100 + Pjax::end();
  101 + ?>
63 </div> 102 </div>
backend/views/cart/view.php
1 <?php 1 <?php
2 2
3 use yii\helpers\Html; 3 use yii\helpers\Html;
4 -use yii\widgets\DetailView; 4 +use yii\grid\GridView;
5 5
6 /* @var $this yii\web\View */ 6 /* @var $this yii\web\View */
7 /* @var $model common\models\CartBills */ 7 /* @var $model common\models\CartBills */
8 8
9 -$this->title = $model->id;  
10 -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Cart Bills'), 'url' => ['index']];  
11 -$this->params['breadcrumbs'][] = $this->title; 9 +$this->title = "Заказ № " . $id;
12 ?> 10 ?>
13 <div class="cart-bills-view"> 11 <div class="cart-bills-view">
14 12
15 <h1><?= Html::encode($this->title) ?></h1> 13 <h1><?= Html::encode($this->title) ?></h1>
16 14
17 - <p>  
18 - <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>  
19 - <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [  
20 - 'class' => 'btn btn-danger',  
21 - 'data' => [  
22 - 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),  
23 - 'method' => 'post',  
24 - ],  
25 - ]) ?>  
26 - </p>  
27 -  
28 - <?= DetailView::widget([  
29 - 'model' => $model,  
30 - 'attributes' => [  
31 - 'id',  
32 - 'account_id',  
33 - 'manager_id',  
34 - 'office_id',  
35 - 'status',  
36 - 'f1',  
37 - 'f2',  
38 - 'f3',  
39 - 'message:ntext',  
40 - 'safe_bill',  
41 - 'delivery',  
42 - 'delivery_price',  
43 - 'timestamp', 15 + <?= GridView::widget([
  16 + 'dataProvider' => $provider,
  17 + 'layout' =>'{items}',
  18 + 'columns'=>[
  19 + 'article',
  20 + 'brand',
  21 + 'importer',
  22 + 'descr',
  23 + 'count',
  24 + 'price',
  25 + 'aggregate',
  26 + 'status_name',
44 ], 27 ],
45 - ]) ?> 28 +
  29 + ]); ?>
46 30
47 </div> 31 </div>
backend/web/css/AdminLTE.css
@@ -2554,6 +2554,7 @@ a:focus { @@ -2554,6 +2554,7 @@ a:focus {
2554 } 2554 }
2555 .table-bordered { 2555 .table-bordered {
2556 border: 1px solid #f4f4f4; 2556 border: 1px solid #f4f4f4;
  2557 +
2557 } 2558 }
2558 .table-bordered > thead > tr > th, 2559 .table-bordered > thead > tr > th,
2559 .table-bordered > tbody > tr > th, 2560 .table-bordered > tbody > tr > th,
backend/web/js/cart.js 0 → 100644
  1 +$(function(){
  2 +
  3 + // cart\view.php
  4 + // для каждой строки обрабатываем клик по ссылке
  5 + $('.cartModalViewButton').click(function (){
  6 + // находим контейнер с модальным контентом и подгружаем в него по аджаксу результат
  7 + $('#modal').modal('show')
  8 + .find('.modalContent')
  9 + .load($(this).attr('value')); // в 'value' - у нас указан путь с гет параметрами к конроллеру
  10 + $.pjax.reload({container:'#gridViewContent'});
  11 + });
  12 +
  13 +});
  14 +
common/models/Cart.php
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace common\models; 3 namespace common\models;
4 4
  5 +use backend\models\Importers;
5 use Yii; 6 use Yii;
6 7
7 /** 8 /**
@@ -44,6 +45,18 @@ class Cart extends \backend\components\base\BaseActiveRecord @@ -44,6 +45,18 @@ class Cart extends \backend\components\base\BaseActiveRecord
44 ]; 45 ];
45 } 46 }
46 47
  48 + public function getImporter ()
  49 + {
  50 + return Importers::findOne(['id' => $this->import_id])->name;
  51 + }
  52 + public function getStatus_name ()
  53 + {
  54 + return DicStatuses::findOne(['id' => $this->status])->name;
  55 + }
  56 + public function getAggregate ()
  57 + {
  58 + return (float)$this->price * (float)$this->count;
  59 + }
47 /** 60 /**
48 * @inheritdoc 61 * @inheritdoc
49 */ 62 */
@@ -52,15 +65,18 @@ class Cart extends \backend\components\base\BaseActiveRecord @@ -52,15 +65,18 @@ class Cart extends \backend\components\base\BaseActiveRecord
52 return [ 65 return [
53 'bill_id' => Yii::t('app', 'Bill ID'), 66 'bill_id' => Yii::t('app', 'Bill ID'),
54 'account_id' => Yii::t('app', 'Account ID'), 67 'account_id' => Yii::t('app', 'Account ID'),
55 - 'count' => Yii::t('app', 'Count'),  
56 - 'price' => Yii::t('app', 'Price'), 68 + 'count' => Yii::t('app', 'Кол-во'),
  69 + 'price' => Yii::t('app', 'Цена'),
57 'price_purchase' => Yii::t('app', 'Price Purchase'), 70 'price_purchase' => Yii::t('app', 'Price Purchase'),
58 - 'status' => Yii::t('app', 'Status'),  
59 - 'article' => Yii::t('app', 'Article'),  
60 - 'brand' => Yii::t('app', 'Brand'),  
61 - 'descr' => Yii::t('app', 'Descr'), 71 + 'status' => Yii::t('app', 'id status'),
  72 + 'status_name' => Yii::t('app', 'Статус'),
  73 + 'article' => Yii::t('app', 'Артикул'),
  74 + 'brand' => Yii::t('app', 'Бренд'),
  75 + 'descr' => Yii::t('app', 'Описание'),
62 'import_id' => Yii::t('app', 'Import ID'), 76 'import_id' => Yii::t('app', 'Import ID'),
  77 + 'importer' => Yii::t('app', 'Поставщик'),
63 'timestamp' => Yii::t('app', 'Timestamp'), 78 'timestamp' => Yii::t('app', 'Timestamp'),
  79 + 'aggregate' => Yii::t('app', 'Сумма'),
64 ]; 80 ];
65 } 81 }
66 } 82 }
common/models/CartBillsSearch.php
@@ -52,9 +52,15 @@ class CartBillsSearch extends CartBillsView @@ -52,9 +52,15 @@ class CartBillsSearch extends CartBillsView
52 $this->load($params); 52 $this->load($params);
53 53
54 if (!$this->validate()) { 54 if (!$this->validate()) {
55 - // uncomment the following line if you do not want to return any records when validation fails  
56 - // $query->where('0=1'); 55 +
57 return $dataProvider; 56 return $dataProvider;
  57 +
  58 + }
  59 +
  60 + if ( !$params || !$params['CartBillsSearch'] ) {
  61 + // если не переданы параметры - показываем первые 100 записей
  62 + $query->limit = 100;
  63 +
58 } 64 }
59 65
60 $query->andFilterWhere([ 66 $query->andFilterWhere([
@@ -63,22 +69,15 @@ class CartBillsSearch extends CartBillsView @@ -63,22 +69,15 @@ class CartBillsSearch extends CartBillsView
63 'status_id' => $this->status, 69 'status_id' => $this->status,
64 ]); 70 ]);
65 71
66 - if($this->dt !== null || $this->date_to !== null){  
67 - $date_from = mktime(0,0,0,(int)substr($this->dt,4,2),(int)substr($this->dt,1,2),(int)substr($this->dt,7,4));  
68 - $date_to = mktime(23,59,59,(int)substr($this->date_to,4,2),(int)substr($this->date_to,1,2),(int)substr($this->date_to,7,4)); 72 + if( !empty( $this->dt ) || !empty( $this->date_to ) ){
  73 + $date_from = \Yii::$app->converter->convertTo( 'timestamp', $this->dt );
  74 + $date_to = \Yii::$app->converter->convertTo( 'timestamp', $this->date_to, ['begin_of_the_day' => false] );
69 75
70 $query->andFilterWhere([ 76 $query->andFilterWhere([
71 'between', 'dt', $date_from, $date_to 77 'between', 'dt', $date_from, $date_to
72 ]); 78 ]);
73 - }  
74 -  
75 79
76 -  
77 -// $query->andFilterWhere(['like', 'f1', $this->f1])  
78 -// ->andFilterWhere(['like', 'f2', $this->f2])  
79 -// ->andFilterWhere(['like', 'f3', $this->f3])  
80 -// ->andFilterWhere(['like', 'message', $this->message])  
81 -// ->andFilterWhere(['like', 'delivery', $this->delivery]); 80 + }
82 81
83 return $dataProvider; 82 return $dataProvider;
84 } 83 }
tests/runtime/cache/co/converter.bin deleted
1 -a:2:{i:0;a:3:{s:5:"class";s:42:" common\components\parsers\CustomConverter";s:13:"configuration";a:2:{s:5:"brand";a:2:{i:0;s:5:"BRAND";i:1;s:11:"CROSS_BRAND";}s:7:"crosses";a:0:{}}s:6:"hasKey";i:1;}i:1;N;}  
2 \ No newline at end of file 0 \ No newline at end of file
tests/runtime/cache/pa/parser.bin 0 → 100644
  1 +a:2:{i:0;a:7:{s:5:"class";s:41:"common\components\parsers\CustomCsvParser";s:22:"auto_detect_first_line";b:1;s:19:"min_column_quantity";i:4;s:14:"converter_conf";a:3:{s:5:"class";s:42:" common\components\parsers\CustomConverter";s:6:"hasKey";i:1;s:13:"configuration";a:2:{s:5:"brand";a:2:{i:0;s:5:"BRAND";i:1;s:11:"CROSS_BRAND";}s:7:"crosses";a:0:{}}}s:12:"basic_column";a:5:{s:0:"";s:10:"Пусто";s:7:"ARTICLE";s:14:"Артикул";s:13:"CROSS_ARTICLE";s:25:"Кросс артикул";s:5:"BRAND";s:10:"Бренд";s:11:"CROSS_BRAND";s:21:"Кросс бренд";}s:4:"file";i:0;s:9:"file_path";s:57:"C:\xampp\htdocs\ital\tests\_data\parser\crosses\test1.csv";}i:1;N;}
0 \ No newline at end of file 2 \ No newline at end of file
tests/unit/CrossesParsingTest.php
@@ -19,18 +19,6 @@ class CrossesParsingTest extends \Codeception\TestCase\Test @@ -19,18 +19,6 @@ class CrossesParsingTest extends \Codeception\TestCase\Test
19 { 19 {
20 $this->options[ 'mode' ] = 'crosses'; 20 $this->options[ 'mode' ] = 'crosses';
21 21
22 - $this->options[ 'crosses' ] = [  
23 - 'class' => 'common\components\parsers\CustomCsvParser',  
24 - 'auto_detect_first_line' => true,  
25 - 'min_column_quantity' => 4,  
26 - 'keys' =>['ARTICLE', 'CROSS_ARTICLE', 'BRAND', 'CROSS_BRAND'],  
27 - 'converter_conf' => [  
28 - 'class' => ' common\components\parsers\CustomConverter',  
29 - 'configuration' => [  
30 - "brand" => ['BRAND', 'CROSS_BRAND'],  
31 - "crosses" => [],  
32 - ]]  
33 - ];  
34 22
35 $this->file_path = Yii::getAlias('@data_parser') . '\crosses\test1.csv'; 23 $this->file_path = Yii::getAlias('@data_parser') . '\crosses\test1.csv';
36 24