AutomatedBilling/MonthEndScript

From MikroTik Wiki
Revision as of 16:53, 25 July 2008 by Omega-00 (talk | contribs) (month values don't work unless in quotes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is the Month End script attached to the Automated Billing System.

 :local date
 :local day
 :local month
 :local year
 :local yeardiv
 :local yearmult
 :local leapyear
 :local lastday
 :global found 
  
 :set date [system clock get date]
 :set month [:pick $date 0 3]
 :set day [:pick $date 4 6]
 :set year [:pick $date 7 11]
 
 :set yeardiv ($year / 4)
 :set yearmult ($yeardiv * 4)
 
 :if ([$yearmult] = $year) do={ :set leapyear true } else={ :set leapyear false }
 :if ([$month] = "jan") do={ :set lastday 31 }
 :if ([$month] = "feb") do={ 
        :if ($leapyear = true) do={ :set lastday 29 }
        :if ($leapyear = false) do={ :set lastday 28 } }
 :if ([$month] = "mar") do={ :set lastday 31 } 
 :if ([$month] = "apr") do={ :set lastday 30 }
 :if ([$month] = "may") do={ :set lastday 31 }
 :if ([$month] = "jun") do={ :set lastday 30 }
 :if ([$month] = "jul") do={ :set lastday 31 }
 :if ([$month] = "aug") do={ :set lastday 31 }
 :if ([$month] = "sep") do={ :set lastday 30 }
 :if ([$month] = "oct") do={ :set lastday 31 }
 :if ([$month] = "nov") do={ :set lastday 30 }
 :if ([$month] = "dec") do={ :set lastday 31 }
 :if ([$lastday] = $day) do={ :set found true } else={ :set found false }

This script basically chops up the Date into Month, Day and Year. It uses Month to assign how many days there are in that month, and uses Year to calculate whether or not it is a leapyear.

The Leapyer true/false value is also used to see if February should have 28 or 29 days.

Then, it quite simply takes the Last Day of This Month and This Year, and see if it is equal to the Current Date, and returns True or False, which the Oversight script will then use to take the appropriate action.