@@ -1949,10 +1949,21 @@ filterUploadedFromLocation.Trim();
19491949 {
19501950 var url = $" /download/pod/{pod .InvoiceDocEntry }/{pod .Id }" ;
19511951 await JS .InvokeVoidAsync (" downloadAuthenticatedFile" , url , pod .FileName );
1952+ await LogPodAuditAsync (
1953+ AuditActions .DownloadPod ,
1954+ pod ,
1955+ true ,
1956+ $" Downloaded POD '{pod .FileName }' for {GetPodInvoiceLabel (pod )}." );
19521957 }
19531958 catch (Exception ex )
19541959 {
19551960 Logger .LogError (ex , " Error downloading POD {PodId}" , pod .Id );
1961+ await LogPodAuditAsync (
1962+ AuditActions .DownloadPod ,
1963+ pod ,
1964+ false ,
1965+ $" Failed to download POD '{pod .FileName }' for {GetPodInvoiceLabel (pod )}." ,
1966+ ex .Message );
19561967 }
19571968 }
19581969
@@ -1976,10 +1987,22 @@ filterUploadedFromLocation.Trim();
19761987 viewerDataUri = await JS .InvokeAsync <string >(
19771988 " createAuthenticatedObjectUrl" ,
19781989 $" /download/pod/{pod .InvoiceDocEntry }/{pod .Id }" );
1990+
1991+ await LogPodAuditAsync (
1992+ AuditActions .ViewPod ,
1993+ pod ,
1994+ true ,
1995+ $" Viewed POD '{pod .FileName }' for {GetPodInvoiceLabel (pod )}." );
19791996 }
19801997 catch (Exception ex )
19811998 {
19821999 Logger .LogError (ex , " Error viewing POD {PodId}" , pod .Id );
2000+ await LogPodAuditAsync (
2001+ AuditActions .ViewPod ,
2002+ pod ,
2003+ false ,
2004+ $" Failed to view POD '{pod .FileName }' for {GetPodInvoiceLabel (pod )}." ,
2005+ ex .Message );
19832006 showViewer = false ;
19842007 }
19852008 finally
@@ -2005,6 +2028,36 @@ filterUploadedFromLocation.Trim();
20052028 }
20062029 }
20072030
2031+ private async Task LogPodAuditAsync (
2032+ string action ,
2033+ PodAttachmentItemDto pod ,
2034+ bool isSuccess ,
2035+ string details ,
2036+ string ? errorMessage = null )
2037+ {
2038+ try
2039+ {
2040+ await AuditService .LogAsync (
2041+ action ,
2042+ " POD" ,
2043+ pod .Id .ToString (CultureInfo .InvariantCulture ),
2044+ details ,
2045+ isSuccess ,
2046+ errorMessage );
2047+ }
2048+ catch (Exception ex )
2049+ {
2050+ Logger .LogWarning (ex , " Failed to write POD audit log for action {Action} and attachment {PodId}" , action , pod .Id );
2051+ }
2052+ }
2053+
2054+ private static string GetPodInvoiceLabel (PodAttachmentItemDto pod )
2055+ {
2056+ return pod .InvoiceDocNum > 0
2057+ ? $" invoice #{pod .InvoiceDocNum }"
2058+ : $" invoice doc entry {pod .InvoiceDocEntry }" ;
2059+ }
2060+
20082061 private void ConfirmDeletePod (PodAttachmentItemDto pod )
20092062 {
20102063 if (! canDeletePods ) return ;
0 commit comments