You are on page 1of 3

CREATE OR REPLACE procedure BI.

mpfl_MAIL_DATA
as

l_verify_flag char(1);
l_org_id hr_operating_units.organization_id%type;
l_error_message varchar2(3000);
owner_ID VARCHAR2(30);
-- html_start VARCHAR2(30) := '<HTML><BODY>';
--html_end VARCHAR2(30) := '</HTML></BODY>';
ccmail VARCHAR2(100);
tomail VARCHAR2(3000);
body_text VARCHAR2(3000); -- := 'AHL_DI_ASSO_DOC_GEN_PVT';
body_text2 VARCHAR2(3000); mnth1 VARCHAR2(10) := null; mnth2
VARCHAR2(10) := null; mnth3 VARCHAR2(10) := null;

begin

select short_no into mnth1 from gl_cur_periods p where


to_date(add_months(sysdate,-3),'dd-mm-yy') between to_date(START_DATE,'dd-mm-
yy') and to_date(END_DATE,'dd-mm-yy');

select short_no into mnth2 from gl_cur_periods p where


to_date(add_months(sysdate,-2),'dd-mm-yy') between to_date(START_DATE,'dd-mm-
yy') and to_date(END_DATE,'dd-mm-yy');

select short_no into mnth3 from gl_cur_periods p where


to_date(add_months(sysdate,-1),'dd-mm-yy') between to_date(START_DATE,'dd-mm-
yy') and to_date(END_DATE,'dd-mm-yy');

declare

cursor h_invoice is

select 'Group' vendor_id from dual


;

cursor l_invoice (p_vendor_id varchar2) is

select tp, SCH ,sum(nvl(decode(short_no,mnth1, amount),0)) c1,


sum(nvl(decode(short_no, mnth2, amount),0)) c2 , sum(nvl(decode(short_no, mnth3,
amount),0)) c3
, (sum(nvl(decode(short_no, mnth3, amount),0)) - sum(nvl(decode(short_no,
mnth2, amount),0))) c4
from bi.gl_info_v a where --trim(DESCRIPTION)=p_vendor_id
--'ANIMESH' --trim(:DESCRIPTION)
headtp='IS' and trim(tp)='SELLING'
--:headtp --and SHORT_NO='0.01'
group by tp, sch
order by tp

---select * from bi.gl_info_v where tp='SELLING'


begin
for h1 in h_invoice loop

l_verify_flag := 'Y';
l_error_message := null;

owner_ID := h1.vendor_id;

-- select NVL(BI.USER_SMTP( h1.vendor_id) ,'') into tomail from dual;

--SELECT DISTINCT --a.user_id ,


--head_name, smtp_type, smtp_name, display_name
-- FROM t_user a, bi.t_smtp_info b
-- WHERE a.user_id = b.user_id and head_name='ANIMESH';

begin

for l1 in l_invoice (h1.vendor_id) loop

begin

IF l1.c4<=0 THEN

body_text := body_text || '<tr><td align="left">' || l1.sch


||'</td><td align="right"> '|| l1.c2 || '</td><td align="right">' || l1.c3 ||
'</td><td align="right" class="td2">' || l1.c4 || '</td></tr>';

-- elsIF trim(upper(l1.recommend))>=1 AND trim(upper(l1.recommend))<=1


THEN
-- mailform := '<td class="td2">' || to_char(l1.EXPIRE_DAYS) ||
'</td>';
else
body_text := body_text || '<tr><td align="left">' || l1.sch
||'</td><td align="right"> '|| l1.c2 || '</td><td align="right">' || l1.c3 ||
'</td><td align="right" class="td1">' || l1.c4 || '</td></tr>';

end if;

commit;

exception

when others then


l_verify_flag := 'N';
l_error_message := l_error_message ||'Data not migrated into
ap_invoices_interface table...' ;

/*
update mpfl_iou_holders
set flag =0
where VENDOR_ID = l1.vendor_id;
*/

commit;

end;

end loop;
--commit;
end;

Insert into BI.MAIL_SENDS (MAIL_OID, MAIL_TO, MAIL_CC, MAIL_SUBJT, MAIL_BODYHTML,


MAIL_REFERENCE)
Values(SQ_MAIL_SENDS.NEXTVAL,tomail,ccmail,'Selling Cost From System',
'<br/><b>Dear Sir,<br/></b>Please see the bellow info and <b>Click</b> <a
href="http://runner.prangroup.com:9502/analytics/">OBIEE Dashboard Link</a> to see
in Details : <br/>
<br/><b>' || owner_ID || ' </b><br/><style>.td1 {text-align: right;
background: white;font-weight: bold;color: black;} .td2 {text-align: right;
background: green;font-weight: bold;color: white;}</style><table><tr><td
align="center", style="background-color:yellow">Selling Cost Information</td><td
width="40"></td><td align="center"</td></tr>
<tr><td>
<table border="1" cellspacing="0"><tr><th width="20"></th><th width="100">'||
mnth2 || '</th><th width="100">'|| mnth3 || '</th><th
width="100">Increase/Decrease</th></tr>' || body_text || '</table>
</td><td></td></tr>
</table> </td></tr> </table> <br/><br/>This is test Selling Cost Info mail from
OBIEE, Trn Date:' || to_date(sysdate,'dd-mm-yy hh24:mi:ss') ||'<br/> <hr
width="820", align="left"> This is system generated automatic mail, do not send
reply mail.','CS-MIS-Report Robot')
;

commit;

body_text := null;
owner_ID := null;
body_text2 := null;
tomail := null;
--'<br/><b>Dear Sir,<br/></b>Please see the bellow info and <a
href="http://runner.prangroup.com:9502/analytics/">Click IS-BS Link Here</a> to see
in Details : <br/>

-- end;

end loop; ---end of header loop


end;
end;
/

You might also like