From 9972d7caa7a3e1a29dc4201e0c7256ba093ea705 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Fri, 11 Mar 2016 00:10:13 -0600 Subject: [PATCH] RT#40806: Enter invoice details from order package page --- FS/FS/cust_main/Packages.pm | 24 +++++++++ FS/FS/quotation_pkg.pm | 24 +++++++-- httemplate/edit/cust_pkg_detail.html | 66 +++-------------------- httemplate/edit/elements/detail-table.html | 85 ++++++++++++++++++++++++++++++ httemplate/edit/process/quick-cust_pkg.cgi | 29 +++++++++- httemplate/edit/quotation_pkg_detail.html | 70 +++--------------------- httemplate/misc/order_pkg.html | 63 ++++++++++++++++++++++ 7 files changed, 232 insertions(+), 129 deletions(-) create mode 100644 httemplate/edit/elements/detail-table.html diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm index 5a14e2e86..1c921d604 100644 --- a/FS/FS/cust_main/Packages.pm +++ b/FS/FS/cust_main/Packages.pm @@ -74,6 +74,14 @@ Optional subject for a ticket created and attached to this customer Optional queue name for ticket additions +=item invoice_details + +Optional arrayref of invoice detail strings to add (creates cust_pkg_detail detailtype 'I') + +=item package_comments + +Optional arrayref of package comment strings to add (creates cust_pkg_detail detailtype 'C') + =back =cut @@ -208,6 +216,22 @@ sub order_pkg { } } + # add details/comments + if ($opt->{'invoice_details'}) { + $error = $cust_pkg->set_cust_pkg_detail('I', @{$opt->{'invoice_details'}}); + } + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "setting invoice details: $error"; + } + if ($opt->{'package_comments'}) { + $error = $cust_pkg->set_cust_pkg_detail('C', @{$opt->{'package_comments'}}); + } + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "setting package comments: $error"; + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error diff --git a/FS/FS/quotation_pkg.pm b/FS/FS/quotation_pkg.pm index 1e5a0da51..b9b37991a 100644 --- a/FS/FS/quotation_pkg.pm +++ b/FS/FS/quotation_pkg.pm @@ -106,7 +106,11 @@ sub detail_table { 'quotation_pkg_detail'; } =item insert Adds this record to the database. If there is an error, returns the error, -otherwise returns false. +otherwise returns false. Accepts the following options: + +quotation_details - optional arrayref of detail strings to add (creates quotation_pkg_detail records) + +copy_on_order - value for this field when creating quotation_pkg_detail records (same for all details) =cut @@ -128,10 +132,22 @@ sub insert { if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; - } else { - $dbh->commit if $oldAutoCommit; - return ''; } + + if ($options{'quotation_details'}) { + $error = $self->set_details( + details => $options{'quotation_details'}, + copy_on_order => $options{'copy_on_order'} ? 'Y' : '', + ); + if ( $error ) { + $error .= ' (setting details)'; + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + $dbh->commit if $oldAutoCommit; + return ''; } =item delete diff --git a/httemplate/edit/cust_pkg_detail.html b/httemplate/edit/cust_pkg_detail.html index b1e60dad5..a1a6db6d3 100644 --- a/httemplate/edit/cust_pkg_detail.html +++ b/httemplate/edit/cust_pkg_detail.html @@ -1,9 +1,4 @@ -<% include("/elements/header-popup.html", $title, '', - ( $cgi->param('error') ? '' : 'onload="addRow()"' ), - ) -%> - -%# <% include('/elements/error.html') %> +<& /elements/header-popup.html, $title &>
@@ -40,17 +35,10 @@ <% ucfirst($name{$detailtype}) %>: -% my $row = 0; -% for ( @details ) { - - - - - - - - -% } +<& elements/detail-table.html, + id => 'DetailTable', + details => \@details, + &> @@ -59,48 +47,6 @@
- - <%init> @@ -136,7 +82,7 @@ my $cust_pkg = qsearchs({ my $part_pkg = $cust_pkg->part_pkg; -my @details = $cust_pkg->cust_pkg_detail($detailtype); +my @details = map { $_->detail } $cust_pkg->cust_pkg_detail($detailtype); my $title = ( scalar(@details) ? 'Edit ' : 'Add ' ). $name{$detailtype}; diff --git a/httemplate/edit/elements/detail-table.html b/httemplate/edit/elements/detail-table.html new file mode 100644 index 000000000..496ba31b3 --- /dev/null +++ b/httemplate/edit/elements/detail-table.html @@ -0,0 +1,85 @@ +<%doc> +Common code for editing invoice/quotation details/comments. + +Expects to be the last element in a two-column table with specified id + + <& /edit/elements/detail-table.html, + id => 'element_id', # required + details => \@details, # plain text strings, existing details + label => 'Comments', # optional, shows on first row only + field => 'comment', # input field name/id, appended with rownum, default 'detail' + &> + + + + + +<%shared> +my $detail_table_init = 0; + +<%init> +my %opt = @_; + +my @details = $opt{'details'} ? @{ $opt{'details'} } : (); +push(@details,'') if $details[$#details] || !@details; +my $id = $opt{'id'} or die "No id specified"; +my $label = $opt{'label'} || ''; +my $field = $opt{'field'} || 'detail'; + + diff --git a/httemplate/edit/process/quick-cust_pkg.cgi b/httemplate/edit/process/quick-cust_pkg.cgi index 60352154a..5afddde15 100644 --- a/httemplate/edit/process/quick-cust_pkg.cgi +++ b/httemplate/edit/process/quick-cust_pkg.cgi @@ -159,14 +159,38 @@ foreach my $quantity_param ( grep { $cgi->param($_) && $cgi->param($_) > 0 } } $hash{cust_pkg_usageprice} = \@cust_pkg_usageprice; +# extract details (false laziness with /misc/order_pkg.html) +my $details = { + 'invoice_detail' => [], + 'package_comment' => [], + 'quotation_detail' => [], +}; +foreach my $field ( $cgi->param ) { + foreach my $detailtype ( keys %$details ) { + if ($field =~ /^$detailtype(\d+)$/) { + $details->{$detailtype}->[$1] = $cgi->param($field); + } + } +} +foreach my $detailtype ( keys %$details ) { + @{ $details->{$detailtype} } = grep { length($_) } @{ $details->{$detailtype} }; +} + if ( $quotationnum ) { $quotation_pkg = new FS::quotation_pkg \%hash; $quotation_pkg->quotationnum($quotationnum); $quotation_pkg->prospectnum($prospect_main->prospectnum) if $prospect_main; + my %opt = @{ $details->{'quotation_detail'} } + ? ( + quotation_details => $details->{'quotation_detail'}, + copy_on_order => scalar($cgi->param('copy_on_order')) ? 'Y' : '', + ) + : (); + #XXX handle new location - $error = $quotation_pkg->insert; + $error = $quotation_pkg->insert(%opt); } else { @@ -194,6 +218,9 @@ if ( $quotationnum ) { $opt{'locationnum'} = $locationnum; } + $opt{'invoice_details'} = $details->{'invoice_detail'} if @{ $details->{'invoice_detail'} }; + $opt{'package_comments'} = $details->{'package_comment'} if @{ $details->{'package_comment'} }; + $error = $cust_main->order_pkg( \%opt ); } diff --git a/httemplate/edit/quotation_pkg_detail.html b/httemplate/edit/quotation_pkg_detail.html index ae09b9c6a..036bffdde 100644 --- a/httemplate/edit/quotation_pkg_detail.html +++ b/httemplate/edit/quotation_pkg_detail.html @@ -1,9 +1,4 @@ -<% include("/elements/header-popup.html", $title, '', - ( $cgi->param('error') ? '' : 'onload="addRow()"' ), - ) -%> - -%# <% include('/elements/error.html') %> +<& /elements/header-popup.html, $title &>
@@ -35,17 +30,11 @@ -% my $row = 0; -% for ( @details ) { - - - <% $row ? '' : 'Detail' %> - - - - - -% } +<& elements/detail-table.html, + id => 'DetailTable', + details => \@details, + label => 'Details', + &> @@ -54,53 +43,6 @@
- - <%init> diff --git a/httemplate/misc/order_pkg.html b/httemplate/misc/order_pkg.html index 4e061e2f7..39cb2f4d6 100644 --- a/httemplate/misc/order_pkg.html +++ b/httemplate/misc/order_pkg.html @@ -196,6 +196,52 @@ % } +% if ($quotationnum) { +
+<% mt('Quotation details') |h %> + + + + + +<& /edit/elements/detail-table.html, + id => 'QuotationDetailTable', + details => $details->{'quotation_detail'}, + field => 'quotation_detail', + &> +
+ +
+% } else { +
+<% mt('Invoice details') |h %> + +<& /edit/elements/detail-table.html, + id => 'InvoiceDetailTable', + details => $details->{'invoice_detail'}, + field => 'invoice_detail', + &> +
+ +
+<% mt('Package comments') |h %> + +<& /edit/elements/detail-table.html, + id => 'PackageCommentTable', + details => $details->{'package_comment'}, + field => 'package_comment', + &> +
+% } + +
% my $onclick = $cgi->param('lock_locationnum') % ? 'document.OrderPkgForm.submit()' @@ -245,6 +291,23 @@ if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) { $quotationnum = $1; } +my $details = { + 'invoice_detail' => [], + 'package_comment' => [], + 'quotation_detail' => [], +}; +foreach my $field ( $cgi->param ) { + foreach my $detailtype ( keys %$details ) { + if ($field =~ /^$detailtype(\d+)$/) { + $details->{$detailtype}->[$1] = $cgi->param($field); + } + } +} +foreach my $detailtype ( keys %$details ) { + @{ $details->{$detailtype} } = grep { length($_) } @{ $details->{$detailtype} }; +} +my $copy_on_order = $cgi->param('copy_on_order'); + die 'no custnum or prospectnum' unless $cust_main || $prospect_main; my $agent = $cust_main ? $cust_main->agent -- 2.11.0