CREATE OR REPLACE PROCEDURE SP_SDA130_ADJ
( FDATE IN VARCHAR2,
TDATE IN VARCHAR2,
DEPT_CODE IN VARCHAR2,
CUST_CODE IN VARCHAR2,
EMPL_ID IN VARCHAR2,
CREATE_USER IN VARCHAR2,
MODIFY_USER IN VARCHAR2,
PC_IP IN VARCHAR2,
SLIP_NO IN OUT VARCHAR2,
SLIP_CNT IN OUT NUMBER
) AS
TYPE ARRTYP IS TABLE OF NUMBER(05)
INDEX BY BINARY_INTEGER;
II BINARY_INTEGER := 0;
CNT BINARY_INTEGER := 0;
V_ARR ARRTYP;
V_DATE VARCHAR2(08);
V_MON VARCHAR2(06);
V_FDATE VARCHAR2(08);
V_TDATE VARCHAR2(08);
V_DEPT VARCHAR2(06);
V_CUST VARCHAR2(06);
V_EMPL VARCHAR2(07);
V_CREATE VARCHAR2(07);
V_MODIFY VARCHAR2(07);
V_IP VARCHAR2(20);
V_RSEQ NUMBER;
--
V_AMT NUMBER;
V_PRICE NUMBER;
V_CNT NUMBER(05);
V_NO NUMBER(05);
V_SEQ VARCHAR2(05);
V_SITE_CODE VARCHAR2(04);
V_SITE_NAME VARCHAR2(40);
BEGIN
SELECT TO_CHAR(SYSDATE,'YYYYMMDD'),TO_CHAR(SYSDATE,'YYYYMM') INTO V_DATE,V_MON FROM DUAL;
V_FDATE := FDATE;
V_TDATE := TDATE;
V_DEPT := DEPT_CODE;
V_CUST := CUST_CODE;
V_EMPL := EMPL_ID;
V_CREATE := CREATE_USER;
V_MODIFY := MODIFY_USER;
V_IP := PC_IP;
--
SELECT NVL(COUNT(DISTINCT CUST_CODE),0) CNT
INTO V_CNT
FROM PURCH
WHERE PURCH_DATE BETWEEN V_FDATE
AND V_TDATE
AND DEPT_CODE = V_DEPT
AND CUST_CODE = DECODE(V_CUST,'!',CUST_CODE,V_CUST)
AND ITEM_CODE NOT IN ('GDR','GACTA','GFA')
AND PURCH_GUBUN = '1'
AND ADJ_SLIP_NO IS NULL;
--
II := 0;
LOOP
II:=II+1;
EXIT WHEN II > V_CNT;
V_ARR(II):=0;
SP_GET_NO(V_DATE,'08',V_NO);
V_ARR(II):=V_NO;
END LOOP;
--
SP_GET_SLIPNO(V_DATE,V_SEQ);
SP_SET_SLIP_M_WORK(V_DATE,V_SEQ,V_DEPT,V_EMPL,'S08',V_CREATE,V_MODIFY,V_IP);
--
SELECT A.BIZ_AREA_CODE,
B.BIZ_AREA_NAME
INTO V_SITE_CODE,
V_SITE_NAME
FROM DEPT A,
BIZ_INFO B
WHERE A.DEPT_CODE = V_DEPT
AND B.BIZ_AREA_CODE = A.BIZ_AREA_CODE;
--
V_AMT:=0;
SLIP_CNT:=0;
II := 0;
FOR I IN (SELECT A.CUST_CODE,
B.CUST_NAME,
SUM(A.PRICE) PRICE,
SUM(A.VAT) VAT
FROM PURCH A,CUST B
WHERE A.PURCH_DATE BETWEEN V_FDATE
AND V_TDATE
AND A.DEPT_CODE = V_DEPT
AND A.CUST_CODE = DECODE(V_CUST,'!',A.CUST_CODE,V_CUST)
AND A.ITEM_CODE NOT IN ('GDR','GACTA','GFA')
AND A.ADJ_SLIP_NO IS NULL
AND A.PURCH_GUBUN = '1'
AND B.CUST_CODE(+) = A.CUST_CODE
GROUP BY A.CUST_CODE,B.CUST_NAME)
LOOP
II:= II+1;
SLIP_CNT:=SLIP_CNT+1;
V_AMT := V_AMT + I.VAT;
SP_SET_SLIP_D_WORK(V_DATE,V_SEQ,0,'D',V_DEPT,'1114600','2110101',I.VAT,V_CREATE,V_MODIFY,V_IP,V_RSEQ) ;
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'14',TO_CHAR(I.PRICE),'');
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'28',V_SITE_CODE,V_SITE_NAME);
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'29','02','세금계산서[일 반]');
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'37',I.CUST_CODE,I.CUST_NAME);
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'38','구매부가세(국내)','');
--
V_NO := V_ARR(II);
SP_SET_SURTAX('1',V_MON,V_NO,V_DATE,V_DATE,V_SEQ,V_RSEQ,'21',V_SITE_CODE,I.CUST_CODE,I.CUST_NAME,
'','','','','','','',
V_DEPT,'','',V_CREATE,V_MODIFY,V_IP);
FOR J IN (SELECT ROWNUM RNO,
B.ACCT_ITEM_CODE,B.REP_ITEM_NAME,
C.UNIT,A.PURCH_QTY,A.PRICE,A.UPRICE,A.VAT
FROM PURCH A,
REP_ITEM B,
ITEM C
WHERE A.PURCH_DATE BETWEEN V_FDATE
AND V_TDATE
AND A.DEPT_CODE = V_DEPT
AND A.CUST_CODE = I.CUST_CODE
AND A.ITEM_CODE NOT IN ('GDR','GACTA','GFA')
AND A.ADJ_SLIP_NO IS NULL
AND A.PURCH_GUBUN = '1'
AND C.ITEM_CODE = A.ITEM_CODE
AND B.REP_ITEM_CODE = C.REP_ITEM_CODE
AND B.DOMAIN_GUBUN = C.DOMAIN_GUBUN)
LOOP
IF J.RNO=1 THEN
SP_SET_SURTAX_ITEMS('1',V_MON,V_NO,1,J.REP_ITEM_NAME,J.PRICE,J.VAT,J.UPRICE,J.PURCH_QTY,V_CREATE,V_MO DIFY,V_IP);
ELSE
EXIT;
END IF;
END LOOP;
END LOOP;
SP_SET_SLIP_D_WORK(V_DATE,V_SEQ,0,'C',V_DEPT,'2110101','1114600',V_AMT,V_CREATE,V_MODIFY,V_IP,V_RSEQ) ;
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'36','105184','영업부');
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'38','구매부가세(국내)','');
SP_SAVE_SLIP(V_DATE,V_SEQ,'S08');
--
UPDATE PURCH
SET ADJ_SLIP_NO = V_DATE||V_SEQ
WHERE PURCH_DATE BETWEEN V_FDATE
AND V_TDATE
AND DEPT_CODE = V_DEPT
AND CUST_CODE = DECODE(V_CUST,'!',CUST_CODE,V_CUST)
AND ITEM_CODE NOT IN ('GDR','GACTA','GFA')
AND ADJ_SLIP_NO IS NULL
AND PURCH_GUBUN = '1';
--
SLIP_NO := V_DATE||V_SEQ;
SLIP_CNT := SLIP_CNT+1;
--
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,SQLCODE||SQLERRM);
END;
( FDATE IN VARCHAR2,
TDATE IN VARCHAR2,
DEPT_CODE IN VARCHAR2,
CUST_CODE IN VARCHAR2,
EMPL_ID IN VARCHAR2,
CREATE_USER IN VARCHAR2,
MODIFY_USER IN VARCHAR2,
PC_IP IN VARCHAR2,
SLIP_NO IN OUT VARCHAR2,
SLIP_CNT IN OUT NUMBER
) AS
TYPE ARRTYP IS TABLE OF NUMBER(05)
INDEX BY BINARY_INTEGER;
II BINARY_INTEGER := 0;
CNT BINARY_INTEGER := 0;
V_ARR ARRTYP;
V_DATE VARCHAR2(08);
V_MON VARCHAR2(06);
V_FDATE VARCHAR2(08);
V_TDATE VARCHAR2(08);
V_DEPT VARCHAR2(06);
V_CUST VARCHAR2(06);
V_EMPL VARCHAR2(07);
V_CREATE VARCHAR2(07);
V_MODIFY VARCHAR2(07);
V_IP VARCHAR2(20);
V_RSEQ NUMBER;
--
V_AMT NUMBER;
V_PRICE NUMBER;
V_CNT NUMBER(05);
V_NO NUMBER(05);
V_SEQ VARCHAR2(05);
V_SITE_CODE VARCHAR2(04);
V_SITE_NAME VARCHAR2(40);
BEGIN
SELECT TO_CHAR(SYSDATE,'YYYYMMDD'),TO_CHAR(SYSDATE,'YYYYMM') INTO V_DATE,V_MON FROM DUAL;
V_FDATE := FDATE;
V_TDATE := TDATE;
V_DEPT := DEPT_CODE;
V_CUST := CUST_CODE;
V_EMPL := EMPL_ID;
V_CREATE := CREATE_USER;
V_MODIFY := MODIFY_USER;
V_IP := PC_IP;
--
SELECT NVL(COUNT(DISTINCT CUST_CODE),0) CNT
INTO V_CNT
FROM PURCH
WHERE PURCH_DATE BETWEEN V_FDATE
AND V_TDATE
AND DEPT_CODE = V_DEPT
AND CUST_CODE = DECODE(V_CUST,'!',CUST_CODE,V_CUST)
AND ITEM_CODE NOT IN ('GDR','GACTA','GFA')
AND PURCH_GUBUN = '1'
AND ADJ_SLIP_NO IS NULL;
--
II := 0;
LOOP
II:=II+1;
EXIT WHEN II > V_CNT;
V_ARR(II):=0;
SP_GET_NO(V_DATE,'08',V_NO);
V_ARR(II):=V_NO;
END LOOP;
--
SP_GET_SLIPNO(V_DATE,V_SEQ);
SP_SET_SLIP_M_WORK(V_DATE,V_SEQ,V_DEPT,V_EMPL,'S08',V_CREATE,V_MODIFY,V_IP);
--
SELECT A.BIZ_AREA_CODE,
B.BIZ_AREA_NAME
INTO V_SITE_CODE,
V_SITE_NAME
FROM DEPT A,
BIZ_INFO B
WHERE A.DEPT_CODE = V_DEPT
AND B.BIZ_AREA_CODE = A.BIZ_AREA_CODE;
--
V_AMT:=0;
SLIP_CNT:=0;
II := 0;
FOR I IN (SELECT A.CUST_CODE,
B.CUST_NAME,
SUM(A.PRICE) PRICE,
SUM(A.VAT) VAT
FROM PURCH A,CUST B
WHERE A.PURCH_DATE BETWEEN V_FDATE
AND V_TDATE
AND A.DEPT_CODE = V_DEPT
AND A.CUST_CODE = DECODE(V_CUST,'!',A.CUST_CODE,V_CUST)
AND A.ITEM_CODE NOT IN ('GDR','GACTA','GFA')
AND A.ADJ_SLIP_NO IS NULL
AND A.PURCH_GUBUN = '1'
AND B.CUST_CODE(+) = A.CUST_CODE
GROUP BY A.CUST_CODE,B.CUST_NAME)
LOOP
II:= II+1;
SLIP_CNT:=SLIP_CNT+1;
V_AMT := V_AMT + I.VAT;
SP_SET_SLIP_D_WORK(V_DATE,V_SEQ,0,'D',V_DEPT,'1114600','2110101',I.VAT,V_CREATE,V_MODIFY,V_IP,V_RSEQ) ;
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'14',TO_CHAR(I.PRICE),'');
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'28',V_SITE_CODE,V_SITE_NAME);
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'29','02','세금계산서[일 반]');
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'37',I.CUST_CODE,I.CUST_NAME);
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'38','구매부가세(국내)','');
--
V_NO := V_ARR(II);
SP_SET_SURTAX('1',V_MON,V_NO,V_DATE,V_DATE,V_SEQ,V_RSEQ,'21',V_SITE_CODE,I.CUST_CODE,I.CUST_NAME,
'','','','','','','',
V_DEPT,'','',V_CREATE,V_MODIFY,V_IP);
FOR J IN (SELECT ROWNUM RNO,
B.ACCT_ITEM_CODE,B.REP_ITEM_NAME,
C.UNIT,A.PURCH_QTY,A.PRICE,A.UPRICE,A.VAT
FROM PURCH A,
REP_ITEM B,
ITEM C
WHERE A.PURCH_DATE BETWEEN V_FDATE
AND V_TDATE
AND A.DEPT_CODE = V_DEPT
AND A.CUST_CODE = I.CUST_CODE
AND A.ITEM_CODE NOT IN ('GDR','GACTA','GFA')
AND A.ADJ_SLIP_NO IS NULL
AND A.PURCH_GUBUN = '1'
AND C.ITEM_CODE = A.ITEM_CODE
AND B.REP_ITEM_CODE = C.REP_ITEM_CODE
AND B.DOMAIN_GUBUN = C.DOMAIN_GUBUN)
LOOP
IF J.RNO=1 THEN
SP_SET_SURTAX_ITEMS('1',V_MON,V_NO,1,J.REP_ITEM_NAME,J.PRICE,J.VAT,J.UPRICE,J.PURCH_QTY,V_CREATE,V_MO DIFY,V_IP);
ELSE
EXIT;
END IF;
END LOOP;
END LOOP;
SP_SET_SLIP_D_WORK(V_DATE,V_SEQ,0,'C',V_DEPT,'2110101','1114600',V_AMT,V_CREATE,V_MODIFY,V_IP,V_RSEQ) ;
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'36','105184','영업부');
SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'38','구매부가세(국내)','');
SP_SAVE_SLIP(V_DATE,V_SEQ,'S08');
--
UPDATE PURCH
SET ADJ_SLIP_NO = V_DATE||V_SEQ
WHERE PURCH_DATE BETWEEN V_FDATE
AND V_TDATE
AND DEPT_CODE = V_DEPT
AND CUST_CODE = DECODE(V_CUST,'!',CUST_CODE,V_CUST)
AND ITEM_CODE NOT IN ('GDR','GACTA','GFA')
AND ADJ_SLIP_NO IS NULL
AND PURCH_GUBUN = '1';
--
SLIP_NO := V_DATE||V_SEQ;
SLIP_CNT := SLIP_CNT+1;
--
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,SQLCODE||SQLERRM);
END;
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
26 | DYNAMIC SQL 이란? (퍼온글 : 출처모름) | 운영자 | 2002.09.17 | 3291 |
» | PL/SQL에서 ARRAY사용 예제 | 운영자 | 2002.09.17 | 3254 |
24 | 년중 몇번째 주간인지 알아내기(FUNCTION) - ORACLE이 제공하는 것과 다름 | 운영자 | 2002.09.17 | 3733 |
23 | SORT후 번호부여 | 운영자 | 2002.09.17 | 2774 |
22 | JOIN 과 UNION 의 선후관계 | 운영자 | 2002.09.17 | 4634 |
21 | 중복 DATA CHECK | 운영자 | 2002.09.17 | 2790 |
20 | crontab 에 오라클 환경변수를 인식시킬때 [1] | 원우석 | 2004.12.06 | 5025 |
19 | oracle proc 에서 stdarg.h파일사용하기위한 환경설정 | 원우석 | 2004.12.06 | 12829 |
18 | 시스템카탈로그에서 프로시져 정보확인 쿼리 | 원우석 | 2004.07.31 | 2976 |
17 | 프로시져생성 문을 실행하는 방법 | 원우석 | 2004.07.31 | 2721 |
16 | 시스템카탈로그에서 테이블 정보확인 쿼리 | 원우석 | 2004.07.31 | 4559 |
15 | DB2 에러 메시지 확인 | 원우석 | 2004.07.31 | 3044 |
14 | 필드 타입케스팅 | 원우석 | 2004.07.31 | 2973 |
13 | 암호화(이름과,암호를 암호화할때) | 원우석 | 2004.07.31 | 2758 |
12 | 결과를 n개 행만을 취할때 | 원우석 | 2004.07.31 | 2561 |
11 | pre컴파일 및 실행계획로그만들기 | 원우석 | 2004.07.31 | 2752 |
10 | CLP 명령모음집 | 원우석 | 2004.07.31 | 2876 |
9 | sql 문 실행명령 | 원우석 | 2004.07.31 | 3567 |
8 | DB2 종료후 다시 시작 | 원우석 | 2004.07.31 | 2936 |
7 | lock 상태 확인 | 원우석 | 2004.07.31 | 4909 |