GIGA wiki

Błędy w parametrach rozliczeń GwMax - skrypty uzgadniające stan

Migracja; autor Wojtek, ostatnia modyfikacja przed importem 2017-06-06T18:02:53.000Z; Błedy-w-parametrach-rozliczen-GwMax-skrypty-uzgadniajace-stan

Skrypty uzgadniające stan parametrów rozliczeń w GwMax
Przed wykonaniem zadbaj o kopię bazy danych


-----------------------------------------------------------------------------------------------------------
-- pokaż elementy paramtrów bez rodzica 
select * 
from YElement_Rozliczen_Kontrahent E
where Not Exists(select * from dbo.YParametr_Rozliczen_Kontrahent P where P.YPRK_Id = E.YERK_IdParametr_Rozliczen_Kontrahent)
 
-- pokaż parametry bez kontrahentów 
select *
from dbo.YElement_Rozliczen_Kontrahent E,
     dbo.YParametr_Rozliczen_Kontrahent P
where P.YPRK_Id = E.YERK_IdParametr_Rozliczen_Kontrahent and P.YPRK_IdKontrahent > 0 and 
      Not Exists( select * from dbo.YKontrahent K where K.YKO_Id = P.YPRK_IdKontrahent)
order by 2     
 
-- pokaż parametry z kontrahentami w archiwum
select *
from dbo.YElement_Rozliczen_Kontrahent E,
     dbo.YParametr_Rozliczen_Kontrahent P,
     dbo.YKontrahent K 
where P.YPRK_Id = E.YERK_IdParametr_Rozliczen_Kontrahent and K.YKO_Id = P.YPRK_IdKontrahent and IsNull( K.YKO_Archiwum, 0) = 1  
order by 2  
 
-- pokaż parametry które wskazują na nie istniejące formuły 
select *
from dbo.YElement_Rozliczen_Kontrahent E,
     dbo.YParametr_Rozliczen_Kontrahent P
where P.YPRK_Id = E.YERK_IdParametr_Rozliczen_Kontrahent and P.YPRK_IdKontrahent > 0 and 
      Not Exists( select * from dbo.YRozliczenie_Obiekt R where R.YROB_Akronim = E.YERK_Akronim)
 
-- pokaż parametry które wskazują formuły w archiwum
select *
from dbo.YElement_Rozliczen_Kontrahent E,
     dbo.YParametr_Rozliczen_Kontrahent P,
     dbo.YRozliczenie_Obiekt R
where P.YPRK_Id = E.YERK_IdParametr_Rozliczen_Kontrahent and R.YROB_Akronim = E.YERK_Akronim and IsNull( R.YROB_Archiwum, 0) = 1

-- pokaż kontrahentów i ich parametry posiadające formuły dla innych kontrahentów
select K.YKO_Akronim as Kontrahent, 
       P.YPRK_Nazwa as Nazwa
 from dbo.YKontrahent K,
      dbo.YParametr_Rozliczen_Kontrahent P,
      dbo.YElement_Rozliczen_Kontrahent E,
      dbo.YRozliczenie_Obiekt F, 
      dbo.YObiekt O
 where K.YKO_Id = P.YPRK_IdKontrahent and 
       P.YPRK_Id = E.YERK_IdParametr_Rozliczen_Kontrahent and 
       E.YERK_Akronim = F.YROB_Akronim and 
       F.YROB_IdObiekt = O.YO_Id and 
       O.YO_IdKontrahent <> K.YKO_Id
 
-----------------------------------------------------------------------------------------------------------
-- usuń parametry bez powiazania z kontrahentem 
delete 
from dbo.YParametr_Rozliczen_Kontrahent 
where YPRK_IdKontrahent > 0 and 
      Not Exists( select * 
                   from dbo.YKontrahent K 
                   where K.YKO_Id = YPRK_IdKontrahent )
 
-- usuń parametry z kontrahentami w archiwum
delete 
from dbo.YElement_Rozliczen_Kontrahent
where Exists( select * 
               from dbo.YParametr_Rozliczen_Kontrahent P,
                    dbo.YKontrahent K 
               where P.YPRK_Id = YERK_IdParametr_Rozliczen_Kontrahent and P.YPRK_IdKontrahent > 0 and
                     K.YKO_Id = P.YPRK_IdKontrahent and IsNull( K.YKO_Archiwum, 0) = 1)
 
-- usuń elementy w parametrach nie występujące w formułach 
delete
from dbo.YElement_Rozliczen_Kontrahent
where Not Exists( select * from dbo.YRozliczenie_Obiekt R where R.YROB_Akronim = YERK_Akronim)
 
-- usuń parametry które wskazują formuły w archiwum
delete
from dbo.YElement_Rozliczen_Kontrahent
where Exists( select * from dbo.YRozliczenie_Obiekt R where R.YROB_Akronim = YERK_Akronim and IsNull( R.YROB_Archiwum, 0) = 1)
 
-----------------------------------------------------------------------------------------------------------
-- pokaż wielokrotne występowanie elementów w parametrach rozliczeń 
select K.YKO_Akronim as Kontrahent, 
       P.YPRK_Nazwa as Parametr,
       E.YERK_Akronim as Formula, 
       (select count(*)
        from dbo.YElement_Rozliczen_Kontrahent EX
        where E.YERK_Akronim = EX.YERK_Akronim) as IloscWystapien
from dbo.YParametr_Rozliczen_Kontrahent P,
     dbo.YKontrahent K,
     dbo.YElement_Rozliczen_Kontrahent E
where K.YKO_Id = P.YPRK_IdKontrahent and P.YPRK_Id = E.YERK_IdParametr_Rozliczen_Kontrahent and
      (select count(*)
        from dbo.YElement_Rozliczen_Kontrahent EX
        where E.YERK_Akronim = EX.YERK_Akronim) > 1
order by 3,1

-- pokaż