1 package FS::part_pkg::sql_external;
4 use vars qw(@ISA %info);
6 #use FS::Record qw(qsearch qsearchs);
7 use FS::part_pkg::flat;
9 @ISA = qw(FS::part_pkg::flat);
12 'name' => 'Base charge plus additional fees for external services from a configurable SQL query',
13 'shortname' => 'External SQL query',
15 'setup_fee' => { 'name' => 'Setup fee for this package',
18 'recur_fee' => { 'name' => 'Base recurring fee for this package',
21 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
22 ' of service at cancellation',
25 'datasrc' => { 'name' => 'DBI data source',
28 'db_username' => { 'name' => 'Database username',
31 'db_password' => { 'name' => 'Database password',
34 'query' => { 'name' => 'SQL query',
38 'fieldorder' => [qw( setup_fee recur_fee unused_credit datasrc db_username db_password query )],
39 #'setup' => 'what.setup_fee.value',
40 #'recur' => q!'my $dbh = DBI->connect("' + what.datasrc.value + '", "' + what.db_username.value + '", "' + what.db_password.value + '" ) or die $DBI::errstr; my $sth = $dbh->prepare("' + what.query.value + '") or die $dbh->errstr; my $price = ' + what.recur_fee.value + '; foreach my $cust_svc ( grep { $_->part_svc->svcdb eq "svc_external" } $cust_pkg->cust_svc ){ my $id = $cust_svc->svc_x->id; $sth->execute($id) or die $sth->errstr; $price += $sth->fetchrow_arrayref->[0]; } $price;'!,
45 my($self, $cust_pkg ) = @_;
47 my $dbh = DBI->connect( map { $self->option($_) }
48 qw( datasrc db_username db_password )
52 my $sth = $dbh->prepare( $self->option('query') )
55 my $price = $self->option('recur_fee');
57 foreach my $cust_svc (
58 grep { $_->part_svc->svcdb eq "svc_external" } $cust_pkg->cust_svc
60 my $id = $cust_svc->svc_x->id;
61 $sth->execute($id) or die $sth->errstr;
62 $price += $sth->fetchrow_arrayref->[0];
73 my($self, $cust_pkg) = @_;
74 $self->option('recur_fee');