fix(pwa): экран баланса повторяет карточку CRM

Итог берётся с сервера, а не складывается из строк (1С округляет статьи до
рублей, итог держит с копейками: −8 976 против −8 976,25). Статья, в которую
платёж провести нечем, показывается, но не притворяется кнопкой — «Страховка».
Пустой снимок 1С даёт «Уточняется» вместо нулей.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
tremble7681andClaude Opus 5 committed 2026-08-18 15:46:35 +10:00
1 parent 39ee2b7a49
commit 8b0ce4cf45
3 files changed
+65 -19

No files matched your search

+35 -12
View File
@@ -13,15 +13,24 @@ export function BalancePage() {
const { data, isLoading, isError, refetch } = useQuery({ queryKey: ["balance"], queryFn: getBalance });
const accounts = data?.accounts ?? [];
const total = accounts.reduce((s, a) => s + a.balance, 0);
// Итог — с сервера (это ровно то число, что видит сотрудник в CRM). Сумма строк
// тут не годится: 1С округляет статьи до рублей, а итог держит с копейками.
const total = data?.total ?? accounts.reduce((s, a) => s + a.balance, 0);
const pending = data?.pending_topup ?? 0;
const noData = !isLoading && !isError && accounts.length === 0;
return (
<div>
<AppHeader />
<div className="card p-4 mb-4 text-center">
<p className="text-muted text-xs mb-1">Баланс</p>
<p className={`text-2xl font-extrabold ${total < 0 ? "text-neg" : "text-pos"}`}>{formatMoney(total)}</p>
{noData ? (
<p className="text-sm font-semibold">Уточняется</p>
) : (
<p className={`text-2xl font-extrabold ${total < 0 ? "text-neg" : "text-pos"}`}>
{formatMoney(total)}
</p>
)}
{pending > 0 && (
// Платёж принят нами, но 1С его ещё не провела. В сумму баланса он не
// входит намеренно: сложить оба источника значило бы показать
@@ -41,16 +50,30 @@ export function BalancePage() {
</div>
) : (
<div className="mb-4">
{accounts.map((a) => (
<button
key={a.bucket}
onClick={() => nav("/topup", { state: { bucket: a.bucket } })}
className="w-full flex justify-between items-center py-3 border-b border-line last:border-0 text-left"
>
<span className="text-sm">{a.bucket}</span>
<b className={a.balance < 0 ? "text-neg" : "text-pos"}>{formatMoney(a.balance)}</b>
</button>
))}
{noData && (
<p className="text-muted text-sm text-center py-6">
Баланс ещё не пришёл из бухгалтерии. Если он нужен прямо сейчас — спросите в парке.
</p>
)}
{accounts.map((a) => {
const row = (
<>
<span className="text-sm">{a.bucket}</span>
<b className={a.balance < 0 ? "text-neg" : "text-pos"}>{formatMoney(a.balance)}</b>
</>
);
const cls = "w-full flex justify-between items-center py-3 border-b border-line last:border-0 text-left";
// В «Страховку» платёж провести нечем — строку показываем, нажатие не
// предлагаем: кнопка, ведущая в отказ, хуже отсутствующей кнопки.
return a.payable ? (
<button key={a.bucket} className={cls}
onClick={() => nav("/topup", { state: { bucket: a.bucket } })}>
{row}
</button>
) : (
<div key={a.bucket} className={cls}>{row}</div>
);
})}
</div>
)}