--THIS FILE IS NEEDED ONLY FOR THE ONLINE UPDATE!!!

--!!!Stored Procedure for initial filling of the table ZADR, only needed in POLAND to fulfill legal requirements (Nota Correction)!!!

CREATE OR REPLACE PROCEDURE StoreZadrData(pZINV_ID IN ZINV.ZINV_ID%TYPE, pXadr_id IN XADR.XADR_ID%TYPE) IS
BEGIN
INSERT INTO zadr
            (zadr_id, zadr_zinv_id, zadr_xadr_id, zadr_xaty_id, zadr_xcou_id,
             zadr_xsta_id, zadr_zip, zadr_street1, zadr_street2, zadr_street3,
             zadr_city, zadr_vat_number, zadr_name1, zadr_name2, zadr_name3)
   (SELECT seq_zadr.NEXTVAL, pzinv_id, xadr_id, xadr_xaty_id, xadr_xcou_id,
           xadr_xsta_id, xadr_zip, xadr_street1, xadr_street2, xadr_street3,
           xadr_city,
           (SELECT xmnr_value
              FROM xmnr, xmty
             WHERE xmnr_xmty_id = xmty_id
               AND xmty_role = 3
               AND xmnr_xcms_id = xcms_id
               AND rownum = 1),
			xcms_name1, xcms_name2, xcms_name3
      FROM xadr, xcms
     WHERE xadr_id = pxadr_id and xcms_id = xadr_xcms_id);
END StoreZadrData;
/