1 package FS::part_pkg::sql_generic;
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 a per-domain metered rate from a configurable SQL query',
13 'shortname' => 'Bulk (per-domain from 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 'recur_included' => { 'name' => 'Units included',
28 'recur_unit_charge' => { 'name' => 'Additional charge per unit',
31 'datasrc' => { 'name' => 'DBI data source',
34 'db_username' => { 'name' => 'Database username',
37 'db_password' => { 'name' => 'Database username',
40 'query' => { 'name' => 'SQL query',
44 'fieldorder' => [qw( setup_fee recur_fee unused_credit recur_included recur_unit_charge datasrc db_username db_password query )],
45 # 'setup' => 'what.setup_fee.value',
46 # 'recur' => '\'my $dbh = DBI->connect(\"\' + what.datasrc.value + \'\", \"\' + what.db_username.value + \'\") or die $DBI::errstr; \'',
47 #'recur' => '\'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 $units = 0; foreach my $cust_svc ( grep { $_->part_svc->svcdb eq \"svc_domain\" } $cust_pkg->cust_svc ) { my $domain = $cust_svc->svc_x->domain; $sth->execute($domain) or die $sth->errstr; $units += $sth->fetchrow_arrayref->[0]; } $units -= \' + what.recur_included.value + \'; $units = 0 if $units < 0; \' + what.recur_fee.value + \' + $units * \' + what.recur_unit_charge.value + \';\'',
48 #'recur' => '\'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 $units = 0; foreach my $cust_svc ( grep { $_->part_svc->svcdb eq "svc_domain" } $cust_pkg->cust_svc ) { my $domain = $cust_svc->svc_x->domain; $sth->execute($domain) or die $sth->errstr; $units += $sth->fetchrow_arrayref->[0]; } $units -= \' + what.recur_included.value + \'; $units = 0 if $units < 0; \' + what.recur_fee.value + \' + $units * \' + what.recur_unit_charge + \';\'',
53 my($self, $cust_pkg ) = @_;
55 my $dbh = DBI->connect( map { $self->option($_) }
56 qw( datasrc db_username db_password )
60 my $sth = $dbh->prepare( $self->option('query') )
64 foreach my $cust_svc (
65 grep { $_->part_svc->svcdb eq "svc_domain" } $cust_pkg->cust_svc
67 my $domain = $cust_svc->svc_x->domain;
68 $sth->execute($domain) or die $sth->errstr;
70 $units += $sth->fetchrow_arrayref->[0];
73 $units -= $self->option('recur_included');
74 $units = 0 if $units < 0;
76 $self->option('recur_fee') + $units * $self->option('recur_unit_charge');
79 sub can_discount { 0; }
82 qw( setup_fee recur_fee recur_unit_charge );
86 my($self, $cust_pkg) = @_;
87 $self->option('recur_fee');