Files
Fuchs_Intranet/Fuchs_Database/dbo/Functions/fds__fn_invoiceBackdate.sql
T
Stefan c741535aec
Playwright Tests / test (push) Canceled after 0s
feat: Implement mfr truncation fix and enhance invoice handling
- Added a new SQL script to address the "String or binary data would be truncated" error in mfr sync by widening the Note fields in service objects and companies to NVARCHAR(MAX).
- Updated the table types and associated stored procedures to accommodate the changes, ensuring compatibility with existing data.
- Queued a re-sync for previously rejected rows due to truncation issues.
- Created application logins for fuchs_fds and fuchs_web with placeholder passwords for initial setup.
- Introduced functions for invoice backdating and invoice date retrieval to streamline invoice processing.
- Developed a password generation function with customizable parameters for length and character types.
- Added a random number generation function to support password creation.
2026-09-30 16:56:08 +02:00

34 lines
1.5 KiB
Transact-SQL

-- =============================================
-- Description: Invoice backdating (ADR 0032). Returns the date an invoice may be backdated to
-- (the last working day Mon-Fri of the previous month, Europe/Berlin), or NULL when
-- backdating is not allowed:
-- * @authuser needs fds_inv > 2, and
-- * no invoice may have been finalized after that date yet (invoice numbers are
-- issued in date order; DateFinalized is stored in UTC, hence the 2h margin).
-- Single source for fds__setInvoiceFinal (@backdate = 1) and the preview dialog.
-- The check is only race-free inside fds__setInvoiceFinal, which serializes all
-- finalizations with a transaction-owned app lock; the preview call is advisory.
-- =============================================
CREATE FUNCTION [dbo].[fds__fn_invoiceBackdate]
(
@authuser varchar(25)
)
RETURNS date
AS
BEGIN
IF [dbo].[fis_getModuleAuth]('fds_inv', @authuser) <= 2
RETURN NULL;
DECLARE @today date = CAST(SYSDATETIMEOFFSET() AT TIME ZONE 'W. Europe Standard Time' AS date);
DECLARE @eom date = EOMONTH(@today, -1);
-- DATEFIRST-independent weekday: 0 = Monday ... 5 = Saturday, 6 = Sunday
DECLARE @bd date = DATEADD(day, CASE DATEDIFF(day, '19000101', @eom) % 7 WHEN 5 THEN -1 WHEN 6 THEN -2 ELSE 0 END, @eom);
IF EXISTS (SELECT 0 FROM [dbo].[fds__invoices]
WHERE [DateFinalized] IS NOT NULL
AND [DateFinalized] >= DATEADD(HOUR, -2, CAST(DATEADD(DAY, 1, @bd) AS datetime)))
RETURN NULL;
RETURN @bd;
END