1 package FS::part_pkg::sql_external;
4 use base qw( FS::part_pkg::recur_Common );
7 #use FS::Record qw(qsearch qsearchs);
10 'name' => 'Base charge plus additional fees for external services from a configurable SQL query',
11 'shortname' => 'External SQL query',
12 'inherit_fields' => [ 'global_Mixin' ],
14 'cutoff_day' => { 'name' => 'Billing Day (1 - 28) for prorating or '.
18 'add_full_period'=> { 'name' => 'When prorating first month, also bill '.
19 'for one full period after that',
23 'recur_method' => { 'name' => 'Recurring fee method',
25 #'options' => \%recur_method,
27 'select_options' => \%FS::part_pkg::recur_Common::recur_method,
29 'datasrc' => { 'name' => 'DBI data source',
32 'db_username' => { 'name' => 'Database username',
35 'db_password' => { 'name' => 'Database password',
38 'query' => { 'name' => 'SQL query',
42 'fieldorder' => [qw( recur_method cutoff_day
43 add_full_period datasrc db_username db_password query
50 my($cust_pkg) = @_; #, $sdate, $details, $param ) = @_;
52 my $price = $self->calc_recur_Common(@_);
54 my $dbh = DBI->connect( map { $self->option($_) }
55 qw( datasrc db_username db_password )
59 my $sth = $dbh->prepare( $self->option('query') )
62 foreach my $cust_svc (
63 grep { $_->part_svc->svcdb eq "svc_external" } $cust_pkg->cust_svc
65 my $id = $cust_svc->svc_x->id;
66 $sth->execute($id) or die $sth->errstr;
67 $price += $sth->fetchrow_arrayref->[0];
73 sub can_discount { 0; }