diff --git a/DokumentyZrodlowe-DekretySkladowe.sql b/DokumentyZrodlowe-DekretySkladowe.sql index fae3568..ee4fab9 100644 --- a/DokumentyZrodlowe-DekretySkladowe.sql +++ b/DokumentyZrodlowe-DekretySkladowe.sql @@ -1,4 +1,4 @@ -SET ANSI_NULLS ON +SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO @@ -7,6 +7,10 @@ IF EXISTS (SELECT * FROM sysobjects WHERE name = 'my_ImpDM_Dekr' AND user_name(u DROP PROCEDURE [CDN].my_ImpDM_Dekr GO +/* + 2026.10.14 - KC: import linii jednostronnych (tylko Wn albo tylko Ma). Wcześniej Wn i Ma były łączone przez inner join + po DT_GIDLp, więc z dekretu o kilku liniach przechodziły tylko linie mające obie strony. +*/ CREATE PROCEDURE [CDN].my_ImpDM_Dekr ( @DZKNr int -- 1 - DZK_DIGNumer @@ -22,21 +26,23 @@ AS insert into @CRE select DT_GIDNumer, DT_GIDLp, DT_DC, DT_Konto, DT_Kwota, DT_DataCentrali from CDN.Dekrety where DT_DC = 2 and DT_GIDNumer = @DZKNr -SELECT Lp = ROW_NUMBER() OVER(ORDER BY DZK_Opis, DEL_Opis, deb.DT_Konto, cre.DT_Konto), +-- linia dekretu może mieć obie strony albo tylko jedną; brakująca strona = pusty numer konta +SELECT Lp = ROW_NUMBER() OVER(ORDER BY DZK_Opis, DEL_Opis, isnull(deb.DT_Konto, ''), isnull(cre.DT_Konto, ''), DEL_GIDLp), DZK_Opis = left (DZK_Opis, 80), - [Data] = DEL_DataWyst, - DataDokumentu = DEL_DataOper, - Kwota = deb.DT_Kwota, - DokZr = DZK_DokumentZrodlowy, - KontoDebet = deb.DT_Konto, - KontoCredit = cre.DT_Konto, + [Data] = DEL_DataWyst, + DataDokumentu = DEL_DataOper, + Kwota = coalesce(deb.DT_Kwota, cre.DT_Kwota), + DokZr = DZK_DokumentZrodlowy, + KontoDebet = isnull(deb.DT_Konto, ''), + KontoCredit = isnull(cre.DT_Konto, ''), Identyfikator = left(DZK_Opis, 80), Opis = left(DEL_Opis, 80), - DataImportu = CDN.TsToDate(coalesce(deb.DT_DataCentrali, 0), 1) + DataImportu = CDN.TsToDate(coalesce(deb.DT_DataCentrali, cre.DT_DataCentrali, 0), 1) FROM CDN.Dziennik inner join CDN.DziennikElem on DZK_GIDNumer = DEL_GIDNumer - inner join @DEB deb ON deb.DT_GIDNumer = DEL_GIDNumer and deb.DT_GIDLp = DEL_GIDLp - inner join @CRE cre ON cre.DT_GIDNumer = DEL_GIDNumer and cre.DT_GIDLp = DEL_GIDLp + left outer join @DEB deb ON deb.DT_GIDNumer = DEL_GIDNumer and deb.DT_GIDLp = DEL_GIDLp + left outer join @CRE cre ON cre.DT_GIDNumer = DEL_GIDNumer and cre.DT_GIDLp = DEL_GIDLp where DZK_GIDNumer = @DZKNr + and (deb.DT_GIDNumer is not null or cre.DT_GIDNumer is not null) order by 1 diff --git a/ImportDokMag/ImportDM.vb b/ImportDokMag/ImportDM.vb index 963e60d..d6829bc 100644 --- a/ImportDokMag/ImportDM.vb +++ b/ImportDokMag/ImportDM.vb @@ -190,17 +190,22 @@ Partial Public Class MainFrm BsTbmy_ImpDM_Dekr.ResetBindings(False) BsTbmy_ImpDM_Dekr.MoveFirst() While i < BsTbmy_ImpDM_Dekr.Count - KontoWn = BsTbmy_ImpDM_Dekr.Current("KontoDebet") - KontoMa = BsTbmy_ImpDM_Dekr.Current("KontoCredit") + KontoWn = If(IsDBNull(BsTbmy_ImpDM_Dekr.Current("KontoDebet")), "", BsTbmy_ImpDM_Dekr.Current("KontoDebet")) + KontoMa = If(IsDBNull(BsTbmy_ImpDM_Dekr.Current("KontoCredit")), "", BsTbmy_ImpDM_Dekr.Current("KontoCredit")) KKS_Wn = 0 KKS_Ma = 0 Rok = Year(DataDok) - sql = "select top(1) KKS_GIDNumer from CDN.Konta where KKS_Rok = " & CStr(Rok) & " and KKS_Konto = '" & KontoWn & "'" - line = GetOneVal(sql, DstConn_str) - If line > "" Then KKS_Wn = CInt(line) - sql = "select top(1) KKS_GIDNumer from CDN.Konta where KKS_Rok = " & CStr(Rok) & " and KKS_Konto = '" & KontoMa & "'" - line = GetOneVal(sql, DstConn_str) - If line > "" Then KKS_Ma = CInt(line) + ' linia jednostronna - pusta strona zostaje z KKSNumer = 0 + If KontoWn > "" Then + sql = "select top(1) KKS_GIDNumer from CDN.Konta where KKS_Rok = " & CStr(Rok) & " and KKS_Konto = '" & KontoWn & "'" + line = GetOneVal(sql, DstConn_str) + If line > "" Then KKS_Wn = CInt(line) + End If + If KontoMa > "" Then + sql = "select top(1) KKS_GIDNumer from CDN.Konta where KKS_Rok = " & CStr(Rok) & " and KKS_Konto = '" & KontoMa & "'" + line = GetOneVal(sql, DstConn_str) + If line > "" Then KKS_Ma = CInt(line) + End If With NotaPozycjaInfo .Kwota = Str(BsTbmy_ImpDM_Dekr.Current("Kwota")) + Chr(0) 'Kwota .NumerDokumentu = NrDok + Chr(0) 'Numer dokumentu diff --git a/ImportDokMag/MainFrm.Designer.vb b/ImportDokMag/MainFrm.Designer.vb index e02e18a..019525c 100644 --- a/ImportDokMag/MainFrm.Designer.vb +++ b/ImportDokMag/MainFrm.Designer.vb @@ -633,7 +633,7 @@ Partial Class MainFrm Me.Name = "MainFrm" Me.Padding = New System.Windows.Forms.Padding(3) Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen - Me.Text = "Import dokumentów magazynowych 2.0.1 z 13.10.2026" + Me.Text = "Import dokumentów magazynowych 2.0.2 z 14.10.2026" Me.TlMainPanel.ResumeLayout(False) Me.Panel1.ResumeLayout(False) Me.Panel1.PerformLayout()