diff --git a/src/features/EntityRoute.tsx b/src/features/EntityRoute.tsx index 515692b..0177685 100644 --- a/src/features/EntityRoute.tsx +++ b/src/features/EntityRoute.tsx @@ -1,7 +1,7 @@ import { lazy, Suspense, useCallback, useEffect, useMemo, useState } from 'react'; import { Link as RouterLink, Navigate, useSearchParams } from 'react-router-dom'; import { HIDDEN_ENTITIES, WIZARD_KEY } from '../layout/nav'; -import { Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, Stack, Typography } from '@mui/material'; +import { Alert, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, Stack, Typography } from '@mui/material'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { rpc } from '../api/client'; import { useNotify } from '../notify/NotifyProvider'; @@ -45,6 +45,12 @@ function dynamicDefaults(entity: string): Record { const PENDING_ENTITY = 'FLEET_PENDING_FINANCIAL_TRANSACTIONS'; +/** + * Big lists that open with no records and no default status: the user enters a search filter first (fleet subscriptions, + * entry permit requests, users, stickers, blacklist, rented trucks affiliation, fleet permits). + */ +const ASK_FOR_FILTER = new Set(['SUBSCRIPTIONS', 'FLEET_REQUEST', 'USERS', 'RFID_TAGS', 'BLACKLISTS', 'RENTED_TRUCK', 'PERMITS']); + /** "05/11/2026 - 16/10/2023" (either order) -> "20231016-20261105" */ function receivablesRange(range: string): string { const ds = range.split('-').map((p) => p.trim().split('/')); @@ -104,6 +110,8 @@ function GridPage({ entity, extraDefaults }: { entity: string; extraDefaults?: R // otherwise every clear would silently snap back to the default instead of showing everything. // plus the two defaults the old pages set in script rather than in the metadata (see dynamicDefaults) const defaultFilter = useMemo(() => { + // these lists open on "All" and wait for the user's own search filter + if (ASK_FOR_FILTER.has(entity)) return {} as Record; const out: Record = Object.fromEntries(fields.filter((f) => f.defaultValue).map((f) => [f.id, f.defaultValue!])); for (const [id, v] of Object.entries({ ...dynamicDefaults(entity), ...extraDefaults })) if (fields.some((f) => f.id === id)) out[id] = v; return out; @@ -195,7 +203,11 @@ function GridPage({ entity, extraDefaults }: { entity: string; extraDefaults?: R {t('TOTAL_BALANCE')} : {totalBalance.toFixed(3)} {t('RO')} )} - + {ASK_FOR_FILTER.has(entity) && !Object.values(filter).some((v) => String(v ?? '').trim() !== '') ? ( + {ui('enterSearchFilter')} + ) : ( + + )} {uploadOpen && (entity === 'RECONCILIATION' || entity === 'RECONCILIATION_POS') && ( setUploadOpen(false)} onDone={() => { setUploadOpen(false); void qc.invalidateQueries({ queryKey: ['grid', entity] }); }} /> )} diff --git a/src/features/forms/EntityForm.tsx b/src/features/forms/EntityForm.tsx index 0dbc6ee..e7340fd 100644 --- a/src/features/forms/EntityForm.tsx +++ b/src/features/forms/EntityForm.tsx @@ -15,7 +15,7 @@ import { fetchRecaptchaSiteKey } from '../../api/session'; import { useRecaptcha } from '../../auth/recaptcha'; import { fromInputDate, resolveFields, toDisplayDate, toInputDate, toPayload, type Mode, type ResolvedField } from './fields'; import { RecordActionButtons } from '../view/RecordActionButtons'; -import { CONFIRM_ENTITIES, CREATE_DEFAULTS, CREATE_HIDDEN, CREATE_REQUIRED, EDIT_HIDDEN_FIELDS, aliasSource, EDIT_HIDDEN_SECTIONS, FLEET_ENTITIES, HIDDEN_CREATE_TITLES, NON_OMANI_ONLY, getLayout, type DynamicLookup } from './layouts'; +import { CONFIRM_ENTITIES, CREATE_DEFAULTS, CREATE_HIDDEN_SECTIONS, CREATE_HIDDEN, CREATE_REQUIRED, EDIT_HIDDEN_FIELDS, aliasSource, EDIT_HIDDEN_SECTIONS, FLEET_ENTITIES, HIDDEN_CREATE_TITLES, NON_OMANI_ONLY, getLayout, type DynamicLookup } from './layouts'; import { AttachmentField } from './AttachmentField'; import { DateField } from '../../components/DateField'; import { ExtraFieldsDialog } from './ExtraFieldsDialog'; @@ -307,6 +307,7 @@ export function EntityForm({ (ownerToggle && (name === 'IS_OWNER' || (isOwner && OWNER_DOC.includes(name)))) || (mode === 'CREATE' && !!CREATE_HIDDEN[entity]?.includes(name)) || (mode === 'EDIT' && !!EDIT_HIDDEN_FIELDS[entity]?.includes(name)) || + (mode === 'CREATE' && !!layout?.sections.some((s) => CREATE_HIDDEN_SECTIONS[entity]?.includes(s.title) && s.fields.includes(name))) || (mode === 'EDIT' && !!layout?.sections.some((s) => EDIT_HIDDEN_SECTIONS[entity]?.includes(s.title) && s.fields.includes(name))) || (!!nonOmaniOnly?.fields.includes(name) && !isNonOmani) || (!!riyadaDoc && name === riyadaDoc && !riyadaRole) || @@ -314,6 +315,9 @@ export function EntityForm({ (entity === 'DEPOSITS' && name === 'RECEIPT_ID' && String(values.TRANSACTION_TYPE ?? '').trim() !== '6') || // stakeholder users deposit for themselves: the stakeholder picker is not shown to them (entity === 'DEPOSITS' && mode === 'CREATE' && user?.role_group === 'STAKEHOLDER' && ['STAKEHOLDER_ENTITY_NUMBER', 'STAKEHOLDER_ENTITY_RECORD_NAME', 'STAKEHOLDER_ENTITY_ID'].includes(name)); + // fleet pages: the free-text plate code (non-Omani documents) is optional, the Omani dropdown stays mandatory + const plateOptional = (name: string) => FLEET_ENTITIES.includes(entity) && plateRules.some((r) => r.text === name); + const plateRequired = (name: string) => isPlateField(name) && !plateOptional(name); // fields that become mandatory because of what was chosen const conditionallyRequired = (name: string) => (mode === 'CREATE' && !!CREATE_REQUIRED[entity]?.includes(name)) || @@ -395,7 +399,7 @@ export function EntityForm({ const v = values[f.name]; const empty = v === undefined || v === null || v === '' || (Array.isArray(v) && !v.length); // whichever of the plate-code pair is showing is the one that must be filled - const required = isPlateField(f.name) || conditionallyRequired(f.name) ? true : f.required; + const required = plateRequired(f.name) || conditionallyRequired(f.name) ? true : plateOptional(f.name) ? false : f.required; if (required && empty) errs[f.name] = t('REQUIRED_FIELD'); else if (!empty && f.regex && typeof v === 'string') { // date patterns are written for the display format dd/mm/yyyy, values are stored as yyyymmdd @@ -482,7 +486,7 @@ export function EntityForm({ const visible = s.fields .map((n) => byName.get(n)) .filter((f): f is ResolvedField => !!f && !f.hidden && !formHidden(f.name)) - .map((f) => (isPlateField(f.name) || conditionallyRequired(f.name) ? { ...f, required: true } : f)) + .map((f) => (plateRequired(f.name) || conditionallyRequired(f.name) ? { ...f, required: true } : plateOptional(f.name) ? { ...f, required: false } : f)) .map((f) => (ownerLocked(f.name) || profileLocked(f.name) ? { ...f, readOnly: true } : f)) .map((f) => (trailerPlateAsSelect(f) ? { ...f, type: 'DROPDOWN', options: byName.get('FLEET_PLATE_CODE')!.options } : f)); if (!visible.length) return null; diff --git a/src/features/forms/generated-layouts.json b/src/features/forms/generated-layouts.json index e8913ab..8546796 100644 --- a/src/features/forms/generated-layouts.json +++ b/src/features/forms/generated-layouts.json @@ -1037,6 +1037,8 @@ "fields": [ "FIRST_WEIGHT", "FIRST_WEIGHT_DATE", + "SECOND_WEIGHT", + "SECOND_WEIGHT_DATE", "NET_WEIGHT" ] }, diff --git a/src/features/forms/layouts.ts b/src/features/forms/layouts.ts index 1fe8893..37555db 100644 --- a/src/features/forms/layouts.ts +++ b/src/features/forms/layouts.ts @@ -143,6 +143,8 @@ export const VIEW_HIDDEN_SECTIONS: Record = { PERSONNEL: ['LICENSEINFO', 'PERSONNEL_INFO'], // the reply box is a popup here; the answers are listed in their own table TICKETS: ['ADD_REPLY'], + // the extra backend fields (type, severity, expiry) are not on the legacy blacklist page + BLACKLISTS: ['BLACKLISTS_INFO'], }; /** Fields that only apply to a non-Omani nationality (passport details), and the nationality field that decides it. */ @@ -151,6 +153,12 @@ export const NON_OMANI_ONLY: Record = { + INVESTORS: ['INVESTORS_INFO'], + COMPANIES: ['COMPANIES_INFO'], +}; + /** Sections whose heading is left out of the create form (the fields stay). */ export const HIDDEN_CREATE_TITLES: Record = { BLACKLISTS: 'BLACKLISTSINFO' }; @@ -185,7 +193,7 @@ export const VIEW_HIDDEN_FIELDS: Record = { ...Object.fromEntries(FLEET_ENTITIES.map((e) => [e, ['NATIONALITY_LICENCE', 'PERSONAL_DOCUMENT_TYPE', 'PERSONAL_DOC_NUMBER']])), USERS: ['LOCATION_IDS'], }; -export const VIEW_LAST_FIELDS: Record = { DEPOSITS: ['NOTES'] }; +export const VIEW_LAST_FIELDS: Record = { DEPOSITS: ['NOTES'], BLACKLISTS: ['NOTES'] }; /** Heading of the group that holds an entity's extra backend-required fields, when "_INFO" would read wrongly. */ const EXTRA_TITLE: Record = { PERMITS: 'TRUCKS_INFO' }; @@ -264,9 +272,14 @@ function build(entity: string, config: AppConfig): EntityLayout | undefined { if (names.has(field) && !dynamic[field]) dynamic[field] = lookup; } - return { ...hand, sections, dynamic, alias }; + return { ...hand, sections, dynamic, alias, viewText: { ...(hand?.viewText ?? {}), ...(VIEW_TEXT[entity] ?? {}) } }; } +/** Record-page values the backend sends ready formatted under another key (the *_GRID ones carry the time of day). */ +const VIEW_TEXT: Record> = { + PERMITS: { CREATION_DATE: 'CREATION_DATE_GRID', FIRST_WEIGHT_DATE: 'FIRST_WEIGHT_DATE_GRID', SECOND_WEIGHT_DATE: 'SECOND_WEIGHT_DATE_GRID' }, +}; + const ENTITY_LOOKUPS: Record> = { // investors that hold the chosen industrial area RENTED_TRUCK: { diff --git a/src/features/gridActions/PendingPayDialog.tsx b/src/features/gridActions/PendingPayDialog.tsx index 26404e1..84dff24 100644 --- a/src/features/gridActions/PendingPayDialog.tsx +++ b/src/features/gridActions/PendingPayDialog.tsx @@ -75,7 +75,8 @@ export function PendingPayDialog({ id, data, onClose, onDone }: { id: string; da if (nafith) { Object.assign(params, { depts_transcation_ids: data.ID, - stakeholder_entity_id: data.STAKEHOLDER_ENTITY_ID, + // legacy: ticking "include the Nafith service" makes the payer's own entity the stakeholder + stakeholder_entity_id: withNafith ? ((user as Record | null)?.related_entity_id ?? data.STAKEHOLDER_ENTITY_ID) : data.STAKEHOLDER_ENTITY_ID, stakeholder_entity_Record_id: data.STAKEHOLDER_ENTITY_RECORD_ID, fleet_entity_id: data.FLEET_ENTITY_ID, fleet_entity_record_id: data.FLEET_ENTITY_RECORD_ID, diff --git a/src/features/search/filters.ts b/src/features/search/filters.ts index f8a2203..eb9d61c 100644 --- a/src/features/search/filters.ts +++ b/src/features/search/filters.ts @@ -32,7 +32,7 @@ interface Row { /** Filters only some roles get: entry permit requests offer the sender / receiver pickers to the shift supervisor and the operations office. */ const ROLE_ONLY_FILTERS: Record = { FLEET_REQUEST: { - roles: ['SHIFT_SUPERVISOR', 'OPOFF'], + roles: ['SHIFT_SUPERVISOR', 'OPOFF', 'LOP_CC'], ids: ['SENDER_RELATED_ENTITY_ID', 'SENDER_RELATED_ENTITY_RECORD_ID', 'RECEIVER_RELATED_ENTITY_ID', 'RECEIVER_RELATED_ENTITY_RECORD_ID'], }, }; diff --git a/src/features/view/EntityEvents.tsx b/src/features/view/EntityEvents.tsx index b6ef0e7..1af3159 100644 --- a/src/features/view/EntityEvents.tsx +++ b/src/features/view/EntityEvents.tsx @@ -11,6 +11,7 @@ import { rpc, type Envelope } from '../../api/client'; import { useAuth } from '../../auth/AuthContext'; import { useLabel, useT, useUi } from '../../i18n'; import { sectionFrame } from '../../components/SectionTitle'; +import { DateField } from '../../components/DateField'; /** * The old record pages ended with a collapsed "Events" card: who did what to the record and when, with a popup that @@ -24,7 +25,14 @@ const EMPTY: Filters = { action: '', login: '', from: '', to: '' }; /** yyyy-mm-dd (date box) -> yyyymmdd (what the backend's "from-to" date range compares) */ const yyyymmdd = (d: string) => d.replace(/-/g, ''); -type Row = [id: string, action: string, user: string, date: string, details: string]; +/** + * A log row is [id, action, user, date, details]; the permit log (and a few others) also carries the kiosk the action + * was made at, between the user and the date: [id, action, user, kiosk, date, details]. + */ +type Row = string[]; +const hasKiosk = (r: Row) => r.length >= 6; +const rowDate = (r: Row) => (hasKiosk(r) ? r[4] : r[3]); +const rowDetails = (r: Row) => String(r[r.length - 1] ?? ''); /** The details icon carries the old / new data as base64 JSON inside its click handler; read it, never run it. */ function parseDetails(html: string): { oldData: Record; newData: Record } | null { @@ -82,6 +90,9 @@ export function EntityEvents({ entity, id }: { entity: string; id: string }) { const reset = () => { setPage(0); setDraft(EMPTY); setApplied(EMPTY); }; const rows = events.data?.rows ?? []; const count = events.data?.records ?? 0; + // the permit log always has the kiosk column, as the old page did, even when a page of rows is empty + const kiosk = entity === 'PERMITS' || rows.some(hasKiosk); + const cols = kiosk ? 5 : 4; return ( @@ -113,8 +124,8 @@ export function EntityEvents({ entity, id }: { entity: string; id: string }) { {actions.map((a) => {t(a.CAPTION_CODE)})} setDraft({ ...draft, login: e.target.value })} /> - setDraft({ ...draft, from: e.target.value })} slotProps={{ inputLabel: { shrink: true } }} /> - setDraft({ ...draft, to: e.target.value })} slotProps={{ inputLabel: { shrink: true } }} /> + setDraft((d) => ({ ...d, from: iso }))} /> + setDraft((d) => ({ ...d, to: iso }))} /> @@ -128,19 +139,21 @@ export function EntityEvents({ entity, id }: { entity: string; id: string }) { {t('ACTION_CODE')} {t('USERNAME')} + {kiosk && {t('KIOSK_NUMBER')}} {t('CREATION_DATE')} - {rows.length === 0 && {t('NO_INFO')}} + {rows.length === 0 && {t('NO_INFO')}} {rows.map((r) => { - const d = parseDetails(String(r[4] ?? '')); + const d = parseDetails(rowDetails(r)); return ( {r[1]} {r[2]} - {r[3]} + {kiosk && {hasKiosk(r) ? r[3] : ''}} + {rowDate(r)} {d && Object.keys(d.newData).length + Object.keys(d.oldData).length > 0 && ( diff --git a/src/features/view/EntityView.tsx b/src/features/view/EntityView.tsx index eb53ac8..5b5dc52 100644 --- a/src/features/view/EntityView.tsx +++ b/src/features/view/EntityView.tsx @@ -1,6 +1,7 @@ import { useMemo, useState } from 'react'; import { SectionTitle, sectionFrame } from '../../components/SectionTitle'; -import { Link as RouterLink } from 'react-router-dom'; +import { Link as RouterLink, useNavigate } from 'react-router-dom'; +import { WeighingDialog } from './WeighingDialog'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { Alert, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, Paper, @@ -53,7 +54,11 @@ function Value({ field, data, layout }: { field: ResolvedField; data: Data; layo const none = —; - if (textKey && String(data[textKey] ?? '').trim()) return <>{String(data[textKey])}; + if (textKey && String(data[textKey] ?? '').trim()) { + const text = String(data[textKey]); + // a date with a time (29/07/2026 11:38:48) must read date first in the right-to-left page too + return /^\d{2}\/\d{2}\/\d{4}/.test(text) ? {text} : <>{text}; + } const forced = (data.__TEXT as Record | undefined)?.[field.name]; if (forced) return <>{forced}; // a stakeholder is stored as an id: show the name the backend sends beside it (investor names come in both languages) @@ -109,6 +114,8 @@ export function EntityView({ entity, id }: { entity: string; id: string }) { const [detPage, setDetPage] = useState(0); const [vatOpen, setVatOpen] = useState(false); const [vat, setVat] = useState(''); + const nav = useNavigate(); + const [wimOpen, setWimOpen] = useState(false); const [replyOpen, setReplyOpen] = useState(false); const [payOpen, setPayOpen] = useState(false); const [renewOpen, setRenewOpen] = useState(false); @@ -148,10 +155,17 @@ export function EntityView({ entity, id }: { entity: string; id: string }) { onSuccess: (res, v) => { // the new password is shown in a box with a copy button, not in a toast that disappears if (isPasswordReset(v.a.ACTION_NAME) && findNewPassword(String(res.MESSAGE ?? ''))) setNewPassword(String(res.MESSAGE)); - else notify.success(String(res.MESSAGE ?? 'SUCCESSFUL.OPERATION'), ui('saved')); + else if (v.a.ACTION_NAME !== 'MFZ_EXIT_INQUIRY') notify.success(String(res.MESSAGE ?? 'SUCCESSFUL.OPERATION'), ui('saved')); // print / invoice actions answer with the generated file's location const file = typeof res.DATA === 'string' ? res.DATA : (res.DATA as { FILE?: string } | undefined)?.FILE; - if (file && /downloadFiles/i.test(file)) void downloadReport(file).catch((e) => notify.error(e)); + if (file && (/downloadFiles/i.test(file) || v.a.ACTION_NAME === 'PRINT_WEIGHING_BRIDGE_DATA')) void downloadReport(file).catch((e) => notify.error(e)); + // free-zone exit inquiry: the result says whether the truck may leave (the old page's messages) + if (v.a.ACTION_NAME === 'MFZ_EXIT_INQUIRY') { + const result = String((res.DATA as { INTEGRATION_RESULT?: string } | undefined)?.INTEGRATION_RESULT ?? ''); + const msg: Record = { True: 'ALLOWED_EXIT_MFZ', Partially: 'ALLOWED_TEMP_EXIT_MFZ', False: 'NOT_ALLOWED_EXIT_MFZ', ERROR: 'ERROR_WITH_EDAA' }; + if (msg[result]) (result === 'True' || result === 'Partially' ? notify.success : notify.warning)(msg[result], t(msg[result])); + if (result === 'True' || result === 'Partially') nav(`/e/${entity}/grid`); + } setAction(null); setExtra(null); void qc.invalidateQueries({ queryKey: ['grid', entity] }); @@ -195,7 +209,7 @@ export function EntityView({ entity, id }: { entity: string; id: string }) { return; } // printing only produces a file: no confirmation, like the old page - if (a.ACTION_NAME === 'PRINT' || a.ACTION_NAME === 'GET_INVOICE') { + if (a.ACTION_NAME === 'PRINT' || a.ACTION_NAME === 'GET_INVOICE' || a.ACTION_NAME === 'PRINT_WEIGHING_BRIDGE_DATA') { run.mutate({ a }); return; } @@ -295,6 +309,11 @@ export function EntityView({ entity, id }: { entity: string; id: string }) { {t(String(a.ACTION_CAPTION_CODE ?? a.ACTION_NAME))} ))} + {actions.some((a) => a.ACTION_NAME === 'VIEW_WIM') && ( + + )} {vatAction && ( + + + ); +} diff --git a/src/features/view/actions.ts b/src/features/view/actions.ts index b6fd0a0..0a27064 100644 --- a/src/features/view/actions.ts +++ b/src/features/view/actions.ts @@ -16,6 +16,9 @@ const SIMPLE = new Set([ 'RECONCILE', 'PRINT', 'GET_INVOICE', // customer service: the support role finishes a ticket 'OPOFF_COMPLETE', + // permits: gate-in / gate-out, release, return to review, extend validity, free-zone exit, weighing slip + 'GIN_EVENT', 'GOUT_EVENT', 'RELEASED', 'MFZ_TEMPORARY_EXIT', 'RETURN_TO_UNDER_REVIEW', 'MFZ_EXTEND_VALIDITY_PERIOD', + 'MFZ_EXIT_INQUIRY', 'PRINT_WEIGHING_BRIDGE_DATA', ]); export const isSimpleAction = (a: EntityAction) => SIMPLE.has(a.ACTION_NAME); diff --git a/src/i18n/ui.ts b/src/i18n/ui.ts index 291a739..8e9c588 100644 --- a/src/i18n/ui.ts +++ b/src/i18n/ui.ts @@ -87,6 +87,7 @@ export const UI = { wizFreeZone: { en: 'One-trip permits for the free-zone package are entered in the previous system for now. Nothing has been submitted.', ar: 'تصاريح الرحلة الواحدة لباقة المنطقة الحرة تُدخل حالياً في النظام السابق. لم يتم إرسال أي طلب.' }, wizSearchFirst: { en: 'Search for the vehicles by plate number, plate code, nationality, owner type or class, then pick the ones to subscribe.', ar: 'ابحث عن المركبات برقم اللوحة أو ترميزها أو الجنسية أو نوع المالك أو الفئة، ثم اختر ما تريد الاشتراك به.' }, wizNeedFilter: { en: 'Enter at least one search filter (for example the plate number).', ar: 'أدخل معياراً واحداً على الأقل للبحث (مثل رقم اللوحة).' }, + enterSearchFilter: { en: 'Choose a status or enter a search filter above to list the records.', ar: 'اختر حالة أو أدخل معياراً للبحث أعلاه لعرض السجلات.' }, gridLoading: { en: 'Loading the list from the system…', ar: 'جاري تحميل القائمة من النظام…' }, gridSearching: { en: 'Updating the results…', ar: 'جاري تحديث النتائج…' }, gridLoadingSlow: { en: 'Large lists can take a few more seconds. Please wait.', ar: 'قد تستغرق القوائم الكبيرة بضع ثوانٍ إضافية. يرجى الانتظار.' }, @@ -191,7 +192,7 @@ export type UiKey = keyof typeof UI; export const SECTION_TITLES: Record = { // the trailer's plate code is captioned "Plate Code" in the metadata, which reads as a duplicate of the truck's TRAILER_PLATE_CODE: { en: 'Trailer Plate Code', ar: 'ترميز لوحة المقطورة' }, - BLACKLISTSINFO: { en: 'Blacklist details', ar: 'تفاصيل القائمة السوداء' }, + BLACKLISTSINFO: { en: 'Blacklist details', ar: 'معلومات المنع' }, OWNERINFO: { en: 'Owner details', ar: 'بيانات المالك' }, INSURANCEINFO: { en: 'Insurance', ar: 'التأمين' }, CAPACITY_OPTIONS: { en: 'Capacity options', ar: 'خيارات الطاقة الاستيعابية' },