diff --git a/models/Order.php b/models/Order.php index 244f1ba..889a514 100755 --- a/models/Order.php +++ b/models/Order.php @@ -54,6 +54,8 @@ * @property string $city * @property string $deliveryString * @property boolean $published + * @property float $credit_sum + * @property int $credit_month */ class Order extends ActiveRecord { @@ -161,6 +163,22 @@ ], [ [ + 'credit_month', + ], + 'integer', + 'min' => 3, + 'max' => 36, + ], + [ + [ + 'credit_sum', + ], + 'number', + 'min' => 300, + 'max' => 25000, + ], + [ + [ 'deadline', 'name', 'numbercard', @@ -246,6 +264,8 @@ 'shipping_by' => Yii::t('app', 'Отправка за счет'), 'city' => Yii::t('app', 'Город'), 'numbercard' => Yii::t('app', '№ карточки'), + 'credit_month' => Yii::t('app', 'Количество месяцев'), + 'credit_sum' => Yii::t('app', 'Сумма кредита'), ]; } diff --git a/views/order/_form.php b/views/order/_form.php index 63a20e9..21fa5f5 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\components\CreditHelper; use common\models\User; use kartik\grid\GridView; use kartik\grid\SerialColumn; @@ -144,571 +145,608 @@ JS; 'main-form', -// 'options' => [ 'class' => 'form-inline' ], + 'id' => 'main-form', + // 'options' => [ 'class' => 'form-inline' ], ] ); ?>
-
-
-
-
- - field($model, 'deadline') - ->widget( - DatePicker::className(), - [ - - ] - ) ?> - - isAdmin()) { - echo $form->field($model, 'pay') - ->widget( - SwitchInput::className(), +
+
+
+
+ + 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') + ->textInput([ 'readonly' => $user->isAdmin() ? false : true ]) ?> + + 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', + ] + ); + ?> +
+
+
+ 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', + ] + ); + } + ?> +
+
+ 'pay', - 'pluginOptions' => [ - 'onText' => \Yii::t('app', 'Оплачено'), - 'offText' => \Yii::t('app', 'Не оплачено'), - ], + '1' => 'Первый номер', + '2' => 'Второй номер', ] ); - } - ?> - - 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') - ->textInput([ 'readonly' => $user->isAdmin() ? false : true ]) ?> - - 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', - ] - ); - ?> -
-
-
- 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', - ] - ); - } - ?> -
-
- 'Первый номер', - '2' => 'Второй номер', - ] - ); - ?> -
+ ?> +
+
+ +
+
+ + 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' => 'Способ оплаты ...' ] + ); ?> + payment == 10) { + ?> +
+
+ field($model, 'credit_sum') + ->textInput( + [ + 'class' => 'form-control credit_input', + ] + ); + ?> +
+
+ field($model, 'credit_month') + ->textInput( + [ + 'class' => 'form-control credit_input', + ] + ); + ?> +
+
+

+ + total); + ?> + + грн/мес +

+
+ + + 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') ?> + +
- -
-
- - 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' => 'Способ оплаты ...' ] - ); ?> - - 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') ?> - -
-


-
- $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)) { +
+ $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)) { + 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', - // 'data' => [ - // 'confirm' => 'Вы уверены, что хотите удалить этот элемент?', - // 'method' => 'GET', - // ], - ] - ); - } - }, - ], - ], - ], - 'responsive' => true, - 'hover' => true, - 'pjax' => true, - 'pjaxSettings' => [ - 'options' => [ - 'scrollTo' => 'false', - 'id' => 'order-products-grid', - ], - ], - ] - ); - ?> -
+ } + + 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', + // 'data' => [ + // 'confirm' => 'Вы уверены, что хотите удалить этот элемент?', + // 'method' => 'GET', + // ], + ] + ); + } + }, + ], + ], + ], + 'responsive' => true, + 'hover' => true, + 'pjax' => true, + 'pjaxSettings' => [ + 'options' => [ + 'scrollTo' => 'false', + 'id' => 'order-products-grid', + ], + ], + ] + ); + ?> +
'total-cost' ]); ?> -

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

+

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

-
- yii\helpers\Url::to([ 'add' ]), - 'id' => 'add-product-form', - ] - ); - $newOrderProduct = new OrderProduct(); - ?> -
- field($newOrderProduct, 'id') - ->widget( - Select2::className(), - [ - 'options' => [ 'placeholder' => 'Search for a product ...' ], - 'pluginOptions' => [ - 'allowClear' => true, - 'disabled' => $model->isNewRecord ? true : false, - 'minimumInputLength' => 3, - 'language' => [ - 'errorLoading' => new JsExpression( - "function () { return 'Waiting for results...'; }" +
+ yii\helpers\Url::to([ 'add' ]), + 'id' => 'add-product-form', + ] + ); + $newOrderProduct = new OrderProduct(); + ?> +
+ field($newOrderProduct, 'id') + ->widget( + Select2::className(), + [ + 'options' => [ 'placeholder' => 'Search for a product ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'disabled' => $model->isNewRecord ? true : false, + 'minimumInputLength' => 3, + 'language' => [ + 'errorLoading' => new JsExpression( + "function () { return 'Waiting for results...'; }" + ), + ], + 'ajax' => [ + 'url' => \yii\helpers\Url::to([ 'find-product' ]), + 'dataType' => 'json', + 'data' => new JsExpression( + 'function(params) { return {q:params.term}; }' + ), + ], + 'escapeMarkup' => new JsExpression( + 'function (markup) { return markup; }' ), - ], - 'ajax' => [ - 'url' => \yii\helpers\Url::to([ 'find-product' ]), - 'dataType' => 'json', - 'data' => new JsExpression( - 'function(params) { return {q:params.term}; }' + 'templateResult' => new JsExpression( + 'function(data) { return data.sku; }' + ), + 'templateSelection' => new JsExpression( + 'function (data) { return data.sku; }' ), ], - 'escapeMarkup' => new JsExpression( - 'function (markup) { return markup; }' - ), - 'templateResult' => new JsExpression( - 'function(data) { return data.sku; }' - ), - 'templateSelection' => new JsExpression( - 'function (data) { return data.sku; }' - ), - ], - ] - ) - ->label('Артикул'); - - ?> -
-
- field( - $newOrderProduct, - 'count' - ) - ->input( - 'number', + ] + ) + ->label('Артикул'); + + ?> +
+
+ field( + $newOrderProduct, + 'count' + ) + ->input( + 'number', + [ + 'disabled' => $model->isNewRecord ? true : false, + ] + ); ?> +
+
+ $model->isNewRecord ? 'btn btn-primary disabled' : 'btn btn-primary', + ] + ) ?> +
+ field($newOrderProduct, 'order_id') + ->hiddenInput( [ - 'disabled' => $model->isNewRecord ? true : false, + '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-primary disabled' : 'btn btn-primary', + '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', ] ) ?>
- 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', - ] - ) ?> -

-- libgit2 0.21.4