/////////////////////////////////////////////////////////////////////////////
// This script fixes problems with converted companies that have non Calendar
// based fiscal years.  There is a bug in conversion which does to correctly
// calculate Period Ending Date for February in the year following a Leap Year.
// This script will generate those periods that were not created by conversion.
//
// This will assert that the script was written to work for a specific
// application version.  Change the version number accordingly.
//
/////////////////////////////////////////////////////////////////////////////

// This does some version checking
VersionDB "5.00.0";
VersionMod OWPW.EXE "5.0.0";

// Prompt the user to backup or bailout
Ask "Your Accounting Periods will be updated. If you have not backed up your company database, you should exit this script. Continue?";

// Add Periods that are missing for 1997 due to Converison Leap Year Caluclation Bug
insert into PERIOD  (PR_OID, PR_NUM, PR_FISCYR, PR_SDATE, PR_EDATE, PR_STAT)
select ABS(NUMBER(*)) + (select MAX(PR_OID) from PERIOD), 
       PR_NUM, PR_FISCYR+1, 
       if PR_SDATE <= '1996-02-29' then pr_sdate+366 else PR_SDATE +365 endif,
       if PR_EDATE < '1996-02-29' then pr_edate+366 else PR_EDATE +365 endif,
       0 from PERIOD P1
  where PR_FISCYR = 1996 and PR_NUM != 0 and 
     PR_NUM not in (select PR_NUM from PERIOD P2 where PR_FISCYR=1997) 
  order by PR_NUM;
COMMIT;
