Files
Fuchs_Intranet/Fuchs_Database/dbo/Stored Procedures/fds__prepReminder.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

58 lines
2.1 KiB
Transact-SQL

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[fds__prepReminder]
@InvId varchar(15)
, @authuser varchar(100)
, @type varchar(1)
, @level int
AS
BEGIN
SET NOCOUNT ON;
IF [dbo].[fis_getModuleAuth]('fds_reminder', @authuser) < 2
THROW 60000, N'not authorized', 1;
ELSE IF ISNULL(@type,'') NOT IN ('f','m','l') OR ISNULL(@level, 0) < 1
THROW 60000, N'inputs not valid', 1;
ELSE IF NOT EXISTS (select 0 FROM [dbo].[fds__invoices] WHERE [id] = @InvId)
THROW 60000, N'invoice not found', 1;
INSERT INTO [dbo].[fds__admin_activity] ([activity] ,[authuser] ,[info])
VALUES ('fds__prepReminder' ,@authuser , (SELECT * FROM (VALUES(@InvId, @authuser, @type, @level)) as z ([InvId],[authuser],[type],[level]) FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER));
DECLARE @now datetime = GETDATE();
DECLARE @today date = CAST(@now as date);
--output
With inv as(
select TOP(1) * FROM [dbo].[fds__invoices] WHERE [id] = @InvId
)
SELECT TOP(1)
[today] = @today
, [invid] = inv.[id]
, [sender] = N'Sebastian Fuchs GmbH & Co. KG ● Germaniastraße 15 ● 40223 Düsseldorf'
, [paymentterms] = [PaymentTerm]
, [invoiceemail] = IIF(ISNULL([SendToemail],'') = '', [dbo].[fds__getCompanyEmail](inv.[customerid]), [SendToemail])
, [invoiceaddress] = IIF(ISNULL([SendToAddress],'') = '', [dbo].[fds__getCompanyNameAddress](inv.[customerid]),[SendToAddress])
, [CustomerId] = [CustomerId]
, [subject] = CASE WHEN @type = 'f' THEN N'Zahlungserinnerung'
WHEN @type = 'm' THEN FORMAT(@level,'0','de-de') + N'. Mahnung'
WHEN @type = 'l' THEN N'Letzte außergerichtliche Mahnung'
ELSE N'Zahlungserinnerung'
END
, [type] = @type
, [invoiceid] = inv.[Invoiceid]
, [invoicedate] = [dbo].[fds__fn_invoiceDate](inv.[DateFinalized], inv.[DateCreated])
, [amount] = inv.[InvoiceBalance]
, [amount_payed] = CAST( ISNULL([dbo].[fds__fn_InvoicePaymentAmount_full](inv.[Id]),0.0) as numeric(10,2))
FROM inv;
END