diff --git a/modules/EcommerceFinance/Services/PayablesUnpricedCycleProcessor.php b/modules/EcommerceFinance/Services/PayablesUnpricedCycleProcessor.php index 309499dcb..81db6a4f2 100644 --- a/modules/EcommerceFinance/Services/PayablesUnpricedCycleProcessor.php +++ b/modules/EcommerceFinance/Services/PayablesUnpricedCycleProcessor.php @@ -294,6 +294,10 @@ class PayablesUnpricedCycleProcessor $rows = DB::connection($connectionName) ->table(SupplierPayableForecastRepository::PRICE_TABLE) ->where('effectStartTime', '<=', $cutoffAt->format('Y-m-d H:i:s')) + ->where(static function ($query) use ($cutoffAt): void { + $query->whereNull('createTime') + ->orWhere('createTime', '<=', $cutoffAt->format('Y-m-d H:i:s')); + }) ->where(static function ($query) use ($cutoffAt): void { $query->whereNull('effectEndTime') ->orWhere('effectEndTime', '') @@ -312,7 +316,9 @@ class PayablesUnpricedCycleProcessor $completed = $this->date($row->createTime ?? null); $end = $this->date($row->effectEndTime ?? null); if ($code === '' || $price === null || $start === null - || $start > $cutoffAt || ($end !== null && $end < $cutoffAt)) { + || $start > $cutoffAt + || ($completed !== null && $completed > $cutoffAt) + || ($end !== null && $end < $cutoffAt)) { continue; } diff --git a/tests/Feature/Business/PayablesUnpricedCycleTest.php b/tests/Feature/Business/PayablesUnpricedCycleTest.php index 21eb91688..c2f04ef6d 100644 --- a/tests/Feature/Business/PayablesUnpricedCycleTest.php +++ b/tests/Feature/Business/PayablesUnpricedCycleTest.php @@ -236,6 +236,9 @@ class PayablesUnpricedCycleTest extends FeatureTestCase 'id:auto:delivery:matched-1' => [ 'supplier' => '供应商甲', 'barCode' => 'M-1', 'qty' => '2', 'unitPrice' => null, 'amount' => null, ], + 'id:auto:delivery:late-created-price' => [ + 'supplier' => '供应商乙', 'barCode' => 'LATE-1', 'qty' => '1', 'unitPrice' => null, 'amount' => null, + ], ], $companyId, $userId, 'test'); $store->saveBatch(PayablesUnpricedCycleProcessor::RETURN_HISTORY_DATASET, [ 'id:auto:return:matched' => [ @@ -257,6 +260,9 @@ class PayablesUnpricedCycleTest extends FeatureTestCase $this->assertSame('8', $pricedReturn[0]['unit_price']); $this->assertSame('24.00', $pricedReturn[0]['amount']); $this->assertSame('2026-10', $pricedDelivery[0]['_accounting_period']); + $remainingDelivery = $store->listRows(PayablesUnpricedCycleProcessor::DELIVERY_HISTORY_DATASET, $companyId); + $this->assertCount(1, $remainingDelivery); + $this->assertSame('LATE-1', $remainingDelivery[0]['barCode']); $this->artisan('payables:unpriced-cycle:auto', [ '--company' => $companyId, @@ -356,6 +362,17 @@ class PayablesUnpricedCycleTest extends FeatureTestCase 'effectEndTime' => null, 'createTime' => '2026-09-01 00:00:00', ], + [ + 'Id' => 4, + 'skucode' => 'LATE-1', + 'priceType' => '定价', + 'originalPrice' => 9, + 'afterPrice' => 9, + 'diffPrice' => 0, + 'effectStartTime' => '2000-01-01 00:00:00', + 'effectEndTime' => null, + 'createTime' => '2026-11-02 09:21:01', + ], ]); DB::connection('business_mirror')->table('business_mirror_table_states')->insert([ 'dataset_key' => 'jiansun.dbo.pm_priceAdjustment_log',