diff --git a/controllers/OrderController.php b/controllers/OrderController.php index bb87173..aa57db7 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -6,6 +6,7 @@ use artweb\artbox\ecommerce\models\OrderLabelHistory; use artweb\artbox\ecommerce\models\OrderSearch; use common\components\CreditHelper; + use common\models\Permissions; use common\models\User; use Yii; use yii\data\ArrayDataProvider; @@ -57,7 +58,12 @@ public function actionIndex() { + /** + * @var Permissions $permissions + */ + $permissions = \Yii::$app->user->identity->permissions; $searchModel = new OrderSearch(); + $searchModel->permissions = $permissions; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render( @@ -65,6 +71,8 @@ [ 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, + 'allowedLabels' => empty($permissions) ? [] : $permissions->labelsArray, + 'canCreate' => empty($permissions) ? false : $permissions->create, ] ); } @@ -247,6 +255,19 @@ public function actionCreate() { + /** + * @var Permissions $permissions + */ + $permissions = \Yii::$app->user->identity->permissions; + + if (empty($permissions)) { + throw new ForbiddenHttpException(); + } else { + if (!$permissions->create) { + throw new ForbiddenHttpException(); + } + } + if (\Yii::$app->request->post('hasEditable')) { $orderProductId = \Yii::$app->request->post('editableKey'); $orderProduct = OrderProduct::findOne($orderProductId); @@ -388,6 +409,14 @@ throw new ForbiddenHttpException(); } } + if (!empty($user->permissions)) { + $permissions = $user->permissions; + if (!in_array($model->label, $user->permissions->labelsArray)) { + throw new ForbiddenHttpException(); + } + } else { + $permissions = Permissions::getDefault(); + } $dataProvider = new ActiveDataProvider( [ @@ -432,6 +461,7 @@ [ 'model' => $model, 'dataProvider' => $dataProvider, + 'permissions' => $permissions, ] ); } else { @@ -440,6 +470,7 @@ [ 'model' => $model, 'dataProvider' => $dataProvider, + 'permissions' => $permissions, ] ); } diff --git a/models/Order.php b/models/Order.php index 3effafa..04d207d 100755 --- a/models/Order.php +++ b/models/Order.php @@ -336,39 +336,38 @@ public static function attributeNames() { return [ - 'name' => Yii::t('app', 'order_name'), - 'phone' => Yii::t('app', 'order_phone'), - 'phone2' => Yii::t('app', 'Конактный телефон 2'), - 'email' => Yii::t('app', 'E-mail'), - 'comment' => Yii::t('app', 'Комментарий '), - 'created_at' => Yii::t('app', 'Дата добавления'), - 'updated_at' => Yii::t('app', 'Дата обновления'), - 'deleted_at' => Yii::t('app', 'Дата удаления'), - 'deadline' => Yii::t('app', 'Дедлайн'), - 'reason' => Yii::t('app', 'Причина'), - 'check' => Yii::t('app', 'Чек'), - 'sms' => Yii::t('app', 'СМС'), - 'consignment' => Yii::t('app', 'Номер накладной'), - 'manager_id' => Yii::t('app', 'Менеджер'), - 'delivery_cost' => Yii::t('app', 'Стоимость доставки'), - 'published' => Yii::t('app', 'Опубликован'), - 'label' => Yii::t('app', 'Метка'), - 'declaration' => Yii::t('app', 'Номер декларации'), - 'delivery' => Yii::t('app', 'Способ доставки'), - 'total' => Yii::t('app', 'Сумма'), - 'adress' => Yii::t('app', 'Адрес'), - 'pay' => Yii::t('app', 'Оплата'), - 'body' => Yii::t('app', 'Комментарий менеджера'), - 'id' => Yii::t('app', 'Номер'), - 'stock' => Yii::t('app', 'Номер склада'), - 'payment' => Yii::t('app', 'Способ оплаты'), - 'insurance' => Yii::t('app', 'Страховка'), - 'amount_imposed' => Yii::t('app', 'Сумма наложенного'), - 'shipping_by' => Yii::t('app', 'Отправка за счет'), - 'city' => Yii::t('app', 'Город'), - 'numbercard' => Yii::t('app', '№ карточки'), - 'credit_month' => Yii::t('app', 'Количество месяцев'), - 'credit_sum' => Yii::t('app', 'Первоначальный взнос'), + 'name' => Yii::t('app', 'order_name'), + 'phone' => Yii::t('app', 'order_phone'), + 'phone2' => Yii::t('app', 'Конактный телефон 2'), + 'email' => Yii::t('app', 'E-mail'), + 'comment' => Yii::t('app', 'Комментарий '), + 'deadline' => Yii::t('app', 'Дедлайн'), + 'reason' => Yii::t('app', 'Причина'), + 'check' => Yii::t('app', 'Чек'), + 'sms' => Yii::t('app', 'СМС'), + 'consignment' => Yii::t('app', 'Номер накладной'), + 'manager_id' => Yii::t('app', 'Менеджер'), + 'delivery_cost' => Yii::t('app', 'Стоимость доставки'), + 'label' => Yii::t('app', 'Метка'), + 'declaration' => Yii::t('app', 'Номер декларации'), + 'delivery' => Yii::t('app', 'Способ доставки'), + 'adress' => Yii::t('app', 'Адрес'), + 'pay' => Yii::t('app', 'Оплата'), + 'body' => Yii::t('app', 'Комментарий менеджера'), + 'stock' => Yii::t('app', 'Номер склада'), + 'payment' => Yii::t('app', 'Способ оплаты'), + 'insurance' => Yii::t('app', 'Страховка'), + 'amount_imposed' => Yii::t('app', 'Сумма наложенного'), + 'shipping_by' => Yii::t('app', 'Отправка за счет'), + 'city' => Yii::t('app', 'Город'), + 'numbercard' => Yii::t('app', '№ карточки'), + 'send_sms' => Yii::t('app', 'Отправлять смс'), + 'product_booking' => Yii::t('app', 'Бронь товара'), + 'product_status' => Yii::t('app', 'Статус товара'), + 'product_return' => Yii::t('app', 'Возврат товара'), + 'add_product' => Yii::t('app', 'Добавить товар'), + 'delete_product' => Yii::t('app', 'Удалить товар'), + 'product_count' => Yii::t('app', 'Количество товара'), ]; } @@ -443,7 +442,7 @@ { return $this->hasMany(OrderLog::className(), [ 'order_id' => 'id' ]); } - + /** * @return \yii\db\ActiveQuery */ diff --git a/models/OrderSearch.php b/models/OrderSearch.php index f7238cd..cd3b5ce 100755 --- a/models/OrderSearch.php +++ b/models/OrderSearch.php @@ -2,13 +2,15 @@ namespace artweb\artbox\ecommerce\models; + use common\models\Permissions; use yii\base\Model; use yii\data\ActiveDataProvider; use yii\helpers\ArrayHelper; - use yii\helpers\VarDumper; /** * OrderSearch represents the model behind the search form about `\artweb\artbox\ecommerce\models\Order`. + * + * @property Permissions $permissions */ class OrderSearch extends Order { @@ -17,6 +19,8 @@ public $date_range; public $sku; + public $permissions; + /** * @inheritdoc */ @@ -160,6 +164,14 @@ $this->declaration, ] ); + + if (!empty($this->permissions)) + { + $query->andFilterWhere([ + 'label' => $this->permissions->labelsArray, + ]); + } + $query->andFilterWhere( [ 'label' => $this->label, diff --git a/views/order/_form.php b/views/order/_form.php index 216bc8c..13e1bd9 100755 --- a/views/order/_form.php +++ b/views/order/_form.php @@ -5,6 +5,7 @@ use artweb\artbox\ecommerce\models\OrderPayment; use artweb\artbox\ecommerce\models\OrderProduct; use backend\models\SmsTemplate; + use common\models\Permissions; use common\models\User; use kartik\grid\GridView; use kartik\grid\SerialColumn; @@ -27,6 +28,7 @@ * @var ActiveForm $form * @var ActiveDataProvider $dataProvider * @var User $user + * @var Permissions $permissions */ $user = \Yii::$app->user->identity; @@ -160,231 +162,266 @@ JS;
- - -
-
-
- -
-
- - field($model, 'deadline') - ->widget( - DatePicker::className(), - [ - - ] - ) ?> - - isAdmin()) { - echo $form->field($model, 'pay') - ->widget( - SwitchInput::className(), - [ - 'name' => 'pay', - 'pluginOptions' => [ - 'onText' => \Yii::t('app', 'Оплачено'), - 'offText' => \Yii::t('app', 'Не оплачено'), - ], - ] - ); - } - ?> - - field($model, 'reason') - ->dropDownList( - Order::REASONS, - [ 'prompt' => 'Выберите причину' ] - ) ?> - - field($model, 'label') - ->dropDownList( - ArrayHelper::map( - Label::find() - ->asArray() - ->all(), - 'id', - 'label' - ), - [ 'prompt' => 'Выберите метку' ] - ); ?> - - field($model, 'name') ?> - - field($model, 'phone') ?> - - field($model, 'phone2') ?> - - field($model, 'email') - ->textInput([ 'readonly' => $user->isAdmin() ? false : true ]) ?> - - field( - $model, - 'numbercard' - ) - ->textInput([ 'readonly' => true ]) ?> - - field($model, 'comment') - ->textarea([ 'rows' => '3' ]) ?> - field($model, 'delivery') - ->dropDownList( - ArrayHelper::map( - Delivery::find() - ->joinWith('lang') - ->asArray() - ->all(), - 'id', - 'lang.title' - ), - [ 'prompt' => \Yii::t('app', 'Выберите доставку ...') ] - ) ?> - - isAdmin()) { - echo $form->field($model, 'manager_id') - ->dropDownList( - ArrayHelper::map( - User::find() - ->asArray() - ->all(), - 'id', - 'username' - ), - [ 'prompt' => \Yii::t('app', 'Менеджер') ] - ); - } - ?> - -

- 'sms-template-selector', - 'name' => 'select-sms-template', - 'data' => ArrayHelper::map( - SmsTemplate::find() - ->asArray() - ->all(), - 'text', - 'title' - ), - 'options' => [ 'placeholder' => \Yii::t('app', 'Выберите шаблон') ], - 'pluginOptions' => [ - 'allowClear' => true, - ], - ] - ); - - ?> -
- 3, - 'id' => 'sms-text-area', - 'class' => 'form-control', - ] - ); - ?> +
+

+ +
-
+
+ + field($model, 'deadline') + ->widget( + DatePicker::className(), + [ + 'disabled' => !$permissions->checkAttr('deadline'), + ] + ) ?> + isNewRecord) { - echo Html::button( - \Yii::t('app', 'Отправить'), - [ - 'class' => 'btn btn-warning disabled', - ] - ); - } else { - echo Html::button( - \Yii::t('app', 'Отправить'), - [ - 'class' => 'btn btn-warning', - 'id' => 'send-sms-action', - ] - ); + if ($permissions->checkAttr('pay')) { + echo $form->field($model, 'pay') + ->widget( + SwitchInput::className(), + [ + 'name' => 'pay', + 'pluginOptions' => [ + 'onText' => \Yii::t('app', 'Оплачено'), + 'offText' => \Yii::t('app', 'Не оплачено'), + ], + ] + ); } ?> -
-
+ + field($model, 'reason') + ->dropDownList( + Order::REASONS, + [ + 'prompt' => 'Выберите причину', + 'disabled' => !$permissions->checkAttr('reason'), + ] + ) ?> + + field($model, 'label') + ->dropDownList( + ArrayHelper::map( + Label::find() + ->asArray() + ->all(), + 'id', + 'label' + ), + [ + 'prompt' => 'Выберите метку', + 'disabled' => !$permissions->checkAttr('label'), + ] + ); ?> + + field($model, 'name') + ->textInput([ 'readonly' => !$permissions->checkAttr('name') ]) ?> + + field($model, 'phone') + ->textInput([ 'readonly' => !$permissions->checkAttr('phone') ]) ?> + + field($model, 'phone2') + ->textInput([ 'readonly' => !$permissions->checkAttr('phone2') ]) ?> + + field($model, 'email') + ->textInput([ 'readonly' => !$permissions->checkAttr('email') ]) ?> + + field( + $model, + 'numbercard' + ) + ->textInput([ 'readonly' => !$permissions->checkAttr('numbercard') ]) ?> + + field($model, 'comment') + ->textarea( + [ + 'rows' => '3', + 'readonly' => !$permissions->checkAttr('comment'), + ] + ) ?> + field($model, 'delivery') + ->dropDownList( + ArrayHelper::map( + Delivery::find() + ->joinWith('lang') + ->asArray() + ->all(), + 'id', + 'lang.title' + ), + [ + 'prompt' => \Yii::t('app', 'Выберите доставку ...'), + 'disabled' => !$permissions->checkAttr('delivery'), + ] + ) ?> + + checkAttr('manager_id')) { + echo $form->field($model, 'manager_id') + ->dropDownList( + ArrayHelper::map( + User::find() + ->asArray() + ->all(), + 'id', + 'username' + ), + [ 'prompt' => \Yii::t('app', 'Менеджер') ] + ); + } + ?> + +

+ 'sms-template-selector', + 'name' => 'select-sms-template', + 'data' => ArrayHelper::map( + SmsTemplate::find() + ->asArray() + ->all(), + 'text', + 'title' + ), + 'options' => [ 'placeholder' => \Yii::t('app', 'Выберите шаблон') ], + 'pluginOptions' => [ + 'allowClear' => true, + ], + ] + ); + + ?> +
'Первый номер', - '2' => 'Второй номер', + 'rows' => 3, + 'id' => 'sms-text-area', + 'class' => 'form-control', ] ); ?> +
+
+
+ checkAttr('send_sms')) { + echo Html::button( + \Yii::t('app', 'Отправить'), + [ + 'class' => 'btn btn-warning disabled', + ] + ); + } else { + echo Html::button( + \Yii::t('app', 'Отправить'), + [ + 'class' => 'btn btn-warning', + 'id' => 'send-sms-action', + ] + ); + } + ?> +
+
+ 'Первый номер', + '2' => 'Второй номер', + ] + ); + ?> +
+
+ +
+
+ + field($model, 'declaration') + ->textInput([ 'readonly' => !$permissions->checkAttr('declaration') ]) ?> + + field($model, 'stock') + ->textInput([ 'readonly' => !$permissions->checkAttr('stock') ]) ?> + + field($model, 'consignment') + ->textInput([ 'readonly' => !$permissions->checkAttr('consignment') ]) ?> + + field($model, 'payment') + ->dropDownList( + ArrayHelper::map( + OrderPayment::find() + ->where([ 'status' => OrderPayment::ACTIVE ]) + ->asArray() + ->all(), + 'id', + 'short' + ), + [ + 'prompt' => 'Способ оплаты ...', + 'disabled' => ( $model->payment == 10 || !$permissions->checkAttr( + 'payment' + ) ) ? 'disabled' : false, + ] + ); ?> + + field($model, 'insurance') + ->textInput([ 'readonly' => !$permissions->checkAttr('insurance') ]) ?> + + field($model, 'amount_imposed') + ->textInput([ 'readonly' => !$permissions->checkAttr('amount_imposed') ]) ?> + + field($model, 'shipping_by') + ->dropDownList( + ArrayHelper::getColumn(Order::SHIPPING_BY, 'label'), + [ + 'prompt' => 'Оплата доставки ...', + 'disabled' => !$permissions->checkAttr('shipping_by'), + ] + ); ?> + + field($model, 'city') + ->textInput([ 'readonly' => !$permissions->checkAttr('city') ]) ?> + + field($model, 'adress') + ->textInput([ 'readonly' => !$permissions->checkAttr('adress') ]) ?> + + field($model, 'body') + ->textarea( + [ + 'rows' => '3', + 'readonly' => !$permissions->checkAttr('body'), + ] + ) ?> + + field($model, 'check') + ->textInput([ 'readonly' => !$permissions->checkAttr('check') ]) ?> + + field($model, 'sms') + ->textInput([ 'readonly' => !$permissions->checkAttr('sms') ]) ?> + + field($model, 'delivery_cost') + ->textInput([ 'readonly' => !$permissions->checkAttr('delivery_cost') ]) ?> +
-
-
- - field($model, 'declaration') ?> - - field($model, 'stock') ?> - - field($model, 'consignment') ?> - - field($model, 'payment') - ->dropDownList( - ArrayHelper::map( - OrderPayment::find() - ->where([ 'status' => OrderPayment::ACTIVE ]) - ->asArray() - ->all(), - 'id', - 'short' - ), - [ - 'prompt' => 'Способ оплаты ...', - 'disabled' => $model->payment == 10 ? 'disabled' : false, - ] - ); ?> - - field($model, 'insurance') ?> - - field($model, 'amount_imposed') ?> - - field($model, 'shipping_by') - ->dropDownList( - ArrayHelper::getColumn(Order::SHIPPING_BY, 'label'), - [ 'prompt' => 'Оплата доставки ...' ] - ); ?> - - field($model, 'city') ?> - - field($model, 'adress') ?> - - field($model, 'body') - ->textarea([ 'rows' => '3' ]) ?> - - field($model, 'check') ?> - - field($model, 'sms') ?> - - field($model, 'delivery_cost') ?>
- - -
-
-
@@ -401,242 +438,247 @@ JS;
-
-
- $dataProvider, - 'rowOptions' => function ($model) { - if ($model->removed) { - return [ 'class' => 'danger' ]; - } else { - return []; - } - }, - 'layout' => '{items}{pager}', - 'columns' => [ - [ - 'class' => SerialColumn::className(), - ], - 'sku', - [ - 'attribute' => 'product_name', - 'content' => function ($model) { - if (!empty( $model->product_name )) { - - if (empty( $model->productVariant )) { - return ''; - } - - return Html::a( - StringHelper::truncate($model->product_name, 10, '...'), - '#', - [ - 'onclick' => 'event.preventDefault();', - 'data-toggle' => 'popover', - 'data-placement' => 'right', - 'data-html' => 'true', - 'data-content' => Html::img( - $model->productVariant->imageUrl, - [ - 'class' => 'img-rounded', - ] - ) . Html::tag('p', $model->product_name), - ] - ); - } else { - return ''; - } - }, - ], - [ - 'attribute' => 'productVariant.product.brand.lang.title', - 'label' => 'Брэнд', - ], - [ - 'attribute' => 'productVariant.lang.title', - 'label' => \Yii::t('app', 'Цвет'), - 'content' => function ($model) { - - if (empty( $model->productVariant )) { - return ''; - } - - if (preg_match('@.*\.(png|jpg|gif)@i', $model->productVariant->lang->title)) { - return ''; - } else { - return $model->productVariant->lang->title; - } - }, - ], - [ - 'attribute' => 'productVariant.size', - 'label' => 'Размер', - ], - 'price', - [ - 'class' => 'kartik\grid\EditableColumn', - 'attribute' => 'count', - 'editableOptions' => [ - 'header' => \Yii::t('app', 'Количество'), - 'inputType' => kartik\editable\Editable::INPUT_SPIN, - 'options' => [ - 'pluginOptions' => [ - 'min' => 0, - 'max' => 5000, - ], - ], - 'pluginEvents' => [ - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', - ], - ], - 'format' => [ - 'decimal', - 0, - ], - 'pageSummary' => false, - ], - 'sum_cost', - [ - 'class' => 'kartik\grid\EditableColumn', - 'attribute' => 'booking', - 'editableOptions' => [ - 'header' => \Yii::t('app', 'Бронь'), - 'inputType' => kartik\editable\Editable::INPUT_TEXT, - 'options' => [ - 'class' => 'booking-typeahead', - 'pluginOptions' => [ - 'min' => 0, - 'max' => 20, - ], - ], - 'pluginEvents' => [ - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', - ], - ], - 'format' => [ - 'text', - ], - 'pageSummary' => false, - ], - [ - 'class' => 'kartik\grid\EditableColumn', - 'attribute' => 'status', - 'editableOptions' => [ - 'header' => \Yii::t('app', 'Статус'), - 'inputType' => kartik\editable\Editable::INPUT_TEXT, - 'options' => [ - 'class' => 'status-typeahead', - 'pluginOptions' => [ - 'min' => 0, - 'max' => 20, - ], - ], - 'pluginEvents' => [ - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', - ], - ], - 'format' => [ - 'text', - ], - 'pageSummary' => false, - ], - [ - 'class' => 'kartik\grid\EditableColumn', - 'attribute' => 'return', - 'editableOptions' => [ - 'header' => \Yii::t('app', 'Возврат'), - 'inputType' => kartik\editable\Editable::INPUT_CHECKBOX, - 'options' => [], - 'pluginEvents' => [ - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', - ], - ], - 'format' => [ - 'boolean', - ], - 'pageSummary' => false, - ], - [ - 'content' => function ($model) { - - if (empty( $model->productVariant )) { - return ''; - } - - $content = ''; - foreach ($model->productVariant->variantStocks as $stock) { - $content .= ''; - } - return Html::a( - '', - '#', - [ - 'onclick' => 'event.preventDefault();', - 'data-toggle' => 'popover', - 'data-placement' => 'left', - 'data-html' => 'true', - 'data-content' => $content . '
Складкол.
' . $stock->stock->title . '' . $stock->quantity . '
', - ] - ); - }, - ], - [ - 'class' => 'yii\grid\ActionColumn', - 'template' => '{delete}', - 'buttons' => [ - 'delete' => function ($url, $product) { - if ($product->removed) { - return ''; - } else { - return Html::a( - Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-trash' ]), - [ - 'delete-product', - 'id' => $product->id, - ], - [ - 'class' => 'delete-button', - ] - ); - } - }, - ], - ], - ], - 'responsive' => true, - 'hover' => true, - 'pjax' => true, - 'pjaxSettings' => [ - 'options' => [ - 'scrollTo' => 'false', - 'id' => 'order-products-grid', - ], - ], - ] - ); - ?> +
+
+ $dataProvider, + 'rowOptions' => function($model) { + if ($model->removed) { + return [ 'class' => 'danger' ]; + } else { + return []; + } + }, + 'layout' => '{items}{pager}', + 'columns' => [ + [ + 'class' => SerialColumn::className(), + ], + 'sku', + [ + 'attribute' => 'product_name', + 'content' => function($model) { + if (!empty($model->product_name)) { + + if (empty($model->productVariant)) { + return ''; + } + + return Html::a( + StringHelper::truncate($model->product_name, 10, '...'), + '#', + [ + 'onclick' => 'event.preventDefault();', + 'data-toggle' => 'popover', + 'data-placement' => 'right', + 'data-html' => 'true', + 'data-content' => Html::img( + $model->productVariant->imageUrl, + [ + 'class' => 'img-rounded', + ] + ) . Html::tag('p', $model->product_name), + ] + ); + } else { + return ''; + } + }, + ], + [ + 'attribute' => 'productVariant.product.brand.lang.title', + 'label' => 'Брэнд', + ], + [ + 'attribute' => 'productVariant.lang.title', + 'label' => \Yii::t('app', 'Цвет'), + 'content' => function($model) { + + if (empty($model->productVariant)) { + return ''; + } + + if (preg_match('@.*\.(png|jpg|gif)@i', $model->productVariant->lang->title)) { + return ''; + } else { + return $model->productVariant->lang->title; + } + }, + ], + [ + 'attribute' => 'productVariant.size', + 'label' => 'Размер', + ], + 'price', + [ + 'class' => 'kartik\grid\EditableColumn', + 'attribute' => 'count', + 'editableOptions' => [ + 'header' => \Yii::t('app', 'Количество'), + 'inputType' => kartik\editable\Editable::INPUT_SPIN, + 'options' => [ + 'pluginOptions' => [ + 'min' => 0, + 'max' => 5000, + ], + 'disabled' => !$permissions->checkAttr('product_count'), + ], + 'pluginEvents' => [ + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', + ], + ], + 'format' => [ + 'decimal', + 0, + ], + 'pageSummary' => false, + ], + 'sum_cost', + [ + 'class' => 'kartik\grid\EditableColumn', + 'attribute' => 'booking', + 'editableOptions' => [ + 'header' => \Yii::t('app', 'Бронь'), + 'inputType' => kartik\editable\Editable::INPUT_TEXT, + 'options' => [ + 'class' => 'booking-typeahead', + 'pluginOptions' => [ + 'min' => 0, + 'max' => 20, + ], + 'disabled' => !$permissions->checkAttr('product_booking'), + ], + 'pluginEvents' => [ + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', + ], + ], + 'format' => [ + 'text', + ], + 'pageSummary' => false, + ], + [ + 'class' => 'kartik\grid\EditableColumn', + 'attribute' => 'status', + 'editableOptions' => [ + 'header' => \Yii::t('app', 'Статус'), + 'inputType' => kartik\editable\Editable::INPUT_TEXT, + 'options' => [ + 'class' => 'status-typeahead', + 'pluginOptions' => [ + 'min' => 0, + 'max' => 20, + ], + 'disabled' => !$permissions->checkAttr('product_status'), + ], + 'pluginEvents' => [ + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', + ], + ], + 'format' => [ + 'text', + ], + 'pageSummary' => false, + ], + [ + 'class' => 'kartik\grid\EditableColumn', + 'attribute' => 'return', + 'editableOptions' => [ + 'header' => \Yii::t('app', 'Возврат'), + 'inputType' => kartik\editable\Editable::INPUT_CHECKBOX, + 'options' => [ + 'disabled' => !$permissions->checkAttr('product_return'), + ], + 'pluginEvents' => [ + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', + ], + ], + 'format' => [ + 'boolean', + ], + 'pageSummary' => false, + ], + [ + 'content' => function($model) { + + if (empty($model->productVariant)) { + return ''; + } + + $content = ''; + foreach ($model->productVariant->variantStocks as $stock) { + $content .= ''; + } + return Html::a( + '', + '#', + [ + 'onclick' => 'event.preventDefault();', + 'data-toggle' => 'popover', + 'data-placement' => 'left', + 'data-html' => 'true', + 'data-content' => $content . '
Складкол.
' . $stock->stock->title . '' . $stock->quantity . '
', + ] + ); + }, + ], + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{delete}', + 'buttons' => [ + 'delete' => function($url, $product) use ($permissions) { + if ($product->removed || !$permissions->checkAttr('delete_product')) { + return ''; + } else { + return Html::a( + Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-trash' ]), + [ + 'delete-product', + 'id' => $product->id, + ], + [ + 'class' => 'delete-button', + ] + ); + } + }, + ], + ], + ], + 'responsive' => true, + 'hover' => true, + 'pjax' => true, + 'pjaxSettings' => [ + 'options' => [ + 'scrollTo' => 'false', + 'id' => 'order-products-grid', + ], + ], + ] + ); + ?> +
-
-
- 'total-cost' ]); ?> -

Сумма заказа : total; ?>

- -
-
-
- yii\helpers\Url::to([ 'add' ]), - 'id' => 'add-product-form', - ] - ); - $newOrderProduct = new OrderProduct(); - ?> +
+ 'total-cost' ]); ?> +

Сумма заказа : total; ?>

+ +
+
+
+ yii\helpers\Url::to([ 'add' ]), + 'id' => 'add-product-form', + ] + ); + $newOrderProduct = new OrderProduct(); + ?>
field($newOrderProduct, 'id') ->widget( @@ -691,64 +733,65 @@ JS; $model->isNewRecord ? 'btn btn-primary disabled' : 'btn btn-primary', + 'class' => ( $model->isNewRecord || !$permissions->checkAttr( + 'add_product' + ) ) ? 'btn btn-primary disabled' : 'btn btn-primary', ] ) ?>
- field($newOrderProduct, 'order_id') - ->hiddenInput( - [ - 'value' => $model->id, - ] - ) - ->label(false) ?> - -
- + field($newOrderProduct, 'order_id') + ->hiddenInput( + [ + 'value' => $model->id, + ] + ) + ->label(false) ?> + +
-
+
- - -
+ + +
-
- isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Сохранить'), - [ - 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg', - 'id' => 'page-submit', - ] - ) ?> - $model->id, - ] - ), - [ - 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', - 'target' => '_blank', - ] - ) ?> - $model->id, - ] - ), - [ - 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', - ] - ) ?> -
+
+ isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Сохранить'), + [ + 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg', + 'id' => 'page-submit', + ] + ) ?> + $model->id, + ] + ), + [ + 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', + 'target' => '_blank', + ] + ) ?> + $model->id, + ] + ), + [ + 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', + ] + ) ?> +


diff --git a/views/order/index.php b/views/order/index.php index 367c9fa..ee9c001 100755 --- a/views/order/index.php +++ b/views/order/index.php @@ -3,6 +3,8 @@ * @var ActiveDataProvider $dataProvider * @var OrderSearch $searchModel * @var View $this + * @var array $allowedLabels + * @var boolean $canCreate */ use artweb\artbox\ecommerce\models\Delivery; @@ -37,7 +39,10 @@ JS; ?>

Заказы

- 'btn btn-success btn-lg' ]) ?> + $canCreate ? 'btn btn-success btn-lg' : 'btn btn-success btn-lg disabled', + + ]) ?>

- - + + 'collapse', -// 'data-target' => '#search-fields', -// 'class' => 'btn btn-default' -//]); -//?> + // echo Html::button(\Yii::t('app', 'Скрыть/Показать'), [ + // 'data-toggle' => 'collapse', + // 'data-target' => '#search-fields', + // 'class' => 'btn btn-default' + //]); + //?>
- +
- -
-
- field($searchModel, 'label') - ->widget( - Select2::className(), - [ - 'data' => Label::find() - ->joinWith('lang') - ->select( - [ - 'CONCAT(order_label.label,order_label_lang.title) AS name', - 'id', - ] - ) - ->indexBy('id') - ->asArray() - ->column(), - 'options' => [ 'placeholder' => 'Выберите метки ...' ], - 'pluginOptions' => [ - 'allowClear' => true, - 'multiple' => true, - ], - ] - ); - ?> - field($searchModel, 'delivery') - ->widget( - Select2::className(), - [ - 'data' => Delivery::find() - ->joinWith('lang') - ->select('order_delivery_lang.title, id') - ->indexBy('id') - ->asArray() - ->column(), - 'options' => [ 'placeholder' => 'Выберите способ доставки ...' ], - 'pluginOptions' => [ - 'allowClear' => true, - 'multiple' => true, - ], - ] - ); - ?> - - field($searchModel, 'sku') - ->widget( - Select2::className(), - [ - 'options' => [ 'placeholder' => 'Search for a product ...' ], - 'pluginOptions' => [ - 'allowClear' => true, - 'minimumInputLength' => 3, - 'language' => [ - 'errorLoading' => new JsExpression( - "function () { return 'Waiting for results...'; }" - ), - ], - 'ajax' => [ - 'url' => \yii\helpers\Url::to([ 'find-product' ]), - 'dataType' => 'json', - 'data' => $query, - ], - 'escapeMarkup' => new JsExpression( - 'function (markup) { return markup; }' - ), - 'templateResult' => new JsExpression( - 'function(data) { return data.sku; }' - ), - 'templateSelection' => new JsExpression( - 'function (data) { + +
+
+ field($searchModel, 'label') + ->widget( + Select2::className(), + [ + 'data' => Label::find() + ->joinWith('lang') + ->select( + [ + 'CONCAT(order_label.label,order_label_lang.title) AS name', + 'id', + ] + ) + ->filterWhere([ 'id' => $allowedLabels ]) + ->indexBy('id') + ->asArray() + ->column(), + 'options' => [ 'placeholder' => 'Выберите метки ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'multiple' => true, + ], + ] + ); + ?> + field($searchModel, 'delivery') + ->widget( + Select2::className(), + [ + 'data' => Delivery::find() + ->joinWith('lang') + ->select('order_delivery_lang.title, id') + ->indexBy('id') + ->asArray() + ->column(), + 'options' => [ 'placeholder' => 'Выберите способ доставки ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'multiple' => true, + ], + ] + ); + ?> + + field($searchModel, 'sku') + ->widget( + Select2::className(), + [ + 'options' => [ 'placeholder' => 'Search for a product ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'language' => [ + 'errorLoading' => new JsExpression( + "function () { return 'Waiting for results...'; }" + ), + ], + 'ajax' => [ + 'url' => \yii\helpers\Url::to([ 'find-product' ]), + 'dataType' => 'json', + 'data' => $query, + ], + 'escapeMarkup' => new JsExpression( + 'function (markup) { return markup; }' + ), + 'templateResult' => new JsExpression( + 'function(data) { return data.sku; }' + ), + 'templateSelection' => new JsExpression( + 'function (data) { if(data.sku == undefined) { return "sku"; } else { return data.sku; } }' - ), - ], - ] - ); - - ?> -
+ ), + ], + ] + ); + + ?> +
-
- field($searchModel, 'manager_id') - ->dropDownList( - ArrayHelper::map( - User::find() - ->asArray() - ->all(), - 'id', - 'username' - ), - [ 'prompt' => \Yii::t('app', 'Выберите менеджера ...') ] - ) ?> - - field($searchModel, 'email') - ->textInput() ?> +
+ field($searchModel, 'manager_id') + ->dropDownList( + ArrayHelper::map( + User::find() + ->asArray() + ->all(), + 'id', + 'username' + ), + [ 'prompt' => \Yii::t('app', 'Выберите менеджера ...') ] + ) ?> + + field($searchModel, 'email') + ->textInput() ?> +
+
+ field($searchModel, 'declaration') + ->textInput() ?> + + field($searchModel, 'consignment') + ->textInput() ?> +
-
- field($searchModel, 'declaration') - ->textInput() ?> - - field($searchModel, 'consignment') - ->textInput() ?> -
-
- +

function($model) { $manager = $model->manager; if (empty($manager)) { - return Html::a($model->id, ['update', 'id' => $model->id], ['target' => '_blank', 'data-pjax' => '0']); + return Html::a( + $model->id, + [ + 'update', + 'id' => $model->id, + ], + [ + 'target' => '_blank', + 'data-pjax' => '0', + ] + ); } else { - return Html::a($model->id, ['update', 'id' => $model->id], ['target' => '_blank', 'data-pjax' => '0']) . '
' . $manager->username; + return Html::a( + $model->id, + [ + 'update', + 'id' => $model->id, + ], + [ + 'target' => '_blank', + 'data-pjax' => '0', + ] + ) . '
' . $manager->username; } }, ], @@ -279,10 +305,10 @@ JS; }, ], [ - 'attribute' => 'phone', - 'content' => function($model) { - return $model->phone . '
' . $model->phone2; - } + 'attribute' => 'phone', + 'content' => function($model) { + return $model->phone . '
' . $model->phone2; + }, ], [ 'attribute' => 'adress', @@ -349,22 +375,25 @@ JS; 'template' => \Yii::$app->user->identity->isAdmin( ) ? '{history} {view} {update} {delete}' : '{view} {update}', 'buttons' => [ - 'update' => function($url, $model) { + 'update' => function($url, $model) { return Html::a( Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-pencil' ]), $url, [ - 'target' => '_blank', - 'data-pjax' => '0', + 'target' => '_blank', + 'data-pjax' => '0', ] ); }, 'history' => function($url, $model) { return Html::a( Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-time' ]), - ['log', 'id' => $model->id], [ - 'target' => '_blank', + 'log', + 'id' => $model->id, + ], + [ + 'target' => '_blank', 'data-pjax' => '0', ] ); diff --git a/views/order/update.php b/views/order/update.php index 41f49c1..e405c63 100755 --- a/views/order/update.php +++ b/views/order/update.php @@ -3,9 +3,11 @@ * @var Order $model * @var View $this * @var ActiveDataProvider $dataProvider + * @var Permissions $permissions */ use artweb\artbox\ecommerce\models\Order; + use common\models\Permissions; use yii\data\ActiveDataProvider; use yii\helpers\Html; use yii\web\View; @@ -16,7 +18,12 @@ 'label' => \Yii::t('app', 'Заказы'), ]; $this->params[ 'breadcrumbs' ][] = [ - 'url' => yii\helpers\Url::to([ '/ecommerce/order/view', 'id' => $model->id, ]), + 'url' => yii\helpers\Url::to( + [ + '/ecommerce/order/view', + 'id' => $model->id, + ] + ), 'label' => \Yii::t('app', 'Заказ #') . $model->id, ]; $this->params[ 'breadcrumbs' ][] = $this->title; @@ -58,18 +65,18 @@ $.ajax({ '; $this->registerJs($js, View::POS_READY); - + if (!empty(\Yii::$app->session->getFlash('label_update'))) { - $js = ' + $js = ' $.notify({ message: "Статус заказа обновлен" }, { type : "warning" }) '; - $this->registerJs($js, View::POS_READY); + $this->registerJs($js, View::POS_READY); } - + ?>

@@ -84,6 +91,7 @@ $.notify({ [ 'model' => $model, 'dataProvider' => $dataProvider, + 'permissions' => $permissions, ] ) ?>
\ No newline at end of file -- libgit2 0.21.4