1 package FS::part_pkg::sql_external;
4 use base qw( FS::part_pkg::recur_Common FS::part_pkg::discount_Mixin );
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 $str = $self->SUPER::price_info;
51 $str .= " plus per-service charges" if $str;
57 my($cust_pkg, $sdate, $details, $param ) = @_;
60 my $dbh = DBI->connect( map { $self->option($_) }
61 qw( datasrc db_username db_password )
65 my $sth = $dbh->prepare( $self->option('query') )
68 foreach my $cust_svc (
69 grep { $_->part_svc->svcdb eq "svc_external" } $cust_pkg->cust_svc
71 my $id = $cust_svc->svc_x->id;
72 $sth->execute($id) or die $sth->errstr;
73 $price += $sth->fetchrow_arrayref->[0];
76 $param->{'override_charges'} = $price;
77 $self->calc_recur_Common($cust_pkg,$sdate,$details,$param);
80 sub can_discount { 1; }