sozsoft-platform/configs/seeds/sql/object/Prc_P_PurchaseRfqRecalc.sql
2026-10-11 22:57:23 +03:00

24 lines
1.3 KiB
Transact-SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

CREATE OR ALTER PROCEDURE [dbo].[Prc_P_PurchaseRfqRecalc]
@Id uniqueidentifier
AS
BEGIN
SET NOCOUNT ON;
-- TenderLineId alternatiflere kopyalanır; ihaledeki aynı kalemi kıyasta birleştiren anahtardır.
UPDATE Prc_T_PurchaseRfqLine SET Amount = ROUND(Quantity * UnitPrice, 2), TenderLineId = ISNULL(TenderLineId, Id)
WHERE PurchaseRfqId = @Id AND IsDeleted = 0;
UPDATE r SET
UntaxedAmount = ISNULL((SELECT SUM(l.Amount) FROM Prc_T_PurchaseRfqLine l WHERE l.PurchaseRfqId = @Id AND l.IsDeleted = 0), 0),
TaxAmount = ISNULL((SELECT SUM(ROUND(l.Amount * l.TaxRate / 100, 2)) FROM Prc_T_PurchaseRfqLine l WHERE l.PurchaseRfqId = @Id AND l.IsDeleted = 0), 0),
SourceDocument = STUFF((SELECT DISTINCT N', ' + m.RequestNo
FROM Prc_T_PurchaseRfqLine l
INNER JOIN Prc_T_MaterialRequestItem i ON i.Id = l.MaterialRequestItemId
INNER JOIN Prc_T_MaterialRequest m ON m.Id = i.MaterialRequestId
WHERE l.PurchaseRfqId = @Id AND l.IsDeleted = 0
FOR XML PATH(''), TYPE).value('.', 'nvarchar(512)'), 1, 2, N'')
FROM Prc_T_PurchaseRfq r
WHERE r.Id = @Id;
UPDATE Prc_T_PurchaseRfq SET TotalAmount = UntaxedAmount + TaxAmount WHERE Id = @Id;
END