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',
14 'setup_fee' => { 'name' => 'Setup fee for this package',
17 'recur_flat' => { 'name' => 'Base recurring fee for this package',
20 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
21 ' of service at cancellation',
24 'recur_included' => { 'name' => 'Units included',
27 'recur_unit_charge' => { 'name' => 'Additional charge per unit',
30 'datasrc' => { 'name' => 'DBI data source',
33 'db_username' => { 'name' => 'Database username',
36 'db_password' => { 'name' => 'Database username',
39 'query' => { 'name' => 'SQL query',
43 'fieldorder' => [qw( setup_fee recur_flat unused_credit recur_included recur_unit_charge datasrc db_username db_password query )],
44 # 'setup' => 'what.setup_fee.value',
45 # 'recur' => '\'my $dbh = DBI->connect(\"\' + what.datasrc.value + \'\", \"\' + what.db_username.value + \'\") or die $DBI::errstr; \'',
46 #'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 + \';\'',
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_flat.value + \' + $units * \' + what.recur_unit_charge + \';\'',
52 my($self, $cust_pkg ) = @_;
54 my $dbh = DBI->connect( map { $self->option($_) }
55 qw( datasrc db_username db_password )
59 my $sth = $dbh->prepare( $self->option('query') )
63 foreach my $cust_svc (
64 grep { $_->part_svc->svcdb eq "svc_domain" } $cust_pkg->cust_svc
66 my $domain = $cust_svc->svc_x->domain;
67 $sth->execute($domain) or die $sth->errstr;
69 $units += $sth->fetchrow_arrayref->[0];
72 $units -= $self->option('recur_included');
73 $units = 0 if $units < 0;
75 $self->option('recur_flat') + $units * $self->option('recur_unit_charge');
79 qw( setup_fee recur_flat recur_unit_charge );
83 my($self, $cust_pkg) = @_;
84 $self->option('recur_flat');