1 package FS::cust_pkg_usageprice;
2 use base qw( FS::Record );
5 use FS::Record qw( dbh ); # qsearch qsearchs );
9 FS::cust_pkg_usageprice - Object methods for cust_pkg_usageprice records
13 use FS::cust_pkg_usageprice;
15 $record = new FS::cust_pkg_usageprice \%hash;
16 $record = new FS::cust_pkg_usageprice { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::cust_pkg_usageprice object represents an specific customer package usage
29 pricing add-on. FS::cust_pkg_usageprice inherits from FS::Record. The
30 following fields are currently supported:
59 Creates a new record. To add the record to the database, see L<"insert">.
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to. You can ask the object for a copy with the I<hash> method.
66 # the new method can be inherited from FS::Record, if a table method is defined
68 sub table { 'cust_pkg_usageprice'; }
72 Adds this record to the database. If there is an error, returns the error,
73 otherwise returns false.
77 Delete this record from the database.
79 =item replace OLD_RECORD
81 Replaces the OLD_RECORD with this one in the database. If there is an error,
82 returns the error, otherwise returns false.
86 Checks all fields to make sure this is a valid record. If there is
87 an error, returns the error, otherwise returns false. Called by the insert
96 $self->ut_numbern('usagepricenum')
97 || $self->ut_number('pkgnum')
98 || $self->ut_number('usagepricepart')
99 || $self->ut_number('quantity')
101 return $error if $error;
108 Returns the price for this customer usage pricing add-on (quantity of this
109 record multiplied by price of the associated FS::part_pkg_usageprice record)
115 sprintf('%.2f', $self->quantity * $self->part_pkg_usageprice->price);
120 Applies this customer usage pricing add-on. (Mulitplies quantity of this record
121 by part_pkg_usageprice.amount, and applies to to any services of this package
122 matching part_pkg_usageprice.target)
124 If there is an error, returns the error, otherwise returns false.
131 my $oldAutoCommit = $FS::UID::AutoCommit;
132 local $FS::UID::AutoCommit = 0;
137 my $part_pkg_usageprice = $self->part_pkg_usageprice;
139 my $amount = $self->quantity * $part_pkg_usageprice->amount;
141 my $target = $part_pkg_usageprice->target;
143 #these are ongoing counters that count down, so increment them
144 if ( $target =~ /^svc_acct.(\w+)$/ ) {
146 my $method = "increment_$1";
148 foreach my $cust_svc ( $self->cust_pkg->cust_svc(svcdb=>'svc_acct') ) {
149 $error ||= $cust_svc->svc_x->$method( $amount );
152 #this is a maximum number, not a counter, so we want to take our number
153 # and add it to the default for the service
154 } elsif ( $target eq 'svc_conferencing.participants' ) {
156 foreach my $cust_svc ($self->cust_pkg->cust_svc(svcdb=>'svc_conferencing')){
157 my $svc_conferencing = $cust_svc->svc_x;
158 my $base_amount = $cust_svc->part_svc->part_svc_column('participants')->columnvalue || 0; #assuming.. D? F would get overridden :/
159 $svc_conferencing->participants( $base_amount + $amount );
160 $error ||= $svc_conferencing->replace;
163 #this has no multiplication involved, its just a set only
164 #} elsif ( $target eq 'svc_conferencing.confqualitynum' ) {
167 } elsif ( $target eq 'sqlradacct_hour.recur_included_total' ) {
169 $error = "Cannot call apply on target $target";
174 $dbh->rollback if $oldAutoCommit;
176 $dbh->commit if $oldAutoCommit;
188 L<FS::part_pkg_usageprice>, L<FS::cust_pkg>, L<FS::Record>