Commit 92914ff125d671e5a6b22f32b36e727668d6ed7f

Authored by Administrator
2 parents c6152cd6 9f082181

Merge branch 'master' of gitlab.artweb.com.ua:root/test_1

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,13 +2,14 @@ @@ -2,13 +2,14 @@
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 -use yii\filters\AccessControl;  
12 13
13 /** 14 /**
14 * CartController implements the CRUD actions for CartBills model. 15 * CartController implements the CRUD actions for CartBills model.
@@ -16,34 +17,7 @@ use yii\filters\AccessControl; @@ -16,34 +17,7 @@ use yii\filters\AccessControl;
16 class CartController extends BaseController 17 class CartController extends BaseController
17 { 18 {
18 public $layout = "/column"; 19 public $layout = "/column";
19 - /**  
20 - * @inheritdoc  
21 - */  
22 - public function behaviors()  
23 - {  
24 - return [  
25 - 'access' => [  
26 - 'class' => AccessControl::className(),  
27 - 'rules' => [  
28 - [  
29 - 'actions' => ['login', 'error', 'download-photo','delete-image' ],  
30 - 'allow' => true,  
31 - ],  
32 - [  
33 - 'actions' => ['logout', 'index','create','update','view','delete',],  
34 - 'allow' => true,  
35 - 'roles' => ['@'],  
36 - ],  
37 - ],  
38 - ],  
39 - 'verbs' => [  
40 - 'class' => VerbFilter::className(),  
41 - 'actions' => [  
42 - 'logout' => ['post'],  
43 - ],  
44 - ],  
45 - ];  
46 - } 20 +
47 /** 21 /**
48 * Lists all CartBills models. 22 * Lists all CartBills models.
49 * @return mixed 23 * @return mixed
@@ -66,8 +40,15 @@ class CartController extends BaseController @@ -66,8 +40,15 @@ class CartController extends BaseController
66 */ 40 */
67 public function actionView($id) 41 public function actionView($id)
68 { 42 {
69 - return $this->render('view', [  
70 - '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,
71 ]); 52 ]);
72 } 53 }
73 54
@@ -81,7 +62,7 @@ class CartController extends BaseController @@ -81,7 +62,7 @@ class CartController extends BaseController
81 */ 62 */
82 protected function findModel($id) 63 protected function findModel($id)
83 { 64 {
84 - if (($model = CartBillsView::findById($id)) !== null) { 65 + if (($model = Cart::findOne(['bill_id' => $id])) !== null) {
85 return $model; 66 return $model;
86 } else { 67 } else {
87 throw new NotFoundHttpException('The requested page does not exist.'); 68 throw new NotFoundHttpException('The requested page does not exist.');
backend/controllers/CrossingUploadController.php
@@ -8,10 +8,14 @@ @@ -8,10 +8,14 @@
8 8
9 namespace backend\controllers; 9 namespace backend\controllers;
10 10
  11 +use backend\components\base\BaseActiveRecord;
11 use backend\components\base\BaseController; 12 use backend\components\base\BaseController;
12 use common\components\CustomArrayHelper; 13 use common\components\CustomArrayHelper;
13 use common\components\CustomVarDamp; 14 use common\components\CustomVarDamp;
  15 +use yii\base\ErrorException;
  16 +use yii\base\Model;
14 use yii\data\ArrayDataProvider; 17 use yii\data\ArrayDataProvider;
  18 +use yii\db\ActiveRecord;
15 use yii\filters\VerbFilter; 19 use yii\filters\VerbFilter;
16 use yii\filters\AccessControl; 20 use yii\filters\AccessControl;
17 use backend\models\UploadFileCrossingForm; 21 use backend\models\UploadFileCrossingForm;
@@ -82,7 +86,7 @@ class CrossingUploadController extends BaseController @@ -82,7 +86,7 @@ class CrossingUploadController extends BaseController
82 //запускаем парсинг 86 //запускаем парсинг
83 $data = $model->readFile(); 87 $data = $model->readFile();
84 // сохраняем в кеш отпарсенные даные 88 // сохраняем в кеш отпарсенные даные
85 - $this->cacheHandler( true, $data, $model ); 89 + $this->cacheHandler( 1, $data, $model );
86 } else if (Yii::$app->getCache()->get('parser_data')) { 90 } else if (Yii::$app->getCache()->get('parser_data')) {
87 $data = json_decode(Yii::$app->getCache()->get('parser_data'), true); 91 $data = json_decode(Yii::$app->getCache()->get('parser_data'), true);
88 } 92 }
@@ -122,13 +126,13 @@ class CrossingUploadController extends BaseController @@ -122,13 +126,13 @@ class CrossingUploadController extends BaseController
122 } 126 }
123 127
124 // провалидируем выбранные колонки 128 // провалидируем выбранные колонки
125 - if ($model->validate()) { 129 + if ( $model->validate() ) {
126 130
127 // валидация успешна у нас есть соответсвие колонок, преобразуем в массив данное соответсвие для дальнейшей работы 131 // валидация успешна у нас есть соответсвие колонок, преобразуем в массив данное соответсвие для дальнейшей работы
128 $arr = $model->toArray(); 132 $arr = $model->toArray();
129 133
130 // получим данные из кеша 134 // получим данные из кеша
131 - $this->cacheHandler( false, $data, $configuration ); 135 + $this->cacheHandler( 0, $data, $configuration );
132 136
133 // соотнесем отпарсенные данные с соответствием полученным от пользователя 137 // соотнесем отпарсенные данные с соответствием полученным от пользователя
134 // для этого преобразуем массив отпарсенных данных - назначим ключи согласно соответствию 138 // для этого преобразуем массив отпарсенных данных - назначим ключи согласно соответствию
@@ -138,19 +142,23 @@ class CrossingUploadController extends BaseController @@ -138,19 +142,23 @@ class CrossingUploadController extends BaseController
138 $data = $this->convertDataByConfiguration( $data, $configuration ); 142 $data = $this->convertDataByConfiguration( $data, $configuration );
139 143
140 $crosses_model = new DetailsCrosses(); 144 $crosses_model = new DetailsCrosses();
141 - $crosses_model->ManualInsertWithIgnore($data);  
142 145
143 - Yii::$app->session->setFlash('success', 'Файл кроссов успешно загружен');  
144 - // все прошло успешно - очищаем кеш  
145 - Yii::$app->getCache()->delete('parser_data');  
146 - Yii::$app->getCache()->delete('parser_configuration'); 146 + if ( $crosses_model->ManualInsertWithIgnore( $data ) ) {
  147 +
  148 + Yii::$app->session->setFlash('success', 'Файл кроссов успешно загружен');
  149 +
  150 + // очистим кеш
  151 + $this->cacheHandler( 2 );
  152 +
  153 + if (file_exists($configuration['file_path']))
  154 + unlink($configuration['file_path']);
  155 + return $this->render('index', ['model' => $configuration]);
  156 +
  157 + }
147 158
148 - if (file_exists($configuration['file_path']))  
149 - unlink($configuration['file_path']);  
150 - return $this->render('index', ['model' => $configuration]);  
151 159
152 } else { 160 } else {
153 - // не прошла валидация форма загрузки файлов 161 + // не прошла валидация формы загрузки файлов
154 $errors_str = ''; 162 $errors_str = '';
155 foreach ($model->getErrors() as $error) { 163 foreach ($model->getErrors() as $error) {
156 $errors_str .= implode(array_values($error)); 164 $errors_str .= implode(array_values($error));
@@ -182,45 +190,82 @@ class CrossingUploadController extends BaseController @@ -182,45 +190,82 @@ class CrossingUploadController extends BaseController
182 $fields[] = 'CROSS_ARTICLE'; 190 $fields[] = 'CROSS_ARTICLE';
183 } 191 }
184 if ($fields) { 192 if ($fields) {
185 - $options ['configuration'] = ["article" => $fields, 193 + $options ['converter_conf']['configuration'] = ["article" => $fields,
186 "string" => ['ARTICLE', 'CROSS_ARTICLE'],]; 194 "string" => ['ARTICLE', 'CROSS_ARTICLE'],];
187 } else { 195 } else {
188 - $options ['configuration'] = ["string" => ['ARTICLE', 'CROSS_ARTICLE'],]; 196 + $options ['converter_conf']['configuration'] = ["string" => ['ARTICLE', 'CROSS_ARTICLE'],];
189 } 197 }
190 198
191 - foreach ($data as &$row) {  
192 - $row = Yii::$app->converter->convertByConfiguration($row, $options); 199 + // получим базовую конфигурацию и объеденим её с той что образовалась после выбора пользователем настроек
  200 + $basic_options = Yii::$app->multiparser->getConfiguration( 'csv', 'crosses' );
  201 + $options = array_merge_recursive( $options, $basic_options );
  202 +
  203 + // для доп массива обратных строк
  204 + $i = count( $data ) - 1;
  205 + $reverse_data = [];
  206 + foreach ( $data as &$row ) {
  207 + $row = Yii::$app->converter->convertByConfiguration( $row, $options['converter_conf'] );
  208 + // нужно добавить обратную строку по кроссам
  209 + $reverse_data[ $i ]['ARTICLE'] = $row['CROSS_ARTICLE'];
  210 + $reverse_data[ $i ]['CROSS_ARTICLE'] = $row['ARTICLE'];
  211 + $reverse_data[ $i ]['BRAND'] = $row['CROSS_BRAND'];
  212 + $reverse_data[ $i ]['CROSS_BRAND'] = $row['BRAND'];
  213 + $i++;
193 } 214 }
194 215
  216 + $data = array_merge( $data, $reverse_data );
195 return $data; 217 return $data;
196 218
197 } 219 }
198 220
199 /** 221 /**
200 - * @param $mode - bool - true - put in cache, otherwise - fetch from cache 222 + * @param $mode - int: 0 - fetch from cache, - 1 - put in cache, <2 - delete from cache
201 * @param $data - array 223 * @param $data - array
202 * @param $configuration - array 224 * @param $configuration - array
203 * @throws \ErrorException 225 * @throws \ErrorException
204 */ 226 */
205 - protected function cacheHandler( $mode, &$data, &$configuration ){  
206 -  
207 - if ( $mode ) {  
208 -  
209 - Yii::$app->getCache()->set('parser_data', json_encode($data), 1800);  
210 - // сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных  
211 - Yii::$app->getCache()->set('parser_configuration', serialize($configuration), 1800);  
212 -  
213 - } else {  
214 -  
215 - if (Yii::$app->getCache()->get('parser_data') && Yii::$app->getCache()->get('parser_configuration')) {  
216 - $data = json_decode(Yii::$app->getCache()->get('parser_data'), true);  
217 - $configuration = unserialize(Yii::$app->getCache()->get('parser_configuration'));  
218 - } else {  
219 - throw new \ErrorException('Ошибка кеша');  
220 - }  
221 - 227 + protected function cacheHandler( $mode, &$data = [], &$configuration = [] ){
  228 + switch ( $mode ) {
  229 + case 0:
  230 + if (Yii::$app->getCache()->get('parser_data') && Yii::$app->getCache()->get('parser_configuration')) {
  231 + $data = json_decode(Yii::$app->getCache()->get('parser_data'), true);
  232 + $configuration = unserialize(Yii::$app->getCache()->get('parser_configuration'));
  233 + } else {
  234 + throw new \ErrorException('Ошибка кеша');
  235 + }
  236 + break;
  237 +
  238 + case 1:
  239 + Yii::$app->getCache()->set('parser_data', json_encode($data), 1800);
  240 + // сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных
  241 + Yii::$app->getCache()->set('parser_configuration', serialize($configuration), 1800);
  242 + break;
  243 +
  244 + default:
  245 + if( Yii::$app->getCache()->exists('parser_data') )
  246 + Yii::$app->getCache()->delete('parser_data');
  247 +
  248 + if( Yii::$app->getCache()->exists('parser_configuration') )
  249 + Yii::$app->getCache()->delete('parser_configuration');
222 } 250 }
223 251
224 -  
225 } 252 }
  253 +
  254 +// protected function validateModel( BaseActiveRecord $model, array $data ){
  255 +//
  256 +// foreach ( $data as $row ) {
  257 +// // подготовим данные к валидации
  258 +// $validate_attr[$model->formName()] = $row;
  259 +// if( !$model->load( $validate_attr ) ){
  260 +// // такой ситуации не должно быть, но на всякий случай
  261 +// throw new ErrorException('Незаполнены обязательные поля формы.');
  262 +// }
  263 +// if ( !$model->validate( ) ) {
  264 +// $model->throwStringErrorException( key( $data ) );
  265 +// };
  266 +// }
  267 +//
  268 +// return true;
  269 +//
  270 +// }
226 } 271 }
227 \ No newline at end of file 272 \ No newline at end of file
backend/controllers/CurrencyController.php
@@ -5,6 +5,7 @@ namespace backend\controllers; @@ -5,6 +5,7 @@ namespace backend\controllers;
5 use Yii; 5 use Yii;
6 use common\models\Currency; 6 use common\models\Currency;
7 use common\models\CurrencySearch; 7 use common\models\CurrencySearch;
  8 +use yii\data\ActiveDataProvider;
8 use yii\web\Controller; 9 use yii\web\Controller;
9 use yii\web\NotFoundHttpException; 10 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter; 11 use yii\filters\VerbFilter;
@@ -50,11 +51,13 @@ class CurrencyController extends Controller @@ -50,11 +51,13 @@ class CurrencyController extends Controller
50 */ 51 */
51 public function actionIndex() 52 public function actionIndex()
52 { 53 {
53 - $searchModel = new CurrencySearch();  
54 - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 54 + $dataProvider = new ActiveDataProvider([
  55 + 'query' => Currency::find(),
  56 + 'sort' => false,
  57 +
  58 + ]);
55 59
56 return $this->render('index', [ 60 return $this->render('index', [
57 - 'searchModel' => $searchModel,  
58 'dataProvider' => $dataProvider, 61 'dataProvider' => $dataProvider,
59 ]); 62 ]);
60 } 63 }
backend/controllers/DetailsDescriptionController.php
@@ -11,7 +11,6 @@ use yii\data\ActiveDataProvider; @@ -11,7 +11,6 @@ use yii\data\ActiveDataProvider;
11 use yii\web\HttpException; 11 use yii\web\HttpException;
12 use yii\web\NotFoundHttpException; 12 use yii\web\NotFoundHttpException;
13 use yii\filters\VerbFilter; 13 use yii\filters\VerbFilter;
14 -use yii\filters\AccessControl;  
15 14
16 /** 15 /**
17 * DetailsDescriptionController implements the CRUD actions for DetailsDescription model. 16 * DetailsDescriptionController implements the CRUD actions for DetailsDescription model.
@@ -20,30 +19,13 @@ class DetailsDescriptionController extends BaseController @@ -20,30 +19,13 @@ class DetailsDescriptionController extends BaseController
20 { 19 {
21 public $layout = "/column"; 20 public $layout = "/column";
22 21
23 - /**  
24 - * @inheritdoc  
25 - */  
26 public function behaviors() 22 public function behaviors()
27 { 23 {
28 return [ 24 return [
29 - 'access' => [  
30 - 'class' => AccessControl::className(),  
31 - 'rules' => [  
32 - [  
33 - 'actions' => ['login', 'error', 'download-photo','delete-image' ],  
34 - 'allow' => true,  
35 - ],  
36 - [  
37 - 'actions' => ['logout', 'index','create','update','view','delete',],  
38 - 'allow' => true,  
39 - 'roles' => ['@'],  
40 - ],  
41 - ],  
42 - ],  
43 'verbs' => [ 25 'verbs' => [
44 'class' => VerbFilter::className(), 26 'class' => VerbFilter::className(),
45 'actions' => [ 27 'actions' => [
46 - 'logout' => ['post'], 28 + 'delete' => ['post'],
47 ], 29 ],
48 ], 30 ],
49 ]; 31 ];
backend/controllers/ParserController.php
@@ -38,22 +38,17 @@ class ParserController extends BaseController @@ -38,22 +38,17 @@ class ParserController extends BaseController
38 'class' => AccessControl::className(), 38 'class' => AccessControl::className(),
39 'rules' => [ 39 'rules' => [
40 [ 40 [
41 - 'actions' => ['login', 'error', 'download-photo','delete-image' ],  
42 - 'allow' => true,  
43 - ],  
44 - [  
45 - 'actions' => ['logout', 'index','create','update','view','delete',],  
46 'allow' => true, 41 'allow' => true,
47 'roles' => ['@'], 42 'roles' => ['@'],
48 ], 43 ],
49 ], 44 ],
50 ], 45 ],
51 - 'verbs' => [  
52 - 'class' => VerbFilter::className(),  
53 - 'actions' => [  
54 - 'logout' => ['post'],  
55 - ],  
56 - ], 46 +// 'verbs' => [
  47 +// 'class' => VerbFilter::className(),
  48 +// 'actions' => [
  49 +// 'logout' => ['post'],
  50 +// ],
  51 +// ],
57 ]; 52 ];
58 } 53 }
59 54
backend/controllers/RgGrupController.php
@@ -14,7 +14,6 @@ use common\components\CustomVarDamp; @@ -14,7 +14,6 @@ use common\components\CustomVarDamp;
14 use common\components\parsers\MailAttachmentsSaver; 14 use common\components\parsers\MailAttachmentsSaver;
15 use common\models\Margins; 15 use common\models\Margins;
16 use common\models\MarginsGroups; 16 use common\models\MarginsGroups;
17 -use yii\filters\VerbFilter;  
18 use yii\filters\AccessControl; 17 use yii\filters\AccessControl;
19 use Yii; 18 use Yii;
20 use yii\web\UploadedFile; 19 use yii\web\UploadedFile;
@@ -36,22 +35,17 @@ class RgGrupController extends BaseController @@ -36,22 +35,17 @@ class RgGrupController extends BaseController
36 'class' => AccessControl::className(), 35 'class' => AccessControl::className(),
37 'rules' => [ 36 'rules' => [
38 [ 37 [
39 - 'actions' => ['login', 'error', 'download-photo','delete-image' ],  
40 - 'allow' => true,  
41 - ],  
42 - [  
43 - 'actions' => ['logout', 'index','create','update','view','delete',],  
44 'allow' => true, 38 'allow' => true,
45 'roles' => ['@'], 39 'roles' => ['@'],
46 ], 40 ],
47 ], 41 ],
48 ], 42 ],
49 - 'verbs' => [  
50 - 'class' => VerbFilter::className(),  
51 - 'actions' => [  
52 - 'logout' => ['post'],  
53 - ],  
54 - ], 43 +// 'verbs' => [
  44 +// 'class' => VerbFilter::className(),
  45 +// 'actions' => [
  46 +// 'logout' => ['post'],
  47 +// ],
  48 +// ],
55 ]; 49 ];
56 } 50 }
57 51
backend/models/Currency.php deleted
1 -<?php  
2 -  
3 -namespace backend\models;  
4 -  
5 -use Yii;  
6 -  
7 -/**  
8 - * This is the model class for table "w_currency".  
9 - *  
10 - * @property integer $id  
11 - * @property string $name  
12 - * @property double $rate  
13 - * @property integer $is_default  
14 - * @property string $timestamp  
15 - */  
16 -class Currency extends \yii\db\ActiveRecord  
17 -{  
18 - /**  
19 - * @inheritdoc  
20 - */  
21 - public static function tableName()  
22 - {  
23 - return 'w_currency';  
24 - }  
25 -  
26 - /**  
27 - * @inheritdoc  
28 - */  
29 - public function rules()  
30 - {  
31 - return [  
32 - [['name', 'rate'], 'required'],  
33 - [['rate'], 'number'],  
34 - [['is_default'], 'integer'],  
35 - [['timestamp'], 'safe'],  
36 - [['name'], 'string', 'max' => 50],  
37 - [['name'], 'unique'],  
38 - [['is_default'], 'unique']  
39 - ];  
40 - }  
41 -  
42 - /**  
43 - * @inheritdoc  
44 - */  
45 - public function attributeLabels()  
46 - {  
47 - return [  
48 - 'id' => 'ID',  
49 - 'name' => 'Name',  
50 - 'rate' => 'Rate',  
51 - 'is_default' => 'Is Default',  
52 - 'timestamp' => 'Timestamp',  
53 - ];  
54 - }  
55 -}  
backend/models/DetailsCrosses.php
@@ -78,8 +78,16 @@ class DetailsCrosses extends \backend\components\base\BaseActiveRecord @@ -78,8 +78,16 @@ class DetailsCrosses extends \backend\components\base\BaseActiveRecord
78 $query = Yii::$app->db->createCommand()->batchInsert($table_name, $keys_arr, $current_batch_array)->sql; 78 $query = Yii::$app->db->createCommand()->batchInsert($table_name, $keys_arr, $current_batch_array)->sql;
79 // добавим ключевое слово - ignore 79 // добавим ключевое слово - ignore
80 $query = preg_replace('/INSERT/','INSERT IGNORE', $query); 80 $query = preg_replace('/INSERT/','INSERT IGNORE', $query);
81 - Yii::$app->db->createCommand($query)->execute(); 81 + $rows = Yii::$app->db->createCommand($query)->execute();
  82 +
  83 +// // если нет результата вернемся с ошибкой
  84 +// if ( $rows == 0 ) {
  85 +// return false;
  86 +// }
82 87
83 } 88 }
  89 +
  90 + return true;
  91 +
84 } 92 }
85 } 93 }
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/views/currency/_form.php
@@ -17,7 +17,7 @@ use yii\widgets\ActiveForm; @@ -17,7 +17,7 @@ use yii\widgets\ActiveForm;
17 <?= $form->field($model, 'rate')->textInput() ?> 17 <?= $form->field($model, 'rate')->textInput() ?>
18 18
19 <div class="form-group"> 19 <div class="form-group">
20 - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 20 + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
21 </div> 21 </div>
22 22
23 <?php ActiveForm::end(); ?> 23 <?php ActiveForm::end(); ?>
backend/views/currency/create.php
@@ -6,7 +6,7 @@ use yii\helpers\Html; @@ -6,7 +6,7 @@ use yii\helpers\Html;
6 /* @var $this yii\web\View */ 6 /* @var $this yii\web\View */
7 /* @var $model common\models\Currency */ 7 /* @var $model common\models\Currency */
8 8
9 -$this->title = 'Create Currency'; 9 +$this->title = 'Добавить валюту';
10 $this->params['breadcrumbs'][] = ['label' => 'Currencies', 'url' => ['index']]; 10 $this->params['breadcrumbs'][] = ['label' => 'Currencies', 'url' => ['index']];
11 $this->params['breadcrumbs'][] = $this->title; 11 $this->params['breadcrumbs'][] = $this->title;
12 ?> 12 ?>
@@ -18,4 +18,5 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -18,4 +18,5 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
18 'model' => $model, 18 'model' => $model,
19 ]) ?> 19 ]) ?>
20 20
  21 + <?= Html::a('Вернуться', ['index'], ['class' => 'btn btn-primary']) ?>
21 </div> 22 </div>
backend/views/currency/index.php
@@ -7,7 +7,7 @@ use yii\grid\GridView; @@ -7,7 +7,7 @@ use yii\grid\GridView;
7 /* @var $searchModel common\models\CurrencySearch */ 7 /* @var $searchModel common\models\CurrencySearch */
8 /* @var $dataProvider yii\data\ActiveDataProvider */ 8 /* @var $dataProvider yii\data\ActiveDataProvider */
9 9
10 -$this->title = 'Currencies'; 10 +$this->title = 'Курс валют';
11 $this->params['breadcrumbs'][] = $this->title; 11 $this->params['breadcrumbs'][] = $this->title;
12 ?> 12 ?>
13 <div class="currency-index"> 13 <div class="currency-index">
@@ -16,20 +16,18 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -16,20 +16,18 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
16 <?php // echo $this->render('_search', ['model' => $searchModel]); ?> 16 <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
17 17
18 <p> 18 <p>
19 - <?= Html::a('Create Currency', ['create'], ['class' => 'btn btn-success']) ?> 19 + <?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
20 </p> 20 </p>
21 21
22 <?= GridView::widget([ 22 <?= GridView::widget([
23 'dataProvider' => $dataProvider, 23 'dataProvider' => $dataProvider,
24 - 'filterModel' => $searchModel,  
25 'columns' => [ 24 'columns' => [
26 ['class' => 'yii\grid\SerialColumn'], 25 ['class' => 'yii\grid\SerialColumn'],
27 -  
28 'name', 26 'name',
29 'rate', 27 'rate',
30 'timestamp', 28 'timestamp',
31 -  
32 - ['class' => 'yii\grid\ActionColumn'], 29 + ['class' => 'yii\grid\ActionColumn',
  30 + 'template' => '{update}'],
33 ], 31 ],
34 ]); ?> 32 ]); ?>
35 33
backend/views/currency/update.php
@@ -5,7 +5,7 @@ use yii\helpers\Html; @@ -5,7 +5,7 @@ use yii\helpers\Html;
5 /* @var $this yii\web\View */ 5 /* @var $this yii\web\View */
6 /* @var $model common\models\Currency */ 6 /* @var $model common\models\Currency */
7 7
8 -$this->title = 'Update Currency: ' . ' ' . $model->name; 8 +$this->title = 'Обновить валюту: ' . ' ' . $model->name;
9 $this->params['breadcrumbs'][] = ['label' => 'Currencies', 'url' => ['index']]; 9 $this->params['breadcrumbs'][] = ['label' => 'Currencies', 'url' => ['index']];
10 $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; 10 $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
11 $this->params['breadcrumbs'][] = 'Update'; 11 $this->params['breadcrumbs'][] = 'Update';
@@ -18,4 +18,5 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;Update&#39;; @@ -18,4 +18,5 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;Update&#39;;
18 'model' => $model, 18 'model' => $model,
19 ]) ?> 19 ]) ?>
20 20
  21 + <?= Html::a('Вернуться', ['index'], ['class' => 'btn btn-primary']) ?>
21 </div> 22 </div>
backend/views/importers/_form.php
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 use yii\helpers\Html; 3 use yii\helpers\Html;
4 use yii\widgets\ActiveForm; 4 use yii\widgets\ActiveForm;
5 use yii\helpers\ArrayHelper; 5 use yii\helpers\ArrayHelper;
6 -use backend\models\Currency; 6 +use common\models\Currency;
7 7
8 /* @var $this yii\web\View */ 8 /* @var $this yii\web\View */
9 /* @var $model backend\models\Importers */ 9 /* @var $model backend\models\Importers */
backend/views/layouts/column.php
@@ -325,7 +325,6 @@ $this-&gt;beginContent(&#39;@app/views/layouts/main.php&#39;); @@ -325,7 +325,6 @@ $this-&gt;beginContent(&#39;@app/views/layouts/main.php&#39;);
325 ['label' => 'Vin коды', 'url' => ['currency/index']], 325 ['label' => 'Vin коды', 'url' => ['currency/index']],
326 ['label' => 'Запросы по номеру', 'url' => ['currency/index']], 326 ['label' => 'Запросы по номеру', 'url' => ['currency/index']],
327 ['label' => 'Офисы', 'url' => ['offices/index']], 327 ['label' => 'Офисы', 'url' => ['offices/index']],
328 - ['label' => 'Валюты', 'url' => ['currency/index']],  
329 ], 328 ],
330 ], 329 ],
331 ['label' => 'Анализ', 'url' => ['#'], 'items' => [ 330 ['label' => 'Анализ', 'url' => ['#'], 'items' => [
backend/web/css/AdminLTE.css
@@ -2558,6 +2558,7 @@ a:focus { @@ -2558,6 +2558,7 @@ a:focus {
2558 } 2558 }
2559 .table-bordered { 2559 .table-bordered {
2560 border: 1px solid #f4f4f4; 2560 border: 1px solid #f4f4f4;
  2561 +
2561 } 2562 }
2562 .table-bordered > thead > tr > th, 2563 .table-bordered > thead > tr > th,
2563 .table-bordered > tbody > tr > th, 2564 .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/components/CommaNumberValidator.php 0 → 100644
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: Tsurkanov
  5 + * Date: 25.11.2015
  6 + * Time: 13:51
  7 + */
  8 +
  9 +namespace common\components;
  10 +
  11 +use yii\validators\NumberValidator;
  12 +
  13 +
  14 +/**
  15 + * Class CommaNumberValidator
  16 + * @package common\components
  17 + * validator identic to NumberValidator,
  18 + * with one change - comma replaced to dot,
  19 + * thus values such 21,4; 45,05 - will be valid
  20 + */
  21 +class CommaNumberValidator extends NumberValidator {
  22 + // override parent pattern - add ',' to it
  23 + public $numberPattern = '/^\s*[-+]?[0-9]*[\.,]?[0-9]+([eE][-+]?[0-9]+)?\s*$/';
  24 +
  25 + public function validateAttribute($model, $attribute)
  26 + {
  27 + $value = $model->$attribute;
  28 + if ( !is_array($value) ) {
  29 + $model->$attribute = $this->commaReplacement( $value );
  30 + $value = $model->$attribute;
  31 + }
  32 +
  33 + if (is_array($value)) {
  34 + $this->addError($model, $attribute, $this->message);
  35 + return;
  36 + }
  37 + $pattern = $this->integerOnly ? $this->integerPattern : $this->numberPattern;
  38 + if (!preg_match($pattern, "$value")) {
  39 + $this->addError($model, $attribute, $this->message);
  40 + }
  41 + if ($this->min !== null && $value < $this->min) {
  42 + $this->addError($model, $attribute, $this->tooSmall, ['min' => $this->min]);
  43 + }
  44 + if ($this->max !== null && $value > $this->max) {
  45 + $this->addError($model, $attribute, $this->tooBig, ['max' => $this->max]);
  46 + }
  47 + }
  48 +
  49 + protected function validateValue($value)
  50 + {
  51 + $value = $this->commaReplacement( $value );
  52 +
  53 + return parent::validateValue( $value );
  54 + }
  55 +
  56 +
  57 + protected function commaReplacement( $value )
  58 + {
  59 + return str_replace( ',', '.', $value );
  60 + }
  61 +}
0 \ No newline at end of file 62 \ No newline at end of file
common/components/parsers/CustomConverter.php
@@ -39,7 +39,6 @@ class CustomConverter extends Converter @@ -39,7 +39,6 @@ class CustomConverter extends Converter
39 39
40 public static function convertToCrosses( array $row ) 40 public static function convertToCrosses( array $row )
41 { 41 {
42 -  
43 $details_model = new DetailsCrosses(); 42 $details_model = new DetailsCrosses();
44 // проверим все ли обязательные колонки были указаны пользователем 43 // проверим все ли обязательные колонки были указаны пользователем
45 $details_model->load(['DetailsCrosses' => $row]); 44 $details_model->load(['DetailsCrosses' => $row]);
@@ -53,6 +52,7 @@ class CustomConverter extends Converter @@ -53,6 +52,7 @@ class CustomConverter extends Converter
53 } 52 }
54 return $row; 53 return $row;
55 } 54 }
  55 +
56 public function ConvertToMultiply(array $row) 56 public function ConvertToMultiply(array $row)
57 { 57 {
58 $PRICE = $row['PRICE']; 58 $PRICE = $row['PRICE'];
@@ -128,7 +128,7 @@ class CustomConverter extends Converter @@ -128,7 +128,7 @@ class CustomConverter extends Converter
128 128
129 public static function convertToBrand($value) 129 public static function convertToBrand($value)
130 { 130 {
131 - $res = self::convertToEncode($value);; 131 + $res = self::convertToEncode($value);
132 $res = trim(strtoupper($res)); 132 $res = trim(strtoupper($res));
133 $res = str_replace("Ä", "A", str_replace("Ö", "O", str_replace("Ü", "U", str_replace("Ë", "E", str_replace("Ò", "O", $res))))); 133 $res = str_replace("Ä", "A", str_replace("Ö", "O", str_replace("Ü", "U", str_replace("Ë", "E", str_replace("Ò", "O", $res)))));
134 $res = str_replace(array('@', '#', '~', '"', "'", "?", "!"), '', $res); 134 $res = str_replace(array('@', '#', '~', '"', "'", "?", "!"), '', $res);
common/components/parsers/config.php
@@ -39,9 +39,10 @@ @@ -39,9 +39,10 @@
39 'crosses' => ['class' => 'common\components\parsers\CustomCsvParser', 39 'crosses' => ['class' => 'common\components\parsers\CustomCsvParser',
40 'auto_detect_first_line' => true, 40 'auto_detect_first_line' => true,
41 'min_column_quantity' => 4, 41 'min_column_quantity' => 4,
42 - // 'keys' =>['ARTICLE', 'CROSS_ARTICLE', 'BRAND', 'CROSS_BRAND'], 42 + // 'keys' =>['ARTICLE', 'CROSS_ARTICLE', 'BRAND', 'CROSS_BRAND'],
43 'converter_conf' => [ 43 'converter_conf' => [
44 'class' => ' common\components\parsers\CustomConverter', 44 'class' => ' common\components\parsers\CustomConverter',
  45 + 'hasKey' => 1,
45 'configuration' => [ 46 'configuration' => [
46 "brand" => ['BRAND', 'CROSS_BRAND'], 47 "brand" => ['BRAND', 'CROSS_BRAND'],
47 "crosses" => [], 48 "crosses" => [],
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 }
common/models/Currency.php
@@ -30,7 +30,10 @@ class Currency extends \yii\db\ActiveRecord @@ -30,7 +30,10 @@ class Currency extends \yii\db\ActiveRecord
30 { 30 {
31 return [ 31 return [
32 [['name', 'rate'], 'required'], 32 [['name', 'rate'], 'required'],
33 - [['rate'], 'number'], 33 +// [['rate'], 'filter','filter' => function($value){
  34 +// return (float) str_replace( ',', '.', $value );}
  35 +// ],
  36 + ['rate', \common\components\CommaNumberValidator::className()],
34 [['is_default'], 'integer'], 37 [['is_default'], 'integer'],
35 [['timestamp'], 'safe'], 38 [['timestamp'], 'safe'],
36 [['name'], 'string', 'max' => 50], 39 [['name'], 'string', 'max' => 50],
common/models/DetailsCrosses.php
@@ -45,8 +45,8 @@ class DetailsCrosses extends \yii\db\ActiveRecord @@ -45,8 +45,8 @@ class DetailsCrosses extends \yii\db\ActiveRecord
45 'ID' => 'ID', 45 'ID' => 'ID',
46 'ARTICLE' => 'АРТИКУЛ', 46 'ARTICLE' => 'АРТИКУЛ',
47 'BRAND' => 'БРЕНД', 47 'BRAND' => 'БРЕНД',
48 - 'CROSS_ARTICLE' => 'КРОСС БРЕНД',  
49 - 'CROSS_BRAND' => 'КРОСС АРТИКУЛ', 48 + 'CROSS_ARTICLE' => 'КРОСС АРТИКУЛ',
  49 + 'CROSS_BRAND' => 'КРОСС БРЕНД',
50 'timestamp' => 'ВРЕМЯ ДОБАВЛЕНИЯ', 50 'timestamp' => 'ВРЕМЯ ДОБАВЛЕНИЯ',
51 ]; 51 ];
52 } 52 }
common/models/DetailsCrossesSearch.php
@@ -47,18 +47,18 @@ class DetailsCrossesSearch extends DetailsCrosses @@ -47,18 +47,18 @@ class DetailsCrossesSearch extends DetailsCrosses
47 ]; 47 ];
48 48
49 // удалим пустые параметры 49 // удалим пустые параметры
50 - if ( isset($params['DetailsCrossesSearch']) && is_array( $params['DetailsCrossesSearch'] )) {  
51 - $params['DetailsCrossesSearch'] = array_filter( $params['DetailsCrossesSearch'], function($val){  
52 - return $val !="";  
53 - });  
54 - } 50 +// if ( isset($params['DetailsCrossesSearch']) && is_array( $params['DetailsCrossesSearch'] )) {
  51 +// $params['DetailsCrossesSearch'] = array_filter( $params['DetailsCrossesSearch'], function($val){
  52 +// return $val !="";
  53 +// });
  54 +// }
55 $this->load($params); 55 $this->load($params);
56 56
57 if ( !$this->validate() ) { 57 if ( !$this->validate() ) {
58 $query->where('0=1'); 58 $query->where('0=1');
59 } 59 }
60 60
61 - if ( !$params || !$params['DetailsCrossesSearch'] ) { 61 + if ( !$params || !isset($params['DetailsCrossesSearch']) ) {
62 // если не переданы параметры - показываем первые 100 записей 62 // если не переданы параметры - показываем первые 100 записей
63 $pagination = false; 63 $pagination = false;
64 $query->limit = 100; 64 $query->limit = 100;
tests/_support/_generated/UnitTesterActions.php
1 -<?php //[STAMP] 76e040407b5f5ec0a4bfcf45c4064e51 1 +<?php //[STAMP] 6943f83782f0ac615ed36fefe0f4d3a8
2 namespace _generated; 2 namespace _generated;
3 3
4 // This class was automatically generated by build task 4 // This class was automatically generated by build task
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/BaseConverterTest.php
@@ -21,18 +21,19 @@ class BaseConverterTest extends \Codeception\TestCase\Test @@ -21,18 +21,19 @@ class BaseConverterTest extends \Codeception\TestCase\Test
21 { 21 {
22 $this->converter = new Converter(); 22 $this->converter = new Converter();
23 23
24 - $this->configuration = ['configuration' =>  
25 - ["encode" => 'encode',  
26 - "string" => ['string1', 'string2' ],  
27 - "float" => 'float',  
28 - "integer" => ['integer1', 'integer2' ], 24 + $this->configuration = ['hasKey' => true,
  25 + 'configuration' =>
  26 + ['encode' => 'encode',
  27 + 'string' => ['string1', 'string2' ],
  28 + 'float' => 'float',
  29 + 'integer' => ['integer1', 'integer2' ],
29 ]]; 30 ]];
30 31
31 $this->wrong_configuration = ['config' => 32 $this->wrong_configuration = ['config' =>
32 - ["encode" => 'encode',  
33 - "string" => 'string',  
34 - "float" => 'float',  
35 - "integer" => 'integer', 33 + ['encode' => 'encode',
  34 + 'string' => 'string',
  35 + 'float' => 'float',
  36 + 'integer' => 'integer',
36 ]]; 37 ]];
37 38
38 $this->data_in = [ 39 $this->data_in = [
@@ -49,7 +50,7 @@ class BaseConverterTest extends \Codeception\TestCase\Test @@ -49,7 +50,7 @@ class BaseConverterTest extends \Codeception\TestCase\Test
49 50
50 public function testConvertByConfig(){ 51 public function testConvertByConfig(){
51 52
52 - $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->configuration ); 53 + $this->data_out = $this->converter->convertByConfiguration( $this->data_in, $this->configuration );
53 $this->assertEquals( $this->data_out['encode'], iconv( 'windows-1251', 'UTF-8', 'test encode string' ), 'Encoding failed' ); 54 $this->assertEquals( $this->data_out['encode'], iconv( 'windows-1251', 'UTF-8', 'test encode string' ), 'Encoding failed' );
54 $this->assertInternalType( 'float', $this->data_out['float'], 'Convert to float is failed' ); 55 $this->assertInternalType( 'float', $this->data_out['float'], 'Convert to float is failed' );
55 56
@@ -58,7 +59,7 @@ class BaseConverterTest extends \Codeception\TestCase\Test @@ -58,7 +59,7 @@ class BaseConverterTest extends \Codeception\TestCase\Test
58 public function testConvertToException(){ 59 public function testConvertToException(){
59 60
60 $this->setExpectedException('\Exception'); 61 $this->setExpectedException('\Exception');
61 - $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->wrong_configuration ); 62 + $this->data_out = $this->converter->convertByConfiguration( $this->data_in, $this->wrong_configuration );
62 63
63 } 64 }
64 65
tests/unit/CrossesParsingTest.php
@@ -13,21 +13,27 @@ class CrossesParsingTest extends \Codeception\TestCase\Test @@ -13,21 +13,27 @@ class CrossesParsingTest extends \Codeception\TestCase\Test
13 13
14 private $options; 14 private $options;
15 private $file_path; 15 private $file_path;
  16 + private $data = [];
16 17
17 public function _before() 18 public function _before()
18 { 19 {
19 $this->options[ 'mode' ] = 'crosses'; 20 $this->options[ 'mode' ] = 'crosses';
20 - $this->options[ 'converter_conf' ] = [ 'configuration' => [ "string" => ['ARTICLE', 'CROSS_ARTICLE'], ] ]; 21 +
  22 +
21 $this->file_path = Yii::getAlias('@data_parser') . '\crosses\test1.csv'; 23 $this->file_path = Yii::getAlias('@data_parser') . '\crosses\test1.csv';
22 24
23 } 25 }
24 26
25 public function testReadCrosses(){ 27 public function testReadCrosses(){
26 28
27 - $data = [];  
28 - $data = Yii::$app->multiparser->parse( $this->file_path, $this->options );  
29 - $this->assertNotEmpty( $data, 'Output array is empty' );  
30 - $this->assertNotCount( 76, $data, 'Output array don`t have 76 rows' ); 29 + $this->data = Yii::$app->multiparser->parse( $this->file_path, $this->options );
  30 + $this->assertNotEmpty( $this->data, 'Output array is empty' );
  31 + $this->assertNotCount( 76, $this->data, 'Output array don`t have 76 rows' );
  32 + $this->assertArrayHasKey( 'ARTICLE', $this->data[0], 'Output array don`t have key - ARTICLE' );
  33 + $this->assertArrayHasKey( 'CROSS_ARTICLE', $this->data[0], 'Output array don`t have key - CROSS_ARTICLE' );
  34 + $this->assertArrayHasKey( 'BRAND', $this->data[0], 'Output array don`t have key - BRAND' );
  35 + $this->assertArrayHasKey( 'CROSS_BRAND', $this->data[0], 'Output array don`t have key - CROSS_BRAND' );
  36 + $this->assertEquals( $this->data[0]['BRAND'], strtoupper($this->data[0]['BRAND']),'BRAND not converted to upper case' );
31 } 37 }
32 38
33 39