Skip to content

Zmiana kontrahenta

Przykład zgłoszenia

Proszę o zmianę kontrahenta w dokumencie "PZ/98/300/1121" z W01311 PLASTIXAL KOŁAKOWSKI MARIUSZ na X48110 PLASTIXAL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ

  • Zmiana kontrahenta na dokumencie magazynowym wymaga jedynie zmiany firmid w nagłowku - document.document
  • Dodatkowo zmiana na fakturze powiązanej wymaga jedynie zmiany issuerid,
SQL
Begin transaction

    declare @documentID uniqueidentifier
    declare @invoiceID uniqueidentifier
    declare @newfirmID uniqueidentifier
    declare @oldfirmID uniqueidentifier

    declare @documentfullnr varchar(20) ='PZ/98/300/1121' --<<<<<wypelnij

    select top 1 @oldfirmID =firmid from firm.firm where  firmnr ='W01311' and status>-1 --<<<<<wypelnij
    select top 1 @newfirmID =firmid from firm.firm where  firmnr ='X48110' and status>-1 --<<<<<wypelnij

    select @documentid = documentid  from document.document where documentfullnr =@documentfullnr
    and firmid =@oldfirmid

    if (@documentid is null or @oldfirmID is null or @newfirmID is null)
    Begin
        raiserror('Dokument nieistnieje ', 16, 1);
    End
        if (@oldfirmID is null )
    Begin
        raiserror('stara firma nie istnieje nieistnieje ', 16, 1);
    End
            if (@newfirmID is null )
    Begin
        raiserror('nowa firma  nieistnieje ', 16, 1);
    End

    --dokument magazynowy
    update document.document set firmid =   @newfirmID where documentid = @documentid

rollback transaction

--FZ
--update document.invoice set issuerID=@newfirmID where invoiceid=@invoiceid