shouldReceive('contractsByName')->andReturn([ '合同快递' => ['contract_start' => '2025-01-01', 'contract_end' => '2025-12-31', 'company' => '原签订公司', 'body' => '原合同主体'], ]); $this->app->instance(CourierInformationMirrorRepository::class, $mirror); } public function test_positive_payables_drive_paid_amount_export_and_next_month_balance(): void { $service = app(PayableSummary::class); $expected = []; foreach ([ ['正数快递', ['K' => 2000, 'L' => 50, 'I' => 100.5, 'S' => 1000], 2050.5, 2050.5], ['一分钱快递', ['K' => 0.01, 'S' => null], 0.01, 0.01], ['零数快递', ['K' => 0.004, 'S' => 9], 0.0, 9.0], ['负数快递', ['I' => -50, 'S' => -5], -50.0, -5.0], ['空值快递', ['I' => -20], -20.0, null], ] as [$carrier, $cells, $payable, $paid]) { $this->row($carrier, $cells); $expected[$carrier] = [$payable, $paid]; } $rows = $service->rows('2026-11'); foreach ($rows as $row) { [$payable, $paid] = $expected[$row['cells']['H']]; $this->assertSame($payable, $row['cells']['R']); $this->assertSame($paid, $row['cells']['S'] ?? null); } $stored = json_decode($service->db()->table('courier_payable_summary_rows')->where('carrier', '正数快递')->value('cells'), true); $this->assertSame(1000, $stored['S']); $file = tempnam(sys_get_temp_dir(), 'courier-auto-paid-'); try { $handle = fopen($file, 'wb'); $service->export('2026-11', $handle); fclose($handle); $book = IOFactory::load($file); $sheet = $book->getSheetByName('汇总'); $this->assertEquals(2050.5, $sheet->getCell('R4')->getValue()); $this->assertEquals(2050.5, $sheet->getCell('S4')->getValue()); $this->assertEquals(9, $sheet->getCell('S6')->getValue()); $this->assertEquals(2054.51, $sheet->getCell('S9')->getValue()); $book->disconnectWorksheets(); } finally { @unlink($file); } $this->assertSame(5, $service->createMonth('2026-12')); $next = collect($service->rows('2026-12'))->keyBy('cells.H'); $this->assertSame(0.0, $next['正数快递']['cells']['I']); $this->assertSame(0.0, $next['一分钱快递']['cells']['I']); $this->assertSame(-9.0, $next['零数快递']['cells']['I']); $this->assertSame(-45.0, $next['负数快递']['cells']['I']); $this->assertSame(-20.0, $next['空值快递']['cells']['I']); } public function test_pages_and_updates_keep_positive_paid_amount_automatic(): void { $positive = $this->row('正数快递', ['K' => 100, 'S' => 7]); $negative = $this->row('负数快递', ['I' => -10, 'S' => 2]); $this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); $this->loginAs(); foreach (['courier-payables', 'courier-payables-final'] as $section) { $page = route('business.pages.show', ['section' => $section, 'page' => 'courier-payable-summary', 'month' => '2026-11']); $response = $this->get($page)->assertOk() ->assertDontSee('aria-label="正数快递 本次实付金额"', false) ->assertSee('aria-label="负数快递 本次实付金额"', false); $this->assertSame(102.0, $response->viewData('content')['psTotals']['S']); $this->withExceptionHandling(); $this->postJson(route("business.$section.courier-payable-summary.update", ['row' => $positive]), ['column' => 'S', 'value' => '5']) ->assertUnprocessable()->assertJsonValidationErrors('courier_summary'); } $update = fn (int $id) => route('business.courier-payables.courier-payable-summary.update', ['row' => $id]); $this->postJson($update($positive), ['column' => 'Q', 'value' => '12.34'])->assertOk(); $this->postJson($update($negative), ['column' => 'S', 'value' => '-3'])->assertOk(); $rows = collect(app(PayableSummary::class)->rows('2026-11'))->keyBy('cells.H'); $this->assertSame(112.34, $rows['正数快递']['cells']['R']); $this->assertSame(112.34, $rows['正数快递']['cells']['S']); $this->assertSame(-3.0, $rows['负数快递']['cells']['S']); } public function test_reconciliation_status_filter_combines_with_other_filters_and_updates_totals(): void { $this->row('已确认快递', ['K' => 100, 'Y' => '已确认', 'C' => '甲公司', 'D' => '负责人甲', 'E' => '承运']); $this->row('待处理快递', ['K' => 80, 'C' => '甲公司', 'D' => '负责人甲', 'E' => '承运']); $this->row('旧账快递', ['I' => -20]); $this->row('无账单快递', []); $this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); $this->loginAs(); foreach (['courier-payables', 'courier-payables-final'] as $section) { $url = route('business.pages.show', ['section' => $section, 'page' => 'courier-payable-summary', 'month' => '2026-11']); $response = $this->get($url . '&' . http_build_query(['status' => '已确认', 'company' => '甲公司', 'owner' => '负责人甲', 'state' => '承运', 'q' => '快递'])) ->assertOk()->assertSee('