Connecting Tech Pros Worldwide Forums | Help | Site Map

Need logic

Familiar Sight
 
Join Date: Jun 2007
Posts: 151
#1: Aug 24 '09
Hi Folks

I have written a code to send emails from oracle. Below is the code. I have registered this is Apps and scheduled the concurrent program to run every day. Now i want implement logic, such that even though the concurrent program runs, it should not send email on Saturdays and Sundays.

The due date in the below code is always the next_day of the day I apply leave. It can be Saturday/Sunday. So my package is dependent on due date.



Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PACKAGE BODY APPS.CBTT_LOA_REM_SUP_PKG AS
  2. PROCEDURE LOA_REM_SUP_MAIL (errbuf out varchar2,
  3.                               retcode out varchar2) is
  4.         l_transaction_id VARCHAR2(2000);
  5.         l_person_name varchar2(240);
  6.         l_itemtype varchar2(5) :='HRSSA';
  7.         l_itemkey varchar2(10);
  8.         conn UTL_SMTP.CONNECTION;
  9.         crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );
  10.         mesg VARCHAR2( 4000 );
  11.         usrname VARCHAR2( 30 );
  12.         l_usraddr VARCHAR2( 100 );
  13.         l_user_name varchar2(240);
  14.         subj varchar2(100) := 'has applied for Leave of Absence';
  15.         Body varchar2(4000);
  16.         l_state varchar2(10);
  17.         addrlist addresslist_tab;
  18.        addrcnt  BINARY_INTEGER:= 0;
  19.         l_current_forward_to_id number := 0;
  20.         l_creator_person_id number := 0;
  21.         l_position_name varchar2(100);
  22.         l_absence_attendance_type_id number;
  23.         l_absence_days  number;
  24.         l_date_end date;
  25.         l_date_start date;
  26.         l_absence_name varchar2(100);
  27.         l_manager_id number;
  28.         l_supervisor_name varchar2(240);
  29.         temp_var1 varchar2(200);
  30.         temp_superviosr_id varchar2(200);
  31.         temp_var3 varchar2(100);
  32.  
  33.  
  34.  
  35.         cursor cur_pending_transactions is
  36.         select hat.transaction_id,
  37.                  hat.item_key,
  38.                  wias.due_date,
  39.                  hat.transaction_effective_date
  40.         from hr_api_transactions hat,
  41.               WF_ITEM_ACTIVITY_STATUSES wias
  42.         where hat.item_type ='HRSSA'
  43.         and   hat.item_type = wias.item_type
  44.         and   hat.item_key = wias.item_key
  45.         and   hat.process_name ='HR_LOA_JSP_PRC'
  46.         and   hat.status = 'Y'  ----Pending For Approval
  47.         and   to_date(wias.due_date) < sysdate
  48.         and   trunc(TRANSACTION_EFFECTIVE_DATE) >= trunc(sysdate-5);
  49.         cursor cur_email_Address (cp_person_id number) is
  50.         select distinct papf.full_name,
  51.                  fu.email_address
  52.         from   fnd_user fu,
  53.                per_all_people_f papf
  54.         where  papf.person_id = cp_person_id
  55.         and    papf.person_id =fu.employee_id
  56.         and    trunc(sysdate) between effective_start_date and effective_end_date;
  57.  
  58.         cursor cur_full_name (cp_person_id number) is
  59.         select distinct full_name
  60.         from   per_all_people_f
  61.         where  person_id  =cp_person_id
  62.         and    business_group_id = 81
  63.         and    trunc(sysdate) between effective_start_date and effective_end_date;
  64.  
  65.         cursor cur_absence_details(cp_transaction_id number,cp_absence_par varchar2) is
  66.         select distinct name,
  67.              decode(datatype,'NUMBER',to_char(number_value),
  68.                                  'DATE',to_char(date_value,'DD-MON-YYYY'),NULL) value        from  hr_api_transactions hat,
  69.                 hr_api_transaction_steps hats,
  70.                 hr_api_transaction_values hatv
  71.         where hat.transaction_id = cp_transaction_id
  72.         and   hat.transaction_id = hats.transaction_id
  73.         and   hats.transaction_step_id = hatv.transaction_step_id
  74.         and   hatv.name = cp_absence_par;
  75.  
  76.         cursor cur_selected_person_id (cp_transaction_id number) is
  77.         select creator_person_id
  78.         from   hr_api_transactions hat
  79.         where  hat.transaction_id = cp_transaction_id;   --- changed to creator_person_id from selector_person_id
  80.  
  81.         cursor cur_hr_person_id is
  82.         select distinct person_id,
  83.                  name
  84.         from  per_all_assignments_f paaf,
  85.                hr_all_positions_f hapf
  86.         where hapf.position_id = paaf.position_id
  87.       and   hapf.name ='87.Assistant Manager,HR.'
  88.         and   paaf.business_group_id  =81
  89.         and   trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
  90.         and   trunc(sysdate) between hapf.effective_start_date and hapf.effective_end_date;
  91.  
  92.         cursor cur_absence_name (cp_attendance_type_id number) is
  93.         select name
  94.         from per_absence_attendance_types
  95.         where absence_attendance_type_id = cp_attendance_type_id
  96.         and    business_group_id = 81;
  97.  
  98.     BEGIN                    for rec_pending in cur_pending_transactions
  99.                     loop
  100.                         l_transaction_id := rec_pending.transaction_id;
  101.                         l_itemkey := rec_pending.item_key;
  102.                         l_current_forward_to_id :=nvl(wf_engine.GetItemAttrNumber(itemtype => l_itemtype        ,itemkey  => l_itemkey     ,aname    => 'FORWARD_TO_PERSON_ID'),wf_engine.GetItemAttrNumber(itemtype   => l_itemtype,itemkey    => l_itemkey,aname      => 'CREATOR_PERSON_ID'));
  103.                         for rec_person_id in cur_selected_person_id(l_transaction_id)
  104.                         loop
  105.                             l_creator_person_id := rec_person_id.creator_person_id;  --changed to creator from selected on jan 5th,vamsidhar pala
  106.                         end loop;
  107.                         for rec_full_name in cur_full_name(l_creator_person_id)
  108.                         loop
  109.                             l_person_name := rec_full_name.full_name;
  110.                         end loop;
  111.                         For rec_absence in cur_absence_details(l_transaction_id,'P_ABSENCE_ATTENDANCE_TYPE_ID')
  112.                         loop
  113.                             l_absence_attendance_type_id := rec_absence.value;
  114.                         end loop;
  115.                         for rec_absence_name in cur_absence_name(l_absence_attendance_type_id)
  116.                         loop
  117.                             l_absence_name := rec_absence_name.name;
  118.                         end loop;
  119.                         For rec_absence in cur_absence_details(l_transaction_id,'P_ABSENCE_DAYS')
  120.                         loop
  121.                             l_absence_days := rec_absence.value;
  122.                         end loop;
  123.                         For rec_absence in cur_absence_details(l_transaction_id,'P_DATE_START')
  124.                         loop
  125.                             l_date_start := rec_absence.value;
  126.                         end loop;
  127.                         For rec_absence in cur_absence_details(l_transaction_id,'P_DATE_END')
  128.                         loop
  129.                             l_date_end := rec_absence.value;
  130.                         end loop;
  131.  
  132. ---------------------------------------------------------------------------------------------------------------------------
  133. if trunc(sysdate) = trunc(rec_pending.due_date) then
  134. for i in 1..2
  135. loop
  136.  
  137. if (i=1) then
  138.  
  139.  
  140. For rec_person in cur_email_address(l_current_forward_to_id)
  141.                                     loop
  142.                                         l_usraddr   := rec_person.email_address;
  143.                                         l_user_name := rec_person.full_name;
  144.                                     End loop;
  145. ---changed by vamsi on 5th january 2009
  146. select distinct supervisor_id into temp_superviosr_id from per_all_people_f a, per_all_assignments_f b
  147. where a.person_id = b.person_id and a.person_id = l_creator_person_id and trunc(b.effective_end_date) >trunc(sysdate);
  148.  
  149. select distinct email_address into temp_var3 from fnd_user where employee_id = temp_superviosr_id;
  150. l_usraddr := temp_var3;
  151.  
  152.  
  153.                                     body := crlf||l_user_name||crlf||crlf||
  154.                                               'Mr./Ms./Mrs '||l_person_name||' submitted an application for '||crlf||crlf||
  155.                                               'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  156.                                               'From Date    : '|| l_date_start ||crlf||
  157.                                               'To Date      : '|| l_date_end ||crlf||
  158.                                               'Duration     : '|| L_absence_days||' day(s)'||crlf||
  159.                                               'on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY')||crlf||crlf||'Please ensure that the application is processed within 24 hours of receipt of this reminder.';
  160.  
  161.  
  162.  
  163. conn:= utl_smtp.open_connection( 'CBMS1',25);
  164.                                 utl_smtp.helo( conn, 'CBMS1');
  165.                                 utl_smtp.mail( conn, l_usraddr );
  166.  
  167.                                 utl_smtp.rcpt( conn, l_usraddr );
  168.                                 addrcnt:= addrcnt + 1;
  169.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  170.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  171.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  172.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  173.                                 FOR i IN 1 .. addrcnt LOOP
  174.                                      mesg:= mesg || addrlist( i );
  175.                                 END LOOP;
  176.                                 mesg:= mesg || '' || crlf || BODY;
  177.                                 utl_smtp.data( conn, mesg );
  178.                                 utl_smtp.quit( conn );
  179.                                 l_usraddr   := '';
  180.                                 l_user_name := '';
  181.                                 addrcnt := 0;
  182. elsif (i =2) then
  183.  
  184.  
  185. l_manager_id := TO_NUMBER(substr(CBTT_AME_PKG.CBTT_AME_MANAGER(l_transaction_id),11));
  186.                                     For rec_person in cur_email_address(l_manager_id)
  187.                                     loop
  188.                                         l_usraddr   := rec_person.email_address;
  189.                                         l_user_name := rec_person.full_name;
  190.                                     End loop;
  191.                                     For rec_person in cur_email_address(l_current_forward_to_id)
  192.                                     loop
  193.                                         l_supervisor_name := rec_person.full_name;
  194.                                     End loop;
  195.                                     body := crlf||l_user_name||crlf||crlf||
  196.                                               'Mr./Ms./Mrs '||l_person_name||' submitted an application for '||crlf||crlf||
  197.                                               'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  198.                                               'From Date    : '|| l_date_start ||crlf||
  199.                                               'To Date      : '|| l_date_end ||crlf||
  200.                                               'Duration     : '|| L_absence_days||' day(s)'||crlf||
  201.                                               'on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY ')||crlf||crlf|| 'The Supervisor has not yet processed the application. Kindly ensure that the Supervisor processes this application within 24 hours of receipt of this reminder. ';
  202.  
  203. conn:= utl_smtp.open_connection( 'CBMS1',25);
  204.                                 utl_smtp.helo( conn, 'CBMS1');
  205.                                 utl_smtp.mail( conn, l_usraddr );
  206.                                 utl_smtp.rcpt( conn, l_usraddr );
  207.                                 addrcnt:= addrcnt + 1;
  208.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  209.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  210.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  211.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  212.                                 FOR i IN 1 .. addrcnt LOOP
  213.                                      mesg:= mesg || addrlist( i );
  214.                                 END LOOP;
  215.                                 mesg:= mesg || '' || crlf || BODY;
  216.                                 utl_smtp.data( conn, mesg );
  217.                                 utl_smtp.quit( conn );
  218.                                 l_usraddr   := '';
  219.                                 l_user_name := '';
  220.                                 addrcnt := 0;
  221.  
  222. end if;
  223. end loop;
  224.  
  225. ---------------------------------------------------------------------------------------------------------------------------
  226.  
  227. elsif trunc((sysdate) - rec_pending.due_date) = 1 
  228. then
  229. ---email to the supervisor
  230. for rec_count in 1..3
  231. loop
  232. if rec_count = 1 
  233. then 
  234.  
  235.                                     For rec_person in cur_email_address(l_current_forward_to_id)
  236.                                     loop
  237.                                         l_usraddr   := rec_person.email_address;
  238.                                         l_user_name := rec_person.full_name;
  239.                                     End loop;
  240. ---changed by vamsi on 5th january 2009
  241. select distinct supervisor_id into temp_superviosr_id from per_all_people_f a, per_all_assignments_f b
  242. where a.person_id = b.person_id and a.person_id = l_creator_person_id and b.effective_end_date ='31-DEC-4712';
  243.  
  244. select distinct email_address into temp_var3 from fnd_user where employee_id = temp_superviosr_id;
  245. l_usraddr := temp_var3;
  246.  
  247.                                     body := crlf||l_user_name||crlf||crlf||
  248.                                               'Mr./Ms./Mrs '||l_person_name||' submitted an application for '||crlf||crlf||
  249.                                               'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  250.                                               'From Date    : '|| l_date_start ||crlf||
  251.                                               'To Date      : '|| l_date_end ||crlf||
  252.                                               'Duration     : '|| L_absence_days||' day(s)'||crlf||
  253.                                               'on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY')||crlf||crlf||
  254.                                               'However, you failed to process the application within the stipulated 48 hour period and have affected the efficiency of the system.
  255.  
  256. The Departmental Manager has been advised of this delay and will liaise with you in this regard.  To ensure the integrity of the system, you are required to process the application via the system.';
  257.  
  258.  
  259. conn:= utl_smtp.open_connection( 'CBMS1',25);
  260.                                 utl_smtp.helo( conn, 'CBMS1');
  261.                                 utl_smtp.mail( conn, l_usraddr );
  262.  
  263.                                 utl_smtp.rcpt( conn, l_usraddr );
  264.                                 addrcnt:= addrcnt + 1;
  265.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  266.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  267.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  268.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  269.                                 FOR i IN 1 .. addrcnt LOOP
  270.                                      mesg:= mesg || addrlist( i );
  271.                                 END LOOP;
  272.                                 mesg:= mesg || '' || crlf || BODY;
  273.                                 utl_smtp.data( conn, mesg );
  274.                                 utl_smtp.quit( conn );
  275.                                 l_usraddr   := '';
  276.                                 l_user_name := '';
  277.                                 addrcnt := 0;
  278.  
  279.  
  280.                                 elsif rec_count = 2 then  ---email to employee who has submitted the application
  281.  
  282. for i in 1..2
  283. loop
  284.  
  285. if (i=1)
  286. then
  287.                                     For rec_person in cur_email_address(l_creator_person_id)
  288.                                     loop
  289.                                         l_usraddr   := rec_person.email_address;
  290.                                         l_user_name := rec_person.full_name;
  291.                                     End loop;
  292.  
  293.                                     body := crlf||l_user_name||crlf||crlf||
  294.                                              'Your application for '||crlf||crlf||
  295.                                              'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  296.                                              'From Date    : '|| l_date_start ||crlf||
  297.                                              'To Date      : '|| l_date_end ||crlf||
  298.                                              'Duration     : '|| L_absence_days||' day(s)'||crlf||crlf||
  299.                                              'submitted on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY')||crlf||crlf||
  300.                                              'was not processed by your Supervisor within the stipulated 48 hour period.'||crlf||crlf||
  301.                                              'This has affected the efficiency of the system.'||crlf||crlf||
  302.                                              'Please liaise with your Supervisor to ensure that your application is immediately processed.';
  303.  
  304.  
  305. conn:= utl_smtp.open_connection( 'CBMS1',25);
  306.                                 utl_smtp.helo( conn, 'CBMS1');
  307.                                 utl_smtp.mail( conn, l_usraddr );
  308.                                 utl_smtp.rcpt( conn, l_usraddr );
  309.                                 addrcnt:= addrcnt + 1;
  310.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  311.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  312.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  313.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  314.                                 FOR i IN 1 .. addrcnt LOOP
  315.                                      mesg:= mesg || addrlist( i );
  316.                                 END LOOP;
  317.                                 mesg:= mesg || '' || crlf || BODY;
  318.                                 utl_smtp.data( conn, mesg );
  319.                                 utl_smtp.quit( conn );
  320.                                 l_usraddr   := '';
  321.                                 l_user_name := '';
  322.                                 addrcnt := 0;
  323.  
  324.  
  325.                                 elsif rec_count = 3 then ---email to Departmental manager of the employee who has submitted the application
  326.                                     l_manager_id := TO_NUMBER(substr(CBTT_AME_PKG.CBTT_AME_MANAGER(l_transaction_id),11));
  327.                                     For rec_person in cur_email_address(l_manager_id)
  328.                                     loop
  329.                                         l_usraddr   := rec_person.email_address;
  330.                                         l_user_name := rec_person.full_name;
  331.                                     End loop;
  332.                                     For rec_person in cur_email_address(l_current_forward_to_id)
  333.                                     loop
  334.                                         l_supervisor_name := rec_person.full_name;
  335.                                     End loop;
  336.                                     body := crlf||l_user_name||crlf||crlf||
  337.                                               'Mr./Ms./Mrs '||l_person_name||' submitted an application for '||crlf||crlf||
  338.                                               'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  339.                                               'From Date    : '|| l_date_start ||crlf||
  340.                                               'To Date      : '|| l_date_end ||crlf||
  341.                                               'Duration     : '|| L_absence_days||' day(s)'||crlf||
  342.                                               'on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY ')||crlf||crlf||
  343.                                               'Mr./Ms./Mrs '||l_supervisor_name||' has not processed the application within the stipulated 48 hour period and this has affected the efficiency of the system. You intervention is required. Kindly instruct the Supervisor to immediately process the application. If the Supervisor is unable to electronically process the application at this time, kindly email the employee advising whether you have approved or rejected the application and submit a copy of the email to the Assistant Manger, HR. The supervisor will be required to approve the application via Self Service at a later date.';
  344.  
  345.  
  346. conn:= utl_smtp.open_connection( 'CBMS1',25);
  347.                                 utl_smtp.helo( conn, 'CBMS1');
  348.                                 utl_smtp.mail( conn, l_usraddr );
  349.                                 utl_smtp.rcpt( conn, l_usraddr );
  350.                                 addrcnt:= addrcnt + 1;
  351.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  352.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  353.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  354.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  355.                                 FOR i IN 1 .. addrcnt LOOP
  356.                                      mesg:= mesg || addrlist( i );
  357.                                 END LOOP;
  358.                                 mesg:= mesg || '' || crlf || BODY;
  359.                                 utl_smtp.data( conn, mesg );
  360.                                 utl_smtp.quit( conn );
  361.                                 l_usraddr   := '';
  362.                                 l_user_name := '';
  363.                                 addrcnt := 0;
  364. ----------added on 15th august 2009
  365. elsif(1=2)
  366. then
  367.  
  368. For rec_person in cur_email_address(l_creator_person_id)
  369.                                     loop
  370.                                         l_usraddr   := rec_person.email_address;
  371.                                         l_user_name := rec_person.full_name;
  372.                                     End loop;
  373.  
  374.                                     body := crlf||l_user_name||crlf||crlf||
  375.                                              'Your application for '||crlf||crlf||
  376.                                              'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  377.                                              'From Date    : '|| l_date_start ||crlf||
  378.                                              'To Date      : '|| l_date_end ||crlf||
  379.                                              'Duration     : '|| L_absence_days||' day(s)'||crlf||crlf||
  380.                                              'submitted on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY')||crlf||crlf||
  381.                                              'was not processed by your Supervisor within the stipulated 48 hour period.'||crlf||crlf||
  382.                                              'This has affected the efficiency of the system.'||crlf||crlf||
  383.                                              'Your Departmental Manager has been advised of this delay and will liaise with you, to advise whether your application has been approved or not';
  384.  
  385.  
  386. conn:= utl_smtp.open_connection( 'CBMS1',25);
  387.                                 utl_smtp.helo( conn, 'CBMS1');
  388.                                 utl_smtp.mail( conn, l_usraddr );
  389.                                 utl_smtp.rcpt( conn, l_usraddr );
  390.                                 addrcnt:= addrcnt + 1;
  391.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  392.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  393.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  394.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  395.                                 FOR i IN 1 .. addrcnt LOOP
  396.                                      mesg:= mesg || addrlist( i );
  397.                                 END LOOP;
  398.                                 mesg:= mesg || '' || crlf || BODY;
  399.                                 utl_smtp.data( conn, mesg );
  400.                                 utl_smtp.quit( conn );
  401.                                 l_usraddr   := '';
  402.                                 l_user_name := '';
  403.                                 addrcnt := 0;
  404.  
  405.  
  406.  
  407. end if;
  408. end loop;
  409.  
  410.  
  411.  
  412. end if;
  413. end loop;
  414.  
  415. -------------------------------------------
  416. elsif trunc((sysdate) - rec_pending.due_date) = 2
  417. then
  418.  
  419. l_manager_id := TO_NUMBER(substr(CBTT_AME_PKG.CBTT_AME_MANAGER(l_transaction_id),11));
  420.                                     For rec_person in cur_email_address(l_manager_id)
  421.                                     loop
  422.                                         l_usraddr   := rec_person.email_address;
  423.                                         l_user_name := rec_person.full_name;
  424.                                     End loop;
  425.                                     For rec_person in cur_email_address(l_current_forward_to_id)
  426.                                     loop
  427.                                         l_supervisor_name := rec_person.full_name;
  428.                                     End loop;
  429.                                     body := crlf||l_user_name||crlf||crlf||
  430.                                               'Mr./Ms./Mrs '||l_person_name||' submitted an application for '||crlf||crlf||
  431.                                               'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  432.                                               'From Date    : '|| l_date_start ||crlf||
  433.                                               'To Date      : '|| l_date_end ||crlf||
  434.                                               'Duration     : '|| L_absence_days||' day(s)'||crlf||
  435.                                               'on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY ')||crlf||crlf||
  436.                                               'Please ensure that the application is processed within 24 hours of receipt of this reminder.';
  437.  
  438.  
  439. conn:= utl_smtp.open_connection( 'CBMS1',25);
  440.                                 utl_smtp.helo( conn, 'CBMS1');
  441.                                 utl_smtp.mail( conn, l_usraddr );
  442.                                 utl_smtp.rcpt( conn, l_usraddr );
  443.                                 addrcnt:= addrcnt + 1;
  444.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  445.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  446.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  447.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  448.                                 FOR i IN 1 .. addrcnt LOOP
  449.                                      mesg:= mesg || addrlist( i );
  450.                                 END LOOP;
  451.                                 mesg:= mesg || '' || crlf || BODY;
  452.                                 utl_smtp.data( conn, mesg );
  453.                                 utl_smtp.quit( conn );
  454.                                 l_usraddr   := '';
  455.                                 l_user_name := '';
  456.                                 addrcnt := 0;
  457.  
  458. -----------------------------------------------------------------------------
  459. elsif trunc((sysdate) - rec_pending.due_date) = 3
  460. then
  461.  
  462.  
  463. for j in 1..2
  464. loop
  465.  
  466. if (j=1) --- Mail to HR Manager
  467. then
  468.  
  469.                                     For rec_hr_manager in cur_hr_person_id
  470.                                     loop
  471.                                         For rec_person in cur_email_address(rec_hr_manager.person_id)
  472.                                         loop
  473.                                             l_usraddr   := rec_person.email_address;
  474.                                             l_user_name := rec_person.full_name;
  475.                                         End loop;
  476.                                     End loop;
  477.                                     body := crlf||l_user_name||crlf||crlf||
  478.                                               'Mr./Ms./Mrs '||l_person_name||' submitted an application for '||crlf||crlf||
  479.                                               'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  480.                                               'From Date    : '|| l_date_start ||crlf||
  481.                                               'To Date      : '|| l_date_end ||crlf||
  482.                                               'Duration     : '|| L_absence_days||' day(s)'||crlf||
  483.                                               'on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY')||crlf||    'The Manager did not process the application within the stipulated 48 hour period and has affected the efficiency of the system. Please contact the employee, the relevant Supervisor and Departmental Manager accordingly. ';
  484.  
  485.  
  486. select distinct email_address into l_usraddr from fnd_user where employee_id = 1557; -----Request from Kurtis Clarke to hard code;
  487.  
  488. conn:= utl_smtp.open_connection( 'CBMS1',25);
  489.                                 utl_smtp.helo( conn, 'CBMS1');
  490.                                 utl_smtp.mail( conn, l_usraddr );
  491.                                 utl_smtp.rcpt( conn, l_usraddr );
  492.                                 addrcnt:= addrcnt + 1;
  493.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  494.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  495.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  496.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  497.                                 FOR i IN 1 .. addrcnt LOOP
  498.                                      mesg:= mesg || addrlist( i );
  499.                                 END LOOP;
  500.                                 mesg:= mesg || '' || crlf || BODY;
  501.                                 utl_smtp.data( conn, mesg );
  502.                                 utl_smtp.quit( conn );
  503.                                 l_usraddr   := '';
  504.                                 l_user_name := '';
  505.                                 addrcnt := 0;
  506.  
  507. elsif(j=2) then
  508.  
  509. l_manager_id := TO_NUMBER(substr(CBTT_AME_PKG.CBTT_AME_MANAGER(l_transaction_id),11));
  510.                                     For rec_person in cur_email_address(l_manager_id)
  511.                                     loop
  512.                                         l_usraddr   := rec_person.email_address;
  513.                                         l_user_name := rec_person.full_name;
  514.                                     End loop;
  515.                                     For rec_person in cur_email_address(l_current_forward_to_id)
  516.                                     loop
  517.                                         l_supervisor_name := rec_person.full_name;
  518.                                     End loop;
  519.                                     body := crlf||l_user_name||crlf||crlf||
  520.                                               'Mr./Ms./Mrs '||l_person_name||' submitted an application for '||crlf||crlf||
  521.                                               'Leave Type   : '|| substr(L_absence_name,6) ||crlf||
  522.                                               'From Date    : '|| l_date_start ||crlf||
  523.                                               'To Date      : '|| l_date_end ||crlf||
  524.                                               'Duration     : '|| L_absence_days||' day(s)'||crlf||
  525.                                               'on '|| To_char(rec_pending.transaction_effective_date,'DD-MON-YYYY ')||crlf||crlf||
  526.                                               'Please ensure that the application is processed within 24 hours of receipt of this reminder.';
  527.  
  528.  
  529. conn:= utl_smtp.open_connection( 'CBMS1',25);
  530.                                 utl_smtp.helo( conn, 'CBMS1');
  531.                                 utl_smtp.mail( conn, l_usraddr );
  532.                                 utl_smtp.rcpt( conn, l_usraddr );
  533.                                 addrcnt:= addrcnt + 1;
  534.                                 addrlist( addrcnt ):= 'To: ' || '<' || l_usraddr || '>' || crlf;
  535.                                 mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
  536.                               'From: ' || 'CBTT Oracle Applications Alert' || ' <applmgr@CBMS1>' || crlf ||
  537.                               'Subject: '||'REMINDER: Pending for Approval of Leave of Absence for '||l_person_name||crlf;
  538.                                 FOR i IN 1 .. addrcnt LOOP
  539.                                      mesg:= mesg || addrlist( i );
  540.                                 END LOOP;
  541.                                 mesg:= mesg || '' || crlf || BODY;
  542.                                 utl_smtp.data( conn, mesg );
  543.                                 utl_smtp.quit( conn );
  544.                                 l_usraddr   := '';
  545.                                 l_user_name := '';
  546.                                 addrcnt := 0;
  547.                                 end if;
  548.                                         end loop;
  549.                         end if;
  550.                     end loop;
  551.     end LOA_REM_SUP_MAIL;
  552. End CBTT_LOA_REM_SUP_PKG;
  553. /
  554.  
  555.  

thanks
vamsi

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Aug 24 '09

re: Need logic


First thing i would suggest you to do is place the UTL_SMTP piece of code in a seperate sub program and call it where ever necessary.Your package body is having lots of redundant code of sending mail functionality.


Second, just add a condition to check if the due date falls on saturday or sunday...if yes then dont call your send mail routine else go ahead....you can handle this by a simple IF in your package body
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#3: Aug 24 '09

re: Need logic


please do not post such lengthy code .

to solve your problem check the day of duedate, that will solve the entire issue.

Follow good programming practices as suggested by Amit.
Familiar Sight
 
Join Date: Jun 2007
Posts: 151
#4: Aug 27 '09

re: Need logic


Thanks a lot,

The due date is always the next day of the leave application. suppose if i apply leave today, the due date in the system will be tommorow

vamsi
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#5: Aug 27 '09

re: Need logic


so can't you check the day of due date before sending the mail and cancel sending of the mails on Saturday and Sunday ?
Familiar Sight
 
Join Date: Jun 2007
Posts: 151
#6: Aug 28 '09

re: Need logic


Hi

The code is written such that,

we compare sysdate-duedate.

So if sysdate-duedate = 1 ---- it sends a mail to some one

if sysdate-duedate =2 ----- it send the other mail

So, i am confused, because if i dont send mail on sunday, then on monday, sysdate - due date will change and i may end up sending worng mails on the wrong days

vamsi
Reply