应付款终版货款对账:导入模板与表格新增「未发出」列 #350

Merged
renshen merged 1 commits from feature/sumu-payment-reconciliation-unsent-column into main 2026-10-16 20:12:24 +08:00
2 changed files with 69 additions and 6 deletions

View File

@ -34,6 +34,11 @@ class PayablesFinalRegistry
/** 所有终版导入模板都带“月份”列,方便按月导入和查看。 */
private const MONTH_FIELD = ['summary_month' => ['label' => '月份', 'type' => 'month']];
/** 供应商应付(终版)在基础字段之后追加的列(只影响终版目录,基础目录的「未发出」另有口径)。 */
private const SUPPLIER_EXTRA_FIELDS = [
'payment-reconciliation' => ['unsent' => ['label' => '未发出', 'type' => 'text']],
];
public function __construct(
private readonly SupplierPayableMaintenanceRegistry $supplier,
private readonly ProductPriceWorkbookImporter $productPrices,
@ -71,12 +76,14 @@ class PayablesFinalRegistry
{
$this->title($section, $dataset);
$fields = $section === self::SECTION_COURIER
? $this->courier->fields($dataset)
: ($dataset === 'product-prices'
? $this->productPrices->templateFields()
: $this->supplier->fields($dataset));
if ($section === self::SECTION_COURIER) {
return self::MONTH_FIELD + $this->courier->fields($dataset);
}
return self::MONTH_FIELD + $fields;
$fields = $dataset === 'product-prices'
? $this->productPrices->templateFields()
: $this->supplier->fields($dataset);
return self::MONTH_FIELD + $fields + (self::SUPPLIER_EXTRA_FIELDS[$dataset] ?? []);
}
}

View File

@ -72,6 +72,62 @@ class SupplierPayableFinalPagesTest extends FeatureTestCase
}
}
public function test_final_payment_reconciliation_template_adds_unsent_as_the_last_column(): void
{
$response = $this->loginAs()
->get(route('business.supplier-payables-final.payment-reconciliation.template'))
->assertOk()
->assertHeader('content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$path = tempnam(sys_get_temp_dir(), 'caiwu-template') . '.xlsx';
try {
file_put_contents($path, $response->streamedContent());
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path);
$header = $spreadsheet->getSheet(0)->rangeToArray('A1:Q1')[0];
$spreadsheet->disconnectWorksheets();
$this->assertSame([
'记录标识', '月份', '供应商', '货号', '商品编码', '规格名称', '数量', '单价', '金额',
'预估单价', '预估金额', '供应商商品编码', '备注', '仓库名称', '快递名称', '快递单号', '未发出',
], $header);
} finally {
@unlink($path);
}
}
public function test_final_payment_reconciliation_import_keeps_the_unsent_column(): void
{
$file = UploadedFile::fake()->createWithContent(
'payment-reconciliation.csv',
"\xEF\xBB\xBF月份,供应商,货号,商品编码,规格名称,数量,单价,金额,预估单价,预估金额,供应商商品编码,备注,仓库名称,快递名称,快递单号,未发出\n"
. "2026-09,终版供应商,X-1,P-1,规格甲,2,10,20,9,18,SC-1,备注甲,华东仓,顺丰,SF-1,未发出\n",
);
$this->loginAs()
->post(route('business.supplier-payables-final.payment-reconciliation.import'), ['import' => $file])
->assertStatus(302)
->assertSessionHas('success', '导入完成:新增 1 条,更新 0 条。');
$this->assertDatabaseHas('supplier_payable_overrides', [
'company_id' => $this->company->id,
'dataset' => 'final:supplier:payment-reconciliation',
]);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'supplier-payables-final',
'page' => 'payment-reconciliation',
]))
->assertOk()
->assertSeeText('未发出')
->assertSeeText('SF-1');
$export = $this->loginAs()->get(route('business.supplier-payables-final.payment-reconciliation.export'));
$export->assertOk();
$this->assertStringContainsString('快递单号,未发出', $export->streamedContent());
}
public function test_product_price_final_page_reuses_the_price_template_columns(): void
{
$this->loginAs()