Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- With version as
- (
- Select
- regnum, max(versionnumber)versionnumber
- From eis_contracts_44_2
- where eis_document_type='contractProcedure'
- Group By regnum
- )
- ,
- cc as
- (
- Select regnum,foundationfcsorderorderplacingsinglecustomertext,
- versionnumber
- From eis_contracts_44_2
- Where eis_document_type='contract'
- )
- ,
- payment as
- (
- Select
- eis_contracts_44_2_id ,
- SUM((case
- when amountrur=''
- then null
- else amountrur end)::DOUBLE PRECISION) amountrur
- From tts_payment055939476779003
- -- where eis_contracts_44_2_id='21a427a4-ecd0-4199-ae6f-2ec37f836f72_2037'
- group by eis_contracts_44_2_id
- )
- Select
- c.id,
- c.regnum, -- Номер реестровой записи контракта (РНК)
- coalesce(NULLIF(c.penaltiespenaltyaccrualpenaltyreasonname, ''), cp.penaltyaccrualpenaltyreasonname ) as name_1, -- Причина начисления неустойки (штрафа, пени)
- coalesce(NULLIF( c.penaltiespenaltyaccrualpenaltydocumentdocumentname, ''), cp.penaltyaccrualpenaltydocumentdocumentname )as name_2, -- Требование заказчика или поставщика
- coalesce(NULLIF(c.penaltiespenaltyaccrualpenaltydocumentdocumentnum, ''), cp.penaltyaccrualpenaltydocumentdocumentnum ) as number_doc, -- номер требования
- coalesce(NULLIF(c. penaltiespenaltyaccrualpenaltydocumentdocumentdate, ''), cp.penaltyaccrualpenaltydocumentdocumentdate ) as date_doc, -- Дата начисления неустойки
- coalesce(NULLIF(c.penaltiespenaltyaccrualaccrualamount, ''), cp.penaltyaccrualaccrualamount) as sum_doc, -- Размер начисленной неустойки (штрафа, пени), рублей
- coalesce(NULLIF(c.penaltiespenaltyaccrualpaymentspaymentamountrur, ''), cp.penaltyaccrualpaymentspaymentamountrur) as pay_sum, -- Размер оплаченной неустойки (штрафа, пени), рублей
- Case when coalesce (NULLIF(c.penaltiespenaltyaccrualpenaltytype, ''), cp.penaltyaccrualpenaltytype)='F' then 'Штраф'
- when coalesce (NULLIF(c.penaltiespenaltyaccrualpenaltytype, ''), cp.penaltyaccrualpenaltytype)='I' then 'Пени'
- Else null End penaltietype,
- cc.foundationfcsorderorderplacingsinglecustomertext as sop -- способ определения поставщика
- -- c.currentcontractstage -- статус контракта
- -- p.amountrur,
- -- cp.eis_contracts_44_2_id,
- -- c.acgz_id
- From eis_contracts_44_2 c
- Join version v on v.regnum=c.regnum and v.versionnumber=c.versionnumber
- Left Join eis_contracts_44_2__penalties cp on cp.eis_contracts_44_2_id=c.acgz_id
- Left Join cc on c.regnum=cc.regnum and v.versionnumber=cc.versionnumber
- left join payment p on p.eis_contracts_44_2_id=c.acgz_id
- Where coalesce (NULLIF(c.penaltiespenaltyaccrualpenaltydocumentdocumentdate, ''), cp.penaltyaccrualpenaltydocumentdocumentdate) between '2023-01-01' and '2023-06-30'
- -- and c.regnum='2783808733022000188'
- -- and t.amountrur is not null
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement