Tworzenie e-Faktur FA.XML (3) za pomocą danych Json.

Wpis #294 z dnia: 26-08-2025

Jedną z metod generowania e-Faktur FA.XML (3) w programie KSeF-link jest przesłanie danych do naszej aplikacji w uproszczonej strukturze Json. Struktura jest zgodna ze sposobem kodowania w naszym kreatorze konwersji pliku Excel, do seryjnego generowania faktur. Przy czym tutaj przesyłamy dane tylko jednej faktury.

Do budowania i testowania struktury Json, dodaj nowy skrypt do listy: Projektowanie API

using System;
using TGSoft.Utils;
using TGSoft.Ksef;
using TGSoft.Ksef.Ver3;

namespace Szark
{
    public class Class1
    {                             
        public Class1(object sender)
        {
        }
        
        public void Main(object jsonParams)
        {
            Json2Faktura j2s = new Json2Faktura(jsonParams.ToStr()) { CalcFwItems = false, CalcTotal = false };
            Faktura fra = j2s.CreateFA();
            if (fra != null)
            {
                fra.ShowXmlDialog();
            }
        }
    }
}

Za pomocą tego skryptu możesz testować dowolne faktury z naszych przykładów, które są zbudowane na podstawie serializacji klas:


public class FakturaDto
{
    public string Key { get; set; }
    public string FunctionName { get; set; }    
    public bool CalcItems { get; set; }
    public bool CalcTotal {  get; set; }

    public KontrahentDto Sprzedawca { get; set; }
    public KontrahentDto Nabywca { get; set; }
    public List<KontrahentDto> Podmiot3 { get; set; }

    public string IDF { get; set; }
    public string TypSZ { get; set; }
    public string KodWaluty { get; set; }
    public string P_1 { get; set; }
    public string P_1M { get; set; }
    public string P_2 { get; set; }
    public string WZ { get; set; }
    public string NumerKSeF { get; set; }
    public string NumerERP { get; set; }
    public string P_6_Od { get; set; }
    public string P_6_Do { get; set; }
    public decimal P_13_1 { get; set; }
    public decimal P_14_1 { get; set; }
    public decimal P_14_1W { get; set; }
    public decimal P_13_2 { get; set; }
    public decimal P_14_2 { get; set; }
    public decimal P_14_2W { get; set; }
    public decimal P_13_3 { get; set; }
    public decimal P_14_3 { get; set; }
    public decimal P_14_3W { get; set; }
    public decimal P_13_4 { get; set; }
    public decimal P_14_4 { get; set; }
    public decimal P_14_4W { get; set; }
    public decimal P_13_5 { get; set; }
    public decimal P_14_5 { get; set; }
    public decimal P_13_6_1 { get; set; }
    public decimal P_13_6_2 { get; set; }
    public decimal P_13_6_3 { get; set; }
    public decimal P_13_7 { get; set; }
    public decimal P_13_8 { get; set; }
    public decimal P_13_9 { get; set; }
    public decimal P_13_10 { get; set; }
    public decimal P_13_11 { get; set; }
    public decimal P_15 { get; set; }
    public decimal WartoscZamowienia { get; set; }

    public decimal KursWalutyZ { get; set; }
    public bool P_16 {  get; set; }
    public bool P_17 { get; set; }
    public bool P_18 { get; set; }
    public bool P_18A { get; set; }
    public string P_19A { get; set; }
    public string P_19B { get; set; }
    public string P_19C { get; set; }
    public bool P_42_5 { get; set; }
    public bool P_23 { get; set; }
    public string P_PMarzy { get; set; }

    public string RodzajFaktury { get; set; }

    public string PrzyczynaKorekty { get; set; }
    public int TypKorekty { get; set; }
    public string[] DaneFaKorygowanej { get; set; }
    public string OkresFaKorygowanej { get; set; }  
    public string NrFaKorygowany { get; set; }
    public string Podmiot1K { get; set; }
    public string Podmiot2K { get; set; }
    public decimal P_15ZK { get; set; } 
    public decimal KursWalutyZK { get; set; }  

    public string[] ZaliczkaCzesciowa { get; set; }
    public int FP { get; set; }
    public int TP { get; set; }
    public string[] DodatkowyOpis { get; set; }
    public string[] NrFaZaliczkowej { get; set; }
    public int ZwrotAkcyzy {  get; set; }

    public string[] Obciazenia {  get; set; }
    public string[] Odliczenia { get; set; }
    public string DataZaplaty { get; set; }
    public string[] PlatnosciCzesciowe { get; set; }
    public string[] TerminPlatnosci { get; set; }
    public string FormaPlatnosci { get; set; }
    public string[] RachunekBankowy { get; set; }
    public string[] RachunekBankowyFaktora { get; set; }
    public string Skonto { get; set; }

    public string[] Umowy { get; set; }
    public string[] Zamowienia { get; set; }
    public string NrPartiiTowaru { get; set; }
    public string WarunkiDostawy { get; set; }
    public decimal KursUmowny { get; set; }
    public string WalutaUmowna { get; set; }
    public int PodmiotPosredniczacy { get; set; }

    public string StopkaFaktury { get; set; }   

    public List<FwItemDto> FwItems { get; set; }
    public List<ZwItemDto> ZwItems { get; set; }
    public List<TransportDto> Transport { get; set; }
    public List<NowySTDto> NowyST { get; set; }
    public List<BlokDanychDto> BlokDanych {  get; set; }    
}

I klasy szczegółowe:

public class KontrahentDto
{
    public string Nazwa { get; set; }
    public string Prefiks { get; set; }
    public string NIP { get; set; }
    public string KodKraju { get; set; }
    public string AdresL1 { get; set; }
    public string AdresL2 { get; set; }
    public string AdresKL1 { get; set; }
    public string AdresKL2 { get; set; }
    public string GLN {  get; set; }
    public string KodKKraju { get; set; }
    public string NrEORI { get; set; }
    public string IDKlienta { get; set; }
    public string NrKlienta { get; set; }
    public string Email { get; set; }
    public string Telefon { get; set; }
    public int Rola { get; set; } // TRolaPodmiotuUpowaznionego, FakturaPodmiot3
    public string OpisRoli { get; set; } // FakturaPodmiot3
    public decimal Udzial { get; set; } // FakturaPodmiot3
    public int JST { get; set; } // Znacznik jednostki podrzędnej JST
    public int GV { get; set; } // Znacznik członka grupy VAT
}


public class FwItemDto
{
    public int NrWierszaFa { get; set; }
    public string Indeks { get; set; }
    public string NazwaTowaruUslugi { get; set; }
    public string JednostkaMiary { get; set; }
    public decimal Ilosc { get; set; }
    public decimal CenaJednostkowaNetto { get; set; }
    public decimal CenaJednostkowaBrutto { get; set; }
    public decimal KwotaRabatu { get; set; }
    public decimal WartoscNetto { get; set; }
    public decimal WartoscBrutto { get; set; }
    public string StrVAT { get; set; }
    public decimal VAT { get; set; }
    public decimal StWD { get; set; }
    public string UU_ID { get; set; }
    public DateTime DataDostawy { get; set; }
    public string GTIN { get; set; }
    public string PKWiU { get; set; }
    public string CN { get; set; }
    public string PKOB { get; set; }
    public string DodatkoweInfo { get; set; }
    public string ProceduraFa { get; set; }
    public decimal KwotaAkcyzy { get; set; }
    public string GTU { get; set; }
    public string Procedura { get; set; }
    public decimal KursWaluty { get; set; }
    public bool StanPrzedKorekta { get; set; }
    public bool Zal15Ustawy { get; set; }
}


public class ZwItemDto
{
    public int NrWierszaZam { get; set; }
    public string Indeks { get; set; }
    public string NazwaTowaruUslugi { get; set; }
    public string JednostkaMiary { get; set; }
    public decimal Ilosc { get; set; }
    public decimal CenaJednostkowaNetto { get; set; }
    public decimal WartoscNetto { get; set; }
    public decimal KwotaVAT { get; set; }
    public string StrVAT { get; set; }
    public decimal StWD { get; set; }
    public bool Zal15Ustawy { get; set; }
    public string UU_ID { get; set; }
    public string GTIN { get; set; }
    public string PKWiU { get; set; }
    public string CN { get; set; }
    public string PKOB { get; set; }
    public string ProceduraZ { get; set; }
    public decimal KwotaAkcyzy { get; set; }
    public string GTU { get; set; }
    public string Procedura { get; set; }
    public bool StanPrzedKorekta { get; set; }
}


public class TransportDto
{
    public string RodzajTransportu { get; set; }
    public string Przewoznik { get; set; }
    public string NrZleceniaTransportu { get; set; }
    public string OpisLadunku { get; set; }
    public string JednostkaOpakowania { get; set; }
    public DateTime DataGodzRozpTransportu { get; set; }
    public DateTime DataGodzZakTransportu { get; set; }

    public string WysylkaZ { get; set; }
    public string[] WysylkaPrzez { get; set; }
    public string WysylkaDo { get; set; }
}


public class NowySTDto
{
    public DateTime P_22A { get; set; }
    public int P_NrWierszaNST { get; set; }
    public string P_22BMK { get; set; } // op: Marka
    public string P_22BMD { get; set; } // op: Model
    public string P_22BK { get; set; }  // op: Kolor
    public string P_22BNR { get; set; } // op: Numer rejestracyjny
    public string P_22BRP { get; set; } // op: Rok produkcji

    public string P_22B { get; set; } // przebieg poj. lądowego
    public string P_22B1 { get; set; } // op - wybór
    public string P_22B2 { get; set; } // op - wybór
    public string P_22B3 { get; set; } // op - wybór
    public string P_22B4 { get; set; } // op - wybór
    public string P_22BT { get; set; } // op

    public string P_22C { get; set; }
    public string P_22C1 { get; set; } // op - wybór

    public string P_22D { get; set; }
    public string P_22D1 { get; set; } // op - wybór
}


public class BlokDanychDto
{
    public string[] MetaDane { get; set; }
    public BDTabelaDto[] Tabela { get; set; }
}


public class BDTabelaDto
{
    public string Opis { get; set; }
    public string[] MetaDane { get; set; }
    public string[] Naglowek { get; set; }
    public string[] Wiersz { get; set; }
    public string Suma { get; set; }
}


Następny dokument 295 : Przetwarzanie Json - generowanie eFaktur XML.