From: jeff Date: Sun, 21 Jun 2009 15:21:32 +0000 (+0000) Subject: CUSTOM packages/actual flag for custom packages #3988 X-Git-Tag: root_of_svc_elec_features~1112 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=04a69f9d197efee6fa396bd35d04ae553e669978 CUSTOM packages/actual flag for custom packages #3988 --- diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index d264fd01f..69a96a99a 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1191,6 +1191,7 @@ sub tables_hashref { 'plan', 'varchar', 'NULL', $char_d, '', '', 'plandata', 'text', 'NULL', '', '', '', 'disabled', 'char', 'NULL', 1, '', '', + 'custom', 'char', 'NULL', 1, '', '', 'taxclass', 'varchar', 'NULL', $char_d, '', '', 'classnum', 'int', 'NULL', '', '', '', 'taxproductnum', 'int', 'NULL', '', '', '', diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 0e5f3b7ca..a510c5245 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -2193,6 +2193,10 @@ active, inactive, suspended, cancel (or cancelled) active, inactive, suspended, one-time charge, inactive, cancel (or cancelled) +=item custom + + boolean selects custom packages + =item classnum =item pkgpart @@ -2321,6 +2325,12 @@ sub search_sql { #eslaf ### + # parse custom + ### + + push @where, "part_pkg.custom = 'Y'" if $params->{custom}; + + ### # parse part_pkg ### diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index fe56c62e1..0562a6d44 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -85,6 +85,8 @@ inherits from FS::Record. The following fields are currently supported: =item disabled - Disabled flag, empty or `Y' +=item custom - Custom flag, empty or `Y' + =item setup_cost - for cost tracking =item recur_cost - for cost tracking @@ -113,9 +115,8 @@ sub table { 'part_pkg'; } =item clone An alternate constructor. Creates a new package definition by duplicating -an existing definition. A new pkgpart is assigned and `(CUSTOM) ' is prepended -to the comment field. To add the package definition to the database, see -L<"insert">. +an existing definition. A new pkgpart is assigned and the custom flag is +set to Y. To add the package definition to the database, see L<"insert">. =cut @@ -124,8 +125,7 @@ sub clone { my $class = ref($self); my %hash = $self->hash; $hash{'pkgpart'} = ''; - $hash{'comment'} = "(CUSTOM) ". $hash{'comment'} - unless $hash{'comment'} =~ /^\(CUSTOM\) /; + $hash{'custom'} = 'Y'; #new FS::part_pkg ( \%hash ); # ? new $class ( \%hash ); # ? } @@ -452,6 +452,7 @@ sub check { || $self->ut_enum('recurtax', [ '', 'Y' ] ) || $self->ut_textn('taxclass') || $self->ut_enum('disabled', [ '', 'Y' ] ) + || $self->ut_enum('custom', [ '', 'Y' ] ) #|| $self->ut_moneyn('setup_cost') #|| $self->ut_moneyn('recur_cost') || $self->ut_floatn('setup_cost') @@ -488,20 +489,30 @@ sub check { ''; } -=item pkg_comment +=item pkg_comment [ OPTION => VALUE... ] Returns an (internal) string representing this package. Currently, "pkgpart: pkg - comment", is returned. "pkg - comment" may be returned in the -future, omitting pkgpart. +future, omitting pkgpart. The comment will have '(CUSTOM) ' prepended if +custom is Y. + +If the option nopkgpart is true then the "pkgpart: ' is omitted. =cut sub pkg_comment { my $self = shift; + my %opt = @_; #$self->pkg. ' - '. $self->comment; #$self->pkg. ' ('. $self->comment. ')'; - $self->pkgpart. ': '. $self->pkg. ' - '. $self->comment; + my $pre = $opt{nopkgpart} ? '' : $self->pkgpart. ': '; + $pre. $self->pkg. ' - '. $self->custom_comment; +} + +sub custom_comment { + my $self = shift; + ( $self->custom ? '(CUSTOM) ' : '' ). $self->comment; } =item pkg_class @@ -1257,6 +1268,33 @@ sub _upgrade_data { # class method } + # now upgrade to the explicit custom flag + + @part_pkg = qsearch({ + 'table' => 'part_pkg', + 'hashref' => { disabled => 'Y', custom => '' }, + 'extra_sql' => "AND comment LIKE '(CUSTOM) %'", + }); + + foreach my $part_pkg (@part_pkg) { + my $new = new FS::part_pkg { $part_pkg->hash }; + $new->custom('Y'); + my $comment = $part_pkg->comment; + $comment =~ s/^\(CUSTOM\) //; + $new->comment($comment); + + my $pkg_svc = { map { $_->svcpart => $_->quantity } $part_pkg->pkg_svc }; + my $primary = $part_pkg->svcpart; + my $options = { $part_pkg->options }; + + my $error = $new->replace( $part_pkg, + 'pkg_svc' => $pkg_svc, + 'primary_svc' => $primary, + 'options' => $options, + ); + die $error if $error; + } + } =item curuser_pkgs_sql @@ -1379,6 +1417,8 @@ plandata should go part_pkg_taxrate is Pg specific +replace should be smarter about managing the related tables (options, pkg_svc) + =head1 SEE ALSO L, L, L, L, L. diff --git a/httemplate/browse/agent_type.cgi b/httemplate/browse/agent_type.cgi index d64ff186a..f07a6515b 100755 --- a/httemplate/browse/agent_type.cgi +++ b/httemplate/browse/agent_type.cgi @@ -44,7 +44,9 @@ my $agent_type = shift; [ { #'data' => $part_pkg->pkg. ' - '. $part_pkg->comment, - 'data' => $type_pkgs->pkg. ' - '. $type_pkgs->comment, + 'data' => $type_pkgs->pkg. ' - '. + ( $type_pkgs->custom ? '(CUSTOM) ' : '' ). + $type_pkgs->comment, 'align' => 'left', 'link' => $p. 'edit/part_pkg.cgi?'. $type_pkgs->pkgpart, }, diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index 8c961b839..c6cbb81a3 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -4,11 +4,11 @@ 'html_posttotal' => $html_posttotal, 'name' => 'package definitions', 'disableable' => 1, - 'disabled_statuspos' => 3, + 'disabled_statuspos' => 4, 'agent_virt' => 1, 'agent_null_right' => [ $edit, $edit_global ], 'agent_null_right_link' => $edit_global, - 'agent_pos' => 5, + 'agent_pos' => 6, 'query' => { 'select' => $select, 'table' => 'part_pkg', 'hashref' => \%hash, @@ -164,10 +164,12 @@ $cgi->param('recurring', $cgi->param('recurring') ^ 1 ); #put it back my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ]; -my @header = ( '#', 'Package', 'Comment' ); -my @fields = ( 'pkgpart', 'pkg', 'comment' ); -my $align = 'rll'; -my @links = ( $link, $link, '' ); +my @header = ( '#', 'Package', 'Comment', 'Custom' ); +my @fields = ( 'pkgpart', 'pkg', 'comment', + sub{ ''.$_[0]->custom.'' } + ); +my $align = 'rllc'; +my @links = ( $link, $link, '', '' ); unless ( 0 ) { #already showing only one class or something? push @header, 'Class'; diff --git a/httemplate/edit/REAL_cust_pkg.cgi b/httemplate/edit/REAL_cust_pkg.cgi index b2c89c32c..a707aca8d 100755 --- a/httemplate/edit/REAL_cust_pkg.cgi +++ b/httemplate/edit/REAL_cust_pkg.cgi @@ -32,6 +32,11 @@ + Custom + <% $part_pkg->custom %> + + + Comment <% $part_pkg->comment %> diff --git a/httemplate/edit/agent_type.cgi b/httemplate/edit/agent_type.cgi index abf4bf89f..8a6fbc255 100755 --- a/httemplate/edit/agent_type.cgi +++ b/httemplate/edit/agent_type.cgi @@ -20,7 +20,7 @@ Select which packages agents of this type may sell to customers
'source_obj' => $agent_type, 'link_table' => 'type_pkgs', 'target_table' => 'part_pkg', - 'name_callback' => sub { $_[0]->pkg. ' - '. $_[0]->comment; }, + 'name_callback' => sub { $_[0]->pkg_comment(nopkgpart => 1); }, 'target_link' => $p.'edit/part_pkg.cgi?', 'disable-able' => 1, diff --git a/httemplate/edit/cust_main/first_pkg/select-part_pkg.html b/httemplate/edit/cust_main/first_pkg/select-part_pkg.html index 1b62035b2..d2d862bea 100644 --- a/httemplate/edit/cust_main/first_pkg/select-part_pkg.html +++ b/httemplate/edit/cust_main/first_pkg/select-part_pkg.html @@ -141,9 +141,7 @@ foreach my $part_pkg ( @part_pkg ) { my @options = ( '', map $pkgpart_svcpart{ $_->pkgpart }, @part_pkg ); my %labels = ( '' => '(none)', - map { $pkgpart_svcpart{ $_->pkgpart } - => $_->pkg. " - ". $_->comment - } + map { $pkgpart_svcpart{ $_->pkgpart } => $_->pkg_comment } @part_pkg ); diff --git a/httemplate/edit/cust_pkg.cgi b/httemplate/edit/cust_pkg.cgi index f927e1042..dd1ed335f 100755 --- a/httemplate/edit/cust_pkg.cgi +++ b/httemplate/edit/cust_pkg.cgi @@ -128,10 +128,10 @@ my %all_comment = (); #} foreach (qsearch('part_pkg', {} )) { $all_pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg'); - $all_comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment'); + $all_comment{ $_ -> getfield('pkgpart') } = $_->custom_comment; next if $_->disabled; $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg'); - $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment'); + $comment{ $_ -> getfield('pkgpart') } = $_->custom_comment; } my($custnum, %remove_pkg); diff --git a/httemplate/edit/part_bill_event.cgi b/httemplate/edit/part_bill_event.cgi index 3b5114122..ffd642bae 100755 --- a/httemplate/edit/part_bill_event.cgi +++ b/httemplate/edit/part_bill_event.cgi @@ -78,7 +78,7 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %> % join("\n", map { % '