feat: implement set-based invoice payment calculations and enhance email logging configuration
Playwright Tests / test (push) Canceled after 0s
Playwright Tests / test (push) Canceled after 0s
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
-- =============================================
|
||||
-- Author: <Author,,Name>
|
||||
-- Create date: <Create Date,,>
|
||||
-- Description: <Description,,>
|
||||
-- Description: Finalized, not-paid, not-canceled, not-storno'd invoices with a balance > 0.
|
||||
-- [PaymentAmount] / [OpenAmount] come from one set-based pass over the banking
|
||||
-- transactions ([fds__fn_InvoicePaymentAmounts]) — use them instead of calling the
|
||||
-- scalar [fds__fn_InvoicePaymentAmount](Id) per row, which re-runs the whole
|
||||
-- banking TVF for every invoice and timed out the dashboard widgets.
|
||||
-- =============================================
|
||||
CREATE FUNCTION [dbo].[fds__fn_unpaidInvoices]
|
||||
(
|
||||
@@ -28,6 +30,10 @@ RETURN
|
||||
and InvoiceBalance > 0
|
||||
AND NOT exists (SELECT 0 FROM [dbo].[fds__invoice_details] as d where d.[StornoTo_InvId] = iv.[id])
|
||||
)
|
||||
SELECT * /*[Rechnung] = [invoiceId], [Name] = [InvoiceTitle] + CHAR(10) + ' (' + (SELECT TOP(1) c.[name] FROM [dbo].[mfr__companies] as c WHERE inv.[customerid] = c.[id]) + ')', [Betrag (net)] = FORMAT([invoicebalance], '#0.00€', 'de'), [Datum] = FORMAT([DateFinalized], 'dd.MM.yy' , 'de'), [Zahlungen] = FORMAT([dbo].[fds__fn_InvoicePaymentAmount]([id]), '#0.00€', 'de'), [order] = ROW_NUMBER() OVER (ORDER BY [DateFinalized], [DateSent]) */
|
||||
SELECT inv.*
|
||||
,[PaymentAmount] = ISNULL(pay.[Amount], 0.0)
|
||||
,[OpenAmount] = CAST(inv.[InvoiceBalance] - ISNULL(pay.[Amount], 0.0) as numeric(10,2))
|
||||
/*[Rechnung] = [invoiceId], [Name] = [InvoiceTitle] + CHAR(10) + ' (' + (SELECT TOP(1) c.[name] FROM [dbo].[mfr__companies] as c WHERE inv.[customerid] = c.[id]) + ')', [Betrag (net)] = FORMAT([invoicebalance], '#0.00€', 'de'), [Datum] = FORMAT([DateFinalized], 'dd.MM.yy' , 'de'), [Zahlungen] = FORMAT([dbo].[fds__fn_InvoicePaymentAmount]([id]), '#0.00€', 'de'), [order] = ROW_NUMBER() OVER (ORDER BY [DateFinalized], [DateSent]) */
|
||||
FROM inv
|
||||
)
|
||||
LEFT JOIN [dbo].[fds__fn_InvoicePaymentAmounts]() as pay ON pay.[InvId] = inv.[Id]
|
||||
)␍
|
||||
Reference in New Issue
Block a user