procedure jv_generate is cnt1 number := 0; jvcnt number := 0; docno varchar2(6); tmp_desc varchar2(25); tmp_date date; begin begin select doc_slno into docno from fin_jv_slno_mas where jv_year = substr(to_char(trunc(sysdate, 'DD'), 'yyyy'), 1, 4) and jv_month = substr(to_char(trunc(sysdate, 'DD'), 'mm'), 1, 2) and rl_code = 'SS' and unit_cd = :global.unit_code and doc_type = 'JV'; exception when no_data_found then msg('JV number not found in FIN_JV_SLNO_MAS... Contact Final Accounts...'); raise form_trigger_failure; when others then msg_error('Error in selecting the JV number from FIn_JV_SLNO_MAS'); end; tmp_date := trunc(sysdate, 'DD'); tmp_desc := 'ADV ' || :sl_code || ' ' || :po_no; BEGIN insert into jdchdr (comp_cd, unit_cd, rl_code, tran_type, doc_type, doc_no, doc_date, doc_desc, enter_date, post_date, user_id) values ('SP', :global.unit_code, 'SS', 'S', 'JVR', docno, tmp_date, tmp_desc, tmp_date, tmp_date, :global.login_id); EXCEPTION when others then msg_error('Error in inserting into JDCHDR '); end; if nvl(:advance_detail.amount, 0) > 0 then if :payment_mode = 'C' or :keyblock.sl_code = '19045' then :advance_amt := :advance_detail.amount; :bank_charge := 0; :party_amt := :advance_detail.amount; else :advance_amt := :advance_detail.amount; :bank_charge := bank_charge(:bank_code, nvl(:advance_detail.amount, 0)); message(:bank_charge); message(:bank_charge); :party_amt := nvl(:advance_detail.amount, 0) - nvl(:bank_charge, 0); end if; end if; if nvl(:advance_amt, 0) <> 0 then Begin insert into jdcline (comp_cd, unit_cd, rl_code, tran_type, doc_type, doc_no, line_slno, line_desc, gl_code, sl_code, link_no, to_be_printed, print_slno, amount, party_code) values ('SP', :global.unit_code, 'SS', 'S', 'JVR', docno, 1, substr(:advance_glsl_desc, 1, 25), '3876', :sl_code, :po_no, 'Y', 1, :advance_amt, :sl_code); EXCEPTION when others then msg_error('Error in inserting into JDCLINE for Advance'); end; end if; begin update fin_jv_slno_mas ---The Update Statement for Incremening---- set doc_slno = SUBSTR(doc_slno, 1, 2) || ltrim(MAX(TO_CHAR(TO_NUMBER(SUBSTR(doc_slno, 3, 4) + 1), '0000'))) where jv_year = substr(to_char(trunc(sysdate, 'DD'), 'yyyy'), 1, 4) and jv_month = substr(to_char(trunc(sysdate, 'DD'), 'mm'), 1, 2) AND RL_CODE = :GLOBAL.RL_CODE AND UNIT_CD = :GLOBAL.UNIT_CODE and doc_type = 'JV'; EXCEPTION when others then msg_error('Error in updating doc_no in the fin_jvslno_mas '); end; if nvl(:party_amt, 0) <> 0 then Begin insert into jdcline (comp_cd, unit_cd, rl_code, tran_type, doc_type, doc_no, line_slno, line_desc, gl_code, sl_code, link_no, to_be_printed, print_slno, amount, party_code) values ('SP', :global.unit_code, 'SS', 'S', 'JVR', docno, 2, substr(:party_glsl_desc, 1, 25), '4002', :sl_code, :po_no, 'Y', 2, -1 * :party_amt, :sl_code); EXCEPTION when others then msg_error('Error in inserting into JDCLINE for Party'); end; end if; if nvl(:bank_charge, 0) <> 0 then Begin insert into jdcline (comp_cd, unit_cd, rl_code, tran_type, doc_type, doc_no, line_slno, line_desc, gl_code, sl_code, link_no, to_be_printed, print_slno, amount, RCN_cd, ccn_cd) values ('SP', :global.unit_code, 'SS', 'S', 'JVR', docno, 3, substr(:party_glsl_desc, 1, 10) || ' - Bnk Chrg', '8791', '00001', :po_no, 'Y', 3, -1 * :bank_charge, '841', '841'); EXCEPTION when others then msg_error('Error in inserting into JDCLINE for Bank Charge'); end; end if; :system.message_level := 5; msg('jv successfully created document no is ' || docno); :created_jv_no := docno; end;