fix: 去除完整报价导出中的重复历史备注 (#1243)
This commit is contained in:
parent
941b1acd19
commit
7a4249d753
@ -20,10 +20,23 @@ final class CourierQuoteChangeExport
|
||||
$values = CourierQuoteDocument::values($values, $change->periodLabel());
|
||||
$rules = CourierQuoteDocument::executionText($rules, $change->periodLabel());
|
||||
$layout = CourierQuoteSignatures::quoteLayout($values);
|
||||
$text = implode("\n", array_map(static fn ($row) => implode("\n", $row), $values));
|
||||
if (filled($rules) && ! str_contains($text, trim($rules))) {
|
||||
$layout['notes'][] = $rules;
|
||||
// Legacy quotations repeat the remarks in billing_rules, sometimes with extra rules.
|
||||
$key = static fn ($text) => preg_replace('/\s+/u', '', $text);
|
||||
$existing = [];
|
||||
foreach ($values as $row) foreach ($row as $value) {
|
||||
foreach (preg_split('/\R/u', (string) $value) as $line) $existing[$key($line)] = true;
|
||||
}
|
||||
foreach ($change->quote_payload['quote_notes'] ?? [] as $note) {
|
||||
foreach (preg_split('/\R/u', CourierQuoteDocument::executionText($note['original'], $change->periodLabel())) as $line) $existing[$key($line)] = true;
|
||||
}
|
||||
$extra = [];
|
||||
foreach (preg_split('/\R/u', $rules) as $line) {
|
||||
if (filled($line) && ! isset($existing[$key($line)])) {
|
||||
$extra[] = $line;
|
||||
$existing[$key($line)] = true;
|
||||
}
|
||||
}
|
||||
if ($extra !== []) $layout['notes'][] = implode("\n", $extra);
|
||||
$table = CourierQuoteSignatures::quoteTableWithNotes($layout)['rows'];
|
||||
abort_if($table === [], 422, '这份变价单没有可导出的完整报价。');
|
||||
|
||||
|
||||
@ -444,10 +444,11 @@ class CourierQuoteChangeWorkflowTest extends FeatureTestCase
|
||||
$this->post(route('business.courier-quote-changes.submit', $change))->assertSessionHasNoErrors();
|
||||
$this->post(route('business.courier-quote-changes.approve', $change))->assertSessionHasNoErrors();
|
||||
$change->refresh()->unsetRelation('version');
|
||||
$change->version->update(['billing_rules' => $original . "\n7.计费方式:面单+运费"]);
|
||||
$approved = $change->version->getAttributes();
|
||||
file_put_contents($this->fixturePath, '{"sheets":[]}');
|
||||
$book = app(\App\Support\CourierQuoteChangeExport::class)->build($change);
|
||||
$this->assertSame($expected, $book->getSheet(0)->getCell('D8')->getValue());
|
||||
$this->assertSame($expected . "\n7.计费方式:面单+运费", $book->getSheet(0)->getCell('D8')->getValue());
|
||||
$this->assertEquals(4, $book->getSheet(0)->getCell('B9')->getValue());
|
||||
$book->disconnectWorksheets();
|
||||
$this->assertSame($approved, $change->version->fresh()->getAttributes());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user