Commit bb852eb8 authored by ssurve's avatar ssurve

fn_pod_chk added


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93972 ce508802-f39f-4f6c-b175-0d175dae99d5
parent ec5eabbf
...@@ -66,6 +66,181 @@ values( 'INVOICE_ID','W_PROOF_OF_DELIVERY','SELECT INVOICE_ID,TRAN_DATE,FIN_ENTI ...@@ -66,6 +66,181 @@ values( 'INVOICE_ID','W_PROOF_OF_DELIVERY','SELECT INVOICE_ID,TRAN_DATE,FIN_ENTI
commit; commit;
-- Function --
create or replace Function fn_pod_chk ( as_saleorder in sorder.sale_order%type)
RETURN number IS
TYPE InvCurTyp IS REF CURSOR;
TYPE DtlCurTyp IS REF CURSOR;
TYPE ItemCurTyp IS REF CURSOR;
inv_cur InvCurTyp;
cnumber number;
inv_type varchar2(3);
inv_type_list varchar2(600);
pod_cnt number;
ls_invoiceid char(10);
ls_sql_stmt varchar2(3000);
ls_custCodeBill customer.cust_code%type;
ls_siteCode site.site_code%type;
-- 17 Sep 2013
hdr_sql_stmt varchar2(3000);
dtl_sql_stmt varchar2(3000);
podqty_sum number;
inv_qty number;
dtl_cur DtlCurTyp;
item_cur ItemCurTyp;
ls_podtranid char(10);
itemcode char(10);
lineno number;
ls_itemSerSO char(5);
itemSerCnt number;
last_day_of_month number;
-- 29-Nov-2013
curr_date varchar2(2);
curr_yr varchar2(2);
invoice_mnth varchar2(2);
begin_date varchar2(8);
end_date varchar2(8);
BEGIN
cnumber := 0;
begin
select var_value into inv_type_list from disparm where var_name = 'POD_INV_TYPE' and prd_code = '999999';
exception when others then
return 1;
end;
begin
select '''' || replace(inv_type_list,',',''',''') || '''' into inv_type_list FROM DUAL;
exception when others then
return 1;
end;
begin
--select site_code, cust_code__bil into ls_siteCode, ls_custCodeBill FROM sorder where sale_order = as_saleorder and order_type in(inv_type_list);
select site_code, cust_code__bil, item_ser into ls_siteCode, ls_custCodeBill, ls_itemSerSO FROM sorder where sale_order = as_saleorder and order_type in(select '''' || replace(var_value,',',''',''') || '''' from disparm where var_name = 'POD_INV_TYPE' and prd_code = '999999');
exception when NO_DATA_FOUND then
return 0;
end;
-- Code to check credit policy defined for item series in regsrd with sale order item series
--begin
--select count(1) into itemSerCnt from itemser_cr_policy where item_ser = ls_itemSerSO;
--exception when NO_DATA_FOUND then
--return 0;
--end;
--inv_type_list := '''' || inv_type_list || '''';
--ls_sql_stmt := 'select invoice_id from invoice where cust_code__bil = ''' || ls_custCodeBill ||''' and site_code = ''' || ls_siteCode ||''' and inv_type in ('||inv_type_list||') and sysdate - conf_date > 29';
-- commented as per new requirement
--ls_sql_stmt := 'select invoice_id from invoice where cust_code__bil = :ls_custCodeBill and site_code = :ls_siteCode and inv_type in ('||inv_type_list||') and sysdate - conf_date > 29';
-- @ Sandesh : Following logic will decide invoice table conf_date range for which POD entry needs to checked
-- If current date is 31 then it will read invoices from previous month's 1st day to 30th day of previous month
-- For e.g. assuming current date is 31-Dec-2013 then invoices will between 1-Nov-2013 to 30-Nov-2013
-- If current date is between 1 to 30 then it will read invoices from 2 previous month's 1st day to 30th day of that month
-- For e.g. assuming current date is 30-Dec-2013 then invoices will between 1-Oct-2013 to 30-Oct-2013
begin
select to_char(sysdate, 'DD'),to_char(sysdate, 'YY') into curr_date,curr_yr FROM DUAL;
if curr_date = '31' then
select to_char(sysdate, 'MM')-1 into invoice_mnth FROM DUAL;
elsif curr_date >= '1' and curr_date <='30' then
select to_char(sysdate, 'MM')-2 into invoice_mnth FROM DUAL;
end if;
begin_date := '1-'||invoice_mnth||'-'||curr_yr;
end_date := '30-'||invoice_mnth||'-'||curr_yr;
exception when others then
return 1;
end;
-- Error if no co
ls_sql_stmt := 'select invoice_id from invoice where cust_code__bil = :ls_custCodeBill and site_code = :ls_siteCode and inv_type in ('||inv_type_list||') and conf_date between '''|| to_date(begin_date) ||''' and '''|| to_date(end_date) ;
dbms_output.put_line('sql - ' || ls_sql_stmt);
begin
-- cursor for multiple invoices against passed cust_code
OPEN inv_cur FOR ls_sql_stmt USING ls_custCodeBill, ls_siteCode;
-- Fetch rows from result set one at a time:
LOOP
FETCH inv_cur INTO ls_invoiceid;
EXIT WHEN inv_cur%NOTFOUND;
begin
select count(1) into pod_cnt from spl_sales_por_hdr where invoice_id = ls_invoiceid and confirmed='Y';
exception when others then
return 1;
end;
--dbms_output.put_line('pod_cnt - ' || pod_cnt);
if pod_cnt = 0 then
cnumber := 1;
exit;
else
-- Logic for partial POD entries starts here
hdr_sql_stmt := 'select tran_id from spl_sales_por_hdr where invoice_id = :ls_invoiceid and confirmed = ''Y'' and wf_status <> ''R'' ';
--dbms_output.put_line('hdr_sql_stmt - ' || hdr_sql_stmt);
begin
open dtl_cur for hdr_sql_stmt USING ls_invoiceid;
LOOP
FETCH dtl_cur INTO ls_podtranid;
EXIT WHEN dtl_cur%NOTFOUND;
begin
dtl_sql_stmt := 'select line_no,item_code,quantity__inv into lineno,itemcode,invqty from spl_sales_por_det where tran_id = :ls_podtranid';
dbms_output.put_line('dtl_sql_stmt - ' || dtl_sql_stmt);
begin
open item_cur for dtl_sql_stmt USING ls_podtranid;
LOOP
FETCH item_cur INTO ls_podtranid,itemcode,lineno,inv_qty;
EXIT WHEN item_cur%NOTFOUND;
select sum(quantity__resale) into podqty_sum from spl_sales_por_det where tran_id = ls_podtranid and item_code = itemcode;
if podqty_sum < inv_qty then
cnumber :=1;
--return cnumber;
exit;
end if;
END LOOP;
CLOSE item_cur;
end;
exception when others then
return 1;
end;
END LOOP;
CLOSE dtl_cur;
end;
-- Logic for partial POD entries ends here
cnumber := 0;
end if;
END LOOP;
-- Close cursor:
CLOSE inv_cur;
exception when others then
return 1;
end;
return cnumber;
END;
/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment