Вы находитесь на странице: 1из 9

ALTER TABLE tbl_menu_USER ADD DESIGNATION_ID VARCHAR2(20);

ALTER TABLE TBL_USER_SCHEME ADD OFFICE_ID VARCHAR2(20);


UPDATE tbl_menu_ROLE SET DESIGNATION_ID = '0000' WHERE USER_TYPE_ID <> '505';
COMMIT;
DELETE FROM tbl_menu_ROLE WHERE DESIGNATION_ID IS NULL;
COMMIT;
UPDATE tbl_menu_USER SET DESIGNATION_ID = '0000'
WHERE LOGIN_ID NOT IN (SELECT LOGIN_ID FROM bhamashahblockqc.TBL_USER_INFO WHERE
USER_TYPE_ID ='505' );
COMMIT;
DELETE FROM TBL_MENU_USER WHERE DESIGNATION_ID IS NULL;
COMMIT;

CREATE SEQUENCE SEQ_BANK_OFFICE_MASTER START WITH 1 INCREMENT BY 1 NOMAXVALUE;


CREATE TABLE TBL_BANK_OFFICE_MASTER (
ID NUMBER(20) NOT NULL,
OFFICE_ID VARCHAR2(100),
SCHEME_ID NUMBER(20),
DISTRICT VARCHAR2(100),
BLOCK_CITY NUMBER(20)
IS_RURAL VARCHAR2(1 CHAR),
ADDRESS VARCHAR2(200),
BANK_ID NUMBER(20),
IFSC_CODE VARCHAR2(15),
BRANCH_ID NUMBER(20),
ACC_NO NUMBER(20),
CREATED_ON DATE DEFAULT SYSDATE,
CREATED_BY VARCHAR2(50),
CONSTRAINT TBL_BANK_OFFICE_MASTER_PK PRIMARY KEY(ID)
);
CREATE OR REPLACE TRIGGER TRG_BANK_OFFICE_MASTER
BEFORE INSERT ON TBL_BANK_OFFICE_MASTER
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT SEQ_BANK_OFFICE_MASTER.NEXTVAL INTO :NEW.id FROM dual;
END;

CREATE OR REPLACE PROCEDURE SP_INSERT_UPDATE_MENU_ROLE (


roleId varchar,
userTypeId varchar,
menuNo varchar,
isActive varchar,
dbtUserType varchar,
loginName varchar)
as
begin
UPDATE TBL_MENU_ROLE

SET IS_ACTIVE = isActive


WHERE ROLE_ID = roleId AND USER_TYPE_ID = userTypeId AND MENU_NO = menuNo and
designation_id = dbtUserType;
UPDATE TBL_MENU_USER SET IS_ACTIVE = CASE WHEN IS_ACTIVE_IND = 'Y' THEN 'Y'
WHEN IS_ACTIVE_IND = 'N' THEN 'N' ELSE isActive END
WHERE ROLE_ID = roleId
AND MENU_NO = menuNo
AND designation_id = dbtUserType
AND LOGIN_ID IN(SELECT LOGIN_ID FROM bhamashahblockqc.TBL_USER_INFO WHERE U
SER_TYPE_ID = userTypeId );
END;

CREATE OR REPLACE PROCEDURE MENU_ROLE_USER_INSERT


AS
BEGIN
INSERT INTO tbl_menu_ROLE (MENU_NO,ROLE_ID,USER_TYPE_ID, IS_ACTIVE,DESIGNATION
_ID)
SELECT DISTINCT MENU_NO, B.ROLE_ID, C.USER_TYPE_ID, 'N' IS_ACTIVE,'0000'
FROM TBL_MENU A , BHAMASHAHBLOCKQC.LU_USER_ROLE B,BHAMASHAHBLOCKQC.LU_USER_TYP
E C
where A.IS_ACTIVE = 'Y' AND B.IS_ACTIVE = 'Y' AND C.IS_ACTIVE = 'Y'
AND not exists (select 1 from tbl_menu_ROLE e where e.ROLE_ID = B.ROLE_ID
AND e.USER_TYPE_ID = C.USER_TYPE_ID and e.MENU_NO = A.MENU_NO and e.DESIGNATIO
N_ID = '0000')
and c.USER_TYPE_ID <> '505';
COMMIT;
INSERT INTO tbl_menu_ROLE (MENU_NO,ROLE_ID,USER_TYPE_ID, IS_ACTIVE,DESIGNATION
_ID)
SELECT DISTINCT MENU_NO, B.ROLE_ID, C.USER_TYPE_ID, 'N' IS_ACTIVE, d.ID DESIGN
ATION_ID
FROM TBL_MENU A , BHAMASHAHBLOCKQC.LU_USER_ROLE B,BHAMASHAHBLOCKQC.LU_USER_TYP
E C , DESIGNATION_MASTER d
where A.IS_ACTIVE = 'Y' AND B.IS_ACTIVE = 'Y' AND C.IS_ACTIVE = 'Y'
AND not exists (select 1 from tbl_menu_ROLE e where e.ROLE_ID = B.ROLE_ID
AND e.USER_TYPE_ID = C.USER_TYPE_ID and e.MENU_NO = A.MENU_NO and d.ID = e.DES
IGNATION_ID)
and c.USER_TYPE_ID ='505';
COMMIT;
INSERT INTO TBL_MENU_USER(MENU_NO,ROLE_ID,LOGIN_ID,IS_ACTIVE,DESIGNATION_ID)
select distinct mr.menu_no,mr.role_id,ur.login_id,MR.IS_ACTIVE,mr.DESIGNATION_
ID
from tbl_menu_role mr, bhamashahblockqc.TBL_USER_ROLE ur
where MR.ROLE_ID = UR.ROLE_ID
and not exists (select 1 from TBL_MENU_USER mu
where MU.LOGIN_ID = UR.LOGIN_ID
and UR.ROLE_ID = MU.ROLE_ID and MU.MENU_NO = MR.MENU_NO
and mu.DESIGNATION_ID = mr.DESIGNATION_ID)
and exists (select 1 from bhamashahblockqc.tbl_user_info ui
where ui.login_id = UR.LOGIN_ID and UI.IS_ACTIVE='1' and UI.USER_TYPE_ID = MR.
USER_TYPE_ID AND UI.USER_TYPE_ID <>'505');
INSERT INTO TBL_MENU_USER(MENU_NO,ROLE_ID,LOGIN_ID,IS_ACTIVE,DESIGNATION_ID)

select distinct mr.menu_no,mr.role_id,ur.login_id,MR.IS_ACTIVE,mr.DESIGNATION_


ID
from tbl_menu_role mr, bhamashahblockqc.TBL_USER_ROLE ur
where MR.ROLE_ID = UR.ROLE_ID
and not exists (select 1 from TBL_MENU_USER mu
where MU.LOGIN_ID = UR.LOGIN_ID
and UR.ROLE_ID = MU.ROLE_ID and MU.MENU_NO = MR.MENU_NO
and mu.DESIGNATION_ID = mr.DESIGNATION_ID)
and exists (select 1 from bhamashahblockqc.tbl_user_info ui, tbl_dbt_users dbt
where ui.login_id = UR.LOGIN_ID and UI.IS_ACTIVE='1' and UI.USER_TYPE_ID = MR.
USER_TYPE_ID
and dbt.login_name = ui.login_name and dbt.id in (select user_id from user_des
ignation_mapping where designation_id=mr.DESIGNATION_ID)
AND UI.USER_TYPE_ID = '505');
COMMIT;
END;
CREATE OR REPLACE PROCEDURE SP_GET_MENU_ROLE(RESULTSET OUT SYS_REFCURSOR,
selectedRoleId varchar,
selectedUserTypeId varchar,
isrural varchar,
district varchar,
city_block varchar,
dbtUserTypeId varchar)
AS
loginId varchar2(20);
BEGIN
OPEN RESULTSET FOR
SELECT A.MENU_NAME, a.menu_code,A.MENU_LEVEL, A.MENU_NO, A.HAS_SUBMENU , B.I
S_ACTIVE
FROM tbl_menu a , tbl_menu_role b
WHERE A.MENU_NO = B.MENU_NO and B.ROLE_ID = selectedRoleId
AND B.USER_TYPE_ID = selectedUserTypeId and designation_id=dbtUserTypeId
ORDER BY A.MENU_NO;
END;

create or replace PROCEDURE SP_GET_MASTER_DATA(


RESULTSET OUT SYS_REFCURSOR,
masterName VARCHAR,
loginId varchar)
AS
countRec varchar2(20);
BEGIN
countRec:='0';
IF(masterName='ROLE_TYPES') THEN
OPEN RESULTSET FOR
select ROLE_ID,ROLE_NAME,IS_ACTIVE from bhamashahblockqc.lu_user_role where
IS_ACTIVE = 'Y' ORDER BY 1;
END IF;

IF(masterName='USER_TYPES') THEN
OPEN RESULTSET FOR
select USER_TYPE_ID,USER_TYPE_NAME,IS_ACTIVE from bhamashahblockqc.lu_user_T
YPE where IS_ACTIVE = 'Y' ORDER BY 1;
END IF;
IF(masterName='DESIGNATION') THEN
SELECT COUNT(*) INTO countRec FROM BHAMASHAHBLOCKQC.TBL_USER_INFO WHERE LOGI
N_ID = loginId AND LOGIN_NAME = 'SuperAdmin';
IF(countRec>'0') THEN
OPEN RESULTSET FOR
SELECT ID, INITCAP(NAME), IS_ACTIVE
FROM DESIGNATION_MASTER A
WHERE IS_ACTIVE = 'Y' ORDER BY NAME;
ELSE
OPEN RESULTSET FOR
SELECT ID, INITCAP(NAME), IS_ACTIVE
FROM DESIGNATION_MASTER A
WHERE IS_ACTIVE = 'Y' AND A.ID = '1001' ORDER BY NAME;
END IF;
END IF;
IF(masterName='OFFICE') THEN
OPEN RESULTSET FOR
SELECT OFFICE_ID, INITCAP(OFFICE_NAME),IS_ACTIVE
FROM OFFICE_MASTER
WHERE IS_ACTIVE = 'Y'
AND DEPT_ID = loginId
AND OFFICE_NAME IS NOT NULL
ORDER BY OFFICE_NAME;
END IF;
IF(masterName='DEPARTMENT') THEN
OPEN RESULTSET FOR
SELECT DEPARTMENT_ID, INITCAP(DEPARTMENT_NAME),IS_ACTIVE
FROM BHAMASHAHBLOCKQC.LU_DEPARTMENT
WHERE IS_ACTIVE = 'Y' AND IS_SEEDING = 'Y'
AND DEPARTMENT_ID IN (SELECT B.DEPARTMENT_ID FROM BHAMASHAHBLOCKQC.TBL_USE
R_DEPARTMENT B WHERE B.LOGIN_ID = loginId)
ORDER BY DEPARTMENT_NAME;
END IF;
IF(masterName='USER_TYPE') THEN
OPEN RESULTSET FOR
SELECT USER_TYPE_ID, USER_TYPE_NAME,IS_ACTIVE
FROM BHAMASHAHBLOCKQC.LU_USER_TYPE
WHERE IS_ACTIVE = 'Y' AND USER_TYPE_ID = '505' ORDER BY USER_TYPE_NAME;
END IF;
IF(masterName='SCHEME_TYPE') THEN
OPEN RESULTSET FOR
SELECT ID, INITCAP(SCHEME_TYPE_NAME),IS_ACTIVE
FROM SCHEME_TYPES
WHERE IS_ACTIVE = 'Y' ORDER BY SCHEME_TYPE_NAME;
END IF;

IF(masterName='BENEFIT_TYPE') THEN
OPEN RESULTSET FOR
SELECT ID, INITCAP(BENEFIT_TYPE_NAME),IS_ACTIVE
FROM BENEFIT_TYPES
WHERE IS_ACTIVE = 'Y' ORDER BY BENEFIT_TYPE_NAME;
END IF;
IF(masterName='BENEFIT_AMOUNT') THEN
OPEN RESULTSET FOR
SELECT ID, INITCAP(BENEFIT_AMOUNT_NAME),IS_ACTIVE
FROM BENEFIT_AMOUNTS
WHERE IS_ACTIVE = 'Y' ORDER BY BENEFIT_AMOUNT_NAME;
END IF;
IF(masterName='DISBURSEMENT_LEVEL') THEN
OPEN RESULTSET FOR
SELECT ID, INITCAP(DISBURSEMENT_LEVEL_NAME),IS_ACTIVE
FROM DISBURSEMENT_LEVELS
WHERE IS_ACTIVE = 'Y' ORDER BY ID;
END IF;
IF(masterName='DISBURSEMENT_SOURCE') THEN
OPEN RESULTSET FOR
SELECT ID, INITCAP(DISBURSEMENT_SOURCE_NAME),IS_ACTIVE
FROM DISBURSEMENT_SOURCES
WHERE IS_ACTIVE = 'Y' ORDER BY ID;
END IF;
IF(masterName='NONCASH_TYPE') THEN
OPEN RESULTSET FOR
SELECT ID, INITCAP(NONCASH_NAME),IS_ACTIVE
FROM NONCASH_TYPES
WHERE IS_ACTIVE = 'Y' ORDER BY ID;
END IF;
IF(masterName='BUDGET_HEAD_MASTER') THEN
OPEN RESULTSET FOR
SELECT A.BUDGET_ID, A.BUDGET_ID,'Y'
FROM BUDGET_HEAD_MASTER A
WHERE A.DEPT_ID in (SELECT B.DEPARTMENT_ID FROM BHAMASHAHBLOCKQC.TBL_USER_DE
PARTMENT B WHERE B.LOGIN_ID = loginId)
ORDER BY A.BUDGET_ID;
END IF;
IF(masterName='FREQUENCY_TYPES') THEN
OPEN RESULTSET FOR
SELECT ID, FREQUENCY_TYPE_NAME, IS_ACTIVE FROM FREQUENCY_TYPES WHERE IS_ACTI
VE = 'Y' ORDER BY 1;
END IF;
END;

create or replace PROCEDURE SP_GET_USER_SCHEME(


RESULTSET OUT SYS_REFCURSOR,
schemeUserName VARCHAR,
isrural VARCHAR,

district VARCHAR,
city_block VARCHAR,
loginUserId VARCHAR,
loginUserName VARCHAR,
modeVal VARCHAR)
AS
loginId VARCHAR2(20);
BEGIN
BEGIN
SELECT login_id INTO loginId FROM bhamashahblockqc.TBL_USER_INFO WHERE login_n
ame= schemeUserName AND NVL(CREATED_BY,'0') = loginUserId;
EXCEPTION WHEN OTHERS THEN
loginId:='0';
END;
IF(loginId<>'0') THEN
IF(modeVal = 'OLD') THEN
OPEN RESULTSET FOR
SELECT
s.department_id,
(select D.DEPARTMENT_name from bhamashahblockqc.LU_DEPARTMENT D where D.
DEPARTMENT_ID = S.DEPARTMENT_ID ) as department_name,
S.SCHEME_ID,
upper(s.scheme_name ) scheme_name,
(SELECT 'Y' FROM TBL_USER_SCHEME US WHERE US.SCHEME_ID=S.SCHEME_ID AND U
S.LOGIN_ID= loginId ) as checked
FROM
LU_SCHEME S
WHERE
S.IS_ACTIVE='Y'
and exists (select 1 from bhamashahblockqc.TBL_USER_DEPARTMENT UD, bhama
shahblockqc.LU_DEPARTMENT D
where UD.DEPARTMENT_ID = D.DEPARTMENT_ID
AND D.DEPARTMENT_ID = S.DEPARTMENT_ID
AND D.IS_ACTIVE='Y'
AND UD.LOGIN_ID = loginId)
ORDER BY s.department_id ;
END IF;
IF(modeVal = 'NEW') THEN
OPEN RESULTSET FOR
SELECT
s.department_id,
(select D.DEPARTMENT_name from bhamashahblockqc.LU_DEPARTMENT D where
D.DEPARTMENT_ID = S.DEPARTMENT_ID ) as department_name,
S.ID,
upper(s.scheme_name ) scheme_name,
(SELECT 'Y' FROM TBL_USER_SCHEME US WHERE US.SCHEME_ID = S.ID AND US.L
OGIN_ID= loginId ) as checked,
(SELECT DS.DISBURSEMENT_SOURCE_NAME FROM DISBURSEMENT_SOURCES DS WHER
E DS.ID = S.DISBURSEMENT_SOURCE_ID ),
S.DISBURSEMENT_SOURCE_ID
FROM
TBL_SCHEMES S
WHERE
exists (select 1 from bhamashahblockqc.TBL_USER_DEPARTMENT UD,bhamasha
hblockqc.LU_DEPARTMENT D
where UD.DEPARTMENT_ID = D.DEPARTMENT_ID
AND D.DEPARTMENT_ID = S.DEPARTMENT_ID

AND D.IS_ACTIVE='Y'
AND UD.LOGIN_ID = loginId )
AND S.created_by = loginUserName
ORDER BY s.department_id ;
END IF;
ELSE
OPEN RESULTSET FOR
SELECT 1 FROM DUAL WHERE 1=2;
END IF;

END;

create or replace procedure SP_GET_OFFICE_MASTER_DATA (


RESULTSET OUT SYS_REFCURSOR,
returnValue OUT varchar,
schemeId varchar,
userId varchar,
disbursementSourceId varchar,
loginName varchar)
AS
loginId varchar2(20);
distId varchar2(20);
blockId varchar2(20);
cityId varchar2(20);
isRural varchar2(20);
BEGIN
BEGIN
SELECT LOGIN_ID INTO loginId FROM BHAMASHAHBLOCKQC.TBL_USER_INFO WHERE LOG
IN_NAME = userId AND ROWNUM =1 ;
EXCEPTION WHEN OTHERS THEN
loginId:='-1';
returnValue:='USER_NOT_FOUND';
END;
IF (loginId <> '-1') THEN
BEGIN
SELECT NVL(DISTRICT_ID,'0'),nvl(BLOCK_ID,'0'),nvl(CITY_ID,'0'),nvl(IS_RU
RAL,'B') INTO distId, blockId, cityId, isRural
FROM BHAMASHAHBLOCKQC.TBL_USER_LOCATION
WHERE LOGIN_ID = loginId AND ROWNUM =1;
EXCEPTION WHEN OTHERS THEN
distId:='-1';
returnValue:='USER_LOCATION_NOT_FOUND';
END;
IF(isRural='1') THEN
isRural:='U';
END IF;
IF(isRural='0') THEN
isRural:='R';
END IF;

END IF;
DBMS_OUTPUT.PUT_LINE('distId: '||distId ||' blockId : '|| blockId ||' cityId
: '|| cityId ||' isRural : '|| isRural);
IF(disbursementSourceId='1002') THEN
IF (loginId<> '-1' AND distId <> '-1') THEN
IF(distId = '0') THEN
OPEN RESULTSET FOR
SELECT
A.ID,
A.OFFICE_ID ||' : '||A.ADDRESS,
A.OFFICE_ID
FROM TBL_BANK_OFFICE_MASTER A WHERE A.SCHEME_ID = schemeId;
END IF;
IF(distId <> '0' and blockId = '0' and isRural = 'B') THEN
OPEN RESULTSET FOR
SELECT
A.ID,
A.OFFICE_ID ||' : '||A.ADDRESS||' '||
(SELECT B.DISTRICT_NAME_ENG FROM DISTRICT_MASTER B WHERE B.DISTRICT_ID
= A.DISTRICT AND ROWNUM=1),
A.OFFICE_ID
FROM TBL_BANK_OFFICE_MASTER A WHERE A.SCHEME_ID = schemeId;
END IF;
IF(distId <> '0' and cityId = '0' AND isRural = 'B') THEN
OPEN RESULTSET FOR
SELECT
A.ID,
A.OFFICE_ID ||' : '||A.ADDRESS||' '||
(SELECT B.DISTRICT_NAME_ENG FROM DISTRICT_MASTER B WHERE B.DISTRICT_ID
= A.DISTRICT AND ROWNUM=1),
A.OFFICE_ID
FROM TBL_BANK_OFFICE_MASTER A WHERE A.SCHEME_ID = schemeId;
END IF;
IF(distId <> '0' and blockId <> '0' and isRural = 'R') THEN
OPEN RESULTSET FOR
SELECT
A.ID,
A.OFFICE_ID ||' : '||A.ADDRESS||' '||
(SELECT C.BLOCK_NAME_ENG FROM BLOCK_MASTER C WHERE C.DISTRICT_ID = A.D
ISTRICT AND C.BLOCK_ID = A.BLOCK_CITY AND A.IS_RURAL = 'Y' AND ROWNUM=1)||' '||
(SELECT B.DISTRICT_NAME_ENG FROM DISTRICT_MASTER B WHERE B.DISTRICT_ID
= A.DISTRICT AND ROWNUM=1),
A.OFFICE_ID
FROM TBL_BANK_OFFICE_MASTER A
WHERE A.SCHEME_ID = schemeId
and A.BLOCK_CITY = blockId
AND A.IS_RURAL = 'Y';
END IF;
IF(distId <> '0' and cityId <> '0' and isRural = 'U') THEN
OPEN RESULTSET FOR
SELECT
A.ID,
A.OFFICE_ID ||' : '||A.ADDRESS||' '||
(SELECT C.CITY_NAME_ENG FROM CITY_MASTER C WHERE C.DISTRICT_ID = A.DIS
TRICT AND C.CITY_ID = A.BLOCK_CITY AND A.IS_RURAL = 'N' AND ROWNUM=1)||' '||

(SELECT B.DISTRICT_NAME_ENG FROM DISTRICT_MASTER B WHERE B.DISTRICT_ID


= A.DISTRICT AND ROWNUM=1),
A.OFFICE_ID
FROM TBL_BANK_OFFICE_MASTER A WHERE A.SCHEME_ID = schemeId
and A.BLOCK_CITY = cityId
AND A.IS_RURAL = 'N';
END IF;
END IF;
END IF;
END;

create or replace PROCEDURE SP_GET_MAPPED_SCHEME_USERS (


RESULTSET OUT SYS_REFCURSOR,
loginName VARCHAR)
AS
BEGIN
OPEN RESULTSET FOR
SELECT ID,
(SELECT B.SCHEME_NAME FROM TBL_SCHEMES B WHERE B.ID = A.SCHEME_ID AND ROWNUM
= 1) AS SCHEME_NAME,
(SELECT C.LOGIN_NAME FROM TBL_DBT_USERS C WHERE C.ID = A.DBT_USER_ID AND ROW
NUM = 1) AS SSOID,
(SELECT E.DISBURSEMENT_SOURCE_NAME FROM DISBURSEMENT_SOURCES E WHERE E.ID IN
(SELECT F.DISBURSEMENT_SOURCE_ID FROM TBL_SCHEMES F WHERE F.ID = A.SCHEME_ID AN
D ROWNUM = 1) ) AS DISBURSEMENT_SOURCE_NAME,
(SELECT D.DISBURSEMENT_SOURCE_ID FROM TBL_SCHEMES D WHERE D.ID = A.SCHEME_ID
AND ROWNUM = 1) AS DISBURSEMENT_SOURCE_ID,
(SELECT H.OFFICE_ID||' '||H.ADDRESS ||' '||(SELECT DISTRICT_NAME_ENG FROM DI
STRICT_MASTER WHERE DISTRICT_ID = H.DISTRICT AND ROWNUM =1)
FROM TBL_BANK_OFFICE_MASTER H
WHERE H.SCHEME_ID = A.SCHEME_ID AND A.OFFICE_ID = H.ID) AS OFFICE_NAME,
(SELECT G.ID FROM TBL_BANK_OFFICE_MASTER G
WHERE G.SCHEME_ID = A.SCHEME_ID AND A.OFFICE_ID = G.ID) AS OFFICE_ID
FROM TBL_USER_SCHEME A
WHERE A.DBT_USER_ID IS NOT NULL
AND A.CREATED_BY = loginName
ORDER BY A.CREATED_DT DESC;
END;