修复报价变价新增省份入口不显示 (#1436)
This commit is contained in:
parent
696327fb38
commit
a026cdc1f0
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -143,8 +143,15 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@php
|
||||
[$provinceColumns, $provinceRemarks] = \App\Support\CourierQuoteProvinceAdditions::fields($source);
|
||||
@endphp
|
||||
<section class="quote-change-panel" aria-labelledby="quote-detail-edit-title">
|
||||
<header class="quote-change-panel__header"><div><div class="quote-change-panel__title" id="quote-detail-edit-title"><span class="material-icons-outlined" aria-hidden="true">difference</span><span>{{ $change ? '变价明细' : '第三步:编辑新价格' }}</span></div><div class="quote-change-panel__hint">可修改新价格和报价备注;系统会再次核对原价格和原备注。</div></div></header>
|
||||
<header class="quote-change-panel__header"><div><div class="quote-change-panel__title" id="quote-detail-edit-title"><span class="material-icons-outlined" aria-hidden="true">difference</span><span>{{ $change ? '变价明细' : '第三步:编辑新价格' }}</span></div><div class="quote-change-panel__hint">可修改新价格和报价备注;系统会再次核对原价格和原备注。</div></div>
|
||||
@if($provinceColumns)
|
||||
<button type="button" class="quote-change-button" data-add-province>+ 新增省份</button>
|
||||
@endif
|
||||
</header>
|
||||
<div class="quote-change-panel__body">
|
||||
<div class="quote-change-alert"><span class="material-icons-outlined" aria-hidden="true">verified_user</span><span>保存草稿不会让报价生效。提交后由指定审核人员审核并生成新版本;待审核单可在详情页撤回修改后重提。本人单据的审核权限以指定授权为准。</span></div>
|
||||
<div class="quote-batch-tools" aria-label="批量调整">
|
||||
@ -202,7 +209,6 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@php([$provinceColumns, $provinceRemarks] = \App\Support\CourierQuoteProvinceAdditions::fields($source))
|
||||
@if($provinceColumns)
|
||||
<div data-province-editor>
|
||||
<p class="quote-change-panel__hint">仅新增原报价没有的省份。新增报价随本次变价审核生效。</p>
|
||||
@ -214,7 +220,6 @@
|
||||
<template data-province-template>
|
||||
@include('business.pages.courier-payables.quote-change-province-fields', ['provinceIndex' => '__INDEX__', 'province' => []])
|
||||
</template>
|
||||
<button type="button" class="quote-change-button" data-add-province>+ 新增省份</button>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@ -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 => {
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user