diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS.pm | 2 | ||||
-rw-r--r-- | FS/FS/AccessRight.pm | 2 | ||||
-rw-r--r-- | FS/FS/Schema.pm | 13 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 3 | ||||
-rw-r--r-- | FS/FS/cust_pkg.pm | 72 | ||||
-rw-r--r-- | FS/FS/cust_pkg_detail.pm | 140 | ||||
-rw-r--r-- | FS/MANIFEST | 2 | ||||
-rw-r--r-- | FS/t/cust_pkg_detail.t | 5 |
8 files changed, 239 insertions, 0 deletions
@@ -198,6 +198,8 @@ L<FS::cust_pkg> - Customer package class L<FS::cust_pkg_option> - Customer package option class +L<FS::cust_pkg_detail> - Customer package details class + L<FS::reason_type> - Reason type class L<FS::reason> - Reason class diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 81b653404..27486da35 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -114,6 +114,8 @@ assigned to users and/or groups. 'Cancel customer package later', 'Add on-the-fly cancel reason', #NEW 'Add on-the-fly suspend reason', #NEW + 'Edit customer package invoice details', #NEW + 'Edit customer package comments', #NEW ### # customer service rights diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 1d6bd7c07..e71ded3e0 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -791,6 +791,19 @@ sub tables_hashref { 'index' => [ [ 'pkgnum' ], [ 'optionname' ] ], }, + 'cust_pkg_detail' => { + 'columns' => [ + 'pkgdetailnum', 'serial', '', '', '', '', + 'pkgnum', 'int', '', '', '', '', + 'detail', 'varchar', '', $char_d, '', '', + 'detailtype', 'char', '', 1, '', '', # "I"nvoice or "C"omment + 'weight', 'int', '', '', '', '', + ], + 'primary_key' => 'pkgdetailnum', + 'unique' => [], + 'index' => [ [ 'pkgnum', 'detailtype' ] ], + }, + 'cust_pkg_reason' => { 'columns' => [ 'num', 'serial', '', '', '', '', diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 7da43998b..939888ee1 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2089,6 +2089,9 @@ sub bill { warn " charges (setup=$setup, recur=$recur); adding line items\n" if $DEBUG > 1; + + push @details, map { $_->detail } $cust_pkg->cust_pkg_detail('I'); + my $cust_bill_pkg = new FS::cust_bill_pkg ({ 'invnum' => $invnum, 'pkgnum' => $cust_pkg->pkgnum, diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index c8d1cfed3..cbec585e4 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -14,6 +14,7 @@ use FS::cust_main; use FS::type_pkgs; use FS::pkg_svc; use FS::cust_bill_pkg; +use FS::cust_pkg_detail; use FS::h_cust_svc; use FS::reg_code; use FS::part_svc; @@ -999,6 +1000,77 @@ sub cust_bill_pkg { qsearch( 'cust_bill_pkg', { 'pkgnum' => $self->pkgnum } ); } +=item cust_pkg_detail [ DETAILTYPE ] + +Returns any customer package details for this package (see +L<FS::cust_pkg_detail>). + +DETAILTYPE can be set to "I" for invoice details or "C" for comments. + +=cut + +sub cust_pkg_detail { + my $self = shift; + my %hash = ( 'pkgnum' => $self->pkgnum ); + $hash{detailtype} = shift if @_; + qsearch({ + 'table' => 'cust_pkg_detail', + 'hashref' => \%hash, + 'order_by' => 'ORDER BY weight, pkgdetailnum', + }); +} + +=item set_cust_pkg_detail DETAILTYPE [ DETAIL, DETAIL, ... ] + +Sets customer package details for this package (see L<FS::cust_pkg_detail>). + +DETAILTYPE can be set to "I" for invoice details or "C" for comments. + +If there is an error, returns the error, otherwise returns false. + +=cut + +sub set_cust_pkg_detail { + my( $self, $detailtype, @details ) = @_; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + foreach my $current ( $self->cust_pkg_detail($detailtype) ) { + my $error = $current->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error removing old detail: $error"; + } + } + + foreach my $detail ( @details ) { + my $cust_pkg_detail = new FS::cust_pkg_detail { + 'pkgnum' => $self->pkgnum, + 'detailtype' => $detailtype, + 'detail' => $detail, + }; + my $error = $cust_pkg_detail->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error adding new detail: $error"; + } + + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + =item cust_svc [ SVCPART ] Returns the services for this package, as FS::cust_svc objects (see diff --git a/FS/FS/cust_pkg_detail.pm b/FS/FS/cust_pkg_detail.pm new file mode 100644 index 000000000..b8c692c72 --- /dev/null +++ b/FS/FS/cust_pkg_detail.pm @@ -0,0 +1,140 @@ +package FS::cust_pkg_detail; + +use strict; +use vars qw( @ISA ); +use FS::Record qw( qsearch qsearchs ); + +@ISA = qw(FS::Record); + +=head1 NAME + +FS::cust_pkg_detail - Object methods for cust_pkg_detail records + +=head1 SYNOPSIS + + use FS::cust_pkg_detail; + + $record = new FS::cust_pkg_detail \%hash; + $record = new FS::cust_pkg_detail { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::cust_pkg_detail object represents an example. FS::cust_pkg_detail inherits from +FS::Record. The following fields are currently supported: + +=over 4 + +=item pkgdetailnum + +primary key + +=item pkgnum + +pkgnum + +=item detail + +detail + +=item detailtype + +detailtype + +=item weight + +weight + + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new example. To add the example to the database, see L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I<hash> method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'cust_pkg_detail'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +# the insert method can be inherited from FS::Record + +=item delete + +Delete this record from the database. + +=cut + +# the delete method can be inherited from FS::Record + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid example. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('pkgdetailnum') + || $self->ut_number('pkgnum') + || $self->ut_text('detail') + || $self->ut_('detailtype') + || $self->ut_number('weight') + ; + return $error if $error; + + $self->SUPER::check; +} + +=back + +=head1 BUGS + +The author forgot to customize this manpage. + +=head1 SEE ALSO + +L<FS::Record>, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index d864d2ea3..8293b014b 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -378,3 +378,5 @@ t/cust_pay_pending.t FS/part_pkg_taxclass.pm t/part_pkg_taxclass.t FS/Yori.pm +FS/cust_pkg_detail.pm +t/cust_pkg_detail.t diff --git a/FS/t/cust_pkg_detail.t b/FS/t/cust_pkg_detail.t new file mode 100644 index 000000000..15dec0014 --- /dev/null +++ b/FS/t/cust_pkg_detail.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::cust_pkg_detail; +$loaded=1; +print "ok 1\n"; |