1 package FS::part_pkg::sql_external;
2 use base qw( FS::part_pkg::discount_Mixin 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' => [ 'prorate_Mixin', 'global_Mixin' ],
14 'cutoff_day' => { 'name' => 'Billing Day (1 - 28) for prorating or '.
19 'recur_method' => { 'name' => 'Recurring fee method',
21 #'options' => \%recur_method,
23 'select_options' => \%FS::part_pkg::recur_Common::recur_method,
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( recur_method cutoff_day ),
39 FS::part_pkg::prorate_Mixin::fieldorder,
40 qw( datasrc db_username db_password query
47 my $str = $self->SUPER::price_info(@_);
48 $str .= " plus per-service charges" if $str;
54 my($cust_pkg, $sdate, $details, $param ) = @_;
57 my $dbh = DBI->connect( map { $self->option($_) }
58 qw( datasrc db_username db_password )
62 my $sth = $dbh->prepare( $self->option('query') )
65 foreach my $cust_svc (
66 grep { $_->part_svc->svcdb eq "svc_external" } $cust_pkg->cust_svc
68 my $id = $cust_svc->svc_x->id;
69 $sth->execute($id) or die $sth->errstr;
70 $price += $sth->fetchrow_arrayref->[0];
73 $param->{'override_charges'} = $price;
74 ($cust_pkg->quantity || 1) * $self->calc_recur_Common($cust_pkg,$sdate,$details,$param);
77 sub can_discount { 1; }