PANTHEON™ Help

 Toc
 PANTHEON Help - Welcome
[Collapse]PANTHEON
 [Collapse]Guides for PANTHEON
  [Expand]Guide for PANTHEON
  [Expand]Guide for PANTHEON Retail
  [Expand]Guide for PANTHEON Vet
  [Expand]Guide for PANTHEON Farming
 [Collapse]User Manuals for PANTHEON
  [Collapse]User Manual for PANTHEON
   [Collapse]Getting Started
     Dictionary of terms
     First steps with PANTHEON
    [Expand]Using PANTHEON at Tecta, a fictional company
    [Expand]Instructions for Ensuring Compliance of PANTHEON with SAS
    [Expand]PANTHEON Installation
    [Collapse]PANTHEON System
     [Expand]PANTHEON System data
     [Collapse]MS SQL Server
       Download and install MS SQL Server
       Upgrading MS SQL Server to 2019 or 2022
       MS Management Studio - Download and install
       Restoring database onto SQL server
       Adding users to server level (AddUser_PAX)
       Installing SQL for external access
       Installing PANTHEON clients
       Nastavitve MS SQL strežnika za večja Pantheon™ oko
       Changing SQL Sort Order
      [Expand]MS SQL Server Security
      [Expand]Useful SQL Queries
       SQLExecute
      [Collapse]SQL Server Jobs
       [Expand]Refresh Stock
        E-Mail Reminders for Overdue Receivables
        DB Maintenance Plan
     [Expand]Microsoft Windows Utilities
     [Expand]Security Policy
     [Expand]Database Administration
    [Expand]PANTHEON Basics
    [Expand]PANTHEON Help
    [Expand]Materials and Goods Movements
    [Expand]Assigning Identifiers
    [Expand]Frequently asked questions about Pantheon (F.A.Q.)
    [Expand]Archive
   [Expand]User Manual for eBusiness
   [Expand]Settings
   [Expand]Orders
   [Expand]Goods
   [Expand]Manufacturing
   [Expand]Service
   [Expand]Help
   [Expand]Personnel
   [Expand]Financials
   [Expand]Analytics
  [Expand]User Manual for PANTHEON Retail
  [Expand]User manual for PANTHEON Vet
  [Expand]User Manual for PANTHEON Farming
[Collapse]PANTHEON Web
 [Collapse]Guides for PANTHEON Web
  [Expand]Guide for PANTHEON Web Light
  [Expand]Guide for PANTHEON Web Terminal
  [Expand]Guide for PANTHEON Web Legal
  [Expand]Old products Archive
 [Collapse]User Manuals for PANTHEON Web
  [Expand]Getting started PANTHEON Web
  [Expand]User Manual for PANTHEON Web Light
  [Expand]User Manual for PANTHEON Web Terminal
  [Expand]User Manual for PANTHEON Web Legal
  [Expand]Old products Archive
[Collapse]PANTHEON Granules
 [Collapse]Guides for PANTHEON Granules
  [Expand]Personnel Granule
  [Expand]Travel Orders Granule
  [Expand]Documents and Tasks Granule
  [Expand]Dashboard Granule
  [Expand]B2B Orders Granule
  [Expand]Field Service Granule
  [Expand]Fixed Assets Inventory Granule
  [Expand]Warehouse Inventory Granule
 [Collapse]User Manuals for PANTHEON Granules
  [Expand]Getting started
  [Expand]Personnel Granule
  [Expand]Travel Orders Granule
  [Expand]Documents and Tasks Granule
  [Expand]B2B Orders Granule
  [Expand]Dashboard Granule
  [Expand]Field Service Granule
  [Expand]Fixed Assets Inventory Granule
  [Expand]Warehouse Inventory Granule
  [Expand]Archive
[Expand]User Site

Load Time: 484.3808 ms
"
  2657 | 3054 | 337125 | Updated
Label

E-Mail Reminders for Overdue Receivables

E-Mail Reminders for Overdue Receivables

E-Mail Reminders for Overdue Receivables

This topic contains instructions for a job that finds overdue receivables and sends out e-mails to financial managers of debtors.

First, global variables are declared:

declare
  @cSubjekt char(40),         -- subject ID
  @cImePriimek varchar(255),  -- full name of financial manager
  @cEmail varchar(255),       -- e-mail address
  @cVezniDok varchar(20),     -- linked document (invoice number)
  @dDatumVal datetime,        -- due date
  @dDatumDok datetime,        -- document date
  @mDebet money,              -- debit amount
  @mKredit money,             -- credit amount
  @mSaldo money,              -- balance
  @mGrandTotal money,         -- total balance of subject
  @cNaslovEmaila varchar(255), -- e-mail subject
  @cSeznam varchar(8000)       -- list of overdue invoices

The following piece of code opens the recordset with names, subject IDs and e-mail addresses. Because e-mails are sent out only to those that have an e-mail address, a normal join suffices, instead of a right/left join:

-- prepare recordset with all financial managers
declare crDolzniki cursor local fast_forward for
  select RTrim(C.IME)+' '+RTrim(C.PRIIMEK) as IMEPRIIMEK,C.SUBJEKT, A.TEL
    from CONTACTS C
    join CONTADDRESS A on C.SUBJEKT = A.SUBJEKT and C.POZ = A.POZ and TIP = 'E'
    where C.VLOGA like 'Financial manager'

open crDolzniki
fetch next from crDolzniki into @cImePriimek, @cSubjekt, @cEmail
while @@fetch_status = 0
  begin  -- loop through all financial managers
    -- !!! INSERT SOMETHING USEFUL HERE !!! --
    fetch next from crDolzniki into @cImePriimek, @cSubjekt, @cEmail
  end  

close crDolzniki
deallocate crDolzniki

 

The following piece finds all overdue invoices of a given subject and puts them in a recordset.

    -- za vsakega naredi recordset z zapadlimi postavkami
    declare crOdprte cursor local fast_forward for
      select 
          P.VEZNIDOK,
          (select top 1 X.DATUMVAL    
             from TEMEPOZ X 
             where X.SUBJEKT = P.SUBJEKT
               and X.KONTO = P.KONTO 
               and X.VEZNIDOK = P.VEZNIDOK 
               and X.DEBET <> 0  
             order by X.DATUMVAL) as DATUMVAL,
          (select top 1 X.DATUMDOK    
             from TEMEPOZ X 
             where X.SUBJEKT = P.SUBJEKT
               and X.KONTO = P.KONTO 
               and X.VEZNIDOK = P.VEZNIDOK 
               and X.DEBET <> 0  
             order by X.DATUMVAL) as DATUMDOK,
          Sum(P.DEBET) as DEBET, 
          Sum(P.KREDIT) as KREDIT, 
          Sum(P.DEBET -P.KREDIT) as Saldo
        from TEME G
          join TEMEPOZ P on P.KLJUC = G.KLJUC 
            and P.KONTO = '1200' 
            and (P.DATUMVAL <= GetDate())
        where P.SUBJEKT = @cSubjekt
        group by P.VEZNIDOK, P.SUBJEKT, P.KONTO
        having (Sum(P.DEBET - P.KREDIT) <> 0)
        order by P.VEZNIDOK    

Now you have to put data from that recordset into the e-mail message body (variable @cSeznam).

    set @cSeznam = ''
    set @mGrandTotal = 0
    open crOdprte
    fetch next from crOdprte into @cVezniDok,@dDatumVal,@dDatumDok,@mDebet,@mKredit,@mSaldo
    while @@fetch_status = 0 
      begin 
        set @cSeznam = @cSeznam + @cVezniDok + Convert(char(12),@dDatumVal,104) + Convert(char(12),@dDatumDok,104) 
                       + Convert(char(17),@mDebet,1) + Convert(char(17),@mKredit,1) + Convert(char(17),@mSaldo,1) + Char(13) + Char(10)
        set @mGrandTotal = @mGrandTotal + @mSaldo
        fetch next from crOdprte into @cVezniDok,@dDatumVal,@dDatumDok,@mDebet,@mKredit,@mSaldo
      end 
    close crOdprte
    deallocate crOdprte

Check if the list is not empty and send the message.

    if @cSeznam <> ''
      begin
        set @cNaslovEmaila = 'List of overdue items for ' + @cSubjekt + ' as of: ' + Convert(varchar(12),GetDate(),104)
        set @cSeznam = '-----------------------------------------------------------------------------------------------' + Char(13) + Char(10) + @cSeznam 
        set @cSeznam = 'Linked document      Due date  Doc. date              Debit           Credit            Balance' + Char(13) + Char(10) + @cSeznam 
        set @cSeznam = @cNaslovEmaila + Char(13) + Char(10) + @cSeznam 
        set @cSeznam = @cSeznam + Char(13) + Char(10) + 'Total:.....................................................................' + Convert(char(19),@mGrandTotal,1)
        -- send e-mail
        exec master.dbo.xp_sendmail
          @recipients = @cEmail, 
          @message = @cSeznam,
          @subject = @cNaslovEmaila
      end    

Add the complete query to SQL Server jobs, define a schedule and it's ready to go.

 

054318.gif One step of an SQL Server job can have at most 7800 characters.
The query below  is without comments and unnecessary spaces to obey this limitation.
declare
  @cSubjekt char(40),
  @cImePriimek varchar(255),
  @cEmail varchar(255),
  @cVezniDok varchar(20),
  @dDatumVal datetime,
  @dDatumDok datetime,
  @mDebet money,
  @mKredit money,
  @mSaldo money,
  @mGrandTotal money,
  @cNaslovEmaila varchar(255),
  @cSeznam varchar(8000)
declare crDolzniki cursor local fast_forward for
  select RTrim(C.IME)+' '+RTrim(C.PRIIMEK) as IMEPRIIMEK,C.SUBJEKT, A.TEL
  from CONTACTS C
  join CONTADDRESS A on C.SUBJEKT = A.SUBJEKT and C.POZ = A.POZ and TIP = 'E'
  where C.VLOGA like 'Finančni direktor'

open crDolzniki
fetch next from crDolzniki into @cImePriimek, @cSubjekt, @cEmail
while @@fetch_status = 0
  begin 
  declare crOdprte cursor local fast_forward for
  select 
  P.VEZNIDOK,
  (select top 1 X.DATUMVAL  
 from TEMEPOZ X 
 where X.SUBJEKT = P.SUBJEKT
 and X.KONTO = P.KONTO 
 and X.VEZNIDOK = P.VEZNIDOK 
 and X.DEBET <> 0  
 order by X.DATUMVAL) as DATUMVAL,
  (select top 1 X.DATUMDOK  
 from TEMEPOZ X 
 where X.SUBJEKT = P.SUBJEKT
 and X.KONTO = P.KONTO 
 and X.VEZNIDOK = P.VEZNIDOK 
 and X.DEBET <> 0  
 order by X.DATUMVAL) as DATUMDOK,
  Sum(P.DEBET) as DEBET, 
  Sum(P.KREDIT) as KREDIT, 
  Sum(P.DEBET -P.KREDIT) as Saldo
  from TEME G
  join TEMEPOZ P on P.KLJUC = G.KLJUC 
  and P.KONTO = '1200' 
  and (P.DATUMVAL <= GetDate())
  where P.SUBJEKT = @cSubjekt
  group by P.VEZNIDOK, P.SUBJEKT, P.KONTO
  having (Sum(P.DEBET - P.KREDIT) <> 0)
  order by P.VEZNIDOK  
  set @cSeznam = ''
  set @mGrandTotal = 0
  open crOdprte
  fetch next from crOdprte into @cVezniDok,@dDatumVal,@dDatumDok,@mDebet,@mKredit,@mSaldo
  while @@fetch_status = 0 
  begin
  set @cSeznam = @cSeznam + @cVezniDok + Convert(char(12),@dDatumVal,104) + Convert(char(12),@dDatumDok,104) 
 + Convert(char(17),@mDebet,1) + Convert(char(17),@mKredit,1) + Convert(char(17),@mSaldo,1) + Char(13) + Char(10)
  set @mGrandTotal = @mGrandTotal + @mSaldo
  fetch next from crOdprte into @cVezniDok,@dDatumVal,@dDatumDok,@mDebet,@mKredit,@mSaldo
  end
  close crOdprte
  deallocate crOdprte
  if @cSeznam <> ''
  begin
  set @cNaslovEmaila = 'List of overdue items for ' + @cSubjekt + ' as of: ' + Convert(varchar(12),GetDate(),104)
  set @cSeznam = '-----------------------------------------------------------------------------------------------' + Char(13) + Char(10) + @cSeznam 
  set @cSeznam = 'Linked document      Due date  Doc. date              Debit           Credit            Balance' + Char(13) + Char(10) + @cSeznam 
  set @cSeznam = @cNaslovEmaila + Char(13) + Char(10) + @cSeznam 
  set @cSeznam = @cSeznam + Char(13) + Char(10) + 'Total:.....................................................................' + Convert(char(19),@mGrandTotal,1)
  exec master.dbo.xp_sendmail
  @recipients = @cEmail, 
  @message = @cSeznam,
  @subject = @cNaslovEmaila
  end  
  fetch next from crDolzniki into @cImePriimek, @cSubjekt, @cEmail
  end 
close crDolzniki
deallocate crDolzniki


 

Rate this topic
Was this topic usefull?
Comments
Comment will also bo visible in forum!