started implementing pwc invoice enhanced cost and expence capturing

This commit is contained in:
laxmanhalaki 2026-02-09 20:53:39 +05:30
parent edd1967336
commit 08cda349f3
6 changed files with 1656 additions and 1237 deletions

View File

@ -18,11 +18,11 @@ interface ActivityInformationCardProps {
updatedAt?: string | Date; updatedAt?: string | Date;
} }
export function ActivityInformationCard({ export function ActivityInformationCard({
activityInfo, activityInfo,
className, className,
createdAt, createdAt,
updatedAt updatedAt
}: ActivityInformationCardProps) { }: ActivityInformationCardProps) {
// Defensive check: Ensure activityInfo exists // Defensive check: Ensure activityInfo exists
if (!activityInfo) { if (!activityInfo) {
@ -109,7 +109,7 @@ export function ActivityInformationCard({
</label> </label>
<p className="text-sm text-gray-900 font-medium mt-1 flex items-center gap-2"> <p className="text-sm text-gray-900 font-medium mt-1 flex items-center gap-2">
<DollarSign className="w-4 h-4 text-green-600" /> <DollarSign className="w-4 h-4 text-green-600" />
{activityInfo.estimatedBudget {activityInfo.estimatedBudget
? formatCurrency(activityInfo.estimatedBudget) ? formatCurrency(activityInfo.estimatedBudget)
: 'TBD'} : 'TBD'}
</p> </p>
@ -147,23 +147,40 @@ export function ActivityInformationCard({
<label className="text-xs font-medium text-gray-500 uppercase tracking-wide mb-3 block"> <label className="text-xs font-medium text-gray-500 uppercase tracking-wide mb-3 block">
Closed Expenses Breakdown Closed Expenses Breakdown
</label> </label>
<div className="bg-blue-50 border border-blue-200 rounded-lg p-3 space-y-2"> <div className="bg-blue-50 border border-blue-200 rounded-lg overflow-hidden">
{activityInfo.closedExpensesBreakdown.map((item: { description: string; amount: number }, index: number) => ( <table className="w-full text-xs sm:text-sm">
<div key={index} className="flex justify-between items-center text-sm"> <thead className="bg-blue-100/50">
<span className="text-gray-700">{item.description}</span> <tr>
<span className="font-medium text-gray-900"> <th className="px-3 py-2 text-left font-semibold text-blue-900">Description</th>
{formatCurrency(item.amount)} <th className="px-3 py-2 text-right font-semibold text-blue-900 w-24">Base</th>
</span> <th className="px-3 py-2 text-right font-semibold text-blue-900 w-24">GST</th>
</div> <th className="px-3 py-2 text-right font-semibold text-blue-900 w-28">Total</th>
))} </tr>
<div className="pt-2 border-t border-blue-300 flex justify-between items-center"> </thead>
<span className="font-semibold text-gray-900">Total</span> <tbody className="divide-y divide-blue-200/50">
<span className="font-bold text-blue-600"> {activityInfo.closedExpensesBreakdown.map((item: any, index: number) => (
{formatCurrency( <tr key={index} className="hover:bg-blue-100/30">
activityInfo.closedExpensesBreakdown.reduce((sum: number, item: { description: string; amount: number }) => sum + item.amount, 0) <td className="px-3 py-2 text-gray-700">
)} {item.description}
</span> {item.gstRate ? <span className="text-[10px] text-gray-400 block">{item.gstRate}% GST</span> : null}
</div> </td>
<td className="px-3 py-2 text-right text-gray-900">{formatCurrency(item.amount)}</td>
<td className="px-3 py-2 text-right text-gray-900">{formatCurrency(item.gstAmt || 0)}</td>
<td className="px-3 py-2 text-right font-medium text-gray-900">
{formatCurrency(item.totalAmt || (item.amount + (item.gstAmt || 0)))}
</td>
</tr>
))}
<tr className="bg-blue-100/50 font-bold">
<td colSpan={3} className="px-3 py-2 text-blue-900">Final Claim Amount</td>
<td className="px-3 py-2 text-right text-blue-700">
{formatCurrency(
activityInfo.closedExpensesBreakdown.reduce((sum: number, item: any) => sum + (item.totalAmt || (item.amount + (item.gstAmt || 0))), 0)
)}
</td>
</tr>
</tbody>
</table>
</div> </div>
</div> </div>
)} )}
@ -175,8 +192,8 @@ export function ActivityInformationCard({
Description Description
</label> </label>
<div className="mt-2 bg-gray-50 p-3 rounded-lg border border-gray-200"> <div className="mt-2 bg-gray-50 p-3 rounded-lg border border-gray-200">
<FormattedDescription <FormattedDescription
content={activityInfo.description || ''} content={activityInfo.description || ''}
className="text-sm" className="text-sm"
/> />
</div> </div>

View File

@ -26,6 +26,11 @@ interface DMSDetails {
remarks?: string; remarks?: string;
createdByName?: string; createdByName?: string;
createdAt?: string; createdAt?: string;
// PWC fields
irn?: string;
ackNo?: string;
ackDate?: string;
signedInvoiceUrl?: string;
} }
interface ClaimAmountDetails { interface ClaimAmountDetails {
@ -37,6 +42,8 @@ interface ClaimAmountDetails {
interface CostBreakdownItem { interface CostBreakdownItem {
description: string; description: string;
amount: number; amount: number;
gstAmt?: number;
totalAmt?: number;
} }
interface RoleBasedVisibility { interface RoleBasedVisibility {
@ -85,7 +92,7 @@ export function ProcessDetailsCard({
const calculateTotal = (items?: CostBreakdownItem[]) => { const calculateTotal = (items?: CostBreakdownItem[]) => {
if (!items || items.length === 0) return 0; if (!items || items.length === 0) return 0;
return items.reduce((sum, item) => sum + (item.amount ?? 0), 0); return items.reduce((sum, item) => sum + (item.totalAmt ?? (item.amount + (item.gstAmt ?? 0))), 0);
}; };
// Don't render if nothing to show // Don't render if nothing to show
@ -120,7 +127,7 @@ export function ProcessDetailsCard({
</Label> </Label>
</div> </div>
<p className="font-bold text-gray-900 mb-2">{ioDetails.ioNumber}</p> <p className="font-bold text-gray-900 mb-2">{ioDetails.ioNumber}</p>
{ioDetails.remarks && ( {ioDetails.remarks && (
<div className="pt-2 border-t border-blue-100"> <div className="pt-2 border-t border-blue-100">
<p className="text-xs text-gray-600 mb-1">Remark:</p> <p className="text-xs text-gray-600 mb-1">Remark:</p>
@ -171,21 +178,54 @@ export function ProcessDetailsCard({
<div className="flex items-center gap-2 mb-2"> <div className="flex items-center gap-2 mb-2">
<Activity className="w-4 h-4 text-purple-600" /> <Activity className="w-4 h-4 text-purple-600" />
<Label className="text-xs font-semibold text-purple-900 uppercase tracking-wide"> <Label className="text-xs font-semibold text-purple-900 uppercase tracking-wide">
DMS Number DMS & E-Invoice Details
</Label> </Label>
</div> </div>
<p className="font-bold text-gray-900 mb-2">{dmsDetails.dmsNumber}</p>
<div className="grid grid-cols-2 gap-3 mb-2">
<div>
<p className="text-[10px] text-gray-500 uppercase">DMS Number</p>
<p className="font-bold text-sm text-gray-900">{dmsDetails.dmsNumber || 'N/A'}</p>
</div>
{dmsDetails.ackNo && (
<div>
<p className="text-[10px] text-gray-500 uppercase">Ack No</p>
<p className="font-bold text-sm text-purple-700">{dmsDetails.ackNo}</p>
</div>
)}
</div>
{dmsDetails.irn && (
<div className="mb-2 p-2 bg-purple-50 rounded border border-purple-100">
<p className="text-[10px] text-purple-600 uppercase font-semibold">IRN</p>
<p className="text-[10px] font-mono break-all text-gray-700 leading-tight">
{dmsDetails.irn}
</p>
</div>
)}
{dmsDetails.signedInvoiceUrl && (
<Button
variant="outline"
size="sm"
className="w-full h-8 text-xs gap-2 mb-2 border-purple-200 text-purple-700 hover:bg-purple-50"
onClick={() => window.open(dmsDetails.signedInvoiceUrl, '_blank')}
>
<Receipt className="w-3.5 h-3.5" />
View E-Invoice
</Button>
)}
{dmsDetails.remarks && ( {dmsDetails.remarks && (
<div className="pt-2 border-t border-purple-100"> <div className="pt-2 border-t border-purple-100">
<p className="text-xs text-gray-600 mb-1">Remarks:</p> <p className="text-[10px] text-gray-500 uppercase mb-1">Remarks</p>
<p className="text-xs text-gray-900">{dmsDetails.remarks}</p> <p className="text-xs text-gray-900">{dmsDetails.remarks}</p>
</div> </div>
)} )}
<div className="pt-2 border-t border-purple-100 mt-2"> <div className="pt-2 border-t border-purple-100 mt-2">
<p className="text-xs text-gray-500">By {dmsDetails.createdByName}</p> <p className="text-[10px] text-gray-500">By {dmsDetails.createdByName}</p>
<p className="text-xs text-gray-500">{formatDate(dmsDetails.createdAt)}</p> <p className="text-[10px] text-gray-500">{formatDate(dmsDetails.createdAt)}</p>
</div> </div>
</div> </div>
)} )}
@ -241,10 +281,10 @@ export function ProcessDetailsCard({
</div> </div>
<div className="space-y-1.5 pt-1"> <div className="space-y-1.5 pt-1">
{estimatedBudgetBreakdown.map((item, index) => ( {estimatedBudgetBreakdown.map((item, index) => (
<div key={index} className="flex justify-between items-center text-xs"> <div key={index} className="flex justify-between items-center text-[10px] sm:text-xs">
<span className="text-gray-700">{item.description}</span> <div className="text-gray-700 truncate mr-2" title={item.description}>{item.description}</div>
<span className="font-medium text-gray-900"> <span className="font-medium text-gray-900 whitespace-nowrap">
{formatCurrency(item.amount)} {formatCurrency(item.totalAmt ?? (item.amount + (item.gstAmt ?? 0)))}
</span> </span>
</div> </div>
))} ))}
@ -269,10 +309,10 @@ export function ProcessDetailsCard({
</div> </div>
<div className="space-y-1.5 pt-1"> <div className="space-y-1.5 pt-1">
{closedExpensesBreakdown.map((item, index) => ( {closedExpensesBreakdown.map((item, index) => (
<div key={index} className="flex justify-between items-center text-xs"> <div key={index} className="flex justify-between items-center text-[10px] sm:text-xs">
<span className="text-gray-700">{item.description}</span> <div className="text-gray-700 truncate mr-2" title={item.description}>{item.description}</div>
<span className="font-medium text-gray-900"> <span className="font-medium text-gray-900 whitespace-nowrap">
{formatCurrency(item.amount)} {formatCurrency(item.totalAmt ?? (item.amount + (item.gstAmt ?? 0)))}
</span> </span>
</div> </div>
))} ))}

View File

@ -11,6 +11,12 @@ import { format } from 'date-fns';
interface ProposalCostItem { interface ProposalCostItem {
description: string; description: string;
amount?: number | null; amount?: number | null;
gstRate?: number;
gstAmt?: number;
cgstAmt?: number;
sgstAmt?: number;
igstAmt?: number;
totalAmt?: number;
} }
interface ProposalDetails { interface ProposalDetails {
@ -32,7 +38,7 @@ export function ProposalDetailsCard({ proposalDetails, className }: ProposalDeta
if (proposalDetails.estimatedBudgetTotal !== undefined && proposalDetails.estimatedBudgetTotal !== null) { if (proposalDetails.estimatedBudgetTotal !== undefined && proposalDetails.estimatedBudgetTotal !== null) {
return proposalDetails.estimatedBudgetTotal; return proposalDetails.estimatedBudgetTotal;
} }
// Calculate sum from costBreakup items // Calculate sum from costBreakup items
if (proposalDetails.costBreakup && proposalDetails.costBreakup.length > 0) { if (proposalDetails.costBreakup && proposalDetails.costBreakup.length > 0) {
const total = proposalDetails.costBreakup.reduce((sum, item) => { const total = proposalDetails.costBreakup.reduce((sum, item) => {
@ -41,7 +47,7 @@ export function ProposalDetailsCard({ proposalDetails, className }: ProposalDeta
}, 0); }, 0);
return total; return total;
} }
return 0; return 0;
}; };
@ -99,7 +105,13 @@ export function ProposalDetailsCard({ proposalDetails, className }: ProposalDeta
Item Description Item Description
</th> </th>
<th className="px-4 py-2 text-right text-xs font-semibold text-gray-700 uppercase tracking-wide"> <th className="px-4 py-2 text-right text-xs font-semibold text-gray-700 uppercase tracking-wide">
Amount Base Amount
</th>
<th className="px-4 py-2 text-right text-xs font-semibold text-gray-700 uppercase tracking-wide">
GST
</th>
<th className="px-4 py-2 text-right text-xs font-semibold text-gray-700 uppercase tracking-wide">
Total
</th> </th>
</tr> </tr>
</thead> </thead>
@ -107,16 +119,27 @@ export function ProposalDetailsCard({ proposalDetails, className }: ProposalDeta
{(proposalDetails.costBreakup || []).map((item, index) => ( {(proposalDetails.costBreakup || []).map((item, index) => (
<tr key={index} className="hover:bg-gray-50"> <tr key={index} className="hover:bg-gray-50">
<td className="px-4 py-3 text-sm text-gray-900"> <td className="px-4 py-3 text-sm text-gray-900">
{item.description} <div>{item.description}</div>
{item.gstRate ? (
<div className="text-[10px] text-gray-400">
{item.cgstAmt ? `CGST: ${item.gstRate / 2}%, SGST: ${item.gstRate / 2}%` : `IGST: ${item.gstRate}%`}
</div>
) : null}
</td>
<td className="px-4 py-3 text-sm text-gray-900 text-right">
{formatCurrency(item.amount)}
</td>
<td className="px-4 py-3 text-sm text-gray-900 text-right">
{formatCurrency(item.gstAmt)}
</td> </td>
<td className="px-4 py-3 text-sm text-gray-900 text-right font-medium"> <td className="px-4 py-3 text-sm text-gray-900 text-right font-medium">
{formatCurrency(item.amount)} {formatCurrency(item.totalAmt || (item.amount || 0) + (item.gstAmt || 0))}
</td> </td>
</tr> </tr>
))} ))}
<tr className="bg-green-50 font-semibold"> <tr className="bg-green-50 font-semibold">
<td className="px-4 py-3 text-sm text-gray-900"> <td colSpan={3} className="px-4 py-3 text-sm text-gray-900">
Estimated Budget (Total) Estimated Budget (Total Inclusive of GST)
</td> </td>
<td className="px-4 py-3 text-sm text-green-700 text-right"> <td className="px-4 py-3 text-sm text-green-700 text-right">
{formatCurrency(estimatedTotal)} {formatCurrency(estimatedTotal)}

View File

@ -26,7 +26,16 @@ export interface ClaimManagementRequest {
}; };
estimatedBudget?: number; estimatedBudget?: number;
closedExpenses?: number; closedExpenses?: number;
closedExpensesBreakdown?: Array<{ description: string; amount: number }>; closedExpensesBreakdown?: Array<{
description: string;
amount: number;
gstRate?: number;
gstAmt?: number;
cgstAmt?: number;
sgstAmt?: number;
igstAmt?: number;
totalAmt?: number;
}>;
description?: string; description?: string;
}; };
@ -42,7 +51,16 @@ export interface ClaimManagementRequest {
// Proposal Details (Step 1) // Proposal Details (Step 1)
proposalDetails?: { proposalDetails?: {
proposalDocumentUrl?: string; proposalDocumentUrl?: string;
costBreakup: Array<{ description: string; amount: number }>; costBreakup: Array<{
description: string;
amount: number;
gstRate?: number;
gstAmt?: number;
cgstAmt?: number;
sgstAmt?: number;
igstAmt?: number;
totalAmt?: number;
}>;
totalEstimatedBudget: number; totalEstimatedBudget: number;
timelineMode?: 'date' | 'days'; timelineMode?: 'date' | 'days';
expectedCompletionDate?: string; expectedCompletionDate?: string;
@ -70,6 +88,12 @@ export interface ClaimManagementRequest {
creditNoteNumber?: string; creditNoteNumber?: string;
creditNoteDate?: string; creditNoteDate?: string;
creditNoteAmount?: number; creditNoteAmount?: number;
// PWC Fields
irn?: string;
ackNo?: string;
ackDate?: string;
signedInvoiceUrl?: string;
taxBreakdown?: any;
}; };
// Claim Amount // Claim Amount
@ -108,7 +132,7 @@ export function mapToClaimManagementRequest(
const proposalDetails = apiRequest.proposalDetails || {}; const proposalDetails = apiRequest.proposalDetails || {};
const completionDetails = apiRequest.completionDetails || {}; const completionDetails = apiRequest.completionDetails || {};
const internalOrder = apiRequest.internalOrder || apiRequest.internal_order || {}; const internalOrder = apiRequest.internalOrder || apiRequest.internal_order || {};
// Extract new normalized tables // Extract new normalized tables
const budgetTracking = apiRequest.budgetTracking || apiRequest.budget_tracking || {}; const budgetTracking = apiRequest.budgetTracking || apiRequest.budget_tracking || {};
const invoice = apiRequest.invoice || {}; const invoice = apiRequest.invoice || {};
@ -121,44 +145,50 @@ export function mapToClaimManagementRequest(
// Handle both camelCase and snake_case field names from Sequelize // Handle both camelCase and snake_case field names from Sequelize
const periodStartDate = claimDetails.periodStartDate || claimDetails.period_start_date; const periodStartDate = claimDetails.periodStartDate || claimDetails.period_start_date;
const periodEndDate = claimDetails.periodEndDate || claimDetails.period_end_date; const periodEndDate = claimDetails.periodEndDate || claimDetails.period_end_date;
const activityName = claimDetails.activityName || claimDetails.activity_name || ''; const activityName = claimDetails.activityName || claimDetails.activity_name || '';
const activityType = claimDetails.activityType || claimDetails.activity_type || ''; const activityType = claimDetails.activityType || claimDetails.activity_type || '';
const location = claimDetails.location || ''; const location = claimDetails.location || '';
// Activity fields mapped // Activity fields mapped
// Get budget values from budgetTracking table (new source of truth) // Get budget values from budgetTracking table (new source of truth)
const estimatedBudget = budgetTracking.proposalEstimatedBudget || const estimatedBudget = budgetTracking.proposalEstimatedBudget ||
budgetTracking.proposal_estimated_budget || budgetTracking.proposal_estimated_budget ||
budgetTracking.initialEstimatedBudget || budgetTracking.initialEstimatedBudget ||
budgetTracking.initial_estimated_budget || budgetTracking.initial_estimated_budget ||
claimDetails.estimatedBudget || claimDetails.estimatedBudget ||
claimDetails.estimated_budget; claimDetails.estimated_budget;
// Get closed expenses - check multiple sources with proper number conversion // Get closed expenses - check multiple sources with proper number conversion
const closedExpensesRaw = budgetTracking?.closedExpenses || const closedExpensesRaw = budgetTracking?.closedExpenses ||
budgetTracking?.closed_expenses || budgetTracking?.closed_expenses ||
completionDetails?.totalClosedExpenses || completionDetails?.totalClosedExpenses ||
completionDetails?.total_closed_expenses || completionDetails?.total_closed_expenses ||
claimDetails?.closedExpenses || claimDetails?.closedExpenses ||
claimDetails?.closed_expenses; claimDetails?.closed_expenses;
// Convert to number and handle 0 as valid value // Convert to number and handle 0 as valid value
const closedExpenses = closedExpensesRaw !== null && closedExpensesRaw !== undefined const closedExpenses = closedExpensesRaw !== null && closedExpensesRaw !== undefined
? Number(closedExpensesRaw) ? Number(closedExpensesRaw)
: undefined; : undefined;
// Get closed expenses breakdown from new completionExpenses table // Get closed expenses breakdown from new completionExpenses table
const closedExpensesBreakdown = Array.isArray(completionExpenses) && completionExpenses.length > 0 const closedExpensesBreakdown = Array.isArray(completionExpenses) && completionExpenses.length > 0
? completionExpenses.map((exp: any) => ({ ? completionExpenses.map((exp: any) => ({
description: exp.description || exp.itemDescription || '', description: exp.description || exp.itemDescription || '',
amount: Number(exp.amount) || 0 amount: Number(exp.amount) || 0,
})) gstRate: exp.gstRate,
: (completionDetails?.closedExpenses || gstAmt: exp.gstAmt,
completionDetails?.closed_expenses || cgstAmt: exp.cgstAmt,
completionDetails?.closedExpensesBreakdown || sgstAmt: exp.sgstAmt,
[]); igstAmt: exp.igstAmt,
totalAmt: exp.totalAmt
}))
: (completionDetails?.closedExpenses ||
completionDetails?.closed_expenses ||
completionDetails?.closedExpensesBreakdown ||
[]);
const activityInfo = { const activityInfo = {
activityName, activityName,
activityType, activityType,
@ -200,7 +230,18 @@ export function mapToClaimManagementRequest(
const expectedCompletionDate = proposalDetails?.expectedCompletionDate || proposalDetails?.expected_completion_date; const expectedCompletionDate = proposalDetails?.expectedCompletionDate || proposalDetails?.expected_completion_date;
const proposal = proposalDetails ? { const proposal = proposalDetails ? {
proposalDocumentUrl: proposalDetails.proposalDocumentUrl || proposalDetails.proposal_document_url, proposalDocumentUrl: proposalDetails.proposalDocumentUrl || proposalDetails.proposal_document_url,
costBreakup: proposalDetails.costBreakup || proposalDetails.cost_breakup || [], costBreakup: Array.isArray(proposalDetails.costBreakup || proposalDetails.cost_breakup)
? (proposalDetails.costBreakup || proposalDetails.cost_breakup).map((item: any) => ({
description: item.description || '',
amount: Number(item.amount) || 0,
gstRate: item.gstRate,
gstAmt: item.gstAmt,
cgstAmt: item.cgstAmt,
sgstAmt: item.sgstAmt,
igstAmt: item.igstAmt,
totalAmt: item.totalAmt
}))
: [],
totalEstimatedBudget: proposalDetails.totalEstimatedBudget || proposalDetails.total_estimated_budget || 0, totalEstimatedBudget: proposalDetails.totalEstimatedBudget || proposalDetails.total_estimated_budget || 0,
timelineMode: proposalDetails.timelineMode || proposalDetails.timeline_mode, timelineMode: proposalDetails.timelineMode || proposalDetails.timeline_mode,
expectedCompletionDate: expectedCompletionDate, expectedCompletionDate: expectedCompletionDate,
@ -223,21 +264,27 @@ export function mapToClaimManagementRequest(
// Map DMS details from new invoice and credit note tables // Map DMS details from new invoice and credit note tables
const dmsDetails = { const dmsDetails = {
eInvoiceNumber: invoice.invoiceNumber || invoice.invoice_number || eInvoiceNumber: invoice.invoiceNumber || invoice.invoice_number ||
claimDetails.eInvoiceNumber || claimDetails.e_invoice_number, claimDetails.eInvoiceNumber || claimDetails.e_invoice_number,
eInvoiceDate: invoice.invoiceDate || invoice.invoice_date || eInvoiceDate: invoice.invoiceDate || invoice.invoice_date ||
claimDetails.eInvoiceDate || claimDetails.e_invoice_date, claimDetails.eInvoiceDate || claimDetails.e_invoice_date,
dmsNumber: invoice.dmsNumber || invoice.dms_number || dmsNumber: invoice.dmsNumber || invoice.dms_number ||
claimDetails.dmsNumber || claimDetails.dms_number, claimDetails.dmsNumber || claimDetails.dms_number,
creditNoteNumber: creditNote.creditNoteNumber || creditNote.credit_note_number || creditNoteNumber: creditNote.creditNoteNumber || creditNote.credit_note_number ||
claimDetails.creditNoteNumber || claimDetails.credit_note_number, claimDetails.creditNoteNumber || claimDetails.credit_note_number,
creditNoteDate: creditNote.creditNoteDate || creditNote.credit_note_date || creditNoteDate: creditNote.creditNoteDate || creditNote.credit_note_date ||
claimDetails.creditNoteDate || claimDetails.credit_note_date, claimDetails.creditNoteDate || claimDetails.credit_note_date,
creditNoteAmount: creditNote.creditNoteAmount ? Number(creditNote.creditNoteAmount) : creditNoteAmount: creditNote.creditNoteAmount ? Number(creditNote.creditNoteAmount) :
(creditNote.credit_note_amount ? Number(creditNote.credit_note_amount) : (creditNote.credit_note_amount ? Number(creditNote.credit_note_amount) :
(creditNote.creditNoteAmount ? Number(creditNote.creditNoteAmount) : (creditNote.creditNoteAmount ? Number(creditNote.creditNoteAmount) :
(claimDetails.creditNoteAmount ? Number(claimDetails.creditNoteAmount) : (claimDetails.creditNoteAmount ? Number(claimDetails.creditNoteAmount) :
(claimDetails.credit_note_amount ? Number(claimDetails.credit_note_amount) : undefined)))), (claimDetails.credit_note_amount ? Number(claimDetails.credit_note_amount) : undefined)))),
// PWC fields
irn: invoice.irn || claimDetails.irn,
ackNo: invoice.ackNo || claimDetails.ackNo,
ackDate: invoice.ackDate || claimDetails.ackDate,
signedInvoiceUrl: invoice.signedInvoiceUrl || claimDetails.signedInvoiceUrl,
taxBreakdown: invoice.taxBreakdown || claimDetails.taxBreakdown,
}; };
// Map claim amounts // Map claim amounts
@ -266,15 +313,15 @@ export function mapToClaimManagementRequest(
export function determineUserRole(apiRequest: any, currentUserId: string): RequestRole { export function determineUserRole(apiRequest: any, currentUserId: string): RequestRole {
try { try {
// Check if user is the initiator // Check if user is the initiator
if (apiRequest.initiatorId === currentUserId || if (apiRequest.initiatorId === currentUserId ||
apiRequest.initiator?.userId === currentUserId || apiRequest.initiator?.userId === currentUserId ||
apiRequest.requestedBy?.userId === currentUserId) { apiRequest.requestedBy?.userId === currentUserId) {
return 'INITIATOR'; return 'INITIATOR';
} }
// Check if user is a dealer (participant with DEALER type) // Check if user is a dealer (participant with DEALER type)
const participants = apiRequest.participants || []; const participants = apiRequest.participants || [];
const dealerParticipant = participants.find((p: any) => const dealerParticipant = participants.find((p: any) =>
(p.userId === currentUserId || p.user?.userId === currentUserId) && (p.userId === currentUserId || p.user?.userId === currentUserId) &&
(p.participantType === 'DEALER' || p.type === 'DEALER') (p.participantType === 'DEALER' || p.type === 'DEALER')
); );
@ -284,7 +331,7 @@ export function determineUserRole(apiRequest: any, currentUserId: string): Reque
// Check if user is a department lead (approver at level 3) // Check if user is a department lead (approver at level 3)
const approvalLevels = apiRequest.approvalLevels || []; const approvalLevels = apiRequest.approvalLevels || [];
const deptLeadLevel = approvalLevels.find((level: any) => const deptLeadLevel = approvalLevels.find((level: any) =>
level.levelNumber === 3 && level.levelNumber === 3 &&
(level.approverId === currentUserId || level.approver?.userId === currentUserId) (level.approverId === currentUserId || level.approver?.userId === currentUserId)
); );
@ -293,7 +340,7 @@ export function determineUserRole(apiRequest: any, currentUserId: string): Reque
} }
// Check if user is an approver // Check if user is an approver
const approverLevel = approvalLevels.find((level: any) => const approverLevel = approvalLevels.find((level: any) =>
(level.approverId === currentUserId || level.approver?.userId === currentUserId) && (level.approverId === currentUserId || level.approver?.userId === currentUserId) &&
level.status === 'PENDING' level.status === 'PENDING'
); );