m0_70156489 1 settimana fa
parent
commit
cd59853e9b
1 ha cambiato i file con 58 aggiunte e 13 eliminazioni
  1. 58 13
      application/admin/controller/Procuremen.php

+ 58 - 13
application/admin/controller/Procuremen.php

@@ -7350,11 +7350,11 @@ class Procuremen extends Backend
 
         $spreadsheet = new Spreadsheet();
         $sheet = $spreadsheet->getActiveSheet();
-        $sheet->setTitle('协助明细');
+        $sheet->setTitle('外协加工明细');
 
         $mon = (int)substr($ym, 5, 2);
         $sheet->mergeCells('A1:H1');
-        $sheet->setCellValue('A1', $mon . '月协助明细');
+        $sheet->setCellValue('A1', $mon . '月份外协加工明细');
         $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14);
         $sheet->getStyle('A1')->getAlignment()
             ->setHorizontal(Alignment::HORIZONTAL_CENTER)
@@ -7372,6 +7372,7 @@ class Procuremen extends Backend
         $rowNum = 3;
         $sumSubtotalCounts = 0;
         $grandAmount = 0.0;
+        $globalSeq = 0;
 
         if ($groups === []) {
             $sheet->mergeCells('A3:H3');
@@ -7385,14 +7386,13 @@ class Procuremen extends Backend
                 }
                 $groupLineCount = count($items);
                 $subAmount = 0.0;
-                $i = 0;
                 foreach ($items as $line) {
-                    $i++;
+                    $globalSeq++;
                     $dr = $line['detail'];
                     $amt = $this->procuremenExportAmount($dr);
                     $subAmount += $amt;
 
-                    $sheet->setCellValue('A' . $rowNum, $i);
+                    $sheet->setCellValue('A' . $rowNum, $globalSeq);
                     $sheet->setCellValue('B' . $rowNum, $line['CCYDH']);
                     $sheet->setCellValue('C' . $rowNum, $line['CYJMC']);
                     $sheet->setCellValue('D' . $rowNum, $line['company_name']);
@@ -7407,11 +7407,10 @@ class Procuremen extends Backend
                 $sumSubtotalCounts += $groupLineCount;
                 $grandAmount += $subAmount;
 
-                $sheet->setCellValue('A' . $rowNum, $groupLineCount);
                 $sheet->mergeCells('G' . $rowNum . ':H' . $rowNum);
                 $sheet->setCellValue('G' . $rowNum, '¥ ' . number_format($subAmount, 2, '.', ','));
                 $sheet->getStyle('G' . $rowNum)->getAlignment()
-                    ->setHorizontal(Alignment::HORIZONTAL_RIGHT)
+                    ->setHorizontal(Alignment::HORIZONTAL_LEFT)
                     ->setVertical(Alignment::VERTICAL_CENTER);
                 $rowNum++;
             }
@@ -7422,7 +7421,7 @@ class Procuremen extends Backend
         $sheet->mergeCells('G' . $rowNum . ':H' . $rowNum);
         $sheet->setCellValue('G' . $rowNum, '¥ ' . number_format($grandAmount, 2, '.', ','));
         $sheet->getStyle('A' . $rowNum . ':H' . $rowNum)->getFont()->setBold(true);
-        $sheet->getStyle('G' . $rowNum)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
+        $sheet->getStyle('G' . $rowNum)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
 
         $lastRow = $rowNum;
         $sheet->getStyle('A1:H' . $lastRow)->applyFromArray([
@@ -7440,6 +7439,7 @@ class Procuremen extends Backend
             $sheet->getStyle('F3:F' . $lastRow)->getAlignment()->setWrapText(true)->setVertical(Alignment::VERTICAL_TOP);
             $sheet->getStyle('G3:G' . $lastRow)->getAlignment()->setWrapText(true)->setVertical(Alignment::VERTICAL_TOP);
         }
+        $this->applyMonthExportTableAlignment($sheet, 2, 3, $lastRow, 'H');
         $sheet->getColumnDimension('A')->setWidth(7);
         $sheet->getColumnDimension('B')->setWidth(16);
         $sheet->getColumnDimension('C')->setWidth(52);
@@ -7457,7 +7457,8 @@ class Procuremen extends Backend
             $sheet->getColumnDimension('E')->setWidth(28);
         }
 
-        $fileBase = '协助明细_' . str_replace('-', '', $ym);
+        $ymCompact = str_replace('-', '', $ym);
+        $fileBase = $mon . '月份外协加工明细_' . $ymCompact;
         $filename = $fileBase . '.xlsx';
 
         try {
@@ -7478,7 +7479,7 @@ class Procuremen extends Backend
         if (ob_get_length()) {
             ob_end_clean();
         }
-        $asciiName = 'outward_' . str_replace('-', '', $ym) . '.xlsx';
+        $asciiName = 'wxjgmx_' . $ymCompact . '.xlsx';
         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
         header('Content-Disposition: attachment;filename="' . $asciiName . '"; filename*=UTF-8\'\'' . rawurlencode($filename));
         header('Cache-Control: max-age=0');
@@ -7579,20 +7580,40 @@ class Procuremen extends Backend
                 'picked'        => $picked,
             ];
         }
-        usort($lines, function ($a, $b) {
+        $winnerSupplierByOrder = [];
+        foreach ($lines as $line) {
+            $dh = trim((string)($line['CCYDH'] ?? ''));
+            $cn = trim((string)($line['company_name'] ?? ''));
+            if ($dh !== '' && $cn !== '' && !empty($line['picked'])) {
+                $winnerSupplierByOrder[$dh][$cn] = true;
+            }
+        }
+        usort($lines, function ($a, $b) use ($winnerSupplierByOrder) {
             $c = strcmp((string)($a['CCYDH'] ?? ''), (string)($b['CCYDH'] ?? ''));
             if ($c !== 0) {
                 return $c;
             }
-            $c = strcmp((string)($a['gx'] ?? ''), (string)($b['gx'] ?? ''));
+            $dh = trim((string)($a['CCYDH'] ?? ''));
+            $aCn = trim((string)($a['company_name'] ?? ''));
+            $bCn = trim((string)($b['company_name'] ?? ''));
+            $aSupplierWin = ($dh !== '' && $aCn !== '' && !empty($winnerSupplierByOrder[$dh][$aCn]));
+            $bSupplierWin = ($dh !== '' && $bCn !== '' && !empty($winnerSupplierByOrder[$dh][$bCn]));
+            if ($aSupplierWin !== $bSupplierWin) {
+                return $aSupplierWin ? -1 : 1;
+            }
+            $c = strcmp($aCn, $bCn);
             if ($c !== 0) {
                 return $c;
             }
             if (!empty($a['picked']) !== !empty($b['picked'])) {
                 return !empty($a['picked']) ? -1 : 1;
             }
+            $c = strcmp((string)($a['gx'] ?? ''), (string)($b['gx'] ?? ''));
+            if ($c !== 0) {
+                return $c;
+            }
 
-            return strcmp((string)($a['company_name'] ?? ''), (string)($b['company_name'] ?? ''));
+            return 0;
         });
 
         return $lines;
@@ -7671,11 +7692,35 @@ class Procuremen extends Backend
             $sheet->getStyle('D' . $dataStartRow . ':D' . $lastRow)->getAlignment()->setWrapText(true)->setVertical(Alignment::VERTICAL_TOP);
             $sheet->getStyle('E' . $dataStartRow . ':E' . $lastRow)->getAlignment()->setWrapText(true)->setVertical(Alignment::VERTICAL_TOP);
             $sheet->getRowDimension($titleRow)->setRowHeight(28);
+            if ($lastRow >= $dataStartRow) {
+                $this->applyMonthExportTableAlignment($sheet, $headerRow, $dataStartRow, $lastRow, 'H');
+            }
         }
 
         return $lastRow;
     }
 
+    /**
+     * 月度导出表格对齐:表头居中、序号列居中、其余列居左
+     */
+    protected function applyMonthExportTableAlignment(Worksheet $sheet, int $headerRow, int $dataStartRow, int $lastRow, string $lastCol = 'H'): void
+    {
+        if ($lastRow < $dataStartRow || $headerRow < 1) {
+            return;
+        }
+        $sheet->getStyle('A' . $headerRow . ':' . $lastCol . $headerRow)->getAlignment()
+            ->setHorizontal(Alignment::HORIZONTAL_CENTER)
+            ->setVertical(Alignment::VERTICAL_CENTER);
+        $sheet->getStyle('A' . $dataStartRow . ':A' . $lastRow)->getAlignment()
+            ->setHorizontal(Alignment::HORIZONTAL_CENTER)
+            ->setVertical(Alignment::VERTICAL_CENTER);
+        if ($lastCol > 'B') {
+            $sheet->getStyle('B' . $dataStartRow . ':' . $lastCol . $lastRow)->getAlignment()
+                ->setHorizontal(Alignment::HORIZONTAL_LEFT)
+                ->setVertical(Alignment::VERTICAL_CENTER);
+        }
+    }
+
     /**
      * 订单号等用于 PDF 文件名片段(去掉路径非法字符)
      */