From 1ce2f035cac19edbbe1b31a20e954cd97e40da20 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Fri, 11 Mar 2016 00:10:13 -0600 Subject: RT#40806: Enter invoice details from order package page --- 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 ++++++++++++++++++++++ 5 files changed, 188 insertions(+), 125 deletions(-) create mode 100644 httemplate/edit/elements/detail-table.html (limited to 'httemplate') 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 -- cgit v1.2.1