160 lines
4.3 KiB
PHP
160 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Modules\EcommerceFinance\Services\FinanceLedgerBaseImporter;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
use Tests\TestCase;
|
|
|
|
class FinanceLedgerBaseImporterTest extends TestCase
|
|
{
|
|
public function test_account_headers_import_new_keep_column_without_shifting_other_fields(): void
|
|
{
|
|
$sheet = $this->sheet([
|
|
'公司名称',
|
|
'账户简称',
|
|
'账号',
|
|
'开户行',
|
|
'开户城市/网点',
|
|
'账户类型',
|
|
'公司规划',
|
|
'账户是否保留',
|
|
'后4位',
|
|
'单笔限额',
|
|
'日限额',
|
|
'月限额',
|
|
'年限额',
|
|
'可用金额',
|
|
'不可用金额',
|
|
'每日可出',
|
|
'预计出清天数',
|
|
'提额目标',
|
|
'提额状态',
|
|
'提额动作',
|
|
'已做动作',
|
|
'下一步',
|
|
'备注',
|
|
'责任人',
|
|
], [
|
|
'新格式公司',
|
|
'新格式账户',
|
|
'62220001',
|
|
'测试银行',
|
|
'上海 / 测试支行',
|
|
'公户',
|
|
'保留',
|
|
'是',
|
|
'0001',
|
|
'10000',
|
|
'20000',
|
|
'30000',
|
|
'40000',
|
|
123.45,
|
|
6.78,
|
|
116.67,
|
|
2.5,
|
|
'目标',
|
|
'进行中',
|
|
'动作',
|
|
'已做',
|
|
'下一步',
|
|
'备注',
|
|
'责任人',
|
|
]);
|
|
|
|
$rows = $this->importer()->parseAccounts($sheet);
|
|
|
|
$this->assertCount(1, $rows);
|
|
$this->assertSame('是', $rows[0]['account_should_keep']);
|
|
$this->assertSame('0001', $rows[0]['account_last4']);
|
|
$this->assertSame('10000', $rows[0]['single_limit']);
|
|
$this->assertEqualsWithDelta(123.45, $rows[0]['current_balance'], 0.001);
|
|
$this->assertSame('责任人', $rows[0]['owner']);
|
|
}
|
|
|
|
public function test_account_headers_keep_legacy_layout_compatible(): void
|
|
{
|
|
$sheet = $this->sheet([
|
|
'公司名称',
|
|
'账户简称',
|
|
'账号',
|
|
'开户行',
|
|
'开户城市/网点',
|
|
'账户类型',
|
|
'公司规划',
|
|
'后4位',
|
|
'单笔限额',
|
|
'日限额',
|
|
'月限额',
|
|
'年限额',
|
|
'可用金额',
|
|
'不可用金额',
|
|
'每日可出',
|
|
'预计出清天数',
|
|
'提额目标',
|
|
'提额状态',
|
|
'提额动作',
|
|
'已做动作',
|
|
'下一步',
|
|
'备注',
|
|
'责任人',
|
|
], [
|
|
'旧格式公司',
|
|
'旧格式账户',
|
|
'62220002',
|
|
'测试银行',
|
|
'杭州 / 测试支行',
|
|
'个人卡',
|
|
'待注销',
|
|
'0002',
|
|
'1000',
|
|
'2000',
|
|
'3000',
|
|
'4000',
|
|
12.34,
|
|
0,
|
|
12.34,
|
|
null,
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'旧格式责任人',
|
|
]);
|
|
|
|
$rows = $this->importer()->parseAccounts($sheet);
|
|
|
|
$this->assertCount(1, $rows);
|
|
$this->assertSame('', $rows[0]['account_should_keep']);
|
|
$this->assertSame('0002', $rows[0]['account_last4']);
|
|
$this->assertSame('1000', $rows[0]['single_limit']);
|
|
$this->assertEqualsWithDelta(12.34, $rows[0]['current_balance'], 0.001);
|
|
$this->assertSame('旧格式责任人', $rows[0]['owner']);
|
|
}
|
|
|
|
private function importer(): FinanceLedgerBaseImporterForTest
|
|
{
|
|
return new FinanceLedgerBaseImporterForTest();
|
|
}
|
|
|
|
private function sheet(array $headers, array $values): Worksheet
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->fromArray([$headers, $values], null, 'A1');
|
|
|
|
return $sheet;
|
|
}
|
|
}
|
|
|
|
final class FinanceLedgerBaseImporterForTest extends FinanceLedgerBaseImporter
|
|
{
|
|
public function parseAccounts(Worksheet $sheet): array
|
|
{
|
|
return $this->accounts($sheet);
|
|
}
|
|
}
|