#Script based on http://wiki.mikrotik.com/wiki/AutomatedBilling
#Details:
#This Script generates a report of prepaid users consumed on a day n, without entering the userman tool
#Send the report to a defaulted email
# You need to configure the sending of mails on the mikrotik router prior to adding the script
# Rb750r2 v.6.39.1
#Version by ajzh
:local date
:local usrname
:local precio
:local tilltime
:local dia
:local status
:local paycode
:local profilecode
:local profile
:local lastseen
:local total
:local body
:local uptime
:local month
:local 1hora
:local 3horas
:local 5horas
:local 1dia
:local 1mes
#define the names of the profiles with which I count in the userman tool, for this example I put generic names, remove the "" and customize in your mikrotik
:set "profile1" 0
:set "profile2" 0
:set "profile3" 0
:set "profile4" 0
:set "profile5" 0
:log info "Start Dayli Report"
:set month [:pick [/system clock get date] 0 3]
:set date [/system clock get date]
:foreach i in=[/tool user-manager user find last-seen!=never] do={
:set lastseen [/tool user-manager user get $i last-seen]
:set dia [:pick $lastseen 0 11]
:if ( [$dia] = [$date] ) do={
:set profile [/tool user-manager user get $i actual-profile]
:if ( [:len $profile] = 0 ) do={
:set usrname [/tool user-manager user get $i username]
:set uptime [/tool user-manager user get $i uptime]
:set paycode [/tool user-manager payment find user=$usrname ]
:set precio [/tool user-manager payment get $paycode price]
:set total ( $total + ($precio/100) )
:set body ( $body . "User : " . $usrname. " Price: ".($precio/100) . " Uptime: " . $uptime .";\n")
#Here counts the number of cards sold, place the generic prices, delete the "" and personalize it in your mikrotik
:if ( [($precio/100)] = "price1" ) do={ :set profile1 ($profile1 + 1)}
:if ( [($precio/100)] = "price2" ) do={ :set profile2 ($profile2 + 1)}
:if ( [($precio/100)] = "price3" ) do={ :set profile3 ($profile3 + 1)}
:if ( [($precio/100)] = "price4" ) do={ :set profile4 ($profile4 + 1)}
:if ( [($precio/100)] = "price5" ) do={ :set profile5 ($profile5 + 1)}
}
}
}
:if ( [$total] = "0" ) do={
:log info "sin ventas $date"
} else={
/tool e-mail send to="some email" from="email account configurated on your mikrotik" subject="Sales Report of the $date" body="Sales Report Date: $date
Total: $total
Example message in spanish
Fichas de profile1 hora=$profile1
Fichas de profile2 horas=$profile2
Fichas de profile3 horas=$profile3
Fichas de profile4 dia=$profile4
Fichas de profile5 mes=$profile5
Detalle:
$body"
:log info "email sended"
}