Форум программистов, компьютерный форум, киберфорум
PHP: Yii, Yii2
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.86/21: Рейтинг темы: голосов - 21, средняя оценка - 4.86
0 / 0 / 0
Регистрация: 17.10.2015
Сообщений: 126
1

Добавление в model/Search новых атрибутов

17.01.2020, 13:21. Показов 3864. Ответов 8
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Добрый день, подскажите почему при добавлении атрибута Restaurant_Name возникает ошибка Getting unknown property: app\models\TransactionSearch::Restaurant_Name. Restaurant_Name
модель Search
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
 
namespace app\models;
 
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Transaction;
 
/**
 * TransactionSearch represents the model behind the search form of `app\models\Transaction`.
 */
class TransactionSearch extends Transaction
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'card', 'personid', 'account', 'kind', 'summa', 'restaurant', 'rkunit', 'rkcheck', 'vatsuma', 'vatprca', 'vatsumb', 'vatprcb', 'vatsumc', 'vatprcc', 'vatsumd', 'vatprcd', 'vatsume', 'vatprce', 'vatsumf', 'vatprcf', 'vatsumg', 'vatprcg', 'vatsumh', 'vatprch'], 'integer'],
            [['rkdate', 'orderguid', 'datequery', 'Restaurant_Name'], 'safe'],
        ];
    }
 
    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
        
    }
 
    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Transaction::find();
 
        // add conditions that should always apply here
 
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        
        $this->load($params);
 
        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
 
        // grid filtering conditions
  
        $query->andFilterWhere([
            'transaction.id' => $this->id,
            'transaction.card' => $this->card,
            'transaction.personid' => $this->personid,
            'transaction.account' => $this->account,
            'transaction.kind' => $this->kind,
            'transaction.summa' => $this->summa,
            'transaction.restaurant' => $this->restaurant,
            'transaction.rkdate' => $this->rkdate,
            'transaction.rkunit' => $this->rkunit,
            'transaction.rkcheck' => $this->rkcheck,
            'transaction.vatsuma' => $this->vatsuma,
            'transaction.vatprca' => $this->vatprca,
            'transaction.vatsumb' => $this->vatsumb,
            'transaction.vatprcb' => $this->vatprcb,
            'transaction.vatsumc' => $this->vatsumc,
            'transaction.vatprcc' => $this->vatprcc,
            'transaction.vatsumd' => $this->vatsumd,
            'transaction.vatprcd' => $this->vatprcd,
            'transaction.vatsume' => $this->vatsume,
            'transaction.vatprce' => $this->vatprce,
            'transaction.vatsumf' => $this->vatsumf,
            'transaction.vatprcf' => $this->vatprcf,
            'transaction.vatsumg' => $this->vatsumg,
            'transaction.vatprcg' => $this->vatprcg,
            'transaction.vatsumh' => $this->vatsumh,
            'transaction.vatprch' => $this->vatprch,
            'transaction.datequery' => $this->datequery,
            'ifnull(restaurants.name,transaction.restaurant)' => $this->Restaurant_Name,
        ]);
 
        return $dataProvider;
    }
}
Модель таблицы
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
 
namespace app\models;
 
use Yii;
 
/**
 * This is the model class for table "{{%transaction}}".
 *
 * @property int $id
 * @property int $card
 * @property int $personid
 * @property int $account
 * @property int $kind
 * @property int $summa
 * @property int $restaurant
 * @property string $rkdate
 * @property int $rkunit
 * @property int $rkcheck
 * @property int $vatsuma
 * @property int $vatprca
 * @property int $vatsumb
 * @property int $vatprcb
 * @property int $vatsumc
 * @property int $vatprcc
 * @property int $vatsumd
 * @property int $vatprcd
 * @property int $vatsume
 * @property int $vatprce
 * @property int $vatsumf
 * @property int $vatprcf
 * @property int $vatsumg
 * @property int $vatprcg
 * @property int $vatsumh
 * @property int $vatprch
 * @property string $orderguid
 * @property string $datequery
 * @property string RK_Business_Date
 */
class Transaction extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%transaction}}';
    }
 
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['card', 'personid', 'account', 'kind', 'summa', 'restaurant', 'rkunit', 'rkcheck', 'vatsuma', 'vatprca', 'vatsumb', 'vatprcb', 'vatsumc', 'vatprcc', 'vatsumd', 'vatprcd', 'vatsume', 'vatprce', 'vatsumf', 'vatprcf', 'vatsumg', 'vatprcg', 'vatsumh', 'vatprch'], 'integer'],
            [['rkdate', 'datequery','Restaurant_Name'], 'safe'],
            [['orderguid'], 'string', 'max' => 255],
        ];
    }
 
    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'card' => 'Card',
            'personid' => 'Personid',
            'account' => 'Account',
            'kind' => 'Kind',
            'summa' => 'Summa',
            'restaurant' => 'Restaurant',
            'rkdate' => 'Rkdate',
            'rkunit' => 'Rkunit',
            'rkcheck' => 'Rkcheck',
            'vatsuma' => 'Vatsuma',
            'vatprca' => 'Vatprca',
            'vatsumb' => 'Vatsumb',
            'vatprcb' => 'Vatprcb',
            'vatsumc' => 'Vatsumc',
            'vatprcc' => 'Vatprcc',
            'vatsumd' => 'Vatsumd',
            'vatprcd' => 'Vatprcd',
            'vatsume' => 'Vatsume',
            'vatprce' => 'Vatprce',
            'vatsumf' => 'Vatsumf',
            'vatprcf' => 'Vatprcf',
            'vatsumg' => 'Vatsumg',
            'vatprcg' => 'Vatprcg',
            'vatsumh' => 'Vatsumh',
            'vatprch' => 'Vatprch',
            'orderguid' => 'Orderguid',
            'datequery' => 'Datequery',
            'Restaurant_Name' => 'Restaurant_Name',
        ];
    }
 
    /**
     * {@inheritdoc}
     * @return \app\models\query\TransactionQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \app\models\query\TransactionQuery(get_called_class());
    }
}
Контроллер
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
 
namespace app\modules\admin\controllers;
 
use Yii;
use app\models\Transaction;
use app\models\TransactionSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\data\ArrayDataProvider;
 
/**
 * TransactionController implements the CRUD actions for Transaction model.
 */
class TransactionController extends Controller
{
    /**
     * {@inheritdoc}
     */
    
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }
 
    /**
     * Lists all Transaction models.
     * @return mixed
         public function actionIndex()
    {   
        $rest = Transaction::find()
        ->select([
            '*',
            'transaction.restaurant',
            'transaction.restaurant as Restaurant_Code',
            'ifnull(restaurants.name,transaction.restaurant) as Restaurant_Name',
            'CAST(transaction.rkdate as DATE) as RK_Business_Date',
            '(case when cardsactive.code_loyalty=28 then "10%" when cardsactive.code_loyalty=31 then "AutoClub" else "Unknown" end) as Kind',
            'FORMAT(sum(case transaction.Kind when 3 then transaction.Summa/100 else 0 end),2) as Receipts_Amount',
            'FORMAT(SUM(case transaction.Kind when 1 then transaction.Summa/100 else 0 end),2) as Discounts_Amount',
            'COUNT(DISTINCT transaction.orderGUID) as Order_Qnt',
        ])
        ->leftJoin('restaurants', 'restaurants.rkcode=transaction.restaurant')
        ->leftJoin('cardsactive', 'cardsactive.card_number=transaction.card')
        ->asArray()
        ->all();
        var_dump($rest);
        $dataProvider = new ArrayDataProvider([
            'allModels' =>$rest,
        ]);
        $searchModel = new TransactionSearch();
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
     
         public function actionIndex()
    {    
        $searchModel = new TransactionSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
       var_dump($dataProvider);
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
        
        
    }
    
     */
 
    public function actionIndex()
    {   
        
        $searchModel = new TransactionSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $dataProvider->query->select([
            '*',
            'transaction.restaurant',
            'transaction.restaurant as Restaurant_Code',
            'ifnull(restaurants.name,transaction.restaurant) as Restaurant_Name',
            'CAST(transaction.rkdate as DATE) as RK_Business_Date',
            '(case when cardsactive.code_loyalty=28 then "10%" when cardsactive.code_loyalty=31 then "AutoClub" else "Unknown" end) as Kind',
            'FORMAT(sum(case transaction.Kind when 3 then transaction.Summa/100 else 0 end),2) as Receipts_Amount',
            'FORMAT(SUM(case transaction.Kind when 1 then transaction.Summa/100 else 0 end),2) as Discounts_Amount',
            'COUNT(DISTINCT transaction.orderGUID) as Order_Qnt',
        ])
        ->leftJoin('restaurants', 'restaurants.rkcode=transaction.restaurant')
        ->leftJoin('cardsactive', 'cardsactive.card_number=transaction.card')
        ->asArray()
        ->all();
             
            
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
    
 
    /**
     * Displays a single Transaction model.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }
 
    /**
     * Creates a new Transaction model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new Transaction();
 
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }
 
        return $this->render('create', [
            'model' => $model,
        ]);
    }
 
    /**
     * Updates an existing Transaction model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);
 
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }
 
        return $this->render('update', [
            'model' => $model,
        ]);
    }
 
    /**
     * Deletes an existing Transaction model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();
 
        return $this->redirect(['index']);
    }
 
    /**
     * Finds the Transaction model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Transaction the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Transaction::findOne($id)) !== null) {
            return $model;
        }
 
        throw new NotFoundHttpException('The requested page does not exist.');
    }
}
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
17.01.2020, 13:21
Ответы с готовыми решениями:

Добавление новых записей и новых полей
Есть одна проблемка: Делаю программку тут одну, в основе лежит БД(Access 2007). У меня есть...

Переадресация при поиске из Chrome через search-engine.ru на сайт go.mail.ru + реклама в новых вкладках
Добрый вечер! К великому сожалению накачал на свой компьютер вирусов в интернете. Сейчас наблюдаю...

Переадресация при поиске из Chrome через search-engine.ru на сайт go.mail.ru + реклама в новых вкладках
Добрый День . Столкнулся с такими проблемами :переадресация при вводе запроса на сайт мэйл.ру,...

Переадресация при поиске из Chrome через search-engine.ru на сайт go.mail.ru + реклама в новых вкладках - Лече
Переадресация при поиске из Chrome через search-engine.ru на сайт go.mail.ru + реклама в новых...

8
2232 / 1278 / 611
Регистрация: 23.08.2015
Сообщений: 3,228
18.01.2020, 05:11 2
Лучший ответ Сообщение было отмечено Freeslava как решение

Решение

Freeslava, По сути searchModel - это форма. То, что она наследуется от Active Record сделано для упрощения, в идеале, вы должны ее оформлять как форму, т.е. наследовать от Model и прописывать все поля через public свойства. Но это в идеале, если просто хотите добавить поле, то добавьте public свойство.

PHP
1
2
3
4
5
6
7
8
9
10
11
class TransactionSearch extends Transaction
{
    public $Restaurant_Name;
 
    public function rules()
    {
        return [
            [['id', 'card', 'personid', 'account', 'kind', 'summa', 'restaurant', 'rkunit', 'rkcheck', 'vatsuma', 'vatprca', 'vatsumb', 'vatprcb', 'vatsumc', 'vatprcc', 'vatsumd', 'vatprcd', 'vatsume', 'vatprce', 'vatsumf', 'vatprcf', 'vatsumg', 'vatprcg', 'vatsumh', 'vatprch'], 'integer'],
            [['rkdate', 'orderguid', 'datequery', 'Restaurant_Name'], 'safe'],
        ];
    }
1
0 / 0 / 0
Регистрация: 17.10.2015
Сообщений: 126
18.01.2020, 15:02  [ТС] 3
Огромное спасибо, все работает
0
2232 / 1278 / 611
Регистрация: 23.08.2015
Сообщений: 3,228
19.01.2020, 00:13 4
Freeslava, И еще не совсем понятно зачем вы делаете $dataProvider->query->select() внутри контроллера. Для этого же и существует метод search)
Вы даже можете его и переписать и под ArrayDataProvider из вашего закомментированного примера.
0
0 / 0 / 0
Регистрация: 17.10.2015
Сообщений: 126
20.01.2020, 10:24  [ТС] 5
Это от долгих и бессмысленных попыток решения ошибки
0
0 / 0 / 0
Регистрация: 17.10.2015
Сообщений: 126
24.01.2020, 11:09  [ТС] 6
sad67man, Вопрос по этой-же теме когда пытаюсь произвести поиск по данным полям возникает ошибка
Не могу понять где производится COUNT и почему он не видит данную колонку, хотя она прописана в $query
Модель Search
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    public function search($params)
    {
        $query = Transaction::find();
        $query->select([
            '*',
            'transaction.restaurant',
            'transaction.restaurant as Restaurant_Code',
            'ifnull(restaurants.name,transaction.restaurant) as Restaurant_Name',
            'CAST(transaction.rkdate as DATE) as RK_Business_Date',
            '(case when cardsactive.code_loyalty=28 then "10%" when cardsactive.code_loyalty=31 then "AutoClub" else "Unknown" end) as Kind',
            'FORMAT(sum(case transaction.Kind when 3 then transaction.Summa/100 else 0 end),2) as Receipts_Amount',
            'FORMAT(SUM(case transaction.Kind when 1 then transaction.Summa/100 else 0 end),2) as Discounts_Amount',
            'COUNT(DISTINCT transaction.orderGUID) as Order_Qnt',
        ])
        ->leftJoin('restaurants', 'restaurants.rkcode=transaction.restaurant')
        ->leftJoin('cardsactive', 'cardsactive.card_number=transaction.card')
        ->asArray()
        ->all();
        // add conditions that should always apply here
 
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        
        $this->load($params);
 
        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
 
        // grid filtering conditions
  
        $query->andFilterWhere([
            'transaction.id' => $this->id,
            'transaction.card' => $this->card,
            'transaction.personid' => $this->personid,
            'transaction.account' => $this->account,
            'transaction.kind' => $this->kind,
            'transaction.summa' => $this->summa,
            'transaction.restaurant' => $this->restaurant,
            'transaction.rkdate' => $this->rkdate,
            'transaction.rkunit' => $this->rkunit,
            'transaction.rkcheck' => $this->rkcheck,
            'transaction.vatsuma' => $this->vatsuma,
            'transaction.vatprca' => $this->vatprca,
            'transaction.vatsumb' => $this->vatsumb,
            'transaction.vatprcb' => $this->vatprcb,
            'transaction.vatsumc' => $this->vatsumc,
            'transaction.vatprcc' => $this->vatprcc,
            'transaction.vatsumd' => $this->vatsumd,
            'transaction.vatprcd' => $this->vatprcd,
            'transaction.vatsume' => $this->vatsume,
            'transaction.vatprce' => $this->vatprce,
            'transaction.vatsumf' => $this->vatsumf,
            'transaction.vatprcf' => $this->vatprcf,
            'transaction.vatsumg' => $this->vatsumg,
            'transaction.vatprcg' => $this->vatprcg,
            'transaction.vatsumh' => $this->vatsumh,
            'transaction.vatprch' => $this->vatprch,
            'transaction.datequery' => $this->datequery,
            'transaction.restaurant' => $this->Restaurant_Code,
            'Restaurant_Name' => $this->Restaurant_Name,
            'RK_Business_Date' => $this->RK_Business_Date,
            'Kind' => $this->Kind,
            'Receipts_Amount' => $this->Receipts_Amount,
            'Discounts_Amount' => $this->Discounts_Amount,
            'Order_Qnt' => $this->Order_Qnt,
        ]);
        
        return $dataProvider;
    }
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Receipts_Amount' in 'where clause'
The SQL being executed was: SELECT COUNT(*) FROM `transaction` LEFT JOIN `restaurants` ON restaurants.rkcode=transaction.restaurant LEFT JOIN `cardsactive` ON cardsactive.card_number=transaction.card WHERE `Receipts_Amount` LIKE '%3%'
0
2232 / 1278 / 611
Регистрация: 23.08.2015
Сообщений: 3,228
28.01.2020, 01:04 7
Freeslava, COUNT пытается выполнить ActiveDataProvider для построения пагинации. Видимо он перебивает ваши селекты.
Как вариант решения проблемы напишите свой запрос на общее кол-во элементов.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    public function search($params): DataProviderInterface
    {
        $query = Transaction::find()
            ->select([
                '*',
                'transaction.restaurant',
                'transaction.restaurant as Restaurant_Code',
                'ifnull(restaurants.name,transaction.restaurant) as Restaurant_Name',
                'CAST(transaction.rkdate as DATE) as RK_Business_Date',
                '(case when cardsactive.code_loyalty=28 then "10%" when cardsactive.code_loyalty=31 then "AutoClub" else "Unknown" end) as Kind',
                'FORMAT(sum(case transaction.Kind when 3 then transaction.Summa/100 else 0 end),2) as Receipts_Amount',
                'FORMAT(SUM(case transaction.Kind when 1 then transaction.Summa/100 else 0 end),2) as Discounts_Amount',
                'COUNT(DISTINCT transaction.orderGUID) as Order_Qnt',
            ])
            ->leftJoin('restaurants', 'restaurants.rkcode=transaction.restaurant')
            ->leftJoin('cardsactive', 'cardsactive.card_number=transaction.card')
            ->asArray();
 
        if ($this->load($params) && $this->validate()) {
            $query->andFilterWhere([
                'transaction.id' => $this->id,
                'transaction.card' => $this->card,
                'transaction.personid' => $this->personid,
                'transaction.account' => $this->account,
                'transaction.kind' => $this->kind,
                'transaction.summa' => $this->summa,
                'transaction.restaurant' => $this->restaurant,
                'transaction.rkdate' => $this->rkdate,
                'transaction.rkunit' => $this->rkunit,
                'transaction.rkcheck' => $this->rkcheck,
                'transaction.vatsuma' => $this->vatsuma,
                'transaction.vatprca' => $this->vatprca,
                'transaction.vatsumb' => $this->vatsumb,
                'transaction.vatprcb' => $this->vatprcb,
                'transaction.vatsumc' => $this->vatsumc,
                'transaction.vatprcc' => $this->vatprcc,
                'transaction.vatsumd' => $this->vatsumd,
                'transaction.vatprcd' => $this->vatprcd,
                'transaction.vatsume' => $this->vatsume,
                'transaction.vatprce' => $this->vatprce,
                'transaction.vatsumf' => $this->vatsumf,
                'transaction.vatprcf' => $this->vatprcf,
                'transaction.vatsumg' => $this->vatsumg,
                'transaction.vatprcg' => $this->vatprcg,
                'transaction.vatsumh' => $this->vatsumh,
                'transaction.vatprch' => $this->vatprch,
                'transaction.datequery' => $this->datequery,
                'transaction.restaurant' => $this->Restaurant_Code,
                'Restaurant_Name' => $this->Restaurant_Name,
                'RK_Business_Date' => $this->RK_Business_Date,
                'Kind' => $this->Kind,
                'Receipts_Amount' => $this->Receipts_Amount,
                'Discounts_Amount' => $this->Discounts_Amount,
                'Order_Qnt' => $this->Order_Qnt,
            ]);
        }
 
        $pagination = new Pagination([
            'totalCount' => (new Query())->from($query)->count()
        ]);
 
        return new ActiveDataProvider([
            'query' => $query,
            'pagination' => $pagination
        ]);
    }
Добавлено через 33 минуты
Freeslava, И в Mysql нельзя использовать алиасы select-ов в блоках WHERE. Нужно делать как-нибудь по другому. Может через group by и having или совмещать с вашим первым вариантом. Или частично переложить логику на php
0
0 / 0 / 0
Регистрация: 17.10.2015
Сообщений: 126
28.01.2020, 11:32  [ТС] 8
sad67man, Почти получилось
Выдает ошибку
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Order_Qnt' in 'where clause'
The SQL being executed was: SELECT COUNT(*) FROM (SELECT `transaction`.`id`, `transaction`.`restaurant`, `transaction`.`restaurant` AS `Restaurant_Code`, ifnull(restaurants.name,transaction.restaurant) AS `Restaurant_Name`, CAST(transaction.rkdate as DATE) AS `RK_Business_Date`, (case when cardsactive.code_loyalty=28 then "10%" when cardsactive.code_loyalty=31 then "AutoClub" else "Unknown" end) AS `Kind`, FORMAT(sum(case transaction.Kind when 3 then transaction.Summa/100 else 0 end),2) AS `Receipts_Amount`, FORMAT(SUM(case transaction.Kind when 1 then transaction.Summa/100 else 0 end),2) AS `Discounts_Amount`, COUNT(DISTINCT transaction.orderGUID) AS `Order_Qnt` FROM `transaction` LEFT JOIN `restaurants` ON restaurants.rkcode=transaction.restaurant LEFT JOIN `cardsactive` ON cardsactive.card_number=transaction.card WHERE `Order_Qnt`='2') `0`
Теперь мне необходимо понять, как переделать WHERE `Order_Qnt='2' на WHERE "Order_Qnt"='2'
0
2232 / 1278 / 611
Регистрация: 23.08.2015
Сообщений: 3,228
28.01.2020, 12:46 9
Цитата Сообщение от Freeslava Посмотреть сообщение
как переделать WHERE `Order_Qnt='2'
Никак. В WHERE вы можете брать значения из таблиц, но не из SELECT. Чтоб фильтровать по выбранным данным используйте GROUP BY и HAVING
http://old.code.mu/sql/having.html
0
28.01.2020, 12:46
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
28.01.2020, 12:46
Помогаю со студенческими работами здесь

Добавление атрибутов к ActionLink
Добрый день! Есть вопрос. Допустим я использую хелпер @Html.ActionLink(&quot;Жми здесь&quot;, &quot;Show&quot;). ...

Добавление атрибутов к xml файлу
Всем привет,помогите пожалуйста,как мне программно добавить атрибуты (только чтение)к xml файлу.?

Добавление атрибутов к User(gem Devise)
подключить гем devise, установил все настройки сгенерировал User модель достал devise:view...

Добавление полей структур в Model/View Qt
Здравствуйте. Подскажите, как сделать следующее: Есть QTableView, к нему установлена модель,...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
9
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru