Refinery: wage claim row action (new -> close, close -> new), translated log details, hide filled statuses from trips filter
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
18d74d1b53
commit
2cdb74f082
|
|
@ -63,6 +63,11 @@ public sealed class WageClaimsController(IWageClaimService claims) : ControllerB
|
|||
[RequirePermission(PermissionKeys.RefineryWageClaimsClose)]
|
||||
public Task<ClaimResult> Close(long id, CancellationToken ct) => claims.CloseAsync(id, Ip, ct);
|
||||
|
||||
/// <summary>Reopen (CLOSE -> NEW): new action of this system, same permission as the close.</summary>
|
||||
[HttpPost("{id:long}/reopen")]
|
||||
[RequirePermission(PermissionKeys.RefineryWageClaimsClose)]
|
||||
public Task<ClaimResult> Reopen(long id, CancellationToken ct) => claims.ReopenAsync(id, Ip, ct);
|
||||
|
||||
/// <summary>TRANSFER (ترحيل): sends the claim to Jopetrol; refused with a message when the integration is disabled.</summary>
|
||||
[HttpPost("{id:long}/transfer")]
|
||||
[RequirePermission(PermissionKeys.RefineryWageClaimsTransfer)]
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ public interface IWageClaimRepository
|
|||
Task<IReadOnlyList<string>> ClaimTripStatusesAsync(long claimId, CancellationToken ct = default);
|
||||
/// <summary>TRIP_COMPLETE for every trip of the claim: status COMPLETE plus one REFINERY_TRIPS_LOG row each. Returns the number of trips.</summary>
|
||||
Task<int> CompleteClaimTripsAsync(long claimId, string userLogin, long userId, string? ip, CancellationToken ct = default);
|
||||
/// <summary>Undo of the above: COMPLETE trips of the claim go back to EXCHANGED, one REFINERY_TRIPS_LOG row (TRIP_REOPEN) each.</summary>
|
||||
Task<int> ReopenClaimTripsAsync(long claimId, string userLogin, long userId, string? ip, CancellationToken ct = default);
|
||||
Task SetClaimStatusAsync(long claimId, string status, string userLogin, CancellationToken ct = default);
|
||||
|
||||
Task<IReadOnlyList<TransferTripRow>> TripsToTransferAsync(long claimId, CancellationToken ct = default);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ public static class ClaimMessages
|
|||
public const string CommissionVariableIssue = "يوجد خطأ في تعريف قيمة عمولة الاجور"; // ERROR.REFINERY_VARIABLES_COMMISSION_ISSUE
|
||||
/// <summary>New text (the legacy code had no such case): the Jopetrol integration is switched off by configuration.</summary>
|
||||
public const string JopetrolDisabled = "خدمة الترحيل إلى المصفاة غير مفعلة في هذه البيئة، لم يتم تغيير أي شيء";
|
||||
public const string NotFound = "المطالبة غير موجودة";
|
||||
/// <summary>New text: a closed claim that already belongs to a commission claim cannot be reopened.</summary>
|
||||
public const string ReopenHasCommission = "لا يمكن اعادة فتح المطالبة لانها مرتبطة بمطالبة عمولة";
|
||||
public const string NotFound ="المطالبة غير موجودة";
|
||||
|
||||
// log captions (method names of the *_LOG tables)
|
||||
public const string StatusNew = "جديد"; // REFINERY_WAGE_CLAIM.STATUSCODE.NEW
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public interface IWageClaimService
|
|||
Task<PagedResult<ClaimLogRowDto>> LogAsync(long id, PageRequest page, CancellationToken ct);
|
||||
Task<ClaimResult> CreateAsync(CreateWageClaimRequest request, string? ip, CancellationToken ct);
|
||||
Task<ClaimResult> CloseAsync(long id, string? ip, CancellationToken ct);
|
||||
Task<ClaimResult> ReopenAsync(long id, string? ip, CancellationToken ct);
|
||||
Task<ClaimResult> TransferAsync(long id, string? ip, CancellationToken ct);
|
||||
Task<ExportFile> ExportAsync(long id, CancellationToken ct);
|
||||
}
|
||||
|
|
@ -97,6 +98,23 @@ public sealed class WageClaimService(IWageClaimRepository repo, IUnitOfWork unit
|
|||
return new ClaimResult(ClaimMessages.Success, id);
|
||||
}
|
||||
|
||||
/// <summary>Reopen: CLOSE claim -> NEW, its COMPLETE trips back to EXCHANGED. Refused once a commission claim took the wage claim.</summary>
|
||||
public async Task<ClaimResult> ReopenAsync(long id, string? ip, CancellationToken ct)
|
||||
{
|
||||
var claim = await GetAsync(id, ct);
|
||||
if (claim.StatusCode != WageClaimRules.Close) throw new BusinessException("NO_AUTHORITY", ClaimMessages.NoAuthority);
|
||||
if (claim.CommissionClaimId is not null) throw new BusinessException("REOPEN_HAS_COMMISSION", ClaimMessages.ReopenHasCommission);
|
||||
|
||||
await unit.ExecuteInTransactionAsync(async c =>
|
||||
{
|
||||
await repo.ReopenClaimTripsAsync(id, user.UserId, user.Id, ip, c);
|
||||
await repo.SetClaimStatusAsync(id, WageClaimRules.New, user.UserId, c);
|
||||
await repo.AddLogAsync(id, "CLAIM_REOPEN", ClaimLogJson.Status(ClaimMessages.StatusClose), ClaimLogJson.Status(ClaimMessages.StatusNew), user.Id, ip, c);
|
||||
return 0;
|
||||
}, ct);
|
||||
return new ClaimResult(ClaimMessages.Success, id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// factory.TRANSFER (ترحيل): each trip of the claim with TRIP_STATUS 6 is sent to Jopetrol; when the service answers "Status Updated successfully To 7"
|
||||
/// the trip gets TRIP_STATUS 7 and a TRANSFER_TO_REFINERY log row. When the integration is disabled nothing is called and nothing is changed.
|
||||
|
|
|
|||
|
|
@ -143,6 +143,23 @@ internal sealed class WageClaimRepository(IDbSession session, ILogger<WageClaimR
|
|||
""", new { UserLogin = userLogin, ClaimId = claimId }, ct);
|
||||
}
|
||||
|
||||
public async Task<int> ReopenClaimTripsAsync(long claimId, string userLogin, long userId, string? ip, CancellationToken ct = default)
|
||||
{
|
||||
await ExecuteAsync("""
|
||||
INSERT INTO REFINERY_TRIPS_LOG (ID, ENTITIY_ID, METHOD_NAME, LOG_DATE, USER_ID, USER_IP, OLD_DATA, NEW_DATA)
|
||||
SELECT SEQ_REFINERY_TRIPS_LOG.NEXTVAL, t.ID, 'TRIP_REOPEN', SYSDATE, :UserId, :Ip, :OldData, :NewData
|
||||
FROM REFINERY_TRIPS t WHERE t.WAGE_CLAIM_ID = :ClaimId AND t.STATUS_CODE = 'COMPLETE'
|
||||
""", new
|
||||
{
|
||||
UserId = userId.ToString(System.Globalization.CultureInfo.InvariantCulture), Ip = Cut(ip, 50), ClaimId = claimId,
|
||||
OldData = ClaimLogJson.Status(ClaimMessages.TripComplete), NewData = ClaimLogJson.Status(ClaimMessages.TripExchanged),
|
||||
}, ct);
|
||||
return await ExecuteAsync("""
|
||||
UPDATE REFINERY_TRIPS SET STATUS_CODE = 'EXCHANGED', LAST_UPDATE_DATE = SYSDATE, UPDATED_BY = :UserLogin
|
||||
WHERE WAGE_CLAIM_ID = :ClaimId AND STATUS_CODE = 'COMPLETE'
|
||||
""", new { UserLogin = userLogin, ClaimId = claimId }, ct);
|
||||
}
|
||||
|
||||
public Task SetClaimStatusAsync(long claimId, string status, string userLogin, CancellationToken ct = default) =>
|
||||
ExecuteAsync("""
|
||||
UPDATE REFINERY_WAGE_CLAIM SET STATUS_CODE = :Status, LAST_UPDATE_DATE = SYSDATE, UPDATED_BY = :UserLogin WHERE ID = :Id
|
||||
|
|
|
|||
|
|
@ -54,11 +54,12 @@ public class WageClaimServiceTests
|
|||
public List<string> TripStatuses = ["EXCHANGED"];
|
||||
public List<TransferTripRow> ToTransfer = [];
|
||||
public int Candidates = 5;
|
||||
public long? CommissionId;
|
||||
public readonly List<string> Writes = [];
|
||||
|
||||
public Task<PagedResult<WageClaimRowDto>> SearchAsync(WageClaimQuery query, PageRequest page, CancellationToken ct = default) => throw new NotSupportedException();
|
||||
public Task<WageClaimRowDto?> GetAsync(long id, CancellationToken ct = default) =>
|
||||
Task.FromResult<WageClaimRowDto?>(new WageClaimRowDto { Id = id, WageClaimNo = 20230100041, StatusCode = ClaimStatus });
|
||||
Task.FromResult<WageClaimRowDto?>(new WageClaimRowDto { Id = id, WageClaimNo = 20230100041, StatusCode = ClaimStatus, CommissionClaimId = CommissionId });
|
||||
public Task<PagedResult<ClaimTripRowDto>> ClaimTripsAsync(long claimId, PageRequest page, CancellationToken ct = default) => throw new NotSupportedException();
|
||||
public Task<PagedResult<ClaimTripRowDto>> CandidateTripsAsync(IReadOnlyList<string> statuses, DateOnly? from, DateOnly? to, PageRequest page, CancellationToken ct = default) => throw new NotSupportedException();
|
||||
public Task<int> CountCandidateTripsAsync(IReadOnlyList<string> statuses, DateOnly from, DateOnly to, CancellationToken ct = default) => Task.FromResult(Candidates);
|
||||
|
|
@ -66,6 +67,7 @@ public class WageClaimServiceTests
|
|||
public Task<int> AttachTripsAsync(long claimId, IReadOnlyList<string> statuses, DateOnly from, DateOnly to, CancellationToken ct = default) { Writes.Add("attach:" + claimId + ":" + string.Join('+', statuses)); return Task.FromResult(Candidates); }
|
||||
public Task<IReadOnlyList<string>> ClaimTripStatusesAsync(long claimId, CancellationToken ct = default) => Task.FromResult<IReadOnlyList<string>>(TripStatuses);
|
||||
public Task<int> CompleteClaimTripsAsync(long claimId, string userLogin, long userId, string? ip, CancellationToken ct = default) { Writes.Add("tripsComplete:" + userLogin + ":" + userId); return Task.FromResult(1); }
|
||||
public Task<int> ReopenClaimTripsAsync(long claimId, string userLogin, long userId, string? ip, CancellationToken ct = default) { Writes.Add("tripsReopen:" + userLogin + ":" + userId); return Task.FromResult(1); }
|
||||
public Task SetClaimStatusAsync(long claimId, string status, string userLogin, CancellationToken ct = default) { Writes.Add("status:" + status); return Task.CompletedTask; }
|
||||
public Task<IReadOnlyList<TransferTripRow>> TripsToTransferAsync(long claimId, CancellationToken ct = default) => Task.FromResult<IReadOnlyList<TransferTripRow>>(ToTransfer);
|
||||
public Task MarkTripTransferredAsync(TransferTripRow trip, long userId, string? ip, CancellationToken ct = default) { Writes.Add("transferred:" + trip.Id); return Task.CompletedTask; }
|
||||
|
|
@ -104,6 +106,26 @@ public class WageClaimServiceTests
|
|||
Assert.Equal(["tripsComplete:TESTER:77", "status:CLOSE", "log:CLAIM_CLOSE:{\"STATUS_CODE\":\"جديد\"}:{\"STATUS_CODE\":\"تم التسديد\"}"], repo.Writes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reopen_puts_the_trips_and_the_claim_back_and_logs_it()
|
||||
{
|
||||
var repo = new FakeRepo { ClaimStatus = "CLOSE" };
|
||||
await Service(repo).ReopenAsync(5, null, default);
|
||||
Assert.Equal(["tripsReopen:TESTER:77", "status:NEW", "log:CLAIM_REOPEN:{\"STATUS_CODE\":\"تم التسديد\"}:{\"STATUS_CODE\":\"جديد\"}"], repo.Writes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reopen_needs_a_closed_claim_without_a_commission_claim()
|
||||
{
|
||||
var notClosed = new FakeRepo { ClaimStatus = "NEW" };
|
||||
await Assert.ThrowsAsync<BusinessException>(() => Service(notClosed).ReopenAsync(5, null, default));
|
||||
var taken = new FakeRepo { ClaimStatus = "CLOSE", CommissionId = 3 };
|
||||
var ex = await Assert.ThrowsAsync<BusinessException>(() => Service(taken).ReopenAsync(5, null, default));
|
||||
Assert.Equal("REOPEN_HAS_COMMISSION", ex.Code);
|
||||
Assert.Empty(notClosed.Writes);
|
||||
Assert.Empty(taken.Writes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Close_is_refused_while_a_trip_is_not_exchanged()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -90,7 +90,8 @@ export function tripsGrid(onOpen: (r: TripGridRow) => void): GridMeta<TripGridRo
|
|||
key: GRID_TRIPS,
|
||||
endpoint: BASE,
|
||||
rowKey: (r) => r.id,
|
||||
status: { param: 'statusCode', options: statuses },
|
||||
// the two "filled" statuses are not offered as filters (their labels stay for display in the grid)
|
||||
status: { param: 'statusCode', options: statuses.filter((x) => x.value !== 'LOADING_FILL' && x.value !== 'DISCHARGING_FILL') },
|
||||
filters,
|
||||
onRowClick: onOpen,
|
||||
requireFilter: true,
|
||||
|
|
|
|||
|
|
@ -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, TextField, Typography,
|
||||
TableHead, TableRow, TextField, Typography,
|
||||
} from '@mui/material';
|
||||
import SummarizeIcon from '@mui/icons-material/Summarize';
|
||||
import PrintIcon from '@mui/icons-material/Print';
|
||||
|
|
@ -16,6 +16,7 @@ import VisibilityOutlined from '@mui/icons-material/VisibilityOutlined';
|
|||
import { DataGrid } from '@/components/DataGrid';
|
||||
import { LoadingBanner } from '@/components/LoadingBanner';
|
||||
import { PageHeader } from '@/components/PageHeader';
|
||||
import { Pager } from '@/components/Pager';
|
||||
import { SectionPaper } from '@/components/SectionPaper';
|
||||
import { SectionTitle } from '@/components/SectionTitle';
|
||||
import { StatusChip } from '@/components/StatusChip';
|
||||
|
|
@ -321,8 +322,7 @@ function TripLog({ tripId }: { tripId: number }) {
|
|||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<TablePagination component="div" count={q.data.totalCount} page={page - 1} rowsPerPage={10} rowsPerPageOptions={[10]}
|
||||
onPageChange={(_, p) => setPage(p + 1)} />
|
||||
<Pager count={q.data.totalCount} page={page - 1} rowsPerPage={10} rowsPerPageOptions={[10]} onPageChange={(_, p) => setPage(p + 1)} />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
|
@ -333,11 +333,22 @@ function TripLog({ tripId }: { tripId: number }) {
|
|||
}
|
||||
|
||||
function parse(json: string | null): Record<string, unknown> {
|
||||
try { return json ? (JSON.parse(json) as Record<string, unknown>) : {}; } catch { return {}; }
|
||||
if (!json) return {};
|
||||
try {
|
||||
const v = JSON.parse(json) as unknown;
|
||||
if (v && typeof v === 'object') return v as Record<string, unknown>;
|
||||
} catch { /* plain word, see below */ }
|
||||
return { STATUS_CODE: json }; // some old rows hold just the status word
|
||||
}
|
||||
|
||||
function LogDialog({ row, onClose }: { row: TripLogRow | null; onClose: () => void }) {
|
||||
const { t } = useFeatureUi(strings);
|
||||
const { t, tr } = useFeatureUi(strings);
|
||||
/** Status codes shown as captions; any other value stays as it is. */
|
||||
const val = (x: unknown) => {
|
||||
const s = String(x ?? '');
|
||||
const hit = statuses.find((st) => st.value === s.replace(/^STATUSCODE\./i, ''));
|
||||
return hit ? tr(hit.label) : s;
|
||||
};
|
||||
const oldD = parse(row?.oldData ?? null);
|
||||
const newD = parse(row?.newData ?? null);
|
||||
const keys = [...new Set([...Object.keys(oldD), ...Object.keys(newD)])];
|
||||
|
|
@ -357,8 +368,8 @@ function LogDialog({ row, onClose }: { row: TripLogRow | null; onClose: () => vo
|
|||
{keys.map((k) => (
|
||||
<TableRow key={k}>
|
||||
<TableCell>{propertyCaptions[k] ?? k}</TableCell>
|
||||
<TableCell>{String(oldD[k] ?? '')}</TableCell>
|
||||
<TableCell>{String(newD[k] ?? '')}</TableCell>
|
||||
<TableCell>{val(oldD[k])}</TableCell>
|
||||
<TableCell>{val(newD[k])}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ export const methodCaptions: Record<string, string> = {
|
|||
RECEIPT: 'استلام',
|
||||
PAYMENT: 'تسديد',
|
||||
TRIP_COMPLETE: 'تسديد',
|
||||
TRIP_REOPEN: 'اعادة فتح',
|
||||
ACTIVATE_WALLET_EXCHANGE: 'تفعيل صرف المحفظة',
|
||||
CACH_PAYMENT: 'دفع نقدي',
|
||||
ORANGE_PAYMENT: 'دفع اورنج',
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ export function useCreateWageClaim() {
|
|||
}
|
||||
|
||||
/** After close / transfer the claim, its trips and its log change. */
|
||||
function useClaimAction(action: 'close' | 'transfer') {
|
||||
function useClaimAction(action: 'close' | 'transfer' | 'reopen') {
|
||||
const qc = useQueryClient();
|
||||
return useWrite((id: number) => api.post<ClaimResult>(`${BASE}/${id}/${action}`), {
|
||||
invalidate: [gridKey(GRID_WAGE_CLAIMS)],
|
||||
|
|
@ -57,4 +57,5 @@ function useClaimAction(action: 'close' | 'transfer') {
|
|||
});
|
||||
}
|
||||
export const useCloseWageClaim = () => useClaimAction('close');
|
||||
export const useTransferWageClaim = () => useClaimAction('transfer');
|
||||
export const useReopenWageClaim = () => useClaimAction('reopen');
|
||||
export const useTransferWageClaim =() => useClaimAction('transfer');
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
import { useState, type ElementType, type ReactNode } from 'react';
|
||||
import {
|
||||
Box, Button, Collapse, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, Stack, Table, TableBody, TableCell, TableContainer,
|
||||
TableHead, TablePagination, TableRow, Tooltip, Typography,
|
||||
TableHead, TableRow, Tooltip, Typography,
|
||||
} from '@mui/material';
|
||||
import HistoryIcon from '@mui/icons-material/History';
|
||||
import VisibilityOutlined from '@mui/icons-material/VisibilityOutlined';
|
||||
import type { PagedResult } from '@/api/client';
|
||||
import { CopyCell } from '@/components/DataGrid';
|
||||
import { LoadingBanner } from '@/components/LoadingBanner';
|
||||
import { Pager } from '@/components/Pager';
|
||||
import { SectionPaper } from '@/components/SectionPaper';
|
||||
import { SectionTitle } from '@/components/SectionTitle';
|
||||
import { StatusChip } from '@/components/StatusChip';
|
||||
import { formatDate, formatDateTime } from '@/components/meta/format';
|
||||
import { useFeatureUi } from '@/i18n/useUi';
|
||||
import { BASE, useClaimLog } from './api';
|
||||
import { tripStatuses } from './meta';
|
||||
import { claimStatuses, tripStatuses } from './meta';
|
||||
import { propertyCaptions } from '../trips/strings';
|
||||
import strings from './strings';
|
||||
import type { ClaimLogRow, ClaimTripRow } from './types';
|
||||
|
||||
|
|
@ -75,23 +77,22 @@ export function TripsTable(p: {
|
|||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
<TablePagination
|
||||
component="div" count={p.data?.totalCount ?? 0} page={p.page - 1} rowsPerPage={p.pageSize} rowsPerPageOptions={PAGE_SIZES}
|
||||
<Pager
|
||||
count={p.data?.totalCount ?? 0} page={p.page - 1} rowsPerPage={p.pageSize} rowsPerPageOptions={PAGE_SIZES}
|
||||
onPageChange={(_, v) => p.onPage(v + 1)} onRowsPerPageChange={(e) => { p.onPageSize(Number(e.target.value)); p.onPage(1); }}
|
||||
sx={{ direction: 'ltr' }}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** OLD_DATA / NEW_DATA hold a small JSON object ({"STATUS_CODE":"..."}) or a plain word: show "key: value" lines. */
|
||||
function dataLines(text: string | null): string[] {
|
||||
function dataLines(text: string | null, caption: (key: string) => string, value: (v: string) => string): string[] {
|
||||
if (!text) return [];
|
||||
try {
|
||||
const v = JSON.parse(text) as unknown;
|
||||
if (v && typeof v === 'object') return Object.entries(v as Record<string, unknown>).map(([k, x]) => `${k}: ${String(x)}`);
|
||||
if (v && typeof v === 'object') return Object.entries(v as Record<string, unknown>).map(([k, x]) => `${caption(k)}: ${value(String(x))}`);
|
||||
} catch { /* not JSON */ }
|
||||
return [text];
|
||||
return [value(text)];
|
||||
}
|
||||
|
||||
/** Log popup of a claim (legacy "سجل الحركات"): the history of the record, with a view of the old / new data of each action. */
|
||||
|
|
@ -107,6 +108,16 @@ export function ClaimLogSection({ id, base = BASE }: { id: number; base?: string
|
|||
const key = `wc.log.${code}` as keyof typeof strings;
|
||||
return strings[key] ? tr(strings[key]) : code;
|
||||
};
|
||||
/** Status codes (CLOSE, COMPLETE, EXCHANGED...) shown as their captions; any other text stays as it is. */
|
||||
const val = (v: string) => {
|
||||
const code = v.replace(/^STATUSCODE\./i, ''); // some rows hold "STATUSCODE.NEW"
|
||||
const hit = [...claimStatuses, ...tripStatuses].find((s) => s.value === code);
|
||||
return hit ? tr(hit.label) : v;
|
||||
};
|
||||
const prop = (k: string) => {
|
||||
const key = `wc.log.prop.${k}` as keyof typeof strings;
|
||||
return strings[key] ? tr(strings[key]) : (propertyCaptions[k] ?? k);
|
||||
};
|
||||
return (
|
||||
<SectionPaper sx={{ p: 2 }}>
|
||||
<Box role="button" tabIndex={0} aria-expanded={open} onClick={() => setOpen((o) => !o)}
|
||||
|
|
@ -146,9 +157,9 @@ export function ClaimLogSection({ id, base = BASE }: { id: number; base?: string
|
|||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
<TablePagination
|
||||
component="div" count={q.data?.totalCount ?? 0} page={page - 1} rowsPerPage={size} rowsPerPageOptions={[5, 10, 25]}
|
||||
onPageChange={(_, v) => setPage(v + 1)} onRowsPerPageChange={(e) => { setSize(Number(e.target.value)); setPage(1); }} sx={{ direction: 'ltr' }}
|
||||
<Pager
|
||||
count={q.data?.totalCount ?? 0} page={page - 1} rowsPerPage={size} rowsPerPageOptions={[5, 10, 25]}
|
||||
onPageChange={(_, v) => setPage(v + 1)} onRowsPerPageChange={(e) => { setSize(Number(e.target.value)); setPage(1); }}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
|
@ -159,11 +170,11 @@ export function ClaimLogSection({ id, base = BASE }: { id: number; base?: string
|
|||
<Stack spacing={2}>
|
||||
<Box>
|
||||
<Typography variant="caption" color="primary">{t('wc.log.old')}</Typography>
|
||||
{dataLines(detail?.oldData ?? null).map((x, i) => <Typography key={i} variant="body2">{x}</Typography>)}
|
||||
{dataLines(detail?.oldData ?? null, prop, val).map((x, i) => <Typography key={i} variant="body2">{x}</Typography>)}
|
||||
</Box>
|
||||
<Box>
|
||||
<Typography variant="caption" color="primary">{t('wc.log.new')}</Typography>
|
||||
{dataLines(detail?.newData ?? null).map((x, i) => <Typography key={i} variant="body2">{x}</Typography>)}
|
||||
{dataLines(detail?.newData ?? null, prop, val).map((x, i) => <Typography key={i} variant="body2">{x}</Typography>)}
|
||||
</Box>
|
||||
</Stack>
|
||||
</DialogContent>
|
||||
|
|
|
|||
|
|
@ -45,8 +45,16 @@ const filters: FilterMeta[] = [
|
|||
];
|
||||
|
||||
/** Legacy REFINERY_WAGE_CLAIMGRID: no, date, trips, commission claim no, status; filtered to NEW claims on opening (args STATUS_CODE NEW). */
|
||||
export function wageClaimGrid(onOpen: (r: WageClaimRow) => void): GridMeta<WageClaimRow> {
|
||||
export function wageClaimGrid(
|
||||
onOpen: (r: WageClaimRow) => void,
|
||||
status?: { canChange: boolean; onClose: (r: WageClaimRow) => void; onReopen: (r: WageClaimRow) => void },
|
||||
): GridMeta<WageClaimRow> {
|
||||
return {
|
||||
// NEW -> close, CLOSE -> back to new, nothing for the other statuses
|
||||
rowActions: status?.canChange ? [
|
||||
{ key: 'close', label: l('wc.close'), hidden: (r) => r.statusCode !== 'NEW', onClick: status.onClose },
|
||||
{ key: 'reopen', label: l('wc.reopen'), hidden: (r) => r.statusCode !== 'CLOSE', onClick: status.onReopen },
|
||||
] : undefined,
|
||||
key: GRID_WAGE_CLAIMS,
|
||||
endpoint: '/refinery/wage-claims',
|
||||
rowKey: (r) => r.id,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import { useConfirm } from '@/providers/ConfirmProvider';
|
|||
import { useToast } from '@/providers/ToastProvider';
|
||||
import { downloadFile } from '../../grains-orders/api';
|
||||
import {
|
||||
BASE, useCandidateTrips, useClaimTrips, useCloseWageClaim, useCreateWageClaim, useTransferWageClaim, useWageClaim,
|
||||
BASE, useCandidateTrips, useClaimTrips, useCloseWageClaim, useCreateWageClaim, useReopenWageClaim, useTransferWageClaim, useWageClaim,
|
||||
} from './api';
|
||||
import { Block, ClaimLogSection, TripsTable } from './components';
|
||||
import { claimableTripStatuses, claimStatuses, tripStatusLabelKey, wageClaimGrid } from './meta';
|
||||
|
|
@ -32,7 +32,15 @@ export function WageClaimsPage() {
|
|||
const { t } = useFeatureUi(strings);
|
||||
const { can } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const meta = useMemo(() => wageClaimGrid((r) => navigate(`${ROOT}/${r.id}`)), [navigate]);
|
||||
const confirm = useConfirm();
|
||||
const close = useCloseWageClaim();
|
||||
const reopen = useReopenWageClaim();
|
||||
const canChange = can('refinery.wageClaims.close');
|
||||
const meta = useMemo(() => wageClaimGrid((r) => navigate(`${ROOT}/${r.id}`), {
|
||||
canChange,
|
||||
onClose: async (r) => { if (await confirm({ message: t('wc.closeConfirm') })) close.mutate(r.id); },
|
||||
onReopen: async (r) => { if (await confirm({ message: t('wc.reopenConfirm') })) reopen.mutate(r.id); },
|
||||
}), [navigate, canChange, confirm, close, reopen, t]);
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
|
|
|
|||
|
|
@ -68,6 +68,10 @@ export default defineStrings({
|
|||
|
||||
// ---- actions
|
||||
'wc.close': { en: 'Pay', ar: 'تسديد' }, // REFINERY_WAGE_CLAIM.CLAIM_CLOSE
|
||||
'wc.reopen': { en: 'Back to new', ar: 'اعادة الى جديد' },
|
||||
'wc.reopenConfirm': { en: 'Return this claim to New? Its trips go back to Exchanged.', ar: 'هل تريد اعادة هذه المطالبة الى حالة جديد؟ ستعود ارسالياتها الى حالة تم الصرف.' },
|
||||
'wc.log.CLAIM_REOPEN': { en: 'Reopen', ar: 'اعادة فتح' },
|
||||
'wc.log.prop.STATUS_CODE': { en: 'Status', ar: 'الحالة' },
|
||||
'wc.closeConfirm': { en: 'Do you want to mark this claim as paid? Its trips become complete.', ar: 'هل تريد تسديد هذه المطالبة؟ ستصبح ارسالياتها مكتملة.' }, // new
|
||||
'wc.transfer': { en: 'Transfer', ar: 'ترحيل' }, // REFINERY_WAGE_CLAIM.TRANSFER
|
||||
'wc.transferConfirm': { en: 'Send this claim to the refinery (Jopetrol)?', ar: 'هل تريد ترحيل هذه المطالبة إلى المصفاة؟' }, // new
|
||||
|
|
|
|||
Loading…
Reference in New Issue