<?php
-return 1 == 2 ? [
+return 1 == 1 ? [
'class' => yii\db\Connection::class,
'dsn' => strtr('pgsql:host={host};port={port};dbname={dbname}', [
'{host}' => getenv('POSTGRES_HOSTNAME') ?: '127.0.0.1',
AND
p.type_id = 1
AND
- (p.component_parent_id = '' OR p.component_parent_id = 0 OR p.component_parent_id IS NULL)
+ (p.component_parent_id = '' OR p.component_parent_id = '0' OR p.component_parent_id IS NULL)
AND
(sales.order_id='' OR sales.order_id='0')
AND
sales.id = p.check_id
AND
- (p.component_parent_id = '' OR p.component_parent_id = 0 OR p.component_parent_id IS NULL)
+ (p.component_parent_id = '' OR p.component_parent_id = '0' OR p.component_parent_id IS NULL)
AND
(sales.order_id='' OR sales.order_id='0')
AND
products_class.tip = 'matrix'
WHERE
- 1
+ 1 = 1
",
[]
);
WHERE
products_1c.name != ''
- ",
- [
- ':search_in' => $searchIn,
- ]
+ "
);
$data = $command->queryAll();
/** @var Timetable[] $timetable */
$query = Timetable::find()
- ->select(['admin_id', 'MAX(`date`) AS `last_shift`'])
+ ->select(['admin_id', 'MAX(date) AS last_shift'])
->andWhere(['admin_group_id' => $adminGroupId])
->andWhere(['slot_type_id' => [
Timetable::TIMESLOT_WORK, // "работа"
/** @var Timetable[] $timetable */
$queryOtherAdminDay = Timetable::find()
- ->select(['date' => new \yii\db\Expression("DISTINCT(`date`)"), 'id'])
+ ->select(['date' => new \yii\db\Expression("DISTINCT(date)"), 'id'])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo])
->andWhere(['not in', 'date', $adminTableDays])
/** @var Timetable[] $timetable */
$queryOtherAdminNight = Timetable::find()
- ->select(['date' => new \yii\db\Expression("DISTINCT(`date`)"), 'id'])
+ ->select(['date' => new \yii\db\Expression("DISTINCT(date)"), 'id'])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo])
->andWhere(['not in', 'date', $adminTableDaysLast])
->andWhere(['date' => $date])
->andWhere(['<>','admin.group_id', -1])
->andWhere(['shift_id' => $shiftIdForDict])
- ->andWhere(['`timetable`.`store_id`' => $storeId])
+ ->andWhere(['timetable.store_id' => $storeId])
->andWhere(['slot_type_id' => $slotTypeId])
->andWhere(['tabel' => 0])
->asArray()
* @param $adminFloristPrepared
* @return Timetable[]
*/
- public function getTimetableAdminByData($date, $adminFloristPrepared): array
+ public function getTimetableAdminByData($date, $adminFloristPrepared)
{
$timetable = [];
];
}
- /** @var Timetable[] $timetable */
+ /** @var Timetable $timetable */
$timetable = Timetable::find()
->with('admin')
->andWhere(['date' => $date])
->andWhere(['admin_id' => $adminIds])
->andWhere(['slot_type_id' => $slotTypeId])
->andWhere(['tabel' => 0])
- ->orderBy(new Expression('rand()'))
+ ->orderBy(new Expression('random()'))
->asArray()
->one()
;
{
return round(DashboardSales::find()
->select(['summ'])
- ->andWhere(['`store_id`'=> $employeeSelectStoreId])
- ->andWhere(['`field_name`'=> $fieldName])
+ ->andWhere(['store_id'=> $employeeSelectStoreId])
+ ->andWhere(['field_name'=> $fieldName])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo])
->average('summ'), 2);
{
$query = DashboardSales::find()
->select(['summ' => new \yii\db\Expression("SUM(summ)")])
- ->andWhere(['`store_id`'=> $employeeSelectStoreId])
- ->andWhere(['`field_name`'=> $fieldName])
+ ->andWhere(['store_id'=> $employeeSelectStoreId])
+ ->andWhere(['field_name'=> $fieldName])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo]);
public function getSumListField($fieldName, $employeeSelectStoreId, $dateFrom, $dateTo) : array
{
return DashboardSales::find()
- ->andWhere(['`store_id`'=> $employeeSelectStoreId])
- ->andWhere(['`field_name`'=> $fieldName])
+ ->andWhere(['store_id'=> $employeeSelectStoreId])
+ ->andWhere(['field_name'=> $fieldName])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo])
->indexBy('date')
}
$dashboardSales = DashboardSales::find()
- ->andWhere(['`field_name`'=> 'sales_summ'])
+ ->andWhere(['field_name'=> 'sales_summ'])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo])
->asArray()
$avgCheckSummTrigger = 1200;
$dashboardSalesAvgCheck = DashboardSales::find()
- ->andWhere(['`field_name`'=> 'sales_avg_check'])
+ ->andWhere(['field_name'=> 'sales_avg_check'])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo])
->andWhere(['>', 'summ', $avgCheckSummTrigger])
}
$dashboardSales = DashboardSales::find()
- ->andWhere(['`field_name`'=> 'sales_summ'])
+ ->andWhere(['field_name'=> 'sales_summ'])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo])
->asArray()
$avgCheckSummTrigger = 1200;
$dashboardSalesAvgCheck = DashboardSales::find()
- ->andWhere(['`field_name`'=> 'sales_avg_check'])
+ ->andWhere(['field_name'=> 'sales_avg_check'])
->andWhere(['>=', 'date', $dateFrom])
->andWhere(['<=', 'date', $dateTo])
->andWhere(['>', 'summ', $avgCheckSummTrigger])
$adminPayrollIdsCurrentMonth = AdminPayroll::find()
->select(['id'])
->indexBy('id')
- ->andWhere(['`admin_payroll`.`date`' => $yearSelect . '-' . $monthWithZeroSelect])
- ->andWhere(['`admin_payroll`.`store_id`' => $storeId])
+ ->andWhere(['admin_payroll.date' => $yearSelect . '-' . $monthWithZeroSelect])
+ ->andWhere(['admin_payroll.store_id' => $storeId])
->asArray()->column();
$adminPayrollIdsBeforeMonth = AdminPayroll::find()
->select(['id'])
->indexBy('id')
- ->andWhere(['`admin_payroll`.`date`' => $yearBeforeSelect . '-' . $monthWithZeroBeforeSelect])
- ->andWhere(['`admin_payroll`.`store_id`' => $storeId])
+ ->andWhere(['admin_payroll.date' => $yearBeforeSelect . '-' . $monthWithZeroBeforeSelect])
+ ->andWhere(['admin_payroll.store_id' => $storeId])
->asArray()->column();
// массив с полями дашборда
$fields_arr = DashboardFields::find()
->select(['id', 'name'])
- ->andWhere(['`active`' => 1])
+ ->andWhere(['active' => 1])
->andWhere(['<>', 'name', 'sales_summ'])
->indexBy('id')
->asArray()
}
$ids = array_unique($ids);
- //$query->andWhere(['`products_1c`.`parent_id`' => $ids]);// ['`products_1c`.`parent_id`' => $products]
+ //$query->andWhere(['products_1c.parent_id' => $ids]);// ['products_1c.parent_id' => $products]
}
{
$query = Sales::find()
->select([
- '`sales`.`id`',
- '`sales`.`date`',
- '`sales`.`operation`',
- '`sales`.`store_id`',
- '`sales_products`.`price`',
- '`sales_products`.`discount`',
- '`sales_products`.`quantity`',
- '`sales_products`.`summ`',
- '`sales_products`.`product_id`',
- '`products_1c`.`id`',
- '`products_1c`.`parent_id`',
- '`products_1c`.`name`',
+ 'sales.id',
+ 'sales.date',
+ 'sales.operation',
+ 'sales.store_id',
+ 'sales_products.price',
+ 'sales_products.discount',
+ 'sales_products.quantity',
+ 'sales_products.summ',
+ 'sales_products.product_id',
+ 'products_1c.id',
+ 'products_1c.parent_id',
+ 'products_1c.`name`',
])
->joinWith('products1c')
if ($isAdministrator) {
$query->select([
'summ' => new \yii\db\Expression("SUM(summ - skidka)"),
- 'date' => new \yii\db\Expression("DATE_FORMAT(date,'%Y-%m-%d')"),
+ 'date' => new \yii\db\Expression("TO_CHAR(date,'%Y-%m-%d')"),
'operation'
]);
} else {
$query->select([
'summ' => new \yii\db\Expression("SUM(summ - skidka)"),
- 'date' => new \yii\db\Expression("(case when (HOUR(date) >= 0 and HOUR(date) <= $dateTimeEndDayPreparedHour)
+ 'date' => new \yii\db\Expression("(case when (extract (HOUR from date) >= 0 and extract(HOUR from date) <= $dateTimeEndDayPreparedHour)
THEN
- DATE_FORMAT(DATE_ADD(date, INTERVAL -1 DAY),'%Y-%m-%d')
+ TO_CHAR(date - INTERVAL '1 DAY','%Y-%m-%d')
ELSE
- DATE_FORMAT(date,'%Y-%m-%d')
+ TO_CHAR(date,'%Y-%m-%d')
END)
"),
'operation'
if ($isAdministrator) {
$query->select([
'summ' => new \yii\db\Expression("SUM(summ - skidka)"),
- 'date' => new \yii\db\Expression("DATE_FORMAT(date,'%Y-%m-%d')"),
+ 'date' => new \yii\db\Expression("TO_CHAR(date,'%Y-%m-%d')"),
'operation'
]);
} else {
'summ' => new \yii\db\Expression("SUM(summ - skidka)"),
'date' => new \yii\db\Expression("(case when (HOUR(date) >= 0 and HOUR(date) < $dateTimeEndDayPreparedHour)
THEN
- DATE_FORMAT(DATE_ADD(date, INTERVAL -1 DAY),'%Y-%m-%d')
+ TO_CHAR(date - INTERVAL '1 DAY','%Y-%m-%d')
ELSE
- DATE_FORMAT(date,'%Y-%m-%d')
+ TO_CHAR(date,'%Y-%m-%d')
END)
"),
'operation'
$orderCondition = "
AND
(
- `order_id` = ''
+ \"order_id\" = ''
OR
- `order_id` = '0'
+ \"order_id\" = '0'
)
";
$queryRow = "
SELECT
count(*) as cnt,
- sum(if(phone!='NULL',1,0)) as bonus_clients_cnt,
+ sum(case when phone is distinct from NULL THEN 1 ELSE 0 END) as bonus_clients_cnt,
sum(summ-skidka) as summ,
store_id,
- DATE_FORMAT(date,'%Y-%m-%d') as date_t
+ to_char(date,'%Y-%m-%d') as date_t
FROM
sales
WHERE
$payArrCondition = "
AND
- `pay_arr` IN (" . $payType . ")
+ \"pay_arr\" IN (" . $payType . ")
";
}
$payArrCondition = "
AND
- `pay_arr` IN (" . $payType . ")
+ \"pay_arr\" IN (" . $payType . ")
";
}
SELECT
count(*) as cnt,
store_id,
- DATE_FORMAT(date,'%Y-%m-%d') as date_t
+ TO_CHAR(date,'%Y-%m-%d') as date_t
FROM
sales
WHERE
if ($shiftTypeDay) {
$hourCondition = "
AND
- HOUR(date) >= 8 #дневная смена
+ extract(HOUR from date) >= 8 /* дневная смена */
AND
- HOUR(date) < 20 #дневная смена
+ extract(HOUR from date) < 20 /* дневная смена */
";
} else {
$hourCondition = "
AND
(
- HOUR(date) >= 20 #ночная смена
+ extract(HOUR from date) >= 20 /* ночная смена */
OR
- HOUR(date) < 8 #ночная смена
+ extract(HOUR from date) < 8 /* ночная смена */
)
";
$orderCondition = "
AND
(
- `order_id` = ''
+ order_id = ''
OR
- `order_id` = '0'
+ order_id = '0'
)
";
SELECT
count(*) as cnt,
store_id,
- (case when (HOUR(date) >= 0 and HOUR(date) < 8)
+ (case when (extract(HOUR from date) >= 0 and extract(HOUR from date) < 8)
THEN
- DATE_FORMAT(DATE_ADD(date, INTERVAL -1 DAY),'%Y-%m-%d')
+ TO_CHAR(date - INTERVAL '1 DAY','%Y-%m-%d')
ELSE
- DATE_FORMAT(date,'%Y-%m-%d')
+ TO_CHAR(date,'%Y-%m-%d')
END)
AS date_t
FROM
if ($shiftTypeDay) {
$hourCondition = "
AND
- HOUR(date) >= 8 #дневная смена
+ extract(hour from date) >= 8 /* дневная смена */
AND
- HOUR(date) < 20 #дневная смена
+ extract(hour from date) < 20 /* дневная смена */
";
} else {
$hourCondition = "
AND
(
- HOUR(date) >= 20 #ночная смена
+ extract(hour from date) >= 20 /* ночная смена */
OR
- HOUR(date) < 8 #ночная смена
+ extract(hour from date) < 8 /* ночная смена */
)
";
$orderCondition = "
AND
(
- `order_id` = ''
+ order_id = ''
OR
- `order_id` = '0'
+ order_id = '0'
)
";
SELECT
count(*) as cnt,
store_id,
- (DATE_FORMAT(date,'%Y-%m-%d'))
+ (TO_CHAR(date,'%Y-%m-%d'))
AS date_t,
- (DATE_FORMAT(date,'%Y-%m-%d_%k'))
+ (TO_CHAR(date,'%Y-%m-%d_%k'))
AS date_k,
- (DATE_FORMAT(date,'%k'))
+ (TO_CHAR(date,'%k'))
AS date_t_h,
- (DATE_FORMAT(date,'%Y-%m-%d'))
+ (TO_CHAR(date,'%Y-%m-%d'))
AS date_t_d
FROM
sales
sales.date,
sales.number,
(p.summ) AS summ,
- p.`product_id` AS product_guid,
+ p.product_id AS product_guid,
sales.summ AS sales_summ,
sales.skidka,
0 as bonus,
AND
products_class.tip = 'matrix'
WHERE
- 1
+ 1 = 1
)
AND
sales.date >= :date_from
AND
products_class.tip = 'matrix'
WHERE
- 1
+ 1 = 1
)
AND
sales.date >= :date_from
$connection = Yii::$app->getDb();
- $selectColumn = "(p.`summ` - p.`discount`) AS summ, `sales`.`operation`, `sales`.`store_id`, `sales`.`store_id_1c`";
+ $selectColumn = "(p.summ - p.discount) AS summ, sales.operation, sales.store_id, sales.store_id_1c";
if ($isAdministrator) {
- $selectColumn .= ", DATE_FORMAT(`sales`.`date`,'%Y-%m-%d')
+ $selectColumn .= ", TO_CHAR(sales.date,'%Y-%m-%d')
AS date";
} else {
- $selectColumn .= ", (case when (HOUR(`sales`.`date`) >= 0 and HOUR(`sales`.`date`) < $dateTimeEndDayPreparedHour)
+ $selectColumn .= ", (case when (extract (hour from sales.date) >= 0 and extract(hour from sales.date) < $dateTimeEndDayPreparedHour)
THEN
- DATE_FORMAT(DATE_ADD(`sales`.`date`, INTERVAL -1 DAY),'%Y-%m-%d')
+ TO_CHAR(sales.date - INTERVAL '1 DAY','%Y-%m-%d')
ELSE
- DATE_FORMAT(`sales`.`date`,'%Y-%m-%d')
+ TO_CHAR(sales.date,'%Y-%m-%d')
END)
AS date
";
SELECT
" . $selectColumn . "
FROM
- `sales_products` as p,
- `sales`
+ sales_products as p,
+ sales
WHERE
- `sales`.`store_id_1c` = :store_id_1c
+ sales.store_id_1c = :store_id_1c
AND
- `sales`.`id` = p.`check_id`
+ sales.id = p.check_id
AND (
- `sales`.`order_id`=''
+ sales.order_id=''
OR
- `sales`.`order_id`='0'
+ sales.order_id='0'
)
AND
- p.`product_id` IN (
+ p.product_id IN (
SELECT
- `products_1c`.`id`
+ products_1c.id
FROM
- `products_1c`
- RIGHT JOIN `products_class`
+ products_1c
+ RIGHT JOIN products_class
ON
- `products_1c`.`parent_id` = `products_class`.`category_id`
+ products_1c.parent_id = products_class.category_id
AND
- `products_class`.`tip` = 'matrix'
+ products_class.tip = 'matrix'
WHERE
- 1
+ 1 = 1
)
AND
- `sales`.`date` >= :date_from
+ sales.date >= :date_from
AND
- `sales`.`date` <= :date_to
+ sales.date <= :date_to
",
[ ':store_id_1c' => $entityCityStoreEmployeeSelect,
sales.date,
sales.number,
(p.summ) AS summ,
- p.`product_id` AS product_guid,
+ p.product_id AS product_guid,
sales.summ AS sales_summ,
sales.skidka,
0 as bonus,
AND
products_class.tip = 'matrix'
WHERE
- 1
+ 1 = 1
)
AND
sales.date >= :date_from
AND
products_class.tip = 'matrix'
WHERE
- 1
+ 1 = 1
)
AND
sales.date >= :date_from
$command = $connection->createCommand("
SELECT
DISTINCT (sales.id),
- DATE_FORMAT(sales.date, '%d.%m в %H:%i') as dt,
- DATE_FORMAT(sales.date, '%Y-%m-%d') as sales_date_dt,
+ TO_CHAR(sales.date, '%d.%m в %H:%i') as dt,
+ TO_CHAR(sales.date, '%Y-%m-%d') as sales_date_dt,
sales.date,
sales.matrix,
sales.skidka,
'id' => 'id',
'providers_arr' => 'providers_arr',
'status' => 'status',
- 'date_start' => "DATE_FORMAT(`date_start`, '%Y-%m-%d')",
- 'date_add' => "DATE_FORMAT(`date_add`, '%Y-%m-%d')",
- 'division_date' => "DATE_FORMAT(`division_date`, '%Y-%m-%d')",
- 'date_update' => "UNIX_TIMESTAMP(`date_update`)",
+ 'date_start' => "DATE_FORMAT(date_start, '%Y-%m-%d')",
+ 'date_add' => "DATE_FORMAT(date_add, '%Y-%m-%d')",
+ 'division_date' => "DATE_FORMAT(division_date, '%Y-%m-%d')",
+ 'date_update' => "UNIX_TIMESTAMP(date_update)",
'parent_id'
]
)
} else {
// иначе идем к родителю и узнаем дату матери к которой будем привязываться
$date_start = StoreOrders::find()
- ->select(['date_start' => "DATE_FORMAT(`date_start`, '%Y-%m-%d')"])
+ ->select(['date_start' => "DATE_FORMAT(date_start, '%Y-%m-%d')"])
->andWhere(['id' => $OrderData["parent_id"]])
->asArray()
->scalar();
->select([
'field_name',
'product_id',
- 'sum' => "SUM(`value`)",
+ 'sum' => "SUM(value)",
])
->andWhere(['order_id'=>$this->orderId])
->andWhere(['store_id' => ''])
'field_name',
'product_id',
'color',
- 'sum' => "SUM(`value`)",
+ 'sum' => "SUM(value)",
])
->andWhere(['order_id'=>$this->orderId])
->andWhere(['<>', 'store_id', ''])
// );
$vnesli = StoreOrderStatus::find()
- ->select(['`order_id`'])
+ ->select(['order_id'])
->andWhere(['order_id' => $orderId])
->andWhere(['status_id' => $status_order_id])
->andWhere(['status' => 1])
->groupBy(['order_id'])
->asArray()
- ->count('`order_id`');
+ ->count('order_id');
$store_order_status=array();
if ($shiftTypeDay) {
$hourCondition = "
AND
- `date_hour` >= 8 #дневная смена
+ date_hour >= 8 /* дневная смена */
AND
- `date_hour` < 20 #дневная смена
+ date_hour < 20 /* дневная смена */
";
} else {
$hourCondition = "
AND
(
- `date_hour` >= 20 #ночная смена
+ date_hour >= 20 /* ночная смена */
OR
- `date_hour` < 8 #ночная смена
+ date_hour < 8 /* ночная смена */
)
";
$command = $connection->createCommand(
"
SELECT
- SUM(`counter`) as cnt,
- `date_hour`,
+ SUM(counter) as cnt,
+ date_hour,
store_id,
- (case when (`date_hour` >= 0 and `date_hour` < 8)
+ (case when (date_hour >= 0 and date_hour < 8)
THEN
- DATE_FORMAT(DATE_ADD(date, INTERVAL -1 DAY),'%Y-%m-%d')
+ TO_CHAR(date - INTERVAL '1 DAY','%Y-%m-%d')
ELSE
- DATE_FORMAT(date,'%Y-%m-%d')
+ TO_CHAR(date,'%Y-%m-%d')
END)
AS date_t,
- CONCAT ((DATE_FORMAT(date,'%Y-%m-%d_')),`date_hour`)
+ CONCAT ((TO_CHAR(date,'%Y-%m-%d_')),date_hour)
AS date_k
FROM
AND
date<=:date_to
GROUP BY
- `date_hour`,
- `date_t`,
- `date_k`,
- `store_id`
+ date_hour,
+ date_t,
+ date_k,
+ store_id
",
[
':date_from' => $dateFrom,
$postJson = Yii::$app->request->post();
unset($postJson["_csrf"]);
$post = \yii\helpers\Json::encode($postJson);
+ $post = str_replace('"', '\'', $post);
$app->db->createCommand(
- 'INSERT INTO page_statistics (admin_id, url, post, created_at) VALUES ("' . $_SESSION['admin_id'] . '", "'
- . $url . '", :post, NOW())'
+ 'INSERT INTO page_statistics (admin_id, url, post, created_at) VALUES (\'' . $_SESSION['admin_id'] . '\', \''
+ . $url . '\', :post, NOW())'
)->bindParam(':post', $post, PDO::PARAM_STR)->execute();
}