]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-403] sales and fot columns in payroll
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 16 Apr 2025 14:02:35 +0000 (17:02 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 16 Apr 2025 14:02:35 +0000 (17:02 +0300)
erp24/actions/payroll/IndexAction.php
erp24/views/payroll/index.php

index 3e4ce27ea4d8f875bef4d0010b959928b4c7b910..d0ee27beeceb4172f7b19abfeec7813b7d046535 100755 (executable)
@@ -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
index 4d7ed4e48d61f92cc04f215a6100ed325f6a5ba4..6977bd5a54164514a7ee138986e9d1e9fc959693 100755 (executable)
@@ -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)){
                         <thead>
                             <th>№</th>
                             <th>Магазин</th>
+                            <th>Продажи за месяц без доставки</th>
+                            <th>Продажи за месяц с доставкой</th>
                             
                             ';
                             $keyNumHead = 0;
                             foreach ($payrollStoreColumn as $key => $row) {
                                 echo "<th class='toggle-column-" . $keyNumHead . "'>" . $row . "</th>";
                                 $keyNumHead++;
+                                if ($keyNumHead == 1) {
+                                    echo "<th class='toggle-column-" . $keyNumHead . "'>% ФОТ</th>";
+                                    $keyNumHead++;
+                                    echo "<th class='toggle-column-" . $keyNumHead . "'>% ФОТ с доставкой</th>";
+                                    $keyNumHead++;
+                                }
                             }
 
                         echo '
@@ -112,11 +123,23 @@ if (!empty($payrollStore)){
                             echo "<tr>
                                         <td>" . $num . " </td>
                                         <td style='white-space: normal;' ><a href='/payroll/store?YearMonthSearchForm[store_id]=" . $payrollStoreRow['store']['id'] . $partUrl . "'>" . $payrollStoreRow['store']['name'] . " </a></td>";
+                            $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 "      <td>" . HtmlHelper::getNumberFormat($salesOfflineAndReturn) . "</td>";
+                            echo "      <td>" . HtmlHelper::getNumberFormat($salesOnlineAndReturn) . "</td>";
                                 $payrollStoreRowColumn = ArrayHelper::getValue($payrollStoreRow, 'column');
                                 $keyNumBody = 0;
-                                foreach ($payrollStoreRowColumn as $columnValue) {
+                                foreach ($payrollStoreRowColumn as $ind => $columnValue) {
                                     echo "<td class='toggle-column-" . $keyNumBody . "'>" . HtmlHelper::getNumberFormat($columnValue) . "</td>";
                                     $keyNumBody++;
+                                    if ($keyNumBody == 1){
+                                        $columnValue = $salesOfflineAndReturn > 0 ? $payrollStoreRowColumn['Зарплата сотрудника'] * 100 / $salesOfflineAndReturn : 0;
+                                        echo "<td class='toggle-column-" . $keyNumBody . "'>" . HtmlHelper::getNumberFormat($columnValue) . "</td>";
+                                        $keyNumBody++;
+                                        $columnValue = $salesOnlineAndReturn > 0 ? $payrollStoreRowColumn['Зарплата сотрудника'] * 100 / $salesOnlineAndReturn : 0;
+                                        echo "<td class='toggle-column-" . $keyNumBody . "'>" . HtmlHelper::getNumberFormat($columnValue) . "</td>";
+                                        $keyNumBody++;
+                                    }
                                 }
                             echo "
                                     </tr>";