feat: podpora neplatících osob u objednávek
CI / Generate TypeScript types (push) Successful in 14s
CI / Server unit tests (push) Successful in 20s
CI / Build server (push) Successful in 24s
CI / Build client (push) Successful in 33s
CI / Playwright E2E tests (push) Successful in 1m17s
CI / Build and push Docker image (push) Successful in 39s
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 14s
CI / Server unit tests (push) Successful in 20s
CI / Build server (push) Successful in 24s
CI / Build client (push) Successful in 33s
CI / Playwright E2E tests (push) Successful in 1m17s
CI / Build and push Docker image (push) Successful in 39s
CI / Notify (push) Successful in 2s
This commit is contained in:
5 files changed
+103
-48
No files matched your search
@@ -2,6 +2,7 @@ import { useState, useEffect } from "react";
|
||||
import { Modal, Button, Form, Table, Alert } from "react-bootstrap";
|
||||
import { generateQr, OrderGroup, OrderGroupMember, QrRecipient } from "../../../../types";
|
||||
import { sanitizeQrMessage } from "../../Utils";
|
||||
import { computeFeeShare, computeMemberTotal, countActiveMembers, isActiveMember } from "../../utils/groupFees";
|
||||
|
||||
type Props = {
|
||||
isOpen: boolean;
|
||||
@@ -31,32 +32,25 @@ export default function PayForGroupModal({ isOpen, onClose, onSuccess, group, pa
|
||||
const entries: DinerEntry[] = (Object.entries(group.members) as [string, OrderGroupMember][]).map(([login, member]) => ({
|
||||
login,
|
||||
member,
|
||||
included: login !== payerLogin,
|
||||
// Standardně zahrnout všechny, kdo nejsou plátce a něco si objednali.
|
||||
included: login !== payerLogin && isActiveMember(member),
|
||||
}));
|
||||
setDiners(entries);
|
||||
setError(null);
|
||||
setSuccess(false);
|
||||
}, [isOpen, group, payerLogin]);
|
||||
|
||||
const memberCount = diners.length;
|
||||
const fees = group.fees ?? 0;
|
||||
const shipping = group.shipping ?? 0;
|
||||
const tip = group.tip ?? 0;
|
||||
const totalFees = fees + shipping + tip;
|
||||
const feeShare = memberCount > 0 ? Math.round(totalFees / memberCount) : 0;
|
||||
// Poplatky se dělí jen mezi aktivní strávníky (kdo si reálně něco objednal).
|
||||
const activeCount = countActiveMembers(group.members);
|
||||
const feeShare = computeFeeShare(totalFees, activeCount);
|
||||
const feeParams = { totalFees, discountType: group.discountType, discountValue: group.discountValue ?? 0 };
|
||||
|
||||
const getMemberTotal = (entry: DinerEntry): number => {
|
||||
const base = entry.member.amount ?? 0;
|
||||
const surcharge = entry.member.surchargeAmount ?? 0;
|
||||
const discountType = group.discountType;
|
||||
const discountValue = group.discountValue ?? 0;
|
||||
const discount = discountValue > 0
|
||||
? (discountType === 'percent'
|
||||
? Math.round((base + surcharge) * discountValue / 100)
|
||||
: Math.round(discountValue / memberCount))
|
||||
: 0;
|
||||
return base + surcharge + feeShare - discount;
|
||||
};
|
||||
const getMemberTotal = (entry: DinerEntry): number =>
|
||||
computeMemberTotal(entry.member, feeParams, feeShare, activeCount);
|
||||
|
||||
const includedNonPayers = diners.filter(d => d.included && d.login !== payerLogin);
|
||||
|
||||
@@ -157,13 +151,16 @@ export default function PayForGroupModal({ isOpen, onClose, onSuccess, group, pa
|
||||
<tbody>
|
||||
{diners.map(d => {
|
||||
const isPayer = d.login === payerLogin;
|
||||
const active = isActiveMember(d.member);
|
||||
const total = getMemberTotal(d);
|
||||
const surcharge = d.member.surchargeAmount ?? 0;
|
||||
return (
|
||||
<tr key={d.login} className={!d.included && !isPayer ? 'text-muted' : ''}>
|
||||
<tr key={d.login} className={(!d.included && !isPayer) || !active ? 'text-muted' : ''}>
|
||||
<td className="text-center">
|
||||
{isPayer ? (
|
||||
<small className="text-muted">plátce</small>
|
||||
) : !active ? (
|
||||
<small className="text-muted">jen objednává</small>
|
||||
) : (
|
||||
<Form.Check
|
||||
type="checkbox"
|
||||
@@ -186,7 +183,7 @@ export default function PayForGroupModal({ isOpen, onClose, onSuccess, group, pa
|
||||
</td>
|
||||
{hasFees && (
|
||||
<td className="text-end">
|
||||
{feeShare > 0 ? `${feeShare / 100} Kč` : '—'}
|
||||
{active && feeShare > 0 ? `${feeShare / 100} Kč` : '—'}
|
||||
</td>
|
||||
)}
|
||||
<td className="text-end fw-bold">
|
||||
|
||||
Reference in new issue
Block a user