From 174734c359dfe403950861d8ab2f3a006d25dd61 Mon Sep 17 00:00:00 2001 From: Samer Salameh Date: Sun, 15 Nov 2026 15:21:24 +0300 Subject: [PATCH] Billing entry: editable weights and fines, all destinations; searchable company lists; dark disabled text Co-Authored-By: Claude Sonnet 5.5 --- .../Grains/Orders/BillingService.cs | 10 ++-- .../Grains/Orders/OrdersContracts.cs | 6 +- .../Grains/Orders/OrdersRepositories.cs | 2 +- .../Grains/Orders/OrdersValidators.cs | 2 + src/NTP.Domain/Grains/Orders/OrdersDomain.cs | 3 +- .../Grains/Orders/BillingRepository.cs | 10 ++-- .../Grains/Orders/OrderLookupRepository.cs | 4 +- .../features/grains-orders/meta/billing.tsx | 8 +-- web/src/features/grains-orders/pages.tsx | 55 ++++++++----------- web/src/features/grains-orders/strings.ts | 1 + .../features/grains-permits/meta/permits.tsx | 2 +- .../features/grains-registry/meta/trailers.ts | 4 +- .../features/grains-registry/meta/trucks.ts | 4 +- web/src/theme/theme.ts | 8 ++- 14 files changed, 64 insertions(+), 55 deletions(-) diff --git a/src/NTP.Application/Grains/Orders/BillingService.cs b/src/NTP.Application/Grains/Orders/BillingService.cs index c46bfc6..320e88f 100644 --- a/src/NTP.Application/Grains/Orders/BillingService.cs +++ b/src/NTP.Application/Grains/Orders/BillingService.cs @@ -43,15 +43,15 @@ public sealed class BillingService( { await validator.ValidateAndThrowAsync(request, ct); - // Weights are re-read server side (legacy trusted hidden form fields). var info = await repository.GetPermitBillingInfoAsync(request.Pn, ct) ?? throw OrdersErrors.InvalidPn(); if (info.Scac != request.Scac) throw OrdersErrors.PnNotOfCompany(); if (!BillingCalculator.IsDischargeAfterLoad(request.LoadDate, request.DischargeDate)) throw OrdersErrors.DischargeBeforeLoad(); - var lnw = BillingCalculator.NetWeight(info.Lgw, info.Ltw); - var dnw = BillingCalculator.NetWeight(info.Dgw, info.Dtw); - if (dnw == 0) throw OrdersErrors.ReceivedWeightMissing(); + // Sent / received weights are typed by the user (prefilled from the permit), like the legacy LNW / DNW inputs. + var lnw = request.Lnw; + var dnw = request.Dnw; + if (dnw <= 0) throw OrdersErrors.ReceivedWeightMissing(); if (!BillingCalculator.IsSentWeightInRange(lnw)) throw OrdersErrors.SentWeightRange(); // PRICE / FINEPRICE come from the static price table (legacy: readonly inputs filled from the same table). @@ -73,7 +73,7 @@ public sealed class BillingService( request.LoadDate.Date, request.DischargeDate.Date, info.Dtw, info.Dgw, dnw, info.Ltw, info.Lgw, lnw, request.Scac, request.InvoiceNumber, GrainsOrderConstants.BillingOriginId, - price.Value, finePrice.Value, finalCost, loseFine, user.UserId), token); + price.Value, finePrice.Value, finalCost, loseFine, user.UserId, request.DemurrageFine, request.OtherFine), token); return new OrdersResult(OrdersErrors.Success, id); }, ct); diff --git a/src/NTP.Application/Grains/Orders/OrdersContracts.cs b/src/NTP.Application/Grains/Orders/OrdersContracts.cs index 6392f21..72f21f7 100644 --- a/src/NTP.Application/Grains/Orders/OrdersContracts.cs +++ b/src/NTP.Application/Grains/Orders/OrdersContracts.cs @@ -114,7 +114,11 @@ public sealed record AddBillingRequest( DateTime DischargeDate, long Destination, long CargoType, - string Tn); + string Tn, + decimal Lnw = 0, + decimal Dnw = 0, + decimal DemurrageFine = 0, + decimal OtherFine = 0); public sealed record WageRate(decimal Wage); public sealed record FineRate(decimal Allowance, decimal Fine); diff --git a/src/NTP.Application/Grains/Orders/OrdersRepositories.cs b/src/NTP.Application/Grains/Orders/OrdersRepositories.cs index 7da14c2..b5d894c 100644 --- a/src/NTP.Application/Grains/Orders/OrdersRepositories.cs +++ b/src/NTP.Application/Grains/Orders/OrdersRepositories.cs @@ -29,7 +29,7 @@ public interface IOrderLookupRepository /// LOCATIONS where DOMAIN='GN', STATUS=1 and TYPE = EN (loading) or EX (destination). Task> GetLocationsAsync(string type, CancellationToken ct = default); - /// Invoice.cfc getLocations: GN exit locations with AREA IS NULL and STATUS=1. + /// Invoice.cfc getLocations: every active GN exit location (STATUS=1), AREA NULL first. Task> GetBillingDestinationsAsync(CancellationToken ct = default); /// register.getDistination: GN exit locations of GN_TYPE 'PCKD', ordered by SORTORDER. diff --git a/src/NTP.Application/Grains/Orders/OrdersValidators.cs b/src/NTP.Application/Grains/Orders/OrdersValidators.cs index c1c191b..9d24506 100644 --- a/src/NTP.Application/Grains/Orders/OrdersValidators.cs +++ b/src/NTP.Application/Grains/Orders/OrdersValidators.cs @@ -46,6 +46,8 @@ public sealed class AddBillingValidator : AbstractValidator RuleFor(x => x.Destination).GreaterThan(0).WithMessage("الى مطلوب"); RuleFor(x => x.CargoType).GreaterThan(0).WithMessage("نوع المادة مطلوب"); RuleFor(x => x.Tn).NotEmpty().MaximumLength(20).WithMessage("رقم السيارة مطلوب"); + RuleFor(x => x.DemurrageFine).GreaterThanOrEqualTo(0).WithMessage("غرامة التاخير غير صحيحة"); + RuleFor(x => x.OtherFine).GreaterThanOrEqualTo(0).WithMessage("غرامات أخرى غير صحيحة"); } } diff --git a/src/NTP.Domain/Grains/Orders/OrdersDomain.cs b/src/NTP.Domain/Grains/Orders/OrdersDomain.cs index 3f8b444..a97e917 100644 --- a/src/NTP.Domain/Grains/Orders/OrdersDomain.cs +++ b/src/NTP.Domain/Grains/Orders/OrdersDomain.cs @@ -59,4 +59,5 @@ public sealed record NewTenderOrder( public sealed record NewGrainsBilling( long Pn, string SerialNo, string Tn, long CargoType, long Destination, DateTime LoadDate, DateTime DischargeDate, decimal Dtw, decimal Dgw, decimal Dnw, decimal Ltw, decimal Lgw, decimal Lnw, long Scac, long InvoiceNumber, - long Origin, decimal Price, decimal FinePrice, decimal FinalCost, decimal LoseFine, string CreateUserId = ""); + long Origin, decimal Price, decimal FinePrice, decimal FinalCost, decimal LoseFine, string CreateUserId = "", + decimal DemurrageFine = 0, decimal OtherFine = 0); diff --git a/src/NTP.Infrastructure/Persistence/Repositories/Grains/Orders/BillingRepository.cs b/src/NTP.Infrastructure/Persistence/Repositories/Grains/Orders/BillingRepository.cs index 59572cd..e38112c 100644 --- a/src/NTP.Infrastructure/Persistence/Repositories/Grains/Orders/BillingRepository.cs +++ b/src/NTP.Infrastructure/Persistence/Repositories/Grains/Orders/BillingRepository.cs @@ -81,17 +81,19 @@ internal sealed class BillingRepository(IDbSession session, ILogger("NewId")); @@ -116,7 +118,7 @@ internal sealed class BillingRepository(IDbSession session, ILogger 'DELETED' diff --git a/src/NTP.Infrastructure/Persistence/Repositories/Grains/Orders/OrderLookupRepository.cs b/src/NTP.Infrastructure/Persistence/Repositories/Grains/Orders/OrderLookupRepository.cs index 1640432..7675aa1 100644 --- a/src/NTP.Infrastructure/Persistence/Repositories/Grains/Orders/OrderLookupRepository.cs +++ b/src/NTP.Infrastructure/Persistence/Repositories/Grains/Orders/OrderLookupRepository.cs @@ -32,8 +32,8 @@ internal sealed class OrderLookupRepository(IDbSession session, ILogger> GetBillingDestinationsAsync(CancellationToken ct = default) => OptionsAsync(""" SELECT id AS Id, name AS Name FROM LOCATIONS t - WHERE t.domain = 'GN' AND t.type = 'EX' AND t.area IS NULL AND t.status = '1' - ORDER BY name, id + WHERE t.domain = 'GN' AND t.type = 'EX' AND t.status = '1' + ORDER BY t.area NULLS FIRST, name, id """, null, ct); public Task> GetPackedDestinationsAsync(CancellationToken ct = default) => diff --git a/web/src/features/grains-orders/meta/billing.tsx b/web/src/features/grains-orders/meta/billing.tsx index c71d07d..a1a1064 100644 --- a/web/src/features/grains-orders/meta/billing.tsx +++ b/web/src/features/grains-orders/meta/billing.tsx @@ -57,10 +57,10 @@ export const billingForm: FormMeta = { { name: 'destination', type: 'select', label: { en: 'To', ar: 'الى' }, required: true, options: billingDestinationOptions }, { name: 'cargoType', type: 'select', label: { en: 'Cargo type', ar: 'نوع المادة' }, required: true, options: cargoTypeOptions }, { name: 'tn', type: 'text', label: { en: 'Truck number', ar: 'رقم السيارة' }, required: true, inputKind: 'plate', maxLength: 20 }, - { name: 'lnw', type: 'number', label: { en: 'Sent weight', ar: 'الوزن المرسل' }, readOnly: true }, - { name: 'dnw', type: 'number', label: { en: 'Received weight', ar: 'الوزن المستلم' }, readOnly: true }, - { name: 'price', type: 'number', label: { en: 'Price', ar: 'السعر' }, readOnly: true }, - { name: 'finePrice', type: 'number', label: { en: 'Fine price', ar: 'سعر التغريم' }, readOnly: true }, + { name: 'lnw', type: 'number', label: { en: 'Sent weight', ar: 'الوزن المرسل' }, required: true, min: 0, max: 50000 }, + { name: 'dnw', type: 'number', label: { en: 'Received weight', ar: 'الوزن المستلم' }, required: true, min: 0 }, + { name: 'demurrageFine', type: 'number', label: { en: 'Delay fine', ar: 'غرامة التاخير' }, min: 0 }, + { name: 'otherFine', type: 'number', label: { en: 'Other fines', ar: 'غرامات أخرى' }, min: 0 }, ], }, ], diff --git a/web/src/features/grains-orders/pages.tsx b/web/src/features/grains-orders/pages.tsx index f1d2cd4..f144e3b 100644 --- a/web/src/features/grains-orders/pages.tsx +++ b/web/src/features/grains-orders/pages.tsx @@ -1,7 +1,7 @@ import { useEffect, useMemo, useState, type KeyboardEvent } from 'react'; import { useNavigate } from 'react-router-dom'; import { - Alert, Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, Paper, Stack, + Alert, Autocomplete, Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, Paper, Stack, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, Typography, } from '@mui/material'; import AddIcon from '@mui/icons-material/Add'; @@ -287,6 +287,24 @@ export function BillingListPage() { ); } +/** Company drop list the user can type in to search (by name or number). */ +function CompanySelect(props: { value: string; onChange: (v: string) => void; exclude?: number }) { + const { t } = useFeatureUi(strings); + const companies = useCompanies(); + const options = (companies.data ?? []).filter((c) => c.scac !== props.exclude); + const selected = options.find((c) => String(c.scac) === props.value) ?? null; + return ( + c.label ?? String(c.scac)} + isOptionEqualToValue={(a, b) => a.scac === b.scac} + onChange={(_, c) => props.onChange(c ? String(c.scac) : '')} + noOptionsText={t('ord.noCompany')} + renderInput={(params) => } + /> + ); +} + /** Company + permit-number picker shared by the billing and weights screens. */ function PermitBar(props: { withCompany: boolean; @@ -298,21 +316,12 @@ function PermitBar(props: { hint: string; }) { const { t } = useFeatureUi(strings); - const companies = useCompanies(); return ( {props.hint} {props.withCompany && ( - props.onScac(e.target.value)} - slotProps={{ select: { native: true }, inputLabel: { shrink: true } }} - sx={{ flex: 2 }} - > - - {(companies.data ?? []).map((c) => )} - + )} (null); const current = useCompanyDestinations(scac); @@ -548,14 +556,7 @@ export function CompanyDestinationsPage() { - setScac(e.target.value ? Number(e.target.value) : null)} - slotProps={{ select: { native: true }, inputLabel: { shrink: true } }} - > - - {(companies.data ?? []).filter((c) => c.scac !== INDIVIDUALS_SCAC).map((c) => )} - + setScac(v ? Number(v) : null)} exclude={INDIVIDUALS_SCAC} /> {scac === null && {t('ord.compDest.pick')}} {scac !== null && (current.isPending || groupsData.isPending) && } @@ -691,7 +692,6 @@ const pad = (v: number, int: number) => v.toFixed(3).padStart(int + 4, '0'); export function InvoiceCheckPage() { const { t } = useFeatureUi(strings); const toast = useToast(); - const companies = useCompanies(); const [scac, setScac] = useState(''); const [inv, setInv] = useState(''); const invoices = useInvoiceNumbers(scac); @@ -731,14 +731,7 @@ export function InvoiceCheckPage() { actions={} > - { setScac(e.target.value); setInv(''); setRows(null); }} - slotProps={{ select: { native: true }, inputLabel: { shrink: true } }} - > - - {(companies.data ?? []).map((c) => )} - + { setScac(v); setInv(''); setRows(null); }} /> { setInv(e.target.value); setRows(null); }} diff --git a/web/src/features/grains-orders/strings.ts b/web/src/features/grains-orders/strings.ts index f172e59..08d01ca 100644 --- a/web/src/features/grains-orders/strings.ts +++ b/web/src/features/grains-orders/strings.ts @@ -24,6 +24,7 @@ export default defineStrings({ 'ord.export.xlsx': { en: 'Export Excel', ar: 'تصدير Excel' }, 'ord.export.failed': { en: 'Could not download the file', ar: 'تعذر تنزيل الملف' }, 'ord.company': { en: 'Company', ar: 'الشركة' }, + 'ord.noCompany': { en: 'No matching company', ar: 'لا توجد شركة مطابقة' }, 'ord.selectCompany': { en: 'Select a company', ar: 'اختر الشركة' }, 'ord.load': { en: 'Load', ar: 'تحميل' }, diff --git a/web/src/features/grains-permits/meta/permits.tsx b/web/src/features/grains-permits/meta/permits.tsx index e91a8ab..b3ea147 100644 --- a/web/src/features/grains-permits/meta/permits.tsx +++ b/web/src/features/grains-permits/meta/permits.tsx @@ -68,7 +68,7 @@ export const permitFilters = (companyUser: boolean): FilterMeta[] => [ { name: 'creationDate', type: 'date', label: { en: 'Turn date', ar: 'تاريخ الدور' } }, { name: 'shipmentMode', type: 'select', label: { en: 'Cargo class', ar: 'نوع المادة' }, options: shipmentModeOptions }, { name: 'destAddressId', type: 'select', label: { en: 'Destination', ar: 'الوجهة' }, options: exitLocationOptions }, - ...(companyUser ? [] : [{ name: 'companyCode', type: 'select', label: { en: 'Company', ar: 'اسم الشركة' }, options: companyFilterOptions } as FilterMeta]), + ...(companyUser ? [] : [{ name: 'companyCode', type: 'autocomplete', label: { en: 'Company', ar: 'اسم الشركة' }, options: companyFilterOptions } as FilterMeta]), { name: 'tenderOrder', type: 'select', label: { en: 'By order', ar: 'حسب الطلبية' }, options: tenderOrderDateOptions }, ]; diff --git a/web/src/features/grains-registry/meta/trailers.ts b/web/src/features/grains-registry/meta/trailers.ts index 9045a34..4b1d914 100644 --- a/web/src/features/grains-registry/meta/trailers.ts +++ b/web/src/features/grains-registry/meta/trailers.ts @@ -16,7 +16,7 @@ export function trailerGrid(h: { isCompanyUser: boolean; onOpen: (r: TrailerRow) filters: [ { name: 'tn', type: 'text', label: lbl('Trailer number', 'رقم المقطورة'), inputKind: 'plate' }, { name: 'chasesNumber', type: 'text', label: lbl('Chassis number', 'رقم الشصي'), ltr: true }, - ...(h.isCompanyUser ? [] : [{ name: 'tcscac', type: 'select' as const, label: lbl('Company', 'الشركة'), options: companyOptions }]), + ...(h.isCompanyUser ? [] : [{ name: 'tcscac', type: 'autocomplete' as const, label: lbl('Company', 'الشركة'), options: companyOptions }]), ], columns: [ { key: 'tn', header: lbl('Number', 'الرقم'), ltr: true }, @@ -54,7 +54,7 @@ export function trailerForm(o: TrailerFormOptions): FormMeta { pattern: DIGITS_ONLY(12), readOnly: o.isEdit, }, { - name: 'tcscac', type: 'select', label: lbl('Company', 'الشركة'), required: true, options: companyOptions, + name: 'tcscac', type: 'autocomplete', label: lbl('Company', 'الشركة'), required: true, options: companyOptions, disabledWhen: o.isEdit || o.companyLocked ? { field: 'tcscac', op: 'notEmpty' } : undefined, }, { name: 'chasesNumber', type: 'text', label: lbl('Chassis number', 'رقم الشصي'), requiredWhen: full, maxLength: 20, ltr: true, pattern: NO_SPECIAL }, diff --git a/web/src/features/grains-registry/meta/trucks.ts b/web/src/features/grains-registry/meta/trucks.ts index 5c56104..2c0a3df 100644 --- a/web/src/features/grains-registry/meta/trucks.ts +++ b/web/src/features/grains-registry/meta/trucks.ts @@ -24,7 +24,7 @@ export function truckGrid(h: { isCompanyUser: boolean; onOpen: (r: TruckRow) => { value: 'Tripper', label: lbl('Tipper', 'قلاب') }, { value: 'Single', label: lbl('Single', 'سنجل') }, ] }, - ...(h.isCompanyUser ? [] : [{ name: 'tcscac', type: 'select' as const, label: lbl('Company', 'الشركة'), options: companyOptions }]), + ...(h.isCompanyUser ? [] : [{ name: 'tcscac', type: 'autocomplete' as const, label: lbl('Company', 'الشركة'), options: companyOptions }]), ], columns: [ { key: 'tn', header: lbl('Number', 'الرقم'), ltr: true }, @@ -73,7 +73,7 @@ export function truckForm(o: TruckFormOptions): FormMeta { pattern: DIGITS_ONLY(12), readOnly: o.isEdit, }, { - name: 'tcscac', type: 'select', label: lbl('Company', 'الشركة'), required: true, options: companyOptions, + name: 'tcscac', type: 'autocomplete', label: lbl('Company', 'الشركة'), required: true, options: companyOptions, disabledWhen: o.isEdit || o.companyLocked ? { field: 'tcscac', op: 'notEmpty' } : undefined, }, { name: 'chasesNumber', type: 'text', label: lbl('Chassis number', 'رقم الشصي'), requiredWhen: isBadiya, maxLength: 20, ltr: true, pattern: NO_SPECIAL }, diff --git a/web/src/theme/theme.ts b/web/src/theme/theme.ts index a481287..20e73ea 100644 --- a/web/src/theme/theme.ts +++ b/web/src/theme/theme.ts @@ -56,7 +56,13 @@ export function buildTheme(mode: ThemeMode, direction: 'rtl' | 'ltr'): Theme { }, MuiDialogActions: { styleOverrides: { root: { padding: '8px 24px 16px', gap: 4 } } }, MuiTable: { defaultProps: { size: 'small' } }, - MuiInputBase: { styleOverrides: { root: { fontSize: BASE } } }, + // disabled / read-only fields keep the normal dark text (MUI greys it out by default, which is hard to read) + MuiInputBase: { + styleOverrides: { + root: { fontSize: BASE, '&.Mui-disabled': { color: k.text, WebkitTextFillColor: k.text } }, + input: { '&.Mui-disabled': { color: k.text, WebkitTextFillColor: k.text } }, + }, + }, MuiMenuItem: { styleOverrides: { root: { fontSize: BASE } } }, MuiInputLabel: { styleOverrides: { root: { fontSize: BASE } } }, MuiFormHelperText: { styleOverrides: { root: { fontSize: 12 } } },