From: ivan Date: Mon, 8 Sep 2008 02:47:20 +0000 (+0000) Subject: add package invoice details & comments, RT#3810 X-Git-Tag: freeside_1_7_4rc1~201 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=92eb0dcaf696fa84c2fe7d2141dafe6661b8cfdd;p=freeside.git add package invoice details & comments, RT#3810 --- diff --git a/FS/FS.pm b/FS/FS.pm index 8480a2214..e4c87a98c 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -198,6 +198,8 @@ L - Customer package class L - Customer package option class +L - Customer package details class + L - Reason type class L - 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). + +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). + +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 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, 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"; diff --git a/httemplate/edit/cust_pkg_detail.html b/httemplate/edit/cust_pkg_detail.html new file mode 100644 index 000000000..1e4c80250 --- /dev/null +++ b/httemplate/edit/cust_pkg_detail.html @@ -0,0 +1,146 @@ +<% include("/elements/header-popup.html", $title, '', + ( $cgi->param('error') ? '' : 'onload="addRow()"' ), + ) +%> + +%# <% include('/elements/error.html') %> + +
+ + + + + + +% if ( $curuser->option('show_pkgnum') ) { + + + + + + +% } + + + + + + + + + + + + + + + + + + + + +% my $row = 0; +% if ( $cgi->param('error') || $cgi->param('magic') ) { +% my $param = $cgi->Vars; +% +% for ( $row = 0; exists($param->{"detail$row"}); $row++ ) { + + + + + +% } +% +% } + +
Package #<% $pkgnum %>
Package<% $part_pkg->pkg %>
Comment<% $part_pkg->comment %>
Status<% ucfirst($cust_pkg->status) %>
<% ucfirst($name{$detailtype}) %>:
+ " rownum="<% $row %>" onkeyup = "possiblyAddRow;" > +
+ +
+ + +
+ + + + + +<%init> + +my %access_right = ( + 'I' => 'Edit customer package invoice details', + 'C' => 'Edit customer package comments', +); + +my %name = ( + 'I' => 'invoice details', + 'C' => 'package comments', +); + +my $curuser = $FS::CurrentUser::CurrentUser; + +$cgi->param('detailtype') =~ /^(\w)$/ or die 'illegal detailtype'; +my $detailtype = $1; + +my $right = $access_right{$detailtype}; +die "access denied" + unless $curuser->access_right($right); + +$cgi->param('pkgnum') =~ /^(\d+)$/ or die 'illegal pkgnum'; +my $pkgnum = $1; + +my $cust_pkg = qsearchs({ + 'table' => 'cust_pkg', + 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', + 'hashref' => { 'pkgnum' => $pkgnum }, + 'extra_sql' => ' AND '. $curuser->agentnums_sql, +}); + +my $part_pkg = $cust_pkg->part_pkg; + +my @details = $cust_pkg->cust_pkg_detail($detailtype); + +my $title = ( scalar(@details) ? 'Edit ' : 'Add ' ). $name{$detailtype}; + + diff --git a/httemplate/edit/process/cust_pkg_detail.html b/httemplate/edit/process/cust_pkg_detail.html new file mode 100644 index 000000000..132ff63c5 --- /dev/null +++ b/httemplate/edit/process/cust_pkg_detail.html @@ -0,0 +1,59 @@ +% if ( $error ) { +<% header('Error') %> +<% $error |h %>

+
+ +% } else { +<% header($action) %> + + +% } +<%init> + +my %access_right = ( + 'I' => 'Edit customer package invoice details', + 'C' => 'Edit customer package comments', +); + +my %name = ( + 'I' => 'invoice details', + 'C' => 'package comments', +); + +my $curuser = $FS::CurrentUser::CurrentUser; + +$cgi->param('detailtype') =~ /^(\w)$/ or die 'illegal detailtype'; +my $detailtype = $1; + +my $right = $access_right{$detailtype}; +die "access denied" + unless $curuser->access_right($right); + +$cgi->param('pkgnum') =~ /^(\d+)$/ or die 'illegal pkgnum'; +my $pkgnum = $1; + +my $cust_pkg = qsearchs({ + 'table' => 'cust_pkg', + 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', + 'hashref' => { 'pkgnum' => $pkgnum }, + 'extra_sql' => ' AND '. $curuser->agentnums_sql, +}); + + +my @orig_details = $cust_pkg->cust_pkg_detail($detailtype); + +my $action = ucfirst($name{$detailtype}). + ( scalar(@orig_details) ? ' changed ' : ' added ' ); + +my $param = $cgi->Vars; +my @details = (); +for ( my $row = 0; exists($param->{"detail$row"}); $row++ ) { + push @details, $param->{"detail$row"} + if $param->{"detail$row"} =~ /\S/; +} + +my $error = $cust_pkg->set_cust_pkg_detail($detailtype, @details); + + diff --git a/httemplate/pref/pref-process.html b/httemplate/pref/pref-process.html index 704286568..93d73e00a 100644 --- a/httemplate/pref/pref-process.html +++ b/httemplate/pref/pref-process.html @@ -28,7 +28,8 @@ % } % % #XXX autogen -% my @paramlist = qw( menu_position email_address +% my @paramlist = qw( menu_position show_pkgnum +% email_address % height width availHeight availWidth colorDepth % ); % diff --git a/httemplate/pref/pref.html b/httemplate/pref/pref.html index ec8aefd80..77f8cec68 100644 --- a/httemplate/pref/pref.html +++ b/httemplate/pref/pref.html @@ -53,8 +53,20 @@ Email Address
- - + + +Development +<% ntable("#cccccc",2) %> + + + Show internal package numbers: + option('show_pkgnum') ? 'CHECKED' : '' %>> + + + +
+ + % foreach my $prop (qw( height width availHeight availWidth colorDepth )) {