1 package FS::part_pkg::sql_generic;
4 use vars qw(@ISA %info);
6 #use FS::Record qw(qsearch qsearchs);
9 @ISA = qw(FS::part_pkg::flat);
12 'name' => 'Base charge plus a per-domain metered rate from a configurable SQL query',
14 'setup_fee' => { 'name' => 'Setup fee for this package',
17 'recur_flat' => { 'name' => 'Base monthly charge for this package',
20 'recur_included' => { 'name' => 'Units included',
23 'recur_unit_charge' => { 'name' => 'Additional charge per unit',
26 'datasrc' => { 'name' => 'DBI data source',
29 'db_username' => { 'name' => 'Database username',
32 'db_password' => { 'name' => 'Database username',
35 'query' => { 'name' => 'SQL query',
39 'fieldorder' => [qw( setup_fee recur_flat recur_included recur_unit_charge datasrc db_username db_password query )],
40 # 'setup' => 'what.setup_fee.value',
41 # 'recur' => '\'my $dbh = DBI->connect(\"\' + what.datasrc.value + \'\", \"\' + what.db_username.value + \'\") or die $DBI::errstr; \'',
42 #'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_flat.value + \' + $units * \' + what.recur_unit_charge.value + \';\'',
43 #'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_flat.value + \' + $units * \' + what.recur_unit_charge + \';\'',
48 my($self, $cust_pkg ) = @_;
50 my $dbh = DBI->connect( map { $self->option($_) }
51 qw( datasrc db_username db_password )
55 my $sth = $dbh->prepare( $self->option('query') )
59 foreach my $cust_svc (
60 grep { $_->part_svc->svcdb eq "svc_domain" } $cust_pkg->cust_svc
62 my $domain = $cust_svc->svc_x->domain;
63 $sth->execute($domain) or die $sth->errstr;
65 $units += $sth->fetchrow_arrayref->[0];
68 $units -= $self->option('recur_included');
69 $units = 0 if $units < 0;
71 $self->option('recur_flat') + $units * $self->option('recur_unit_charge');
75 qw( setup_fee recur_flat recur_unit_charge );
79 my($self, $cust_pkg) = @_;
80 $self->option('recur_flat');