#Here are a few notes on this script. # #This is written for User Manager. #It requires that your user manager has a First-Name, Last-Name and an E-mail entry #for every single user. If you have a company name, then you will need to adapt this script. #In my case, I just write Company Name over the First and Last name fields. # #You will also need to add your Starting Invoice Number in the Comment field #of each and every user. If this is not there, the script won't run properly. #My starting invoice number was 10001. (Don't use 00001, otherwise increment will #update the next invoice to be "2" instead of "00002". Put the 1 in front. # #The IP Pool names that this script checks for, is 64, 128, 256 and usagebased. #You may need to adapt that to your own IP pools and amounts. #The Amounts payable for my respective pools are: 220, 330, 450, #and usagebased has a base-charge of 150, and usage gets calculated at 7 per 100mb. # #Other things you will need to change: # #This applies to Both E-mails being sent: #/tool e-mail send to=accounts@YourWISP.com # from=NoReply@YourWISP.com # server=Your.Mail.Server # #This applies to the Second E-mail being sent: #Invoice For Wireless Internet Services $poolname kbps Package # #Under "Our Banking Details are as follow:" #Enter your own banking details, if applicable. #I request my users to state their username as deposit references. # #At the bottom of the script, add your own details as the Signature of the E-mail. # #Take note that this script runs the "reset-counters" command at the end. #If this is a problem for you, take it out, but take note that you will be billing #any usage-based customers then with cumulative month-to-month usage, #and not for that month only, because your counters will still have the previousmonths' usage on it. # #If you want to have previous months' usage still logged, #check out /tool/user-manager/log and see if you can write a script that can #add up total usage for each user, and also separate months' usage. #The way I have it set up, is to have two E-mails sent out - #One to the client, and one to Accounts e-mail, where I store all previous mails, #in case of query. # #Best of luck. #define a couple of variables :local uptime :local count :local usrname :local clientname :local clientsurname :local poolname :local accounttype :local discount :local amount :local discountedamount :local discountcheck :local date :local invoice :local nextinvoicenumber :local bytesin :local bytesout :local bytestotal :local gigstotal :local email :local basecharge :local usagecharge :local total :local disabled :local doespay # Loop through all the users in User Manager /tool user-manager user :foreach i in=[ /tool user-manager user find subscriber=admin ] do={ :set disabled [get $i disabled] :if ([$disabled] = false) do={ #pull some data from it, and print it on screen :set date [/system clock get date] :set usrname [get $i name] :set uptime [get $i uptime-used] :set clientname [get $i first-name] :set clientsurname [get $i last-name] :set poolname [get $i pool-name] :set discountcheck [get $i discount] :set invoice [get $i comment] :set nextinvoicenumber ($invoice + 1) :if ([get $i download-used] > 0) do={ :set bytesin [get $i download-used] } else={ :set bytesin 0 } :if ([get $i upload-used] > 0) do={ :set bytesout [get $i upload-used] } else={ :set bytesout 0 } :set bytestotal ($bytesin + $bytesout) :set gigstotal ($bytestotal / 1000000) :put $bytesin :put $bytesout :put $bytestotal :put $gigstotal :put $disabled :set email [get $i email] :set basecharge 150 :set usagecharge 0 :put $poolname /tool user-manager user set $i comment=$nextinvoicenumber :if ([$discountcheck] > 0 ) do={ :set discount [get $i discount] } else={ :set discount 0 } :if ([$poolname] = "64") do={ :set amount "220" } :if ([$poolname] = "128") do={ :set amount "330" } :if ([$poolname] = "256") do={ :set amount "450" } :if ([$poolname] = "usagebased") do={ :set usagecharge ((($gigstotal/100) * 7) + 7) } :if ([$poolname] = "usagebased") do={ :set amount $basecharge} :set discountedamount ($amount - $discount) :set total ($discountedamount + $usagecharge) :if ([$total] = 0) do={ :set doespay "This is a Complimentary Account"} else={ :set doespay "-" } /tool e-mail send to=accounts@YourWISP.com from=NoReply@YourWISP.com server=Your.Mail.Server subject="Invoice for user $usrname" body="Sent Invoice to $email Invoice: $usrname-$date-$invoice Date: $date Data: $gigstotal MB Uptime: $uptime Subtotal: R $amount.00 Usage Charge: R $usagecharge.00 Discount: -R $discount.00 Total: R $total.00 $doespay" :log info "Sent Invoice for $usrname to Accounting" /tool e-mail send to=$email from=NoReply@YourWISP.com server=Your.Mail.Server subject=Usage body="Dear $clientname $clientsurname Invoice For Wireless Internet Services $poolname kbps Package Invoice Number: $usrname-$date-$invoice This is an invoice for user account: $usrname Your current total uptime is $uptime Total Data Transferred: $gigstotal MB Subtotal: R $amount.00 Usage Charge: R $usagecharge.00 Discount: -R $discount.00 --------- Total: R $total.00 ========= This is the payable amount on your user account. Our Banking Details are as follow: Bank: YourBankName Branch: BranchCOde Account: AccountNumber Holder: AccountHolderName Reference: $usrname Please remember to state your Username as reference for the deposit, in order to avoid confusion among transactions. If you have received this invoice in error, please reply to this E-mail stating that you are not the intended recipient, and then delete this message. Should there be any incorrect information on this report, please inform us immediately. Warm Regards Users Accounting YourWISPName YourAddress Tel: YourTel Fax: YourFax E-mail: admin@YourWISP.com" :log info "Sent Invoice for user $usrname to $email" /tool user-manager user reset-counters $i } }