X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg_usageprice.pm;h=29e6278820131c6f9e3b6a2b7caa0b6abf448820;hp=5380081b501e1a4aa989b403423f7cd6decd3b1f;hb=ffa18709ee8a4d05e18d2d406cf73afe79e52524;hpb=8861d46820af163c7de7839178b6120c9b32ab2c diff --git a/FS/FS/cust_pkg_usageprice.pm b/FS/FS/cust_pkg_usageprice.pm index 5380081b5..29e627882 100644 --- a/FS/FS/cust_pkg_usageprice.pm +++ b/FS/FS/cust_pkg_usageprice.pm @@ -2,7 +2,7 @@ package FS::cust_pkg_usageprice; use base qw( FS::Record ); use strict; -#use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( dbh ); # qsearch qsearchs ); =head1 NAME @@ -103,13 +103,89 @@ sub check { $self->SUPER::check; } +=item price + +Returns the price for this customer usage pricing add-on (quantity of this +record multiplied by price of the associated FS::part_pkg_usageprice record) + +=cut + +sub price { + my $self = shift; + sprintf('%.2f', $self->quantity * $self->part_pkg_usageprice->price); +} + +=item apply + +Applies this customer usage pricing add-on. (Mulitplies quantity of this record +by part_pkg_usageprice.amount, and applies to to any services of this package +matching part_pkg_usageprice.target) + +If there is an error, returns the error, otherwise returns false. + +=cut + +sub apply { + my $self = shift; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error = ''; + + my $part_pkg_usageprice = $self->part_pkg_usageprice; + + my $amount = $self->quantity * $part_pkg_usageprice->amount; + + my $target = $part_pkg_usageprice->target; + + #these are ongoing counters that count down, so increment them + if ( $target =~ /^svc_acct.(\w+)$/ ) { + + my $method = "increment_$1"; + + foreach my $cust_svc ( $self->cust_pkg->cust_svc(svcdb=>'svc_acct') ) { + $error ||= $cust_svc->svc_x->$method( $amount ); + } + + #this is a maximum number, not a counter, so we want to take our number + # and add it to the default for the service + } elsif ( $target eq 'svc_conferencing.participants' ) { + + foreach my $cust_svc ($self->cust_pkg->cust_svc(svcdb=>'svc_conferencing')){ + my $svc_conferencing = $cust_svc->svc_x; + my $base_amount = $cust_svc->part_svc->part_svc_column('participants')->columnvalue || 0; #assuming.. D? F would get overridden :/ + $svc_conferencing->participants( $base_amount + $amount ); + $error ||= $svc_conferencing->replace; + } + + #this has no multiplication involved, its just a set only + #} elsif ( $target eq 'svc_conferencing.confqualitynum' ) { + + + } elsif ( $target eq 'sqlradacct_hour.recur_included_total' ) { + + $error = "Cannot call apply on target $target"; + + } + + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + } else { + $dbh->commit if $oldAutoCommit; + } + return $error; + +} + =back =head1 BUGS =head1 SEE ALSO -L +L, L, L =cut