<?php /** * @author: Eugene Brx * @email: compuniti@mail.ru * @date: 23.10.15 * @time: 14:21 */ $query = \app\modules\user\models\Orders::find()->where(['related_detail' => $model->id])->all(); echo \kartik\grid\GridView::widget(['id' => 'manager-related-details-grid-' . $model->id, 'dataProvider' => new \yii\data\ArrayDataProvider(['allModels' => $query, 'sort' => false, 'key' => 'id']), 'resizableColumns' => false, 'layout' => '{items}', 'tableOptions' => ['style' => 'display:' . (!empty($query) ? 'table' : 'none') . '; margin-top:5px; width:99%;float:right', 'data' => ['related-detail' => $model->id], 'class' => 'related-table'], 'rowOptions' => ['class' => \kartik\grid\GridView::TYPE_WARNING], 'export' => false, 'pjax' => true, 'pjaxSettings' => ['neverTimeout' => true, 'options' => ['id' => 'manager-related-details-grid-' . $model->id . '-pjax']], 'columns' => [['label' => 'Артикул', 'value' => function ($model) { return !empty($model['product_article']) ? $model['product_article'] : $model['product_id']; }, 'contentOptions' => ['class' => 'part_article']], ['label' => 'Производитель', 'value' => 'manufacture'], ['label' => 'Название', 'value' => 'part_name'], ['label' => 'Цена', 'value' => 'part_price'], ['label' => 'Кол-во', 'value' => 'quantity'], ['label' => 'Сумма', 'value' => 'cost'], ['header' => 'Оплата', 'class' => '\\kartik\\grid\\CheckboxColumn', 'vAlign' => \kartik\grid\GridView::ALIGN_TOP, 'rowSelectedClass' => \kartik\grid\GridView::TYPE_SUCCESS, 'checkboxOptions' => function ($model) { return ['value' => $model['id'], 'checked' => $model['is_paid'], 'onClick' => 'updatePaidStatus(this)']; }], ['label' => 'Поставщик', 'value' => 'provider.name'], ['label' => 'ID заказа поставщика', 'class' => 'kartik\\grid\\EditableColumn', 'format' => 'raw', 'editableOptions' => function ($model) { return ['header' => 'ID поставщика', 'name' => 'OrdersSearch[order_provider_id]', 'value' => $model['order_provider_id'], 'contentOptions' => ['class' => 'editable-inline-in-table'], 'type' => \kartik\popover\PopoverX::TYPE_SUCCESS, 'inputType' => \kartik\editable\Editable::INPUT_TEXT, 'size' => 'md', 'containerOptions' => ['id' => 'text-danger'], 'options' => ['class' => 'form-control', 'placeholder' => 'Введите ID заказа у поставщика...'], 'asPopover' => false, 'ajaxSettings' => ['url' => '/autoparts/orders/order-provider-status'], 'submitButton' => ['icon' => '<i class="glyphicon glyphicon-ok"></i>'], 'pluginEvents' => ['editableSuccess' => 'function(event, val, form, data){ var status_td = $(event.target).parents("tr").find("td.provider_status_text > select"); if(data.status !== undefined){ if(!status_td.find("option[value="+data.status+"]").length) status_td.append("<option value=\\""+data.status+"\\">"+data.status_text+"</option>"); status_td.val(data.status).change(); } }']]; }], ['label' => 'Статус поставщика', 'attribute' => 'providerOrderStatusName.status_name', 'contentOptions' => ['class' => 'provider_status_text'], 'format' => 'raw', 'value' => function ($model, $key) { $states = \yii\helpers\ArrayHelper::map($model['allProviderOrderStatusName'], 'status_code', 'status_name'); $params = ['class' => 'form-control', 'onChange' => 'setOrderProviderState(' . $key . ', this)', 'style' => 'font-size:12px', 'prompt' => 'Выбрать статус']; return \yii\helpers\Html::dropDownList('provider_status', $model['order_provider_status'], $states, $params); }], ['label' => 'Срок', 'value' => 'delivery_days'], ['label' => 'Статус', 'attribute' => 'state', 'contentOptions' => ['class' => 'detailStatus'], 'format' => 'raw', 'value' => function ($model, $key) { return !isset($model['related_detail']) ? $model['state']['status_name'] : \yii\bootstrap\Html::activeDropDownList($model, 'status', $model['stateAll'], ['class' => 'form-control', 'style' => 'min-width:125px; font-size:12px', 'onChange' => 'updateStatus(this)', 'id' => 'order-status-' . $key . '-field']); }, 'vAlign' => 'middle'], ['label' => 'Поставщик', 'format' => 'raw', 'value' => function ($model) { $href = '';
public function actionPut() { $params = Yii::$app->request->post(); $post = array_merge(Yii::$app->request->post()); $params = Yii::$app->request->queryParams; switch ($params['mode']) { case 'changeQuantity': if (Yii::$app->request->isAjax) { if (!empty($position = (int) $post['position']) && !empty($quantity = (int) $post['quantity'])) { $basket = BasketSearch::findOne($position); $basket->tovar_count = $quantity; return $basket->update(); } } break; case 'put': $session = new \yii\web\Session(); $id = Yii::$app->request->post('id'); if ($id) { $tovar = Tovar::findOne(['id' => $id]); if ($tovar) { $toBasket = new BasketSearch(); $toBasket->tovar_id = $id; $toBasket->tovar_count = 1; $toBasket->tovar_price = $tovar->price; $toBasket->session_id = Yii::$app->session->id; $toBasket->tovar_min = 1; $toBasket->provider_id = 5; //id=5 провайдер KD ищет в локальной базе if (Yii::$app->user->id) { $toBasket->uid = Yii::$app->user->id; } if ($toBasket->save()) { return '<a class="btn" href="' . url::toRoute(['/basket/basket'], true) . '"><i class="icon-shopping-cart icon-black"></i>Уже в корзине</a>'; } else { if (YII_DEBUG) { var_dump($toBasket->getErrors()); } } } else { return false; } } return '<a class="btn" href="' . url::toRoute(['/basket/basket'], true) . '"><i class="icon-shopping-cart icon-black"></i>Уже в корзине</a>'; break; case 'update': // $data = Yii::$app->request->post(); // if (isset($data) && $data != '') { // $basket = BasketSearch::findOne(['id' => intval($data['row_id'])]); // if ($basket) // $basket->description = Html::encode($data['text']); // if ($basket->save()) // return true; // } if (Yii::$app->request->post('hasEditable')) { $post = Yii::$app->request->post(); $model = $basket = BasketSearch::findOne(['id' => $post['editableKey']]); $data['OrderSearch'] = current($post['OrderSearch']); if ($model->load($data) && $model->save()) { $data = ['output' => $model->comment]; } return Json::encode($data); } break; case 'order': // создаем новый заказ $user_id = Yii::$app->user->id; $number = ($user_id ? $user_id : 'N') . '-' . date("ymdhis"); $orders = explode(';', Yii::$app->request->post('orderData')); $formData = Yii::$app->request->post('formData'); if (isset($formData) && $formData != '') { parse_str($formData, $fdata); $profileData = array_values($fdata['Profile']); } $fdata['deliveryStore'] = isset($fdata['deliveryStore']) ? $fdata['deliveryStore'] : 0; $cityCode = Yii::$app->request->cookies['city']; $city = \app\modules\city\models\CitySearch::find()->where(['id' => $cityCode ? $cityCode : 2097])->one(); $order_data = ['number' => $number, 'date' => date("Y-m-d H:i:s"), 'user_id' => $user_id, 'user_name' => $fdata['Profile']['name'], 'user_email' => $fdata['User']['email'], 'user_telephone' => $fdata['User']['telephone'], 'user_location' => $city->name, 'store_id' => (int) $fdata['deliveryStore']]; $order = new Order(); $order->load($order_data, ''); $order->save(); // передаем id заказа $order_id = $order->id; $order = new OrderUpdate1c(); $order->OrderId = $order_id; $order->save(); $user = \app\modules\user\models\User::findOne($user_id); $user->scenario = 'update'; $user->telephone = $order_data['user_telephone']; $user->save(); $profile = Profile::findOne($user_id); $profile->scenario = 'order'; $profile->name = $order_data['user_name']; $profile->save(); foreach ($orders as $order) { $order = explode(':', $order); $basket = BasketSearch::findOne(['id' => intval($order[0])]); if ($basket) { $product = Tovar::findOne(['id' => $basket->tovar_id]); $data['Orders'] = ['product_id' => $product ? $product->id : null, 'manufacture' => $basket->manufacturer, 'part_name' => $product ? $product->name : $basket->part_name, 'part_price' => $basket->tovar_price, 'product_article' => $product ? null : $basket->part_number, 'quantity' => $order[1], 'reference' => '', 'status' => \app\modules\user\models\Orders::ORDER_ADOPTED, 'datetime' => date('Y-m-d H:i:s'), 'description' => $basket->description, 'order_id' => (int) $order_id, 'provider_id' => (int) $basket->provider_id, 'delivery_days' => (int) $basket->period]; $Orders = new Orders(); if ($Orders->load($data) && $Orders->save()) { $basket->delete(); } } } return true; break; case 'remove': if (BasketSearch::deleteAll(['in', 'id', $post['id']])) { return JSON::encode($_POST); } //$this->basket_row($dataProvider); break; } }
public function actionProviderOrderStateUpdate() { $post = Yii::$app->request->post(); if (($orderPosition = Orders::findOne((int) $post['id'])) !== null) { $orderPosition->order_provider_status = $post['Orders']['order_provider_status']; if ($orderPosition->save()) { $status = OrderStateRelation::findOne(['provider_id' => $orderPosition->provider_id, 'provider_state_id' => $orderPosition->order_provider_status]); if (isset($status->innerState)) { return $status->inner_state_id; } } } }
/** * @return \yii\db\ActiveQuery */ public function getOrders() { return $this->hasOne(Orders::className(), ['provider_id' => 'provider_id', 'order_provider_status' => 'status_code']); }
public function getOrderSumma() { return $this->hasMany(Orders::className(), ['order_id' => 'id'])->where(['related_detail' => null])->sum('part_price * quantity'); }