Refinery trips: bank account number is mandatory for the الحوالات and bank reports
Choosing either report opens a dialog with the account number field instead of the browser prompt; an empty value shows "يجب ادخال رقم الحساب" and nothing is generated until a number is entered. The report keeps the list's status, wage-claim and payment-date filters. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ef0e72ff9d
commit
0819427bdf
|
|
@ -2,7 +2,7 @@ import { useState, type ElementType, type ReactNode } from 'react';
|
|||
import { Link as RouterLink, useNavigate, useParams } from 'react-router-dom';
|
||||
import {
|
||||
Alert, Box, Button, Dialog, GlobalStyles, DialogActions, DialogContent, DialogTitle, Link, Menu, MenuItem, Stack, Table, TableBody, TableCell,
|
||||
TableHead, TableRow, TablePagination, Typography,
|
||||
TableHead, TableRow, TablePagination, TextField, Typography,
|
||||
} from '@mui/material';
|
||||
import SummarizeIcon from '@mui/icons-material/Summarize';
|
||||
import PrintIcon from '@mui/icons-material/Print';
|
||||
|
|
@ -53,29 +53,37 @@ export function TripsPage() {
|
|||
};
|
||||
// the report uses the filters of the list (they are in the URL query string)
|
||||
const current = () => Object.fromEntries([...new URLSearchParams(window.location.search)].filter(([k]) => !['page', 'size', 'f'].includes(k)));
|
||||
|
||||
// the account-list reports (الحوالات and the bank report) cannot run without a bank account number: a dialog asks for it and refuses an empty value
|
||||
const [ask, setAsk] = useState<'exchange' | 'bank' | null>(null);
|
||||
const [account, setAccount] = useState('');
|
||||
const [accountError, setAccountError] = useState(false);
|
||||
const askAccount = (kind: 'exchange' | 'bank') => {
|
||||
setMenu(null);
|
||||
setAccount(current().bankAccount ?? '');
|
||||
setAccountError(false);
|
||||
setAsk(kind);
|
||||
};
|
||||
const submitAccount = () => {
|
||||
const value = account.trim();
|
||||
if (!value) { setAccountError(true); return; }
|
||||
// the legacy filters of the list: status, wage-claim flag and payment dates
|
||||
const c = current();
|
||||
const params: Record<string, string> = { bankAccount: value };
|
||||
for (const k of ['statusCode', 'hasWageClaim', 'paymentedDateFrom', 'paymentedDateTo']) if (c[k]) params[k] = c[k];
|
||||
const kind = ask;
|
||||
setAsk(null);
|
||||
if (kind === 'exchange') void run('exchange', params, 'refinery-transfers.xlsx');
|
||||
else if (kind === 'bank') void run('bank', params, 'refinery-bank.xlsx');
|
||||
};
|
||||
const reports: { key: string; label: string; show: boolean; go: () => void }[] = [
|
||||
{ key: 'trips', label: t('trips.report.trips'), show: can('refinery.trips.report'), go: () => void run('trips', current(), 'refinery-trips.xlsx') },
|
||||
{ key: 'operator', label: t('trips.report.operator'), show: can('refinery.trips.operatorReport'), go: () => void run('operator', current(), 'refinery-trips-operator.xlsx') },
|
||||
{
|
||||
// الحوالات: the list of ONE bank account (legacy refineryBankReport), so the account number is asked first; the other filters are the
|
||||
// legacy ones (status, wage claim flag, payment dates), taken from the list
|
||||
key: 'exchange', label: t('trips.report.exchange'), show: can('refinery.trips.exchangeReport'), go: () => {
|
||||
const c = current();
|
||||
const account = window.prompt(t('trips.report.bankAsk'), c.bankAccount ?? '')?.trim();
|
||||
if (!account) { setMenu(null); return; }
|
||||
const params: Record<string, string> = { bankAccount: account };
|
||||
for (const k of ['statusCode', 'hasWageClaim', 'paymentedDateFrom', 'paymentedDateTo']) if (c[k]) params[k] = c[k];
|
||||
void run('exchange', params, 'refinery-transfers.xlsx');
|
||||
},
|
||||
},
|
||||
// الحوالات: the list of ONE bank account (legacy refineryBankReport): the account number is mandatory, see the dialog below
|
||||
{ key: 'exchange', label: t('trips.report.exchange'), show: can('refinery.trips.exchangeReport'), go: () => askAccount('exchange') },
|
||||
{ key: 'diesel', label: t('trips.report.diesel'), show: can('refinery.trips.dieselReport'), go: () => void run('diesel', current(), 'refinery-diesel.xlsx') },
|
||||
{ key: 'cards', label: t('trips.report.cards'), show: can('refinery.trips.cardsReport'), go: () => void run('cards', { tn: current().tn ?? '' }, 'refinery-cards.xlsx') },
|
||||
{
|
||||
key: 'bank', label: t('trips.report.bank'), show: can('refinery.trips.bankReport'), go: () => {
|
||||
const account = window.prompt(t('trips.report.bankAsk'), current().bankAccount ?? '');
|
||||
if (account) void run('bank', { bankAccount: account, statusCode: current().statusCode ?? '' }, 'refinery-bank.xlsx');
|
||||
},
|
||||
},
|
||||
{ key: 'bank', label: t('trips.report.bank'), show: can('refinery.trips.bankReport'), go: () => askAccount('bank') },
|
||||
].filter((r) => r.show);
|
||||
|
||||
const meta = tripsGrid((r) => navigate(`${ROOT}/${r.id}`));
|
||||
|
|
@ -93,6 +101,23 @@ export function TripsPage() {
|
|||
)}
|
||||
/>
|
||||
<DataGrid meta={meta} />
|
||||
<Dialog open={ask !== null} onClose={() => setAsk(null)} fullWidth maxWidth="xs">
|
||||
<form noValidate onSubmit={(e) => { e.preventDefault(); submitAccount(); }}>
|
||||
<DialogTitle>{ask === 'bank' ? t('trips.report.bank') : t('trips.report.exchange')}</DialogTitle>
|
||||
<DialogContent>
|
||||
<TextField
|
||||
autoFocus required fullWidth margin="dense" label={t('trips.bankAccount')} value={account}
|
||||
onChange={(e) => { setAccount(e.target.value); if (e.target.value.trim()) setAccountError(false); }}
|
||||
error={accountError} helperText={accountError ? t('trips.report.bankAsk') : ' '}
|
||||
slotProps={{ htmlInput: { dir: 'ltr' } }}
|
||||
/>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => setAsk(null)}>{t('common.cancel')}</Button>
|
||||
<Button type="submit" variant="contained">{t('trips.report.create')}</Button>
|
||||
</DialogActions>
|
||||
</form>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ export default defineStrings({
|
|||
'trips.report.diesel': { en: 'Diesel charges (Excel)', ar: 'شحن الديزل (Excel)' },
|
||||
'trips.report.cards': { en: 'Diesel balances (Excel)', ar: 'أرصدة الديزل (Excel)' },
|
||||
'trips.report.bank': { en: 'Bank report (Excel)', ar: 'تقرير البنك (Excel)' },
|
||||
'trips.report.bankAsk': { en: 'Enter the bank account number of the report', ar: 'يجب ادخال رقم الحساب' },
|
||||
'trips.report.bankAsk': { en: 'The bank account number is required', ar: 'يجب ادخال رقم الحساب' },
|
||||
'trips.report.create': { en: 'Create report', ar: 'إنشاء التقرير' },
|
||||
'trips.report.done': { en: 'The report was generated', ar: 'تم انشاء التقرير بنجاح' },
|
||||
|
||||
// form sections
|
||||
|
|
|
|||
Loading…
Reference in New Issue