feat: 发票基础信息新增筛选与合计行
This commit is contained in:
parent
e188aaff5f
commit
8d715c6265
@ -28,6 +28,7 @@ use App\Models\Business\CourierQuoteSignature;
|
||||
use App\Models\Business\CourierQuoteVersion;
|
||||
use App\Models\Business\CourierSigningSubject;
|
||||
use App\Models\Business\InstallationDetail;
|
||||
use App\Models\Business\InvoiceBasic;
|
||||
use App\Models\Business\InvoiceBasicDetail;
|
||||
use App\Models\Business\InventoryWarehouseNameMapping;
|
||||
use App\Models\Business\Todo;
|
||||
@ -3938,6 +3939,12 @@ class Pages extends Controller
|
||||
): array {
|
||||
$descriptor = null;
|
||||
$rows = collect();
|
||||
$isInvoiceBasicPage = ($section['slug'] ?? null) === 'invoice-management'
|
||||
&& ($page['slug'] ?? null) === 'basic-information';
|
||||
$invoiceBasicFilters = ['seller_entity' => '', 'store_name' => '', 'period' => ''];
|
||||
$invoiceBasicPeriodOptions = collect();
|
||||
$invoiceBasicPageTotals = ['invoice_limit' => 0.0, 'output_amount' => 0.0, 'input_amount' => 0.0];
|
||||
$invoiceBasicAllTotals = ['invoice_limit' => 0.0, 'output_amount' => 0.0, 'input_amount' => 0.0];
|
||||
$invoiceBasicDetails = collect();
|
||||
$tabValue = null;
|
||||
$tabColumn = null;
|
||||
@ -4086,6 +4093,66 @@ class Pages extends Controller
|
||||
} else {
|
||||
$query = ($descriptor->model)::query();
|
||||
|
||||
if ($isInvoiceBasicPage) {
|
||||
$invoiceBasicFilters = [
|
||||
'seller_entity' => mb_substr(trim((string) request()->query('seller_entity', '')), 0, 100),
|
||||
'store_name' => mb_substr(trim((string) request()->query('store_name', '')), 0, 100),
|
||||
'period' => trim((string) request()->query('period', '')),
|
||||
];
|
||||
|
||||
if ($invoiceBasicFilters['period'] !== ''
|
||||
&& preg_match('/^\d{4}-\d{2}$/', $invoiceBasicFilters['period']) !== 1) {
|
||||
$invoiceBasicFilters['period'] = '';
|
||||
}
|
||||
|
||||
if ($invoiceBasicFilters['seller_entity'] !== '') {
|
||||
$needle = '%' . addcslashes($invoiceBasicFilters['seller_entity'], '%_\\') . '%';
|
||||
$query->where('store_entity', 'like', $needle);
|
||||
}
|
||||
|
||||
if ($invoiceBasicFilters['store_name'] !== '') {
|
||||
$needle = '%' . addcslashes($invoiceBasicFilters['store_name'], '%_\\') . '%';
|
||||
$pairs = collect();
|
||||
try {
|
||||
$pairs = InvoiceBasicDetail::query()
|
||||
->where('shop_name', 'like', $needle)
|
||||
->select(['seller_entity', 'period'])
|
||||
->distinct()
|
||||
->limit(500)
|
||||
->get();
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
}
|
||||
|
||||
$query->where(function ($builder) use ($needle, $pairs): void {
|
||||
$builder->where('store_name', 'like', $needle);
|
||||
foreach ($pairs as $pair) {
|
||||
$builder->orWhere(function ($sub) use ($pair): void {
|
||||
$sub->where('store_entity', $pair->seller_entity)
|
||||
->where('period', $pair->period);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ($invoiceBasicFilters['period'] !== '') {
|
||||
$query->where('period', $invoiceBasicFilters['period']);
|
||||
}
|
||||
|
||||
$invoiceBasicPeriodOptions = InvoiceBasic::query()
|
||||
->select('period')
|
||||
->where('period', '<>', '')
|
||||
->distinct()
|
||||
->orderByDesc('period')
|
||||
->pluck('period');
|
||||
|
||||
$invoiceBasicAllTotals = [
|
||||
'invoice_limit' => round((float) (clone $query)->sum('invoice_limit'), 2),
|
||||
'output_amount' => round((float) (clone $query)->sum('output_amount'), 2),
|
||||
'input_amount' => round((float) (clone $query)->sum('input_amount'), 2),
|
||||
];
|
||||
}
|
||||
|
||||
if ($descriptor->tabFilterColumn && $activeTab) {
|
||||
$tabValue = TableRegistry::tabValue($section['slug'], $page['slug'], $activeTab['slug']);
|
||||
|
||||
@ -4102,6 +4169,15 @@ class Pages extends Controller
|
||||
|
||||
$rows = $query->orderByDesc('id')->paginate(50)->withQueryString();
|
||||
|
||||
if ($isInvoiceBasicPage) {
|
||||
$invoiceBasicPageRows = $rows->getCollection();
|
||||
$invoiceBasicPageTotals = [
|
||||
'invoice_limit' => round((float) $invoiceBasicPageRows->sum('invoice_limit'), 2),
|
||||
'output_amount' => round((float) $invoiceBasicPageRows->sum('output_amount'), 2),
|
||||
'input_amount' => round((float) $invoiceBasicPageRows->sum('input_amount'), 2),
|
||||
];
|
||||
}
|
||||
|
||||
if (($section['slug'] ?? null) === 'invoice-management'
|
||||
&& ($page['slug'] ?? null) === 'basic-information') {
|
||||
try {
|
||||
@ -4153,6 +4229,10 @@ class Pages extends Controller
|
||||
'inventoryWarehouseMappingView' => $inventoryWarehouseMappingView,
|
||||
'receiptStats' => $receiptStats,
|
||||
'invoiceBasicDetails' => $invoiceBasicDetails,
|
||||
'invoiceBasicFilters' => $invoiceBasicFilters,
|
||||
'invoiceBasicPeriodOptions' => $invoiceBasicPeriodOptions,
|
||||
'invoiceBasicPageTotals' => $invoiceBasicPageTotals,
|
||||
'invoiceBasicAllTotals' => $invoiceBasicAllTotals,
|
||||
'payablesFinal' => $this->payablesFinalData($section, $page),
|
||||
];
|
||||
}
|
||||
|
||||
@ -1097,6 +1097,10 @@
|
||||
font-weight: 600;
|
||||
}
|
||||
.invoice-detail-table .num { text-align: right; }
|
||||
.invoice-total-row td {
|
||||
background: var(--vip-content-accent-soft, #f7f0de);
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
@endif
|
||||
<div class="biz-card mt-6">
|
||||
@ -1147,6 +1151,58 @@
|
||||
@endunless
|
||||
</div>
|
||||
|
||||
@if ($isInvoiceBasicPage)
|
||||
<form
|
||||
class="biz-filter-bar"
|
||||
method="GET"
|
||||
action="{{ route('business.pages.show', [
|
||||
'section' => $section['slug'],
|
||||
'page' => $page['slug'],
|
||||
]) }}"
|
||||
role="search"
|
||||
aria-label="发票基础信息筛选"
|
||||
>
|
||||
<div class="biz-filter-field">
|
||||
<label for="invoice-filter-seller">店铺主体</label>
|
||||
<input
|
||||
id="invoice-filter-seller"
|
||||
class="biz-filter-input"
|
||||
type="search"
|
||||
name="seller_entity"
|
||||
value="{{ $invoiceBasicFilters['seller_entity'] ?? '' }}"
|
||||
placeholder="输入销方主体"
|
||||
>
|
||||
</div>
|
||||
<div class="biz-filter-field">
|
||||
<label for="invoice-filter-shop">店铺名称</label>
|
||||
<input
|
||||
id="invoice-filter-shop"
|
||||
class="biz-filter-input"
|
||||
type="search"
|
||||
name="store_name"
|
||||
value="{{ $invoiceBasicFilters['store_name'] ?? '' }}"
|
||||
placeholder="输入店铺名称"
|
||||
>
|
||||
</div>
|
||||
<div class="biz-filter-field">
|
||||
<label for="invoice-filter-period">期间</label>
|
||||
<select id="invoice-filter-period" class="biz-filter-select" name="period">
|
||||
<option value="">全部期间</option>
|
||||
@foreach (($invoiceBasicPeriodOptions ?? collect()) as $periodOption)
|
||||
<option value="{{ $periodOption }}" @selected(($invoiceBasicFilters['period'] ?? '') === $periodOption)>{{ $periodOption }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="biz-btn biz-btn-primary">查询</button>
|
||||
@if (collect($invoiceBasicFilters ?? [])->filter()->isNotEmpty())
|
||||
<a class="biz-btn biz-btn-ghost" href="{{ route('business.pages.show', [
|
||||
'section' => $section['slug'],
|
||||
'page' => $page['slug'],
|
||||
]) }}">重置</a>
|
||||
@endif
|
||||
</form>
|
||||
@endif
|
||||
|
||||
@if ($isStoreReceivingAccountsPage)
|
||||
<form class="biz-filter-bar" method="GET" action="{{ route('business.pages.show', [
|
||||
'section' => $section['slug'], 'page' => $page['slug'], 'tab' => $activeTab['slug'] ?? null,
|
||||
@ -1287,6 +1343,30 @@
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
@if ($isInvoiceBasicPage)
|
||||
<tfoot>
|
||||
@foreach ([
|
||||
'本页合计' => ($invoiceBasicPageTotals ?? []),
|
||||
'全部合计' => ($invoiceBasicAllTotals ?? []),
|
||||
] as $totalLabel => $totals)
|
||||
<tr class="invoice-total-row">
|
||||
<td></td>
|
||||
@foreach ($descriptor->fields as $field)
|
||||
<td class="@if ($field['currency']) num @endif">
|
||||
@if ($field['name'] === 'store_name')
|
||||
{{ $totalLabel }}
|
||||
@elseif (array_key_exists($field['name'], $totals))
|
||||
{{ number_format((float) $totals[$field['name']], 2) }}
|
||||
@endif
|
||||
</td>
|
||||
@endforeach
|
||||
@unless ($descriptor->readOnly)
|
||||
<td></td>
|
||||
@endunless
|
||||
</tr>
|
||||
@endforeach
|
||||
</tfoot>
|
||||
@endif
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
129
tests/Feature/Business/InvoiceBasicFiltersTotalsTest.php
Normal file
129
tests/Feature/Business/InvoiceBasicFiltersTotalsTest.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Business;
|
||||
|
||||
use App\Models\Auth\Permission;
|
||||
use App\Models\Business\InvoiceBasic;
|
||||
use App\Models\Business\InvoiceBasicDetail;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class InvoiceBasicFiltersTotalsTest extends FeatureTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user->attachPermission(
|
||||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||||
);
|
||||
|
||||
InvoiceBasic::create([
|
||||
'company_id' => $this->company->id,
|
||||
'store_name' => '多店铺(2)',
|
||||
'store_entity' => '甲公司',
|
||||
'invoice_issuer' => '甲开票员',
|
||||
'invoice_limit' => 50,
|
||||
'output_amount' => 300,
|
||||
'input_amount' => 100,
|
||||
'period' => '2026-10',
|
||||
]);
|
||||
InvoiceBasic::create([
|
||||
'company_id' => $this->company->id,
|
||||
'store_name' => '乙店铺',
|
||||
'store_entity' => '乙公司',
|
||||
'invoice_issuer' => '乙开票员',
|
||||
'invoice_limit' => 20,
|
||||
'output_amount' => 200,
|
||||
'input_amount' => 50,
|
||||
'period' => '2026-11',
|
||||
]);
|
||||
|
||||
InvoiceBasicDetail::create([
|
||||
'company_id' => $this->company->id,
|
||||
'period' => '2026-10',
|
||||
'seller_entity' => '甲公司',
|
||||
'shop_name' => '一号店',
|
||||
'invoice_count' => 1,
|
||||
'output_amount' => 100,
|
||||
'tax_amount' => 10,
|
||||
'net_amount' => 90,
|
||||
]);
|
||||
InvoiceBasicDetail::create([
|
||||
'company_id' => $this->company->id,
|
||||
'period' => '2026-10',
|
||||
'seller_entity' => '甲公司',
|
||||
'shop_name' => '二号店',
|
||||
'invoice_count' => 2,
|
||||
'output_amount' => 200,
|
||||
'tax_amount' => 20,
|
||||
'net_amount' => 180,
|
||||
]);
|
||||
InvoiceBasicDetail::create([
|
||||
'company_id' => $this->company->id,
|
||||
'period' => '2026-11',
|
||||
'seller_entity' => '乙公司',
|
||||
'shop_name' => '三号店',
|
||||
'invoice_count' => 1,
|
||||
'output_amount' => 200,
|
||||
'tax_amount' => 20,
|
||||
'net_amount' => 180,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_invoice_basic_shows_filters_and_page_and_all_totals(): void
|
||||
{
|
||||
$this->loginAs()
|
||||
->get($this->pageUrl())
|
||||
->assertOk()
|
||||
->assertSeeText('店铺主体')
|
||||
->assertSeeText('店铺名称')
|
||||
->assertSeeText('期间')
|
||||
->assertSeeText('本页合计')
|
||||
->assertSeeText('全部合计')
|
||||
->assertSeeText('300.00')
|
||||
->assertSeeText('200.00')
|
||||
->assertSeeText('500.00')
|
||||
->assertSeeText('150.00')
|
||||
->assertSeeText('70.00')
|
||||
->assertSee('<option value="2026-10"', false)
|
||||
->assertSee('<option value="2026-11"', false);
|
||||
}
|
||||
|
||||
public function test_invoice_basic_filters_by_seller_and_period(): void
|
||||
{
|
||||
$this->loginAs()
|
||||
->get($this->pageUrl(['seller_entity' => '甲公司']))
|
||||
->assertOk()
|
||||
->assertSeeText('多店铺(2)')
|
||||
->assertDontSeeText('乙公司')
|
||||
->assertDontSeeText('乙店铺');
|
||||
|
||||
$this->loginAs()
|
||||
->get($this->pageUrl(['period' => '2026-11']))
|
||||
->assertOk()
|
||||
->assertSeeText('乙店铺')
|
||||
->assertSeeText('乙公司')
|
||||
->assertDontSeeText('多店铺(2)');
|
||||
}
|
||||
|
||||
public function test_invoice_basic_filters_by_shop_name_inside_details(): void
|
||||
{
|
||||
$this->loginAs()
|
||||
->get($this->pageUrl(['store_name' => '二号店']))
|
||||
->assertOk()
|
||||
->assertSeeText('多店铺(2)')
|
||||
->assertSeeText('甲公司')
|
||||
->assertDontSeeText('乙公司')
|
||||
->assertDontSeeText('三号店');
|
||||
}
|
||||
|
||||
private function pageUrl(array $query = []): string
|
||||
{
|
||||
$url = route('business.pages.show', [
|
||||
'section' => 'invoice-management',
|
||||
'page' => 'basic-information',
|
||||
]);
|
||||
|
||||
return $query === [] ? $url : $url . '?' . http_build_query($query);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user