From: Alexander Smirnov Date: Wed, 16 Apr 2025 14:02:35 +0000 (+0300) Subject: [ERP-403] sales and fot columns in payroll X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=269add33161e5a3be28b260dc90cfa63616b1847;p=erp24_rep%2Fyii-erp24%2F.git [ERP-403] sales and fot columns in payroll --- diff --git a/erp24/actions/payroll/IndexAction.php b/erp24/actions/payroll/IndexAction.php index 3e4ce27e..d0ee27be 100755 --- a/erp24/actions/payroll/IndexAction.php +++ b/erp24/actions/payroll/IndexAction.php @@ -10,6 +10,7 @@ use yii_app\helpers\HtmlHelper; use yii_app\records\AdminPayroll; use yii_app\records\AdminPayrollValues; use yii_app\records\AdminPayrollValuesDict; +use yii_app\records\Sales; class IndexAction extends Action { @@ -167,6 +168,59 @@ class IndexAction extends Action $partUrl = '&YearMonthSearchForm[year]=' . $yearSelect . '&YearMonthSearchForm[month]=' . $monthSelect; + $monthSelectPad0 = $monthSelect < 10 ? '0' . $monthSelect : $monthSelect; + $t = date('t', strtotime(date($yearSelect . '-' . $monthSelectPad0 . '-01'))); + $dateSelectMonthStart = date($yearSelect . '-' . $monthSelectPad0 . '-01 00:00:00'); + $dateSelectMonthEnd = date($yearSelect . '-' . $monthSelectPad0 . '-' . $t .' 23:59:59'); + $salesOffline = Sales::find()->alias('s') + ->select(['SUM(s.summ - s.skidka) as total', 's.store_id']) + ->joinWith('saleCheck') + ->andWhere(['between' , 's.date', $dateSelectMonthStart, $dateSelectMonthEnd]) + ->andWhere(['s.operation' => Sales::OPERATION_SALE]) + ->andWhere([ + 'and', + ['s.order_id' => ['', '0']], + [ + 'or', + 'sc.order_id IS NULL', + ['sc.order_id' => ['', '0']] + ] + ]) + ->groupBy(['s.store_id']) + ->indexBy('store_id') + ->asArray()->all(); + + $salesOfflineReturn = Sales::find()->alias('s') + ->select(['SUM(s.summ - s.skidka) as total', 's.store_id']) + ->joinWith('saleCheck') + ->andWhere(['between' , 's.date', $dateSelectMonthStart, $dateSelectMonthEnd]) + ->andWhere(['s.operation' => Sales::OPERATION_RETURN]) + ->andWhere([ + 'and', + ['s.order_id' => ['', '0']], + [ + 'or', + 'sc.order_id IS NULL', + ['sc.order_id' => ['', '0']] + ] + ]) + ->groupBy(['s.store_id']) + ->indexBy('store_id') + ->asArray()->all(); + + $salesOnline = Sales::find()->select(['SUM(summ - skidka) as total', 'store_id']) + ->andWhere(['between' , 'date', $dateSelectMonthStart, $dateSelectMonthEnd]) + ->andWhere(['operation' => Sales::OPERATION_SALE]) + ->groupBy(['store_id']) + ->indexBy('store_id') + ->asArray()->all(); + + $salesOnlineReturn = Sales::find()->select(['SUM(summ - skidka) as total', 'store_id']) + ->andWhere(['between' , 'date', $dateSelectMonthStart, $dateSelectMonthEnd]) + ->andWhere(['operation' => Sales::OPERATION_RETURN]) + ->groupBy(['store_id']) + ->indexBy('store_id') + ->asArray()->all(); return $this->controller->render('/payroll/index', [ 'payrollStore' => $payrollStore, @@ -175,6 +229,10 @@ class IndexAction extends Action 'sumColumnByAlias' => $sumColumnByAlias, 'monthNameSelect' => $monthNameSelect, 'partUrl' => $partUrl, + 'salesOffline' => $salesOffline, + 'salesOfflineReturn' => $salesOfflineReturn, + 'salesOnline' => $salesOnline, + 'salesOnlineReturn' => $salesOnlineReturn, ]); } } \ No newline at end of file diff --git a/erp24/views/payroll/index.php b/erp24/views/payroll/index.php index 4d7ed4e4..6977bd5a 100755 --- a/erp24/views/payroll/index.php +++ b/erp24/views/payroll/index.php @@ -16,7 +16,10 @@ use yii_app\forms\payroll\YearMonthSearchForm; /* @var $monthNameSelect string */ /* @var $partUrl string */ /* @var $yearMonthSearchForm YearMonthSearchForm*/ - +/* @var $salesOffline array */ +/* @var $salesOfflineReturn array */ +/* @var $salesOnline array */ +/* @var $salesOnlineReturn array */ $this->title = 'Зарплаты по магазинам за ' . $monthNameSelect; $this->params['breadcrumbs'][] = $this->title; @@ -94,12 +97,20 @@ if (!empty($payrollStore)){ № Магазин + Продажи за месяц без доставки + Продажи за месяц с доставкой '; $keyNumHead = 0; foreach ($payrollStoreColumn as $key => $row) { echo "" . $row . ""; $keyNumHead++; + if ($keyNumHead == 1) { + echo "% ФОТ"; + $keyNumHead++; + echo "% ФОТ с доставкой"; + $keyNumHead++; + } } echo ' @@ -112,11 +123,23 @@ if (!empty($payrollStore)){ echo " " . $num . " " . $payrollStoreRow['store']['name'] . " "; + $salesOfflineAndReturn = (isset($salesOffline[$key]) ? $salesOffline[$key]['total'] : 0) - (isset($salesOfflineReturn[$key]) ? $salesOfflineReturn[$key]['total'] : 0); + $salesOnlineAndReturn = (isset($salesOnline[$key]) ? $salesOnline[$key]['total'] : 0) - (isset($salesOnlineReturn[$key]) ? $salesOnlineReturn[$key]['total'] : 0); + echo " " . HtmlHelper::getNumberFormat($salesOfflineAndReturn) . ""; + echo " " . HtmlHelper::getNumberFormat($salesOnlineAndReturn) . ""; $payrollStoreRowColumn = ArrayHelper::getValue($payrollStoreRow, 'column'); $keyNumBody = 0; - foreach ($payrollStoreRowColumn as $columnValue) { + foreach ($payrollStoreRowColumn as $ind => $columnValue) { echo "" . HtmlHelper::getNumberFormat($columnValue) . ""; $keyNumBody++; + if ($keyNumBody == 1){ + $columnValue = $salesOfflineAndReturn > 0 ? $payrollStoreRowColumn['Зарплата сотрудника'] * 100 / $salesOfflineAndReturn : 0; + echo "" . HtmlHelper::getNumberFormat($columnValue) . ""; + $keyNumBody++; + $columnValue = $salesOnlineAndReturn > 0 ? $payrollStoreRowColumn['Зарплата сотрудника'] * 100 / $salesOnlineAndReturn : 0; + echo "" . HtmlHelper::getNumberFormat($columnValue) . ""; + $keyNumBody++; + } } echo " ";