diff -Naur astcc.old/astcc-admin.cgi astcc.new/astcc-admin.cgi --- astcc.old/astcc-admin.cgi 2004-12-19 17:36:50.000000000 -0500 +++ astcc.new/astcc-admin.cgi 2005-01-09 11:21:41.705519346 -0500 @@ -86,8 +86,8 @@ $config{'dbpass'}, 'admin'); connect_db(); return -1 unless $dbh; - return -1 unless $dbh->do("CREATE TABLE brands (name CHAR(40) PRIMARY KEY, language CHAR(10), publishednum CHAR(40), did char(40), markup INTEGER, inc INTEGER)"); - return -1 unless $dbh->do("CREATE TABLE cards (number CHAR(20) PRIMARY KEY, language CHAR(10), facevalue INTEGER, used INTEGER NOT NULL, inc INTEGER NOT NULL, markup INTEGER NOT NULL, creation TIMESTAMP, firstuse TIMESTAMP, expiration TIMESTAMP, inuse INTEGER)"); + return -1 unless $dbh->do("CREATE TABLE brands (name CHAR(40) PRIMARY KEY, language CHAR(10), publishednum CHAR(40), did char(40), markup INTEGER, inc INTEGER, fee INTEGER, days INTEGER)"); + return -1 unless $dbh->do("CREATE TABLE cards (number CHAR(20) PRIMARY KEY, language CHAR(10), facevalue INTEGER, used INTEGER NOT NULL, inc INTEGER NOT NULL, markup INTEGER NOT NULL, creation TIMESTAMP, firstuse TIMESTAMP, expiration TIMESTAMP, inuse INTEGER, brand CHAR(40), nextfee INTEGER)"); return -1 unless $dbh->do("CREATE TABLE trunks (name CHAR(40) PRIMARY KEY, tech CHAR(10), path CHAR(40) NOT NULL)"); return -1 unless $dbh->do("CREATE TABLE routes (pattern CHAR(40) PRIMARY KEY, comment CHAR(80), trunks CHAR(80), connectcost INTEGER NOT NULL, includedseconds INTEGER NOT NULL, cost INTEGER NOT NULL)"); return -1 unless $dbh->do("CREATE TABLE cdrs (cardnum CHAR(40), callerid char(80), callednum CHAR(80), trunk CHAR(40), disposition CHAR(20), billseconds INTEGER, billcost INTEGER)"); @@ -240,10 +240,10 @@ } sub addcard() { - my ($number, $language, $seconds, $inc, $markup) = @_; - my $tmp = "INSERT INTO cards (number,language,inc,facevalue,markup,used) VALUES (" . + my ($number, $language, $seconds, $inc, $markup, $brand, $nextfee) = @_; + my $tmp = "INSERT INTO cards (number,language,inc,facevalue,markup,used,brand,nextfee) VALUES (" . $dbh->quote($number) . ", " . $dbh->quote($language) . ", " . $dbh->quote($inc) . ", " . $dbh->quote($seconds) . - ", " . $dbh->quote($markup) . ",0)"; + ", " . $dbh->quote($markup) . ",0,". $dbh->quote($brand) ."," . $dbh->quote($nextfee) .")"; $dbh->do($tmp) || print "$tmp failed"; } @@ -263,7 +263,7 @@ print EMAIL "You have added $count $brand cards in the amount of $pennies cents. \n\n"; } if ($row = $sth->fetchrow_hashref) { - ($language, $inc, $markup) = ($row->{language}, $row->{inc}, $row->{markup}); + ($language, $inc, $markup, $nextfee) = ($row->{language}, $row->{inc}, $row->{markup}, $row->{days}); } $sth->finish; # add cards -- face value is in 1/100 of a penny @@ -273,7 +273,7 @@ } else { $number = &findunique; } - &addcard($number, $language, $pennies * 100, $inc, $markup); + &addcard($number, $language, $pennies * 100, $inc, $markup, $brand, $nextfee); if ($config{'email'} eq "YES") { print EMAIL "$number \n"; } @@ -477,7 +477,7 @@ @cardlist = &list_cards(); $body .= ""; $body .= "" . $status . "\n"; - $body .= "\n"; + $body .= "\n"; foreach (@cardlist) { $cardnum = $_; $cardinfo = &getcard($cardnum); @@ -489,7 +489,7 @@ $color = "#ffffcc"; } - $body .= "\n"; } } @@ -527,11 +527,14 @@ } elsif (param("action$x") eq "Save...") { if ($dbh->do("UPDATE brands SET name=" . $dbh->quote(param("newname$x")) . " WHERE name=" . $dbh->quote(param("item$x")))) { - $tmp = "REPLACE INTO brands (name,language,inc,publishednum,did,markup) VALUES (" . + $tmp = "REPLACE INTO brands (name,language,inc,publishednum,did,markup,days,fee) VALUES (" . $dbh->quote(param("newname$x")) . ", " . $dbh->quote(param("newlang$x")) . ", " . $dbh->quote(param("newinc$x")) . ", " . $dbh->quote(param("newpub$x")) . ", " . $dbh->quote(param("newdid$x")) . - ", " . $dbh->quote(param("newmarkup$x")) . ")"; + ", " . $dbh->quote(param("newmarkup$x")) . + ", " . $dbh->quote(param("newdays$x")) . + ", " . $dbh->quote(param("newfees$x")) . + ")"; if ($dbh->do($tmp)) { $status = "Brand '" . param("newname$x") . "' has been updated"; } else { @@ -541,11 +544,14 @@ $status = "Name is already in use!"; } } elsif (param("action$x") eq "Create...") { - $tmp = "INSERT INTO brands (name,language,inc,publishednum,did,markup) VALUES (" . + $tmp = "INSERT INTO brands (name,language,inc,publishednum,did,markup,days,fee) VALUES (" . $dbh->quote(param("newname$x")) . ", " . $dbh->quote(param("newlang$x")) . ", " . $dbh->quote(param("newinc$x")) . ", " . $dbh->quote(param("newpub$x")) . ", " . $dbh->quote(param("newdid$x")) . - ", " . $dbh->quote(param("newmarkup$x")) . ")"; + ", " . $dbh->quote(param("newmarkup$x")) . + ", " . $dbh->quote(param("newdays$x")) . + ", " . $dbh->quote(param("newfees$x")) . + ")"; if ($dbh->do($tmp)) { $status = "Brand '" . param("newname$x") . "' has been created"; } else { @@ -564,7 +570,7 @@ $sth->execute || return "Something is wrong with the brands database\n"; $body = "
Card NumberAmount UsedFace ValueMarkupCreationFirst UseExpirationIn Use
Card NumberBrandAmount UsedFace ValueMarkupCreationFirst UseExpirationIn Use
$cardnum$cardinfo->{used}$cardinfo->{facevalue}$cardinfo->{markup}$cardinfo->{creation}$cardinfo->{firstuse}$cardinfo->{expiration}$cardinfo->{inuse}"; + $body .= "
$cardnum$cardinfo->{brand}$cardinfo->{used}$cardinfo->{facevalue}$cardinfo->{markup}$cardinfo->{creation}$cardinfo->{firstuse}$cardinfo->{expiration}$cardinfo->{inuse}"; $body .= "
" . "" . start_form . "$status\n" . - "\n"; + "\n"; while($row = $sth->fetchrow_hashref) { $count++; if (!($count % 2)) { @@ -582,6 +588,8 @@ textfield(-name => "newpub$count", -size => 15, -default => $row->{publishednum}) . ""; $body .= "" . "" . - "" . + "" . ""; $body .= ""; $body .= ""; $body .= ""; + $body .= ""; + $body .= ""; + $body .= ""; $body .= ""; $body .= "
" . hidden(-name => 'mode', -value => 'Brands') . "Brand NameLanguagePublished NumberDIDIncMarkup (in 1/100 of 1%)
" . hidden(-name => 'mode', -value => 'Brands') . "Brand NameLanguagePublished NumberDIDIncService Fee (cents)Service Fee DaysMarkup (in 1/100 of 1%)
" . textfield(-name => "newdid$count", -size => 10, -default => $row->{did}) . "" . popup_menu(-name => "newinc$count", -values => \@incs, -default => $row->{inc}) . "" . + textfield(-name => "newfees$count", -size => 2, -default => $row->{fee}) . "" . + textfield(-name => "newdays$count", -size => 2, -default => $row->{days}) . "" . textfield(-name => "newmarkup$count", -size => 5, -default => $row->{markup}) . "" . submit(-name => "action$count", -value => 'Save...') . submit(-name => "action$count", -value => 'Cancel...'); @@ -590,7 +598,7 @@ $body .= "
" . hidden(-name => "item$count", -value => $row->{name}) . "$row->{name}$row->{language}$row->{publishednum}$row->{did}$row->{inc}$row->{markup}$row->{did}$row->{inc}$row->{fee}$row->{days}$row->{markup}"; if (!$editing) { $body .= submit(-name => "action$count", -value => 'Edit...') . @@ -611,6 +619,8 @@ textfield(-name => "newpub$count", -size => 15) . "" . textfield(-name => "newdid$count", -size => 10) . "" . popup_menu(-name => "newinc$count", -values => \@incs) . "" . + textfield(-name => "newfees$count", -size => 2) . "" . + textfield(-name => "newdays$count", -size => 2) . "" . textfield(-name => "newmarkup$count", -size => 5) . "" . submit(-name => "action$count", -value => 'Create...') . submit(-name => "action$count", -value => 'Cancel...'); @@ -912,6 +922,9 @@ $config{emailadd} = param('emailadd'); $config{mailprog} = param('mailprog'); $config{friendsdb} = param('friendsdb'); + $config{maintverbose} = param('maintverbose'); + $config{maintcdr} = param('maintcdr'); + $config{maintname} = param('maintname'); &save_config(); $activity = "Configuration saved..."; if ($action eq "Create Database") { @@ -937,6 +950,9 @@ $body .= "
Admin Email" . textfield(-name => 'emailadd', -default => $config{emailadd}) . "
Email Program" . textfield(-name => 'mailprog', -default => $config{mailprog}) . "
Enable Iax/Sip Friends DB (YES/NO) " . textfield(-name => 'friendsdb', -default => $config{friendsdb}) . "
Verbose account maintainence (YES/NO) " . textfield(-name => 'maintverbose', -default => $config{maintverbose}) . "
Modify CDR to show maintainence fee (YES/NO) " . textfield(-name => 'maintcdr', -default => $config{maintcdr}) . "
CDR Text for maintainence fee" . textfield(-name => 'maintname', -default => $config{maintname}) . "
 " . submit(-name => 'action', -value => 'Save') . "" . submit( -name => 'action', -value => 'Create Database') . " 
"; return $body; diff -Naur astcc.old/chargemaintainence.pl astcc.new/chargemaintainence.pl --- astcc.old/chargemaintainence.pl 1969-12-31 19:00:00.000000000 -0500 +++ astcc.new/chargemaintainence.pl 2005-01-09 10:59:44.569540460 -0500 @@ -0,0 +1,75 @@ +#!/usr/bin/perl +# +# Asterisk(tm) Calling Card Platform +# +# Copyright (C) 2004, Digium, Inc. +# +# Charge a card maintainence fee. +# +# Stephen A. Misel +# +# Some routines borrowed from astcc-admin. These +# should really be placed in a module. +# +# Run this daily from cron. Midnight might be a good time. +# + +use DBI; +my $dbh; +my $config; +&load_config; +&connect_db; + +&updatedates; + +my $sth = $dbh->prepare("select cards.number, brands.fee, brands.days from cards, brands where + cards.nextfee < 1 and cards.brand=brands.name and brands.fee >0 and brands.days > 0"); +$sth->execute; + +while (my (@row) = $sth->fetchrow_array) { + print "Charging $row[0] $row[1] cents.\n" if ($config{'maintverbose'} eq "YES"); + chargefee($row[0], $row[1]); + set_nextfee($row[0], $row[2]); +} + +exit; + + + + +sub load_config() { + open(CFG, ") { + chomp; + my ($var, $val) = split(/\s*\=\s*/); + $config{$var} = $val; + } + close(CFG); +} + +sub connect_db() { + my $dsn = "DBI:mysql:database=$config{'dbname'};host=$config{'dbhost'}"; + $dbh->disconnect if $dbh; + $dbh = DBI->connect($dsn, $config{'dbuser'}, $config{'dbpass'}); +} + +sub set_nextfee { + my ($card, $days) = @_; + my $sth = $dbh->do("UPDATE cards SET nextfee=" . $dbh->quote($days) ." WHERE number=". $dbh->quote($card)); + return; +} + +sub updatedates { + print "Updating card fee dates" if ($config{'maintverbose'} eq "YES"); + $dbh->do("update cards set nextfee=nextfee-1"); + print ": Complete.\n" if ($config{'maintverbose'} eq "YES"); + return; +} + +sub chargefee { + my ($card, $fee) = @_; + my $sth = $dbh->do("INSERT INTO cdrs (cardnum, callerid, billcost) VALUES (" . $dbh->quote($card) . "," + . $dbh->quote($config{'maintname'}).",".$dbh->quote($fee).")") if ($config{'maintcdr'} eq "YES"); + my $sth = $dbh->do("UPDATE cards SET used=used+$fee WHERE number=" . $dbh->quote($card)); + return; +}