Phase 6 of the tenant series. GlobalTables::DEFERRED is now empty and the
coverage test asserts it stays that way.
payments carries the (entity_type, entity_id) pair and belongs to the
receiving side, never the payer: an appointment payment takes the
appointment's environment, a subscription takes the environment its buyer
owns, and an SMS wallet top-up takes the wallet's. The patient never chose
an environment, so TenantFilter stays off for them and they still see their
own payment.
Three corrections to the analysis the phase was planned on, each backed by
the code or the data rather than the plan:
- A third payment type exists. Payment::TYPE_SMS_WALLET is created in
SmsWalletController and already carries its environment in the metadata;
without assigning it the write would fail at flush.
- clinic_subscriptions has no user_id, and its trial rows carry no payment,
so it cannot drive the subscription backfill. The environment is derived
the way handleSubscriptionActivation derives it — and that method now
reads the pair off the payment instead of re-deriving it, so a payment and
the subscription it buys can no longer land on different environments.
- WalletTransaction is not a child of Payment. payment_id is nullable and
none of the four creation sites set it; the wallet is a person's, with a
running balance per user. It and Settlement, which withdraws from that same
wallet, are global with a recorded reason instead.
bank_accounts and pos_devices move from the registering user to the
environment. Their pair is deliberately nullable: nothing in the existing
data says which of a multi-environment owner's cards belongs where, and
guessing would point real money at the wrong account. Ambiguous rows stay
unassigned and the migration reports how many. The cost is that such a row
is invisible in every environment, so the owner reaches it through a
user-scoped lookup that runs outside the filter, and assigns it with
PATCH .../{uuid}/environment. The admin panel marks those rows and offers
the assignment.
Tests: 896 backend (+11), 570 frontend (+4). PHPStan unchanged at its 17
pre-existing errors.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import React from 'react';
|
|
import { PencilIcon } from '@heroicons/react/24/outline';
|
|
import DataTable, { type Column } from '../ui/DataTable';
|
|
import StatusToggle from './StatusToggle';
|
|
import EnvironmentCell from './EnvironmentCell';
|
|
import type { BankAccount } from '../../hooks/usePaymentMethods';
|
|
|
|
/**
|
|
* جدول حسابهای بانکی — پورت مبدأ BankAccountList.jsx.
|
|
* ستون «شماره ترمینال» مبدأ به «شماره کارت» تغییر کرد (حساب بانکی ترمینال ندارد؛
|
|
* فرم افزودن شماره کارت میگیرد).
|
|
*/
|
|
export default function BankAccountTable({
|
|
data,
|
|
loading,
|
|
togglingUuid,
|
|
assigningUuid,
|
|
environmentName,
|
|
onToggle,
|
|
onEdit,
|
|
onAssign,
|
|
onAdd,
|
|
}: {
|
|
data: BankAccount[];
|
|
loading?: boolean;
|
|
togglingUuid: string | null;
|
|
assigningUuid: string | null;
|
|
environmentName: string;
|
|
onToggle: (uuid: string) => void;
|
|
onEdit: (account: BankAccount) => void;
|
|
onAssign: (uuid: string) => void;
|
|
onAdd: () => void;
|
|
}) {
|
|
const columns: Column<BankAccount>[] = [
|
|
{ key: 'bank_name', header: 'نام بانک' },
|
|
{ key: 'card_number', header: 'شماره کارت', render: (r) => r.card_number || '—' },
|
|
{ key: 'account_number', header: 'شماره حساب', render: (r) => r.account_number || '—' },
|
|
{
|
|
key: 'entity_type',
|
|
header: 'محیط',
|
|
render: (r) => <EnvironmentCell entityType={r.entity_type} environmentName={environmentName} />,
|
|
},
|
|
{
|
|
key: 'is_active',
|
|
header: 'وضعیت',
|
|
render: (r) => (
|
|
<StatusToggle
|
|
active={r.is_active}
|
|
disabled={togglingUuid === r.uuid}
|
|
onToggle={() => onToggle(r.uuid)}
|
|
/>
|
|
),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<p style={{ fontSize: 13.5, color: 'var(--text-2)', margin: '0 0 14px' }}>
|
|
مدیریت و اضافه کردن حساب های بانکی کلینیک
|
|
</p>
|
|
<DataTable<BankAccount>
|
|
columns={columns}
|
|
data={data}
|
|
loading={loading}
|
|
emptyMessage="هنوز حساب بانکی ثبت نشده است"
|
|
emptyAction={<button className="btn primary sm" onClick={onAdd}>افزودن حساب بانکی</button>}
|
|
actions={(r) => (
|
|
r.entity_type === null ? (
|
|
<button
|
|
className="btn sm primary"
|
|
disabled={assigningUuid === r.uuid}
|
|
onClick={() => onAssign(r.uuid)}
|
|
>
|
|
انتساب به {environmentName}
|
|
</button>
|
|
) : (
|
|
<button
|
|
className="btn sm ghost"
|
|
style={{ color: 'var(--accent)' }}
|
|
onClick={() => onEdit(r)}
|
|
>
|
|
<PencilIcon style={{ width: 14 }} />
|
|
ویرایش
|
|
</button>
|
|
)
|
|
)}
|
|
/>
|
|
</>
|
|
);
|
|
}
|