/** * @return array */ public function actionAjaxContragent($template = null) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $result = ['more' => false, 'results' => [[0 => Yii::t('app', 'New contragent')]]]; $search = \Yii::$app->request->get('search', []); $customer_id = isset($search['customer']) ? intval($search['customer']) : 0; $query = Contragent::find()->select('id, type')->where(['customer_id' => $customer_id])->asArray(); $result['results'] = array_merge(array_values($query->all()), $result['results']); if (!empty($result['results']) && 'simple' === $template) { $result['cards'] = array_reduce($result['results'], function ($result, $item) { /** @var array $item */ if (!empty($item['id'])) { $result[$item['id']] = \app\modules\shop\widgets\Contragent::widget(['viewFile' => 'contragent/backend_list', 'model' => Contragent::findOne(['id' => $item['id']])]); } return $result; }, []); } return $result; }
$_jsDataFunc = <<<'JSCODE' function (term, page) { return { search: {customer:$('select#order-customer_id').val()} }; } JSCODE; echo \app\backend\widgets\Select2Ajax::widget(['initialData' => [$model->contragent_id => null !== $model->contragent ? $model->contragent->type : 'New contragent'], 'model' => $model, 'modelAttribute' => 'contragent_id', 'form' => $form, 'multiple' => false, 'searchUrl' => \yii\helpers\Url::toRoute(['ajax-contragent', 'template' => 'simple']), 'pluginOptions' => ['minimumInputLength' => null, 'allowClear' => false, 'escapeMarkup' => new \yii\web\JsExpression('function (markup) {return markup;}'), 'templateResult' => new \yii\web\JsExpression($_jsTemplateResultFunc), 'templateSelection' => new \yii\web\JsExpression($_jsSelectionFunc), 'ajax' => ['data' => new \yii\web\JsExpression($_jsDataFunc), 'processResults' => new \yii\web\JsExpression($_jsProcessResultsFunc), 'cache' => true]]]); ?> <?php echo Html::tag('div', Html::a(Yii::t('app', 'Create contragent'), Url::toRoute(['/shop/backend-contragent/create']), ['target' => '_blank', 'class' => 'btn btn-xs btn-info new_contragent']) . Html::a(Yii::t('app', 'Edit contragent'), Url::toRoute(['/shop/backend-contragent/index']), ['target' => '_blank', 'class' => 'btn btn-xs btn-info edit_contragent']), ['class' => 'btn-group col-md-offset-2']); ?> <hr /> <div id="div_contragent"> <?php echo \app\modules\shop\widgets\Contragent::widget(['viewFile' => 'contragent/backend_list', 'model' => $model->contragent]); ?> </div> <?php BackendWidget::end(); ?> <?php BackendWidget::begin(['icon' => 'user', 'title' => Yii::t('app', 'Order delivery information')]); ?> <?php echo \app\modules\shop\widgets\Delivery::widget(['viewFile' => 'delivery/backend_form', 'orderDeliveryInformation' => $model->orderDeliveryInformation, 'form' => $form, 'immutable' => $orderIsImmutable]); ?> <?php BackendWidget::end(); ?>
<?php use app\backend\widgets\BackendWidget; use app\components\Helper; use yii\helpers\Html; /** * @var \yii\web\View $this * @var \app\modules\shop\models\Contragent $model */ $this->title = Yii::t('app', 'Contragent edit'); $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Contragents'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $form = \yii\bootstrap\ActiveForm::begin(['id' => 'contragent-form', 'action' => \yii\helpers\Url::toRoute(['create', 'customer' => $model->customer_id]), 'layout' => 'horizontal']); BackendWidget::begin(['icon' => 'user', 'title' => Yii::t('app', 'Contragent edit'), 'footer' => \yii\helpers\Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success'])]); $_jsTemplateResultFunc = <<<'JSCODE' function (data) { if (data.loading) return data.text; var tpl = '<div class="s2contragent-result">' + '<strong>' + (data.first_name || '') + ' ' + (data.middle_name || '') + ' ' + (data.last_name || '') + ' ' + '</strong>' + '<div>' + (data.email || '') + ' (' + (data.phone || '') + ')</div>' + '</div>'; return tpl; } JSCODE; echo \app\backend\widgets\Select2Ajax::widget(['initialData' => [$model->customer_id => null !== $model->customer ? $model->customer->first_name : 'Guest'], 'model' => $model, 'modelAttribute' => 'customer_id', 'form' => $form, 'multiple' => false, 'searchUrl' => \yii\helpers\Url::toRoute(['ajax-customer']), 'pluginOptions' => ['allowClear' => false, 'escapeMarkup' => new \yii\web\JsExpression('function (markup) {return markup;}'), 'templateResult' => new \yii\web\JsExpression($_jsTemplateResultFunc), 'templateSelection' => new \yii\web\JsExpression('function (data) {return data.first_name || data.text;}')]]); echo \app\modules\shop\widgets\Contragent::widget(['viewFile' => 'contragent/inherit_form', 'model' => $model, 'form' => $form, 'additional' => ['hideHeader' => true]]); BackendWidget::end(); $form->end();
var tpl = '<div class="s2customer-result">' + '<strong>' + (data.type || '') + '</strong>' + '</div>'; return tpl; } JSCODE; $_jsDataFunc = <<<'JSCODE' function (term, page) { return { search: {customer:$('select#order-customer_id').val()} }; } JSCODE; echo \app\backend\widgets\Select2Ajax::widget(['initialData' => [$model->contragent_id => null !== $model->contragent ? $model->contragent->type : 'New contragent'], 'model' => $model, 'modelAttribute' => 'contragent_id', 'form' => $form, 'multiple' => false, 'searchUrl' => \yii\helpers\Url::toRoute(['ajax-contragent']), 'pluginOptions' => ['minimumInputLength' => null, 'allowClear' => false, 'escapeMarkup' => new \yii\web\JsExpression('function (markup) {return markup;}'), 'templateResult' => new \yii\web\JsExpression($_jsTemplateResultFunc), 'templateSelection' => new \yii\web\JsExpression('function (data) {return data.type || data.text;}'), 'ajax' => ['data' => new \yii\web\JsExpression($_jsDataFunc)]]]); echo Html::tag('div', Html::a(Yii::t('app', 'Clear'), '#clear', ['data-sel' => 'order-contragent_id', 'class' => 'col-md-offset-2'])); echo Html::tag('div', \app\modules\shop\widgets\Contragent::widget(['viewFile' => 'contragent/inherit_form', 'model' => \app\modules\shop\models\Contragent::createEmptyContragent($customer), 'form' => $form]), ['id' => 'div_contragent']); ?> </div> </div> <?php BackendWidget::end(); $form->end(); $_js = <<<'JSCODE' $(function(){ $('select#order-user_id').on('change', function(event) { $('select#order-customer_id').val(0).trigger('change'); }); $('select#order-customer_id').on('change', function(event) { if (0 == $(this).val()) { $('div#div_customer').removeClass('hide');
echo $this->render('_items', ['model' => $order, 'items' => $order->items]); ?> <?php echo \app\modules\shop\widgets\OrderTransaction::widget(['model' => $order, 'immutable' => $orderIsImmutable]); ?> <?php $form = \yii\bootstrap\ActiveForm::begin(['id' => 'order-details-form', 'action' => \yii\helpers\Url::to(['/shop/cabinet/update-order', 'hash' => $order->hash]), 'layout' => 'horizontal']); echo \yii\helpers\Html::hiddenInput('orderId', $order->id); ?> <div class="panel panel-default"> <div class="panel-body"> <?php echo \app\modules\shop\widgets\Customer::widget(['viewFile' => 'customer/inherit_form', 'model' => $order->customer, 'form' => $form, 'immutable' => $orderIsImmutable]); ?> <?php echo \app\modules\shop\widgets\Contragent::widget(['viewFile' => 'contragent/inherit_form', 'model' => $order->contragent, 'form' => $form, 'immutable' => $orderIsImmutable]); ?> <?php echo \app\modules\shop\widgets\Delivery::widget(['viewFile' => 'delivery/inherit_form', 'deliveryInformation' => !empty($order->contragent) ? $order->contragent->deliveryInformation : null, 'orderDeliveryInformation' => $order->orderDeliveryInformation, 'form' => $form, 'immutable' => $orderIsImmutable]); ?> </div> <?php echo $orderIsImmutable ? '' : \yii\helpers\Html::tag('div', \yii\helpers\Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-primary']), ['class' => 'panel-footer']); ?> </div> <?php $form->end();
echo empty($model->customer) ? '' : Html::a(Yii::t('app', 'View customer'), \yii\helpers\Url::toRoute(['/shop/backend-customer/edit', 'id' => $model->customer_id]), ['class' => 'btn btn-default']); $this->endBlock(); $form = \yii\bootstrap\ActiveForm::begin(['id' => 'contragent-form', 'action' => \yii\helpers\Url::toRoute(['edit', 'id' => $model->id]), 'layout' => 'horizontal']); BackendWidget::begin(['icon' => 'user', 'title' => Yii::t('app', 'Contragent edit'), 'footer' => $this->blocks['buttons_primary']]); $_jsTemplateResultFunc = <<<'JSCODE' function (data) { if (data.loading) return data.text; var tpl = '<div class="s2contragent-result">' + '<strong>' + (data.first_name || '') + ' ' + (data.middle_name || '') + ' ' + (data.last_name || '') + ' ' + '</strong>' + '<div>' + (data.email || '') + ' (' + (data.phone || '') + ')</div>' + '</div>'; return tpl; } JSCODE; echo \app\backend\widgets\Select2Ajax::widget(['initialData' => [$model->customer_id => null !== $model->customer ? $model->customer->first_name : 'Guest'], 'model' => $model, 'modelAttribute' => 'customer_id', 'form' => $form, 'multiple' => false, 'searchUrl' => \yii\helpers\Url::toRoute(['ajax-customer']), 'pluginOptions' => ['allowClear' => false, 'escapeMarkup' => new \yii\web\JsExpression('function (markup) {return markup;}'), 'templateResult' => new \yii\web\JsExpression($_jsTemplateResultFunc), 'templateSelection' => new \yii\web\JsExpression('function (data) {return data.first_name || data.text;}')]]); echo \app\modules\shop\widgets\Contragent::widget(['viewFile' => 'contragent/backend_contragent', 'model' => $model, 'form' => $form]); BackendWidget::end(); $form->end(); $searchModelConfig = ['defaultOrder' => ['id' => SORT_DESC], 'model' => \app\modules\shop\models\Order::className(), 'partialMatchAttributes' => ['start_date', 'end_date', 'user_username'], 'additionalConditions' => [['contragent_id' => $model->id]]]; /** @var \app\components\SearchModel $searchModel */ $searchModel = new \app\components\SearchModel($searchModelConfig); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); echo \kartik\dynagrid\DynaGrid::widget(['options' => ['id' => 'orders-grid'], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => Html::tag('h3', 'Contragent orders', ['class' => 'panel-title'])], 'rowOptions' => function ($model, $key, $index, $grid) { if ($model->is_deleted) { return ['class' => 'danger']; } return []; }], 'columns' => [['attribute' => 'id'], ['attribute' => 'user_username', 'label' => Yii::t('app', 'User'), 'value' => function ($model, $key, $index, $column) { if ($model === null || $model->user === null) { return null; }