Professional Documents
Culture Documents
SP
SP
SP
[spGetRawTextMResetKasir]
-- Add the parameters for the stored procedure here
--DECLARE
@IDReset UNIQUEIDENTIFIER = '55DADE6C-84CB-48E6-9967-AACCEDBCAD20'
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--Cash Drawer
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(0, 2, 'Open Cash Drawer');
--Separator
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(0, 0, SUBSTRING(@Separator, 0, @PanjangKarakter));
--Separator
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(0, 0, SUBSTRING(@Separator, 0, @PanjangKarakter));
SET @StrTemp
= REPLACE(CONVERT(VARCHAR(100), CAST(ISNULL(@SetorTunai, 0) + ISNULL(@Bon,
0) AS MONEY), 1), '.00', '');
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(1, 0,
SUBSTRING(
' ' + RIGHT(SPACE(@PanjangKarakter) + @StrTemp,
@PanjangKarakter - 19),
0,
@PanjangKarakter
));
--Separator
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(0, 0, SUBSTRING(@Separator, 0, @PanjangKarakter));
DECLARE @i AS INT,
@iMax AS INT,
@IDJenisPembayaran AS INT,
@Jumlah AS MONEY,
@ChargeRp AS MONEY;
SELECT @i = 1,
@iMax = MAX(PKID)
FROM @TempBayar T;
WHILE (@i <= @iMax)
BEGIN
SELECT @IDJenisPembayaran = ISNULL(T.IDJenisPembayaran, 0),
@Variable1 = ISNULL(T.JenisPembayaran, ''),
@Variable3 = REPLACE(CONVERT(VARCHAR(100), CAST(ISNULL(T.Jumlah, 0)
AS MONEY), 1), '.00', ''),
@Jumlah = ISNULL(T.Jumlah, 0)
FROM @TempBayar T
WHERE T.PKID = @i;
SELECT @Selisih =
ISNULL(@SetorTunai, 0) + ISNULL(@Bon, 0) -
ISNULL(MResetDBayar.Jumlah, 0)
+
ISNULL(MResetDSetorVoucher.Jumlah, 0) -
ISNULL(MResetDBayarVoucher.Jumlah, 0)
+
ISNULL(MResetDSetorBank.Jumlah, 0) -
ISNULL(MResetDBayarBank.Jumlah, 0)
+
ISNULL(MResetDSetorPoint.Jumlah, 0) -
ISNULL(MResetDBayarPoint.Jumlah, 0),
@Retur = ISNULL(MSales.Retur, 0),
@Penjualan = ISNULL(MSales.Sales, 0)
FROM MReset (NOLOCK)
LEFT JOIN
(
SELECT IDReset,
SUM(Jumlah) AS Jumlah
FROM dbo.MResetDBayar (NOLOCK)
WHERE IDJenisPembayaran = 1
GROUP BY IDReset
) MResetDBayar
ON MResetDBayar.IDReset = MReset.NoID
LEFT JOIN
(
SELECT IDReset,
SUM(Jumlah) AS Jumlah
FROM dbo.MResetDBayar (NOLOCK)
WHERE IDJenisPembayaran IN (2,3)
GROUP BY IDReset
) MResetDBayarVoucher
ON MResetDBayarVoucher.IDReset = MReset.NoID
LEFT JOIN
(
SELECT IDReset,
SUM(Jumlah) AS Jumlah
FROM dbo.MResetDSetor (NOLOCK)
WHERE IDJenisPembayaran IN (2,3)
GROUP BY IDReset
) MResetDSetorVoucher
ON MResetDSetorVoucher.IDReset = MReset.NoID
LEFT JOIN
(
SELECT IDReset,
SUM(Jumlah) AS Jumlah
FROM dbo.MResetDBayar (NOLOCK)
WHERE IDJenisPembayaran IN (4, 5)
GROUP BY IDReset
) MResetDBayarBank
ON MResetDBayarBank.IDReset = MReset.NoID
LEFT JOIN
(
SELECT IDReset,
SUM(Jumlah) AS Jumlah
FROM dbo.MResetDSetor (NOLOCK)
WHERE IDJenisPembayaran IN (4, 5)
GROUP BY IDReset
) MResetDSetorBank
ON MResetDSetorBank.IDReset = MReset.NoID
LEFT JOIN
(
SELECT IDReset,
SUM(Jumlah) AS Jumlah
FROM dbo.MResetDBayar (NOLOCK)
WHERE IDJenisPembayaran = 6
GROUP BY IDReset
) MResetDBayarPoint
ON MResetDBayarPoint.IDReset = MReset.NoID
LEFT JOIN
(
SELECT IDReset,
SUM(Jumlah) AS Jumlah
FROM dbo.MResetDSetor (NOLOCK)
WHERE IDJenisPembayaran = 6
GROUP BY IDReset
) MResetDSetorPoint
ON MResetDSetorPoint.IDReset = MReset.NoID
LEFT JOIN
(
SELECT MSales.IDReset,
SUM( CASE
WHEN MSalesD.TRN = 'RTN'
OR MSalesD.TRN = 'RTN2' THEN
MSalesD.Jumlah
ELSE
0
END
) AS Retur,
SUM(MSalesD.Jumlah) AS Sales
FROM MSales (NOLOCK)
INNER JOIN MSalesD (NOLOCK)
ON MSales.NoID = MSalesD.IDSales
GROUP BY MSales.IDReset
HAVING MSales.IDReset = @IDReset
) AS MSales
ON MSales.IDReset = MReset.NoID
WHERE MReset.NoID = @IDReset;
--Separator
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(0, 0, SUBSTRING(@Separator, 0, @PanjangKarakter));
--Separator
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(0, 0, SUBSTRING(@Separator, 0, @PanjangKarakter));
--Separator
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(0, 0, SUBSTRING(@Separator, 0, @PanjangKarakter));
--Separator
INSERT INTO @Temp
(
NoUrut,
Type,
Pesan
)
VALUES
(0, 0, SUBSTRING(@Separator, 0, @PanjangKarakter));
--SELECT
--@Variable1 = ISNULL(MUser.Nama, ''),
--@Variable2 = ISNULL(MUserSpv.Nama, '')
--FROM MReset(NOLOCK)
--LEFT JOIN vMUser(NOLOCK) MUser ON MUser.NoID=MReset.IDUser
--LEFT JOIN vMUser(NOLOCK) MUserSpv ON MUserSpv.NoID=MReset.IDSupervisor
--WHERE MReset.NoID=@IDReset
SELECT *
FROM @Temp T
ORDER BY PKID,
NoUrut;
END;