Notes
Notes - notes.io |
IF NOT EXISTS(SELECT TOP 1 1 FROM #ActiveAssetIds)--This check is added as inner join during update and insert
RETURN
CREATE TABLE #NegativeAssetsToBeScrapped
(Id BIGINT,
NewStatus NVARCHAR(30)
)
SELECT
PayableInvoiceAssets.AssetId,
PayableInvoiceAssets.Id
INTO #PIAssetIds
FROM PayableInvoiceAssets
WHERE PayableInvoiceAssets.PayableInvoiceId = @PayableInvoiceId
AND PayableInvoiceAssets.IsActive = 0
IF NOT EXISTS(SELECT TOP 1 1 FROM #PIAssetIds)
RETURN
IF EXISTS(SELECT TOP 1 1 FROM PayableInvoices WHERE PayableInvoices.ParentPayableInvoiceId IS NULL AND PayableInvoices.Id=@PayableInvoiceId AND PayableInvoices.Status='InActive')
BEGIN
INSERT INTO #NegativeAssetsToBeScrapped
SELECT Assets.Id
,@ScrapStatus AS NewStatus
FROM Assets
INNER JOIN #PIAssetIds ON #PIAssetIds.AssetId = Assets.Id
WHERE Assets.Status <> @ScrapStatus
AND Assets.FinancialType <> @NegativeDeposit
END
SELECT
#PIAssetIds.AssetId
,#PIAssetIds.Id
INTO #PIAssetInfo
FROM Assets
INNER JOIN #PIAssetIds ON #PIAssetIds.AssetId = Assets.Id
WHERE Assets.Status <> @ScrapStatus
AND Assets.FinancialType = @NegativeDeposit
AND Assets.Status <> @ErrorStatus
IF EXISTS(SELECT TOP 1 1 FROM #PIAssetInfo)
BEGIN
SELECT
PIAssets.AssetId
,PayableInvoiceDepositAssets.IsActive
,PayableInvoiceDepositTakeDownAssets.TakeDownAssetId
INTO #NegativeAssetInfo
FROM #PIAssetInfo PIAssets
INNER JOIN PayableInvoiceDepositTakeDownAssets ON PIAssets.Id = PayableInvoiceDepositTakeDownAssets.NegativeDepositAssetId
INNER JOIN PayableInvoiceDepositAssets ON PayableInvoiceDepositTakeDownAssets.PayableInvoiceDepositAssetId = PayableInvoiceDepositAssets.Id
IF EXISTS(SELECT TOP 1 1 FROM #NegativeAssetInfo)
BEGIN
INSERT INTO #NegativeAssetsToBeScrapped
SELECT
NegativeAsset.AssetId
,IIF(RealAssets.IsActive = 0 AND NegativeAsset.IsActive <> 0 , @ScrapStatus,@ErrorStatus) AS NewStatus
FROM #NegativeAssetInfo NegativeAsset
LEFT JOIN PayableInvoiceAssets AS RealAssets ON NegativeAsset.TakeDownAssetId = RealAssets.Id
END
END
IF EXISTS(SELECT TOP 1 1 FROM #NegativeAssetsToBeScrapped)
BEGIN
SELECT * INTO #FinalNegativeAssetsToBeScrapped FROM #NegativeAssetsToBeScrapped
WHERE NOT EXISTS(SELECT * FROM PayableInvoiceAssets WHERE AssetId = #NegativeAssetsToBeScrapped.Id and IsActive=1 )
AND EXISTS((SELECT Id FROM #ActiveAssetIds WHERE #NegativeAssetsToBeScrapped.Id = #ActiveAssetIds.Id))
UPDATE Assets SET Status = #FinalNegativeAssetsToBeScrapped.NewStatus,PropertyTaxCost_Amount = 0.0,UpdatedById = @UpdatedById,UpdatedTime = @UpdatedTime
FROM Assets A
INNER JOIN #FinalNegativeAssetsToBeScrapped ON A.Id = #FinalNegativeAssetsToBeScrapped.Id
INSERT INTO AssetHistories
(
[Reason]
,[AsOfDate]
,[AcquisitionDate]
,[Status]
,[FinancialType]
,[SourceModule]
,[SourceModuleId]
,[CreatedById]
,[CreatedTime]
,[UpdatedById]
,[UpdatedTime]
,[CustomerId]
,[ParentAssetId]
,[LegalEntityId]
--,[ContractId]
,[AssetId]
,[IsReversed]
,[PropertyTaxReportCodeId])
SELECT
@Reason,
@InvoiceDate,
Assets.AcquisitionDate,
NewStatus,
Assets.FinancialType,
@SourceModule,
@PayableInvoiceId,
@UpdatedById,
@UpdatedTime,
NULL,
NULL,
Assets.CustomerId,
Assets.ParentAssetId,
Assets.LegalEntityId,
--NULL,
Assets.Id,
0,
Assets.PropertyTaxReportCodeId
FROM Assets
INNER JOIN #FinalNegativeAssetsToBeScrapped ON Assets.Id = #FinalNegativeAssetsToBeScrapped.Id
END
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team