From ff92fba056c2b61753d464c84ecede6ec2f57258 Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 13 Nov 2010 23:23:48 +0000 Subject: [PATCH] hidden pkg_svc flag, RT#9871 --- FS/FS/Schema.pm | 1 + FS/FS/cust_bill.pm | 4 ++-- FS/FS/cust_pkg.pm | 28 +++++++++++++++-------- FS/FS/part_pkg.pm | 43 +++++++++++++++++++++++++----------- FS/FS/pkg_svc.pm | 3 +++ httemplate/edit/process/part_pkg.cgi | 8 +++---- httemplate/elements/tr-pkg_svc.html | 9 +++++++- 7 files changed, 67 insertions(+), 29 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index f63bae929..95c1ce4c9 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 335c4b6a7..b3dd48a69 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 ce5ee1182..e0fb58996 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). +(see L). If MODE is 'I' (for 'invoice'), services with the +I 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 flag will be omitted. Returns a list of lists, calling the label method for all (historical) services (see L) of this billing item. diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index a073cf2c9..98bb74cab 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -144,7 +144,9 @@ Currently available options are: I, I, I, I and I. If I 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 can +be set to a hashref of svcparts and flag values ('Y' or '') to set the +'hidden' field in these records. If I 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, I and I +Currently available options are: I, I, I +and I If I 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 +can be set to a hashref of svcparts and flag values ('Y' or '') to set the +'hidden' field in these records. If I 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 9f3a4a1b7..f79bb5e2d 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; diff --git a/httemplate/edit/process/part_pkg.cgi b/httemplate/edit/process/part_pkg.cgi index 97ae4e7ee..724880190 100755 --- a/httemplate/edit/process/part_pkg.cgi +++ b/httemplate/edit/process/part_pkg.cgi @@ -117,11 +117,11 @@ my $args_callback = sub { #pkg_svc ### - my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) } - map { $_->svcpart } - qsearch('part_svc', {} ); + my @svcparts = map { $_->svcpart } qsearch('part_svc', {}); + my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) } @svcparts; + my %hidden_svc = map { $_ => scalar($cgi->param("hidden$_")) } @svcparts; - push @args, 'pkg_svc' => \%pkg_svc; + push @args, 'pkg_svc' => \%pkg_svc, 'hidden_svc' => \%hidden_svc; ### # cust_pkg and custnum_ref (inserts only) diff --git a/httemplate/elements/tr-pkg_svc.html b/httemplate/elements/tr-pkg_svc.html index e68ed4add..66bbddfda 100644 --- a/httemplate/elements/tr-pkg_svc.html +++ b/httemplate/elements/tr-pkg_svc.html @@ -12,6 +12,7 @@ % 'svcpart' => $svcpart, % 'quantity' => 0, % 'primary_svc' => '', +% 'hidden' => '', % } ); % if ( $cgi->param('error') ) { % my $primary_svc = ( $pkg_svc->primary_svc =~ /^Y/i ); @@ -43,6 +44,10 @@ <% $part_svc->svc %> <% $part_svc->disabled =~ /^Y/i ? ' (DISABLED' : '' %> + + + hidden =~ /^Y/i ? ' CHECKED' : ''%>> + % foreach ( 1 .. $columns-1 ) { % if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) { @@ -68,7 +73,9 @@ my $cgi = $opt{'cgi'}; my $thead = "\n\n". ntable('#cccccc', 2). 'Quan.'. 'Primary'. - 'Service'; + 'Service'. + 'Hide'. + ''; my $part_pkg = $opt{'object'}; my $pkgpart = $part_pkg->pkgpart; -- 2.11.0