fix: 厂家未上传时不生成对账差异 #955
@ -177,6 +177,11 @@ class SupplierReconciliation extends Controller
|
||||
]);
|
||||
[$supplier, $companyId] = $this->returnTarget($request);
|
||||
$detail = $this->pageData->financeDetailForFilters($supplier, $companyId, $request->all());
|
||||
if (($detail['awaitingUpload'] ?? false) === true) {
|
||||
return back()->withErrors([
|
||||
'dingtalk_push' => '厂家尚未上传对账单,暂不能推送差异。',
|
||||
]);
|
||||
}
|
||||
$differences = array_values(array_filter(
|
||||
$detail['rows'],
|
||||
static fn (array $row): bool => ($row['type'] ?? '') !== SupplierStatementMatcher::TYPE_MATCH,
|
||||
|
||||
@ -549,9 +549,36 @@ class SupplierReconciliationPageData
|
||||
));
|
||||
$theirRows = $this->statements->rows($supplier, $companyId);
|
||||
|
||||
if ($theirRows === [] && $mineRows !== []) {
|
||||
$mineAmount = array_sum(array_map(
|
||||
static fn (array $row): float => (float) ($row['amount'] ?? 0),
|
||||
$mineRows,
|
||||
));
|
||||
|
||||
return [
|
||||
'rows' => [],
|
||||
'summary' => [
|
||||
'match' => 0,
|
||||
'supplierExtra' => 0,
|
||||
'mismatch' => 0,
|
||||
'supplierMissing' => 0,
|
||||
'mineAmount' => round($mineAmount, 2),
|
||||
'theirsAmount' => 0.0,
|
||||
'supplierOverQty' => 0.0,
|
||||
'supplierOverAmount' => 0.0,
|
||||
'settleAmount' => 0.0,
|
||||
'differenceAmount' => 0.0,
|
||||
],
|
||||
'mineRows' => count($mineRows),
|
||||
'theirsRows' => 0,
|
||||
'awaitingUpload' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$compared = $this->matcher->compare($mineRows, $theirRows);
|
||||
$compared['mineRows'] = count($mineRows);
|
||||
$compared['theirsRows'] = count($theirRows);
|
||||
$compared['awaitingUpload'] = false;
|
||||
|
||||
return $compared;
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ use Modules\EcommerceFinance\Services\SupplierPayableOverrideStore;
|
||||
use Modules\EcommerceFinance\Services\SupplierStatementMatcher;
|
||||
use Modules\EcommerceFinance\Services\SupplierStatementStore;
|
||||
use Modules\EcommerceFinance\Services\SupplierStatementTemplate;
|
||||
use Modules\EcommerceFinance\View\SupplierReconciliationPageData;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class SupplierReconciliationTest extends FeatureTestCase
|
||||
@ -130,6 +131,64 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
->assertDontSeeText('各厂家上传情况');
|
||||
}
|
||||
|
||||
public function test_supplier_without_upload_does_not_generate_or_push_missing_differences(): void
|
||||
{
|
||||
$store = app(SupplierPayableOverrideStore::class);
|
||||
$companyId = (int) $this->company->id;
|
||||
$store->save('final:supplier:payment-reconciliation', 'line:no-upload', [
|
||||
'summary_month' => '2026-10',
|
||||
'purchaseNo' => '923969',
|
||||
'date' => '2026-10-02',
|
||||
'supplier' => '彩虹',
|
||||
'skuCode' => 'X6013282N24V02',
|
||||
'qty' => '21',
|
||||
'unitPrice' => '159',
|
||||
'amount' => '3339',
|
||||
'reconciler' => '陈亲园',
|
||||
], $companyId, null);
|
||||
|
||||
$detail = app(SupplierReconciliationPageData::class)->financeDetailForFilters(
|
||||
'彩虹',
|
||||
$companyId,
|
||||
['month' => '2026-10', 'reconciler' => '陈亲园'],
|
||||
);
|
||||
|
||||
$this->assertTrue($detail['awaitingUpload']);
|
||||
$this->assertSame([], $detail['rows']);
|
||||
$this->assertSame(1, $detail['mineRows']);
|
||||
$this->assertSame(0, $detail['theirsRows']);
|
||||
$this->assertSame(0, $detail['summary']['supplierMissing']);
|
||||
$this->assertSame(3339.0, $detail['summary']['mineAmount']);
|
||||
$this->assertSame(0.0, $detail['summary']['differenceAmount']);
|
||||
|
||||
$this->loginAs()
|
||||
->get(route('business.pages.show', [
|
||||
'section' => 'supplier-reconciliation',
|
||||
'page' => 'finance-data',
|
||||
'supplier' => '彩虹',
|
||||
'month' => '2026-10',
|
||||
'reconciler' => '陈亲园',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSeeText('该厂家还没有上传对账单')
|
||||
->assertSeeText('厂家少(按厂家结算)')
|
||||
->assertDontSeeText('推送全部差异')
|
||||
->assertDontSeeText('923969');
|
||||
|
||||
Http::fake();
|
||||
$this->loginAs()
|
||||
->post(route('business.supplier-reconciliation.push-differences'), [
|
||||
'supplier' => '彩虹',
|
||||
'month' => '2026-10',
|
||||
'reconciler' => '陈亲园',
|
||||
'scope' => 'all',
|
||||
])
|
||||
->assertSessionHasErrors([
|
||||
'dingtalk_push' => '厂家尚未上传对账单,暂不能推送差异。',
|
||||
]);
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_finance_supplier_filter_requires_an_exact_searchable_name(): void
|
||||
{
|
||||
$store = app(SupplierPayableOverrideStore::class);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user