summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authormark <mark>2010-11-13 23:23:48 +0000
committermark <mark>2010-11-13 23:23:48 +0000
commitff92fba056c2b61753d464c84ecede6ec2f57258 (patch)
treed31db23bf83cb021ebd8932fcda5118a80f3ff8b /FS/FS
parent5188e8406a1fa2bee63ea81090ffefe3d4bf1b89 (diff)
hidden pkg_svc flag, RT#9871
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/cust_bill.pm4
-rw-r--r--FS/FS/cust_pkg.pm28
-rw-r--r--FS/FS/part_pkg.pm43
-rw-r--r--FS/FS/pkg_svc.pm3
5 files changed, 55 insertions, 24 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index f63bae9..95c1ce4 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1601,6 +1601,7 @@ sub tables_hashref {
'svcpart', 'int', '', '', '', '',
'quantity', 'int', '', '', '', '',
'primary_svc','char', 'NULL', 1, '', '',
+ 'hidden', 'char', 'NULL', 1, '', '',
],
'primary_key' => 'pkgsvcnum',
'unique' => [ ['pkgpart', 'svcpart'] ],
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 335c4b6..b3dd48a 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -4102,7 +4102,7 @@ sub _items_cust_bill_pkg {
{
push @d, map &{$escape_function}($_),
- $cust_pkg->h_labels_short($self->_date)
+ $cust_pkg->h_labels_short($self->_date, undef, 'I')
unless $cust_bill_pkg->pkgpart_override; #don't redisplay services
if ( $multilocation ) {
@@ -4164,7 +4164,7 @@ sub _items_cust_bill_pkg {
{
push @d, map &{$escape_function}($_),
- $cust_pkg->h_labels_short(@dates)
+ $cust_pkg->h_labels_short(@dates, 'I')
#$cust_bill_pkg->edate,
#$cust_bill_pkg->sdate)
unless $cust_bill_pkg->pkgpart_override; #don't redisplay services
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index ce5ee11..e0fb589 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1638,23 +1638,32 @@ sub overlimit {
grep { $_->overlimit } $self->cust_svc(@_);
}
-=item h_cust_svc END_TIMESTAMP [ START_TIMESTAMP ]
+=item h_cust_svc END_TIMESTAMP [ START_TIMESTAMP ] [ MODE ]
Returns historical services for this package created before END TIMESTAMP and
(optionally) not cancelled before START_TIMESTAMP, as FS::h_cust_svc objects
-(see L<FS::h_cust_svc>).
+(see L<FS::h_cust_svc>). If MODE is 'I' (for 'invoice'), services with the
+I<pkg_svc.hidden> flag will be omitted.
=cut
sub h_cust_svc {
my $self = shift;
+ my ($end, $start, $mode) = @_;
+ my %search = (
+ 'table' => 'h_cust_svc',
+ 'hashref' => { 'pkgnum' => $self->pkgnum }
+ );
+ @search{'select', 'extra_sql', 'cache_obj', 'addl_from'} =
+ FS::h_cust_svc->sql_h_search($end, $start);
+ if ( $mode eq 'I' ) {
+ $search{'addl_from'} .= ' JOIN cust_pkg USING (pkgnum)
+ JOIN pkg_svc USING (pkgpart, svcpart)';
+ $search{'extra_sql'} = ' AND pkg_svc.hidden IS NULL '.$search{'extra_sql'};
+ }
$self->_sort_cust_svc(
- [ qsearch( 'h_cust_svc',
- { 'pkgnum' => $self->pkgnum, },
- FS::h_cust_svc->sql_h_search(@_),
- )
- ]
+ [ qsearch(\%search) ]
);
}
@@ -1973,11 +1982,12 @@ sub labels {
map { [ $_->label ] } $self->cust_svc;
}
-=item h_labels END_TIMESTAMP [ START_TIMESTAMP ]
+=item h_labels END_TIMESTAMP [ START_TIMESTAMP ] [ MODE ]
Like the labels method, but returns historical information on services that
were active as of END_TIMESTAMP and (optionally) not cancelled before
-START_TIMESTAMP.
+START_TIMESTAMP. If MODE is 'I' (for 'invoice'), services with the
+I<pkg_svc.hidden> flag will be omitted.
Returns a list of lists, calling the label method for all (historical) services
(see L<FS::h_cust_svc>) of this billing item.
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index a073cf2..98bb74c 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -144,7 +144,9 @@ Currently available options are: I<pkg_svc>, I<primary_svc>, I<cust_pkg>,
I<custnum_ref> and I<options>.
If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
-values, appropriate FS::pkg_svc records will be inserted.
+values, appropriate FS::pkg_svc records will be inserted. I<hidden_svc> can
+be set to a hashref of svcparts and flag values ('Y' or '') to set the
+'hidden' field in these records.
If I<primary_svc> is set to the svcpart of the primary service, the appropriate
FS::pkg_svc record will be updated.
@@ -230,6 +232,7 @@ sub insert {
warn " inserting pkg_svc records" if $DEBUG;
my $pkg_svc = $options{'pkg_svc'} || {};
+ my $hidden_svc = $options{'hidden_svc'} || {};
foreach my $part_svc ( qsearch('part_svc', {} ) ) {
my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
my $primary_svc =
@@ -242,6 +245,7 @@ sub insert {
'svcpart' => $part_svc->svcpart,
'quantity' => $quantity,
'primary_svc' => $primary_svc,
+ 'hidden' => $hidden_svc->{$part_svc->svcpart},
} );
my $error = $pkg_svc->insert;
if ( $error ) {
@@ -293,10 +297,13 @@ sub delete {
Replaces OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
-Currently available options are: I<pkg_svc>, I<primary_svc> and I<options>
+Currently available options are: I<pkg_svc>, I<hidden_svc>, I<primary_svc>
+and I<options>
If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
-values, the appropriate FS::pkg_svc records will be replaced.
+values, the appropriate FS::pkg_svc records will be replaced. I<hidden_svc>
+can be set to a hashref of svcparts and flag values ('Y' or '') to set the
+'hidden' field in these records.
If I<primary_svc> is set to the svcpart of the primary service, the appropriate
FS::pkg_svc record will be updated.
@@ -379,8 +386,10 @@ sub replace {
warn " replacing pkg_svc records" if $DEBUG;
my $pkg_svc = $options->{'pkg_svc'} || {};
+ my $hidden_svc = $options->{'hidden_svc'} || {};
foreach my $part_svc ( qsearch('part_svc', {} ) ) {
my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
+ my $hidden = $hidden_svc->{$part_svc->svcpart} || '';
my $primary_svc =
( defined($options->{'primary_svc'}) && $options->{'primary_svc'}
&& $options->{'primary_svc'} == $part_svc->svcpart
@@ -388,17 +397,24 @@ sub replace {
? 'Y'
: '';
-
my $old_pkg_svc = qsearchs('pkg_svc', {
- 'pkgpart' => $old->pkgpart,
- 'svcpart' => $part_svc->svcpart,
- } );
- my $old_quantity = $old_pkg_svc ? $old_pkg_svc->quantity : 0;
- my $old_primary_svc =
- ( $old_pkg_svc && $old_pkg_svc->dbdef_table->column('primary_svc') )
- ? $old_pkg_svc->primary_svc
- : '';
- next unless $old_quantity != $quantity || $old_primary_svc ne $primary_svc;
+ 'pkgpart' => $old->pkgpart,
+ 'svcpart' => $part_svc->svcpart,
+ }
+ );
+ my $old_quantity = 0;
+ my $old_primary_svc = '';
+ my $old_hidden = '';
+ if ( $old_pkg_svc ) {
+ $old_quantity = $old_pkg_svc->quantity;
+ $old_primary_svc = $old_pkg_svc->primary_svc
+ if $old_pkg_svc->dbdef_table->column('primary_svc'); # is this needed?
+ $old_hidden = $old_pkg_svc->hidden;
+ }
+
+ next unless $old_quantity != $quantity ||
+ $old_primary_svc ne $primary_svc ||
+ $old_hidden ne $hidden;
my $new_pkg_svc = new FS::pkg_svc( {
'pkgsvcnum' => ( $old_pkg_svc ? $old_pkg_svc->pkgsvcnum : '' ),
@@ -406,6 +422,7 @@ sub replace {
'svcpart' => $part_svc->svcpart,
'quantity' => $quantity,
'primary_svc' => $primary_svc,
+ 'hidden' => $hidden,
} );
my $error = $old_pkg_svc
? $new_pkg_svc->replace($old_pkg_svc)
diff --git a/FS/FS/pkg_svc.pm b/FS/FS/pkg_svc.pm
index 9f3a4a1..f79bb5e 100644
--- a/FS/FS/pkg_svc.pm
+++ b/FS/FS/pkg_svc.pm
@@ -50,6 +50,8 @@ definition includes
=item primary_svc - primary flag, empty or 'Y'
+=item hidden - 'Y' to hide this service on invoices, null otherwise.
+
=back
=head1 METHODS
@@ -109,6 +111,7 @@ sub check {
|| $self->ut_number('pkgpart')
|| $self->ut_number('svcpart')
|| $self->ut_number('quantity')
+ || $self->ut_enum('hidden', [ '', 'Y' ] )
;
return $error if $error;