diff --git a/app/Http/Controllers/Business/CourierQuoteSignatures.php b/app/Http/Controllers/Business/CourierQuoteSignatures.php index ad1104ba..5937fed0 100644 --- a/app/Http/Controllers/Business/CourierQuoteSignatures.php +++ b/app/Http/Controllers/Business/CourierQuoteSignatures.php @@ -226,6 +226,16 @@ class CourierQuoteSignatures extends Controller break; } } + if ($start === null) { + foreach ($rows as $index => $row) { + if (filled($row[0] ?? null) || $filled($row) < 2) continue; + $next = $rows[$index + 1] ?? []; + if (filled($next[0] ?? null) && collect(array_slice($next, 1))->contains(fn ($cell) => is_numeric($cell))) { + $start = $index; + break; + } + } + } if ($start === null) { foreach ($rows as $index => $row) { if ($filled($row) >= 2) { diff --git a/app/Support/CourierQuoteProvinceAdditions.php b/app/Support/CourierQuoteProvinceAdditions.php index 8f981276..1fd5c2d7 100644 --- a/app/Support/CourierQuoteProvinceAdditions.php +++ b/app/Support/CourierQuoteProvinceAdditions.php @@ -2,28 +2,50 @@ namespace App\Support; -use App\Http\Controllers\Business\CourierQuoteSignatures; use Illuminate\Validation\ValidationException; final class CourierQuoteProvinceAdditions { public static function fields(array $source): array { - $layout = CourierQuoteSignatures::quoteLayout($source['values']); - $header = $layout['table'][0] ?? []; - $rows = array_slice($layout['table'], 1); - $columns = []; - $remarks = null; - foreach ($header as $column => $label) { - if ($column === 0 || blank($label)) continue; - if (preg_match('/^(报价备注|备注|说明)[::]?$/u', trim($label))) { - $remarks = $column; - } elseif (collect($rows)->contains(fn ($row) => is_numeric($row[$column] ?? null))) { - $columns[$column] = (string) $label; + $values = $source['values']; + $priceColumns = []; + $regions = []; + foreach ($values as $rowIndex => $row) { + $region = $row[0] ?? null; + if (!is_string($region) || blank($region)) continue; + + foreach ($row as $column => $value) { + if ($column === 0 || !is_numeric($value) || filled($source['formulas'][$rowIndex][$column] ?? null)) continue; + $priceColumns[$column] ??= $rowIndex; + $regions[$rowIndex] = $region; } } - return [$columns, $remarks, array_map(fn ($row) => (string) ($row[0] ?? ''), $rows), $layout['row_keys']]; + ksort($priceColumns); + $columns = []; + foreach ($priceColumns as $column => $firstPriceRow) { + $columns[$column] = '价格列 ' . $column; + for ($row = $firstPriceRow - 1; $row >= 0; $row--) { + $label = $values[$row][$column] ?? null; + if (!is_string($label) || blank($label) || isset($regions[$row])) continue; + $columns[$column] = trim($label); + break; + } + } + + $remarks = null; + $firstRegionRow = array_key_first($regions) ?? 0; + for ($row = $firstRegionRow - 1; $row >= 0 && $remarks === null; $row--) { + foreach ($values[$row] ?? [] as $column => $label) { + if ($column > 0 && !isset($columns[$column]) && is_string($label) && preg_match('/^(报价备注|备注|说明)[::]?$/u', trim($label))) { + $remarks = $column; + break; + } + } + } + + return [$columns, $remarks, array_values($regions), array_keys($regions)]; } public static function apply(array $source, array $additions): array diff --git a/resources/views/business/pages/courier-payables/quote-change-editor.blade.php b/resources/views/business/pages/courier-payables/quote-change-editor.blade.php index 5f12c95b..1ebef52e 100644 --- a/resources/views/business/pages/courier-payables/quote-change-editor.blade.php +++ b/resources/views/business/pages/courier-payables/quote-change-editor.blade.php @@ -143,8 +143,15 @@ + @php + [$provinceColumns, $provinceRemarks] = \App\Support\CourierQuoteProvinceAdditions::fields($source); + @endphp
-
{{ $change ? '变价明细' : '第三步:编辑新价格' }}
可修改新价格和报价备注;系统会再次核对原价格和原备注。
+
{{ $change ? '变价明细' : '第三步:编辑新价格' }}
可修改新价格和报价备注;系统会再次核对原价格和原备注。
+ @if($provinceColumns) + + @endif +
保存草稿不会让报价生效。提交后由指定审核人员审核并生成新版本;待审核单可在详情页撤回修改后重提。本人单据的审核权限以指定授权为准。
@@ -202,7 +209,6 @@
- @php([$provinceColumns, $provinceRemarks] = \App\Support\CourierQuoteProvinceAdditions::fields($source)) @if($provinceColumns)

仅新增原报价没有的省份。新增报价随本次变价审核生效。

@@ -214,7 +220,6 @@ -
@endif
@@ -247,7 +252,7 @@ const provinceRows = provinceEditor.querySelector('[data-province-rows]'); const provinceTemplate = provinceEditor.querySelector('[data-province-template]'); let nextProvinceIndex = Math.max(-1, ...Array.from(provinceRows.children, row => Number(row.dataset.provinceIndex))) + 1; - provinceEditor.querySelector('[data-add-province]').addEventListener('click', function () { + root.querySelector('[data-add-province]').addEventListener('click', function () { provinceRows.insertAdjacentHTML('beforeend', provinceTemplate.innerHTML.replaceAll('__INDEX__', String(nextProvinceIndex++))); const newRow = provinceRows.lastElementChild; newRow.querySelectorAll('[data-field-name]').forEach(field => { diff --git a/tests/Feature/Business/CourierQuoteChangeWorkflowTest.php b/tests/Feature/Business/CourierQuoteChangeWorkflowTest.php index 2061aaaf..e5d93ab2 100644 --- a/tests/Feature/Business/CourierQuoteChangeWorkflowTest.php +++ b/tests/Feature/Business/CourierQuoteChangeWorkflowTest.php @@ -255,6 +255,32 @@ class CourierQuoteChangeWorkflowTest extends FeatureTestCase $this->assertSame('QB-002', app(QuoteManagementSnapshot::class)->load()['quotes'][1]['id']); } + public function test_province_button_is_visible_when_quote_has_a_preamble_and_an_unlabeled_region_column(): void + { + file_put_contents($this->fixturePath, json_encode(['sheets' => [[ + 'index' => 0, 'name' => '新北中通报价', 'address' => 'A1:E5', + 'values' => [ + ['价格说明', '费用以审核版本为准'], + [], + [null, '一口价', '面单', '费率', '备注'], + ['江苏', 3.8, 3.8, 0.45, null], + ['安徽', 3.8, 3.8, 0.45, null], + ], + 'formulas' => [], + ]]], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)); + + $this->loginAs()->get(route('business.courier-quote-changes.start', ['source_quote_id' => 'QB-001'])) + ->assertOk()->assertSee('data-add-province', false) + ->assertSeeTextInOrder(['第三步:编辑新价格', '+ 新增省份', '批量方式']); + + $source = app(QuoteManagementSnapshot::class)->load()['quotes'][0]; + $result = \App\Support\CourierQuoteProvinceAdditions::apply($source, [ + ['region' => '浙江', 'prices' => [1 => 3.8, 2 => 3.8, 3 => 0.45]], + ]); + $layout = \App\Http\Controllers\Business\CourierQuoteSignatures::quoteLayout($result['values']); + $this->assertSame(['江苏', '安徽', '浙江'], array_column(array_slice($layout['table'], 1), 0)); + } + public function test_a_province_can_be_added_without_changing_existing_prices(): void { $payload = $this->validPayload();