loadtbh_tailieucuanhanvien
CREATE PROCEDURE dbo.loadtbh_TaiLieuCuaNhanVien
@nMaTaiLieuCuaNhanVien [numeric] = 0,
@nMaTaiLieu [numeric] = 0,
@cMaNhanVien [nvarchar](20) = '',
@cNoiLuuTru [nvarchar](100) = '',
@dNgayNhanVanBanTu nvarchar(20) = '',
@dNgayNhanVanBanDen nvarchar(20) = '',
@CapTruyCapDuLieu tinyint =0,
@MaNhanVienDangNhap nvarchar(20)='',
@MaCoCauToChuc nvarchar(20)=''
AS
--Tim phong ban tuong ung voi cap duoc truy xaut du lieu ( Cap >0 ).
--Trường hợp cấp = 0 : là private va all ( không xét đến)
Declare @lag nvarchar(1) -- Language
SELECT @lag = cLanguage FROM tbh_NgonNguHeThong where cMaNhanVien = @MaNhanVienDangNhap
If @CapTruyCapDuLieu <> 0 Begin
If @MaCoCauToChuc=''
Set @MaCoCauToChuc = dbo.GetDepartmentFromOrder(@MaNhanVienDangNhap,@CapTruyCapDuLieu)
End
SELECT nMaTaiLieuCuaNhanVien,
nMaTaiLieu,
cMaNhanVien,
dNgayNhanVanBan,
cNoiLuuTru,
cGhiChu,
CASE WHEN @lag = 'v' THEN 'Được cấp phát' ELSE 'Is Alloted' END AS cLoaiHinhSoHuu
INTO #tmpTable
FROM tbh_TaiLieuCuaNhanVien
UNION
SELECT 0 ,
nMaTaiLieu,
cMaNhanVienNhan,
dNgayGui,
'',
'',
CASE WHEN @lag = 'v' THEN 'Nhận từ nhân viên khác gửi' ELSE ' Not Alloted' END
FROM tbh_GuiTaiLieu
UNION
SELECT 0 ,
nMaTaiLieu,
cMaNhanVienNhan,
dNgayTra,
'',
'',
CASE WHEN @lag = 'v' THEN 'Nhận từ nhân viên khác trả' ELSE ' Not Alloted' END
FROM tbh_TraTaiLieu WHERE bDaTra = 1
SELECT a.*,
b.cTenVanBan As cTentaiLieu,
c.TenDaydu ,
d.cMaCoCauToChuc,
d.cTenCoCauToChuc,
e.cSoTaiLieu
FROM #tmpTable a, --tbh_TaiLieuCuaNhanVien a,
tbh_TaiLieu b,
tbh_NhanVien c,
tbh_CoCauToChuc d,
tbh_TaiLieu e
WHERE
( a.nMaTaiLieuCuaNhanVien = @nMaTaiLieuCuaNhanVien OR @nMaTaiLieuCuaNhanVien = 0 )
AND ( a.nMaTaiLieu = @nMaTaiLieu OR @nMaTaiLieu = 0)
AND ( a.cMaNhanVien = @cMaNhanVien OR @cMaNhanVien ='')
AND ( a.cNoiLuuTru LIKE '%' + @cNoiLuuTru + '%' OR @cNoiLuuTru='')
AND ( cast(a.dNgayNhanVanBan as nvarchar) BETWEEN cast(@dNgayNhanVanBanTu as Datetime) AND cast(@dNgayNhanVanBanDen as DAtetime) Or @dNgayNhanVanBanTu='')
And ((( cMaDuongDan = @MaCoCauToChuc ) or ( c.MaCoCauToChuc = @MaCoCauToChuc ) or
(cMaDuongDan like '%|'+@MaCoCauToChuc+'|%') or ( cMaDuongDan like '%'+@MaCoCauToChuc+'%' ) or (@MaCoCauToChuc= '' )))
AND a.cMaNhanVien = c.MaNhanVien
AND a.nMaTaiLieu = b.nMaTaiLieu
AND c.MaCoCauToChuc = d.cMaCoCauToChuc
And a.nMaTaiLieu = e.nMaTaiLieu
-- Tru di so tai lieu da tra ve cho cong ty
And (a.nMaTaiLieu not in (Select nMaTaiLieu From tbh_TraTaiLieu Where nMaTaiLieu =a.nMaTaiLieu and a.cMaNhanVien= tbh_TraTaiLieu.cMaNhanVienTra AND bDaTra = 1))
--Gui
--And (a.nMaTaiLieu not in (Select nMaTaiLieu From tbh_GuiTaiLieu Where nMaTaiLieu =a.nMaTaiLieu and a.cMaNhanVien= tbh_GuiTaiLieu.cMaNhanVienGui ))
+++++++++++++++++++++++++++++++++++++++++++--------------------------------------------++++++++++++++++++++++++++++++++++++++++++++++++
/*Global Temporary Tables:1 *//* Translation Extracted DDL For Required Objects*/
CREATE GLOBAL TEMPORARY TABLE tt_tmpTable
AS (
OPEN cv_1 FOR
SELECT nMaTaiLieuCuaNhanVien ,
nMaTaiLieu ,
cMaNhanVien ,
dNgayNhanVanBan ,
cNoiLuuTru ,
cGhiChu ,
CASE
WHEN v_lag = 'v' THEN 'Được cấp phát'
ELSE 'Is Alloted'
END cLoaiHinhSoHuu
FROM tbh_TaiLieuCuaNhanVien
UNION
SELECT 0 ,
nMaTaiLieu ,
cMaNhanVienNhan ,
dNgayGui ,
'' ,
'' ,
CASE
WHEN v_lag = 'v' THEN 'Nhận từ nhân viên khác gửi'
ELSE ' Not Alloted'
END col
FROM tbh_GuiTaiLieu
UNION
SELECT 0 ,
nMaTaiLieu ,
cMaNhanVienNhan ,
dNgayTra ,
'' ,
'' ,
CASE
WHEN v_lag = 'v' THEN 'Nhận từ nhân viên khác trả'
ELSE ' Not Alloted'
END col
FROM tbh_TraTaiLieu
);
/
CREATE OR REPLACE PROCEDURE loadtbh_TaiLieuCuaNhanVien
(
v_nMaTaiLieuCuaNhanVien IN NUMBER DEFAULT 0 ,
v_nMaTaiLieu IN NUMBER DEFAULT 0 ,
v_cMaNhanVien IN NVARCHAR2 DEFAULT '' ,
v_cNoiLuuTru IN NVARCHAR2 DEFAULT '' ,
v_dNgayNhanVanBanTu IN NVARCHAR2 DEFAULT '' ,
v_dNgayNhanVanBanDen IN NVARCHAR2 DEFAULT '' ,
v_CapTruyCapDuLieu IN NUMBER DEFAULT 0 ,
v_MaNhanVienDangNhap IN NVARCHAR2 DEFAULT '' ,
iv_MaCoCauToChuc IN NVARCHAR2 DEFAULT '' ,
cv_1 IN OUT SYS_REFCURSOR,
cv_2 IN OUT SYS_REFCURSOR
)
AS
v_MaCoCauToChuc NVARCHAR2(20) := iv_MaCoCauToChuc;
--Tim phong ban tuong ung voi cap duoc truy xaut du lieu ( Cap >0 ).
--Trường hợp cấp = 0 : là private va all ( không xét đến)
v_lag NVARCHAR2(1);-- Language
BEGIN
SELECT cLanguage
INTO v_lag
FROM tbh_NgonNguHeThong
WHERE cMaNhanVien = v_MaNhanVienDangNhap;
IF v_CapTruyCapDuLieu <> 0 THEN
BEGIN
IF v_MaCoCauToChuc IS NULL THEN
v_MaCoCauToChuc := GetDepartmentFromOrder(v_MaNhanVienDangNhap, v_CapTruyCapDuLieu) ;
END IF;
END;
END IF;
DELETE FROM tt_tmpTable;
INSERT INTO tt_tmpTable (
OPEN cv_1 FOR
SELECT nMaTaiLieuCuaNhanVien ,
nMaTaiLieu ,
cMaNhanVien ,
dNgayNhanVanBan ,
cNoiLuuTru ,
cGhiChu ,
CASE
WHEN v_lag = 'v' THEN 'Được cấp phát'
ELSE 'Is Alloted'
END cLoaiHinhSoHuu
FROM tbh_TaiLieuCuaNhanVien
UNION
SELECT 0 ,
nMaTaiLieu ,
cMaNhanVienNhan ,
dNgayGui ,
'' ,
'' ,
CASE
WHEN v_lag = 'v' THEN 'Nhận từ nhân viên khác gửi'
ELSE ' Not Alloted'
END col
FROM tbh_GuiTaiLieu
UNION
SELECT 0 ,
nMaTaiLieu ,
cMaNhanVienNhan ,
dNgayTra ,
'' ,
'' ,
CASE
WHEN v_lag = 'v' THEN 'Nhận từ nhân viên khác trả'
ELSE ' Not Alloted'
END col
FROM tbh_TraTaiLieu
WHERE bDaTra = 1 );
OPEN cv_2 FOR
SELECT a.* ,
b.cTenVanBan cTentaiLieu ,
c.TenDaydu ,
D.cMaCoCauToChuc ,
D.cTenCoCauToChuc ,
e.cSoTaiLieu
FROM tt_tmpTable a--tbh_TaiLieuCuaNhanVien a,
,
tbh_TaiLieu b,
tbh_NhanVien c,
tbh_CoCauToChuc D,
tbh_TaiLieu e
WHERE ( a.nMaTaiLieuCuaNhanVien = v_nMaTaiLieuCuaNhanVien
OR v_nMaTaiLieuCuaNhanVien = 0 )
AND ( a.nMaTaiLieu = v_nMaTaiLieu
OR v_nMaTaiLieu = 0 )
AND ( a.cMaNhanVien = v_cMaNhanVien
OR v_cMaNhanVien IS NULL )
AND ( a.cNoiLuuTru LIKE '%' || v_cNoiLuuTru || '%'
OR v_cNoiLuuTru IS NULL )
AND ( CAST(a.dNgayNhanVanBan AS NVARCHAR2(4000)) BETWEEN CAST(v_dNgayNhanVanBanTu AS DATE) AND CAST(v_dNgayNhanVanBanDen AS DATE)
OR v_dNgayNhanVanBanTu IS NULL )
AND ( ( ( cMaDuongDan = v_MaCoCauToChuc )
OR ( c.MaCoCauToChuc = v_MaCoCauToChuc )
OR ( cMaDuongDan LIKE '%|' || v_MaCoCauToChuc || '|%' )
OR ( cMaDuongDan LIKE '%' || v_MaCoCauToChuc || '%' )
OR ( v_MaCoCauToChuc IS NULL ) ) )
AND a.cMaNhanVien = c.MaNhanVien
AND a.nMaTaiLieu = b.nMaTaiLieu
AND c.MaCoCauToChuc = D.cMaCoCauToChuc
AND a.nMaTaiLieu = e.nMaTaiLieu
-- Tru di so tai lieu da tra ve cho cong ty
AND ( a.nMaTaiLieu NOT IN ( SELECT nMaTaiLieu
FROM tbh_TraTaiLieu
WHERE nMaTaiLieu = a.nMaTaiLieu
AND a.cMaNhanVien = cMaNhanVienTra
AND bDaTra = 1 )
);--Gui
--And (a.nMaTaiLieu not in (Select nMaTaiLieu From tbh_GuiTaiLieu Where nMaTaiLieu =a.nMaTaiLieu and a.cMaNhanVien= tbh_GuiTaiLieu.cMaNhanVienGui ))
END;
Bạn đang đọc truyện trên: AzTruyen.Top