IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[SPUSS_106_OTO_GONDERIM_OLUSTUR]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE SPUSS_106_OTO_GONDERIM_OLUSTUR
GO

CREATE PROCEDURE [dbo].[SPUSS_106_OTO_GONDERIM_OLUSTUR] 
	@BaslangicTarih DATE ,
	@BitisTarih2 DATE,
	@PaketTipi2 INT,
	@TedaviTipi2 INT,
	@SubeId2 INT
AS
BEGIN

DECLARE @Tarih      DATE      = @BaslangicTarih --'2025-01-01';
DECLARE @BitisTarih DATE = @BitisTarih2--'2026-03-01';
DECLARE @PaketTipi  INT   = @PaketTipi2--3;  -- 3 : yatan 106  ,   13 :  ayatan 106
DECLARE @TedaviTipi INT  = @TedaviTipi2--2;   -- <<< TEDAVİ TİPİ 0 HEPSİ   1:A  2:Y   3:G
DECLARE @SubeId INT      = @SubeId2--3;   -- <<< ŞUBE

--DELETE [TUSSOTOGONDERIMAYAR] WHERE ACIKLAMA='@@@'

WHILE @Tarih <= @BitisTarih
BEGIN

    INSERT INTO [dbo].[TUSSOTOGONDERIMAYAR]
    (
        [AKTIF], [DURUM], [BASLANGICTARIHI], [BITISTARIHI],
        [PAKETIPI], [TEDAVITIPI], [USS700], [USS101], [USS102],
        [USSPAKETDURUMU], [USSYATANHASTADURUMU],
        [PAZARTESI], [SALI], [CARSAMBA], [PERSEMBE], [CUMA], [CUMARTESI], [PAZAR],
        [GOREVBASLAMASAATI], [GOREVBASLAMATARIHI], [GOREVBITISTARIHI],
        [ACIKLAMA], [SONGONDERIMZAMANI], [SUBEID]
    )
    VALUES
    (
        0, NULL,
        CAST(@Tarih AS DATETIME),
        CAST(@Tarih AS DATETIME),
        @PaketTipi, @TedaviTipi, 2, 0, 2,
        0, 0,
        0, 0, 0, 0, 0, 0, 1,
        CAST('1899-12-30T00:00:00.000' AS DATETIME),
        CAST('2020-12-31T00:00:00.000' AS DATETIME),
        CAST('2020-12-31T00:00:00.000' AS DATETIME),
        '~~sina 106 cikis gonderim',
        NULL,
        @SubeId
    );

    SET @Tarih = DATEADD(DAY, 1, @Tarih);

END

end--SP