/**
* @throws \Exception
*/
- public function getSalesSum($dateFrom, $dateTo, $salesDelivery = false, $salesTotal = false, $storeId1c = null, $payType = null) : array
+ public function getSalesSum($dateFrom, $dateTo, $salesDelivery = false, $salesTotal = false, $storeId1c = null, $payType = null): array
{
$query = Sales::find()
->alias('s')
}
if (!empty($payType)) {
- if ($payType == '1') {
- $payType = ['1', '3', '1,3', '3,1' ];
+ if ($payType == '1') {
+ $payType = ['1', '3', '1,3', '3,1'];
}
$query->andWhere(['s.pay_arr' => $payType]);
return $query->asArray()->all();
}
+
/**
* @throws \Exception
*/
- public function getSalesShiftSum($dateFrom, $dateTo, $shiftType, $salesDelivery = false, $salesTotal = false, $storeId1c = null) : array
+ public function getSalesShiftSum($dateFrom, $dateTo, $shiftType, $salesDelivery = false, $salesTotal = false, $storeId1c = null): array
{
$shiftTypeValidate = [
'day',
}
if ($shiftType == 'day') {
- $dateFromPrepared = DateHelper::getDateTimeStartSmen($dateFrom);
- $dateToPrepared = DateHelper::getDateTimeEndDaySmen($dateTo);
+ $dateFromPrepared = DateHelper::getDateTimeStartSmen($dateFrom);
+ $dateToPrepared = DateHelper::getDateTimeEndDaySmen($dateTo);
} elseif ($shiftType == 'night') {
- $dateFromPrepared = DateHelper::getDateTimeStartNightSmen($dateFrom);
- $dateToPrepared = DateHelper::getDateTimeEndNightShift($dateTo);
+ $dateFromPrepared = DateHelper::getDateTimeStartNightSmen($dateFrom);
+ $dateToPrepared = DateHelper::getDateTimeEndNightShift($dateTo);
}
$query = Sales::find()
->select([
/**
* @throws \Exception
*/
- public function getSalesType($dateFrom, $dateTo, $salesType = 1, $salesDelivery = false, $storeId1c = null) : array
+ public function getSalesType($dateFrom, $dateTo, $salesType = 1, $salesDelivery = false, $storeId1c = null): array
{
$query = Sales::find()
->select([
$query->andWhere(['pay_arr' => $salesType]);
if ($salesDelivery) {
- $query->andWhere(['not in','order_id',['','0']]);
+ $query->andWhere(['not in', 'order_id', ['', '0']]);
} else {
- $query->andWhere(['order_id'=>['','0']]);
+ $query->andWhere(['order_id' => ['', '0']]);
}
if (!empty($storeId1c)) {
* @return array
* @throws \Exception
*/
- public function getSalesByAdmin($adminGuid, $dateFrom, $dateTo, $isAdministrator, bool $salesDelivery = false, $storeId1c = null) : array
+ public function getSalesByAdmin($adminGuid, $dateFrom, $dateTo, $isAdministrator, bool $salesDelivery = false, $storeId1c = null): array
{
$adminsGuids = $this->adminsGuids;
}
$query->andWhere(['>=', 'date', DateHelper::getDateTimeStartDay($dateFrom, $dateTimeStartDay, $adminId)])
- ->andWhere(['<=', 'date', $dateTimeEndDayPrepared])
- ->andWhere(['seller_id' => $adminGuid]);
+ ->andWhere(['<=', 'date', $dateTimeEndDayPrepared])
+ ->andWhere(['seller_id' => $adminGuid]);
if ($salesDelivery) {
- $query->andWhere(['not in','order_id',['','0']]);
+ $query->andWhere(['not in', 'order_id', ['', '0']]);
} else {
- $query->andWhere(['order_id'=>['','0']]);
+ $query->andWhere(['order_id' => ['', '0']]);
}
if (!empty($storeId1c)) {
* @return array
* @throws \Exception
*/
- public function getSalesByStore($storeId1c, $dateFrom, $dateTo, $isAdministrator, bool $salesDelivery = false) : array
+ public function getSalesByStore($storeId1c, $dateFrom, $dateTo, $isAdministrator, bool $salesDelivery = false): array
{
$adminId = null;
}
$query->andWhere(['>=', 'date', DateHelper::getDateTimeStartDay($dateFrom, $dateTimeStartDay, $adminId)])
- ->andWhere(['<=', 'date', $dateTimeEndDayPrepared]);
+ ->andWhere(['<=', 'date', $dateTimeEndDayPrepared]);
if ($salesDelivery) {
- $query->andWhere(['not in','order_id',['','0']]);
+ $query->andWhere(['not in', 'order_id', ['', '0']]);
} else {
- $query->andWhere(['order_id'=>['','0']]);
+ $query->andWhere(['order_id' => ['', '0']]);
}
$query->andWhere(['store_id_1c' => $storeId1c]);
* @return array
* @throws \Exception
*/
- public function getSalesCountSum(string $dateFrom, string $dateTo, $operation = Sales::OPERATION_SALE, $payType = null) : array
+ public function getSalesCountSum(string $dateFrom, string $dateTo, $operation = Sales::OPERATION_SALE, $payType = null): array
{
$connection = Yii::$app->getDb();
";
-
$queryRow = "
SELECT
count(*) as cnt,
if (!empty($payType)) {
- if ($payType == '1') {
+ if ($payType == '1') {
$payType = "'1', '3', '1,3', '3,1' ";
}
$payArrCondition = "
[
':date_from' => DateHelper::getDateTimeStartDay($dateFrom, true),
':date_to' => DateHelper::getDateTimeEndDay($dateTo, true),
- ':operation' => $operation,
+ ':operation' => $operation,
]
);
* @return array
* @throws \Exception
*/
- public function getSalesCountCheck(string $dateFrom, string $dateTo, $storeId1c, $payType = null, string $operation = Sales::OPERATION_SALE) : array
+ public function getSalesCountCheck(string $dateFrom, string $dateTo, $storeId1c, $payType = null, string $operation = Sales::OPERATION_SALE): array
{
$payArrCondition = "";
if (!empty($payType)) {
- if ($payType == '1') {
+ if ($payType == '1') {
$payType = "'1', '3', '1,3', '3,1' ";
}
$payArrCondition = "
",
[
':date_from' => DateHelper::getDateTimeStartDay($dateFrom, true),
- ':date_to' => DateHelper::getDateTimeEndDay($dateTo,true),
- ':operation' => $operation,
- ':store_id_1c' => $storeId1c,
+ ':date_to' => DateHelper::getDateTimeEndDay($dateTo, true),
+ ':operation' => $operation,
+ ':store_id_1c' => $storeId1c,
]
);
}
-
/**
* @param string $dateFrom
* @param string $dateTo
* @return array
* @throws \Exception
*/
- public function getSalesCount(string $dateFrom, string $dateTo, $storeId) : array
+ public function getSalesCount(string $dateFrom, string $dateTo, $storeId): array
{
$salesCountDaySale = $this->getSalesCountByDay($dateFrom, $dateTo, $storeId, true);
$salesCountDayReturn = $this->getSalesCountByDay($dateFrom, $dateTo, $storeId, true, Sales::OPERATION_RETURN);
];
}
- public function calculateCount($salesCount, $salesCountDayReturn = []) : array
+ public function calculateCount($salesCount, $salesCountDayReturn = []): array
{
$resultSaleCount = [];
return $resultSaleCount;
}
- public function getSalesCalculate($dateFrom, $dateTo, $payType = null) : array
+ public function getSalesCalculate($dateFrom, $dateTo, $payType = null): array
{
$salesCalculateByType = [];
return $salesCalculateByType;
}
- public function salesCalculate($salesCount, $salesCountDayReturn) : array
+ public function salesCalculate($salesCount, $salesCountDayReturn): array
{
$salesCountByDate = [];
];
}
- public function getSalesCountByDay(string $dateFrom,string $dateTo, $storeId, bool $shiftTypeDay, string $operation = Sales::OPERATION_SALE) : array
+ public function getSalesCountByDay(string $dateFrom, string $dateTo, $storeId, bool $shiftTypeDay, string $operation = Sales::OPERATION_SALE): array
{
$connection = Yii::$app->getDb();
if ($shiftTypeDay) {
[
':date_from' => DateHelper::getDateTimeStartDay($dateFrom),
':date_to' => DateHelper::getDateTimeEndDay($dateTo),
- ':operation' => $operation,
- ':store_id' => $storeId,
+ ':operation' => $operation,
+ ':store_id' => $storeId,
]
);
return $command->queryAll();
}
- public function getSalesCountByDayHour(string $dateFrom,string $dateTo, $storeId, bool $shiftTypeDay) : array
+ public function getSalesCountByDayHour(string $dateFrom, string $dateTo, $storeId, bool $shiftTypeDay): array
{
$operation = Sales::OPERATION_SALE;
[
':date_from' => DateHelper::getDateTimeStartDay($dateFrom),
':date_to' => DateHelper::getDateTimeEndDay($dateTo),
- ':operation' => $operation,
- ':store_id' => $storeId,
+ ':operation' => $operation,
+ ':store_id' => $storeId,
]
);
$sales_store_summ = [];
$sales_store_summ_all = [];
- foreach ($salesCount as $row) {
+ foreach ($salesCount as $row) {
$rowDateT = ArrayHelper::getValue($row, 'date_t');
$rowStoreId = ArrayHelper::getValue($row, 'store_id');
$rowCnt = ArrayHelper::getValue($row, 'cnt');
$rowSumm = ArrayHelper::getValue($row, 'summ');
- if(!empty($rowDateT)) {
- $sales_store[$rowDateT][$rowStoreId]=$rowCnt;
- $sales_store_summ[$rowDateT][$rowStoreId] = $rowCnt > 0 ? round($rowSumm/$rowCnt) : 0;
+ if (!empty($rowDateT)) {
+ $sales_store[$rowDateT][$rowStoreId] = $rowCnt;
+ $sales_store_summ[$rowDateT][$rowStoreId] = $rowCnt > 0 ? round($rowSumm / $rowCnt) : 0;
if (!empty(ArrayHelper::getValue($sales_store_summ_all, $rowDateT))) {
$sales_store_summ_all[$rowDateT] = $sales_store_summ_all[$rowDateT] + $rowSumm;
} else {
* @return array
* @throws \Exception
*/
- public function salesSumCalculate(array $salesSum, $byDate = false) : array
+ public function salesSumCalculate(array $salesSum, $byDate = false): array
{
$sales_summ = [];
- foreach ($salesSum as $row) {
+ foreach ($salesSum as $row) {
$rowOperation = ArrayHelper::getValue($row, 'operation');
$rowStoreId1c = ArrayHelper::getValue($row, 'store_id_1c');
$rowSummValue = ArrayHelper::getValue($row, 'summ');
$modifier = 0;
- if($rowOperation == Sales::OPERATION_SALE) {
+ if ($rowOperation == Sales::OPERATION_SALE) {
$modifier = 1;
}
- if($rowOperation == Sales::OPERATION_RETURN) {
+ if ($rowOperation == Sales::OPERATION_RETURN) {
$modifier = -1;
}
* @return array
* @throws \yii\db\Exception
*/
- public function getSalesProducts(string $check_id) : array
+ public function getSalesProducts(string $check_id): array
{
$connection = Yii::$app->getDb();
* @return array
* @throws \yii\db\Exception
*/
- public function getAdminSalesProducts(string $adminGuid, string $dateFrom, string $dateTo, string $salesOperation = Sales::OPERATION_SALE) : array
+ public function getAdminSalesProducts(string $adminGuid, string $dateFrom, string $dateTo, string $salesOperation = Sales::OPERATION_SALE): array
{
$connection = Yii::$app->getDb();
sales.seller_id
",
- [ ':admin_guid' => $adminGuid,
+ [':admin_guid' => $adminGuid,
':sales_operation' => $salesOperation,
':date_from' => DateHelper::getDateTimeStartDay($dateFrom),
':date_to' => DateHelper::getDateTimeEndDay($dateTo),
}
- /**
+ /**
* @return array
*/
public function getAllowedByDate($dateFrom, $dateTo, $configStartStopDate): array
* @return array
* @throws \yii\db\Exception
*/
- public function getMatrixSalesProducts(string $adminGuid, string $dateFrom, string $dateTo, $isAdministrator, $adminGuids = null) : array
+ public function getMatrixSalesProducts(string $adminGuid, string $dateFrom, string $dateTo, $isAdministrator, $adminGuids = null): array
{
$adminsGuids = $this->adminsGuids;
':date_to' => DateHelper::getDateTimeEndDay($dateTo, $dateTimeEndDay, $adminId),
]
);
+ } else if ($dateFrom > '2025-01-01') {
+ $command = $connection->createCommand("
+ SELECT
+ DISTINCT (sales.id),
+ sales.seller_id,
+ sales.date,
+ sales.number,
+ (p.summ) AS summ,
+ p.product_id AS product_guid,
+ sales.summ AS sales_summ,
+ sales.skidka,
+ 0 as bonus,
+ order_id,
+ sales.operation
+ FROM
+ sales_products as p,
+ sales
+ WHERE
+ sales.seller_id IN ('$adminGuid')
+ AND
+ sales.id = p.check_id
+ AND
+ p.product_id IN (
+ SELECT
+ products_1c.id
+ FROM
+ products_1c
+ RIGHT JOIN products_class
+ ON
+ products_1c.parent_id = products_class.category_id
+ AND
+ products_class.tip = 'matrix'
+ WHERE
+ 1 = 1
+ )
+ AND
+ sales.date >= :date_from
+ AND
+ sales.date <= :date_to
+ ORDER BY
+ sales.date ASC
+
+ ",
+ [
+ ':date_from' => DateHelper::getDateTimeStartDay($dateFrom, $dateTimeStartDay, $adminId),
+ ':date_to' => DateHelper::getDateTimeEndDay($dateTo, $dateTimeEndDay, $adminId),
+ ]);
} else {
$command = $connection->createCommand("
SELECT
sales.date <= :date_to
",
- [ ':admin_guid' => $adminGuid,
+ [':admin_guid' => $adminGuid,
':date_from' => DateHelper::getDateTimeStartDay($dateFrom, $dateTimeStartDay, $adminId),
':date_to' => DateHelper::getDateTimeEndDay($dateTo, $dateTimeEndDay, $adminId),
]
* @return array
* @throws \yii\db\Exception
*/
- public function getMatrixSalesShiftByDays(string $adminGuid, string $entityCityStoreEmployeeSelect, string $dateFrom, string $dateTo, $isAdministrator) : array
+ public function getMatrixSalesShiftByDays(string $adminGuid, string $entityCityStoreEmployeeSelect, string $dateFrom, string $dateTo, $isAdministrator): array
{
$result = [];
sales.date <= :date_to
",
- [ ':store_id_1c' => $entityCityStoreEmployeeSelect,
+ [':store_id_1c' => $entityCityStoreEmployeeSelect,
':date_from' => DateHelper::getDateTimeStartDay($dateFrom, $dateTimeStartDay, $adminId),
':date_to' => DateHelper::getDateTimeEndDay($dateTo, $dateTimeEndDay, $adminId),
]
);
- $result = $command->queryAll();
+ $result = $command->queryAll();
}
return $result;
* @return array
* @throws \yii\db\Exception
*/
- public function getMatrixMakeProducts(string $adminGuid, string $dateFrom, string $dateTo,bool $isAdministrator, $adminGuids = null) : array
+ public function getMatrixMakeProducts(string $adminGuid, string $dateFrom, string $dateTo, bool $isAdministrator, $adminGuids = null): array
{
$adminsGuids = $this->adminsGuids;
':date_to' => DateHelper::getDateTimeEndDay($dateTo, $dateTimeEndDay, $adminId),
]
);
+ } else if ($dateFrom > '2025-01-01') {
+ $command = $connection->createCommand("
+ SELECT
+ DISTINCT (sales.id),
+ p.seller_id,
+ sales.date,
+ sales.number,
+ (p.summ) AS summ,
+ p.product_id AS product_guid,
+ sales.summ AS sales_summ,
+ sales.skidka,
+ 0 as bonus,
+ order_id,
+ sales.operation
+ FROM
+ sales_products as p,
+ sales
+ WHERE
+ p.seller_id IN ('$adminGuid')
+ AND
+ sales.id = p.check_id
+ AND
+ p.product_id IN (
+ SELECT
+ products_1c.id
+ FROM
+ products_1c
+ RIGHT JOIN products_class
+ ON
+ products_1c.parent_id = products_class.category_id
+ AND
+ products_class.tip = 'matrix'
+ WHERE
+ 1 = 1
+ )
+ AND
+ sales.date >= :date_from
+ AND
+ sales.date <= :date_to
+ ORDER BY
+ sales.date ASC
+ ", [
+ ':date_from' => DateHelper::getDateTimeStartDay($dateFrom, $dateTimeStartDay, $adminId),
+ ':date_to' => DateHelper::getDateTimeEndDay($dateTo, $dateTimeEndDay, $adminId),
+ ]
+ );
} else {
$command = $connection->createCommand("
SELECT
* @return array
* @throws \Exception
*/
- public function getSalesItems(string $dateFrom, string $dateTo, array $productsArrayServices) : array
+ public function getSalesItems(string $dateFrom, string $dateTo, array $productsArrayServices): array
{
- $where_serv="";
- $i=0;
+ $where_serv = "";
+ $i = 0;
- foreach($productsArrayServices["services"] as $k => $pid) {
- if ($i > 0) $where_serv .=" or ";
- $where_serv .=" sales_items.id_1c='$pid'";
+ foreach ($productsArrayServices["services"] as $k => $pid) {
+ if ($i > 0) $where_serv .= " or ";
+ $where_serv .= " sales_items.id_1c='$pid'";
$i++;
}
* @return array
* @throws \Exception
*/
- public function getSalesServices(string $dateFrom, string $dateTo) : array
+ public function getSalesServices(string $dateFrom, string $dateTo): array
{
$connection = Yii::$app->getDb();
$countByDate = [];
$salesByAdmin = 0;
- foreach($salesArray as $row) {
- $rowDate = date("Y-m-d",strtotime($row['date']));
+ foreach ($salesArray as $row) {
+ $rowDate = date("Y-m-d", strtotime($row['date']));
if (!empty($timeTable)) {
if (!in_array($rowDate, $timeTable)) {
if (!array_key_exists($rowDate, $countByDate)) {
$countByDate[$rowDate] = 0;
}
- if($row["operation"] == Sales::OPERATION_SALE) {
+ if ($row["operation"] == Sales::OPERATION_SALE) {
$sales[$rowDate] += $row["summ"];
$countByDate[$rowDate] += 1;
$salesByAdmin += $row["summ"];
}
- if($row["operation"] == Sales::OPERATION_RETURN) {
+ if ($row["operation"] == Sales::OPERATION_RETURN) {
$sales[$rowDate] -= $row["summ"];
$countByDate[$rowDate] -= 1;
$salesByAdmin -= $row["summ"];
{
$sales = [];
- foreach($salesArray as $row) {
+ foreach ($salesArray as $row) {
$rowDate = $row['date'];
if ($numDayCalculate) {
$rowDate = $this->getRowDate($row['date']);
$sales[$rowDate] = 0;
}
- if($row["operation"] == Sales::OPERATION_SALE) {
+ if ($row["operation"] == Sales::OPERATION_SALE) {
$sales[$rowDate] += $row["summ"];
}
- if($row["operation"] == Sales::OPERATION_RETURN) {
+ if ($row["operation"] == Sales::OPERATION_RETURN) {
$sales[$rowDate] -= $row["summ"];
}
}
$date = $dateToPrepared->format('Y-m-d 23:58:58');
}
- return date("Y-m-d",strtotime($date));
+ return date("Y-m-d", strtotime($date));
}
}