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',
14 'setup_fee' => { 'name' => 'Setup fee for this package',
17 'recur_flat' => { 'name' => 'Base recurring fee for this package',
20 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
21 ' of service at cancellation',
24 'datasrc' => { 'name' => 'DBI data source',
27 'db_username' => { 'name' => 'Database username',
30 'db_password' => { 'name' => 'Database password',
33 'query' => { 'name' => 'SQL query',
37 'fieldorder' => [qw( setup_fee recur_flat unused_credit datasrc db_username db_password query )],
38 #'setup' => 'what.setup_fee.value',
39 #'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_flat.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;'!,
44 my($self, $cust_pkg ) = @_;
46 my $dbh = DBI->connect( map { $self->option($_) }
47 qw( datasrc db_username db_password )
51 my $sth = $dbh->prepare( $self->option('query') )
54 my $price = $self->option('recur_flat');
56 foreach my $cust_svc (
57 grep { $_->part_svc->svcdb eq "svc_external" } $cust_pkg->cust_svc
59 my $id = $cust_svc->svc_x->id;
60 $sth->execute($id) or die $sth->errstr;
61 $price += $sth->fetchrow_arrayref->[0];
72 my($self, $cust_pkg) = @_;
73 $self->option('recur_flat');