From b6538b4641f900da4892d8c44292befb71188822 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 6 Nov 2014 16:48:16 -0800 Subject: [PATCH] delete packages from quotations, RT#30313 --- FS/FS/Template_Mixin.pm | 89 +++++++++++++++++++++++++++---- conf/quotation_html | 6 ++- httemplate/misc/delete-quotation_pkg.html | 21 ++++++++ httemplate/view/quotation.html | 21 +++++++- 4 files changed, 124 insertions(+), 13 deletions(-) create mode 100644 httemplate/misc/delete-quotation_pkg.html diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index ce7efcab1..f70ac3ce2 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -220,26 +220,82 @@ Internal method - returns a filled-in template for this invoice as a scalar. See print_ps and print_pdf for methods that return PostScript and PDF output. -Non optional options include - format - latex, html, template +Required options -Optional options include +=over 4 -template - a value used as a suffix for a configuration template. Please -don't use this. +=item format -time - a value used to control the printing of overdue messages. The +The B option is required and should be set to html, latex (print and PDF) or template (plaintext). + +=back + +Additional options + +=over 4 + +=item notice_name + +Overrides "Invoice" as the name of the sent document. + +=item today + +Used to control the printing of overdue messages. The default is now. It isn't the date of the invoice; that's the `_date' field. It is specified as a UNIX timestamp; see L. Also see L and L for conversion functions. -cid - +=item logo_file + +Logo file (path to temporary EPS file on the local filesystem) + +=item cid + +CID for inline (emailed) images (logo) + +=item locale + +Override customer's locale + +=item unsquelch_cdr + +Overrides any per customer cdr squelching when true + +=item no_number -unsquelch_cdr - overrides any per customer cdr squelching when true +Supress the (invoice, quotation, statement, etc.) number -notice_name - overrides "Invoice" as the name of the sent document (templates from 10/2009 or newer required) +=item no_date -locale - override customer's locale +Supress the date + +=item no_coupon + +Supress the payment coupon + +=item barcode_file + +Barcode file (path to temporary EPS file on the local filesystem) + +=item barcode_img + +Flag indicating the barcode image should be a link (normal HTML dipaly) + +=item barcode_cid + +Barcode CID for inline (emailed) images + +=item preref_callback + +Coderef run for each line item, code should return HTML to be displayed +before that line item (quotations only) + +=item template + +Dprecated. Used as a suffix for a configuration template. Please +don't use this, it deprecated in favor of more flexible alternatives. + +=back =cut @@ -1106,6 +1162,7 @@ sub print_generic { $options{'summary_page'} = $summarypage; $options{'skip_usage'} = scalar(@$extra_sections) && !grep{$section == $_} @$extra_sections; + $options{'preref_callback'} = $params{'preref_callback'}; warn "$me searching for line items\n" if $DEBUG > 1; @@ -1113,7 +1170,8 @@ sub print_generic { foreach my $line_item ( $self->_items_pkg(%options), $self->_items_fee(%options) ) { - warn "$me adding line item $line_item\n" + warn "$me adding line item ". + join(', ', map "$_=>".$line_item->{$_}, keys %$line_item). "\n" if $DEBUG > 1; $line_item->{'ref'} = $line_item->{'pkgnum'}; @@ -2541,6 +2599,9 @@ location (whichever is defined). multisection: a flag indicating that this is a multisection invoice, which does something complicated. +preref_callback: coderef run for each line item, code should return HTML to be +displayed before that line item (quotations only) + Returns a list of hashrefs, each of which may contain: pkgnum, description, amount, unit_amount, quantity, pkgpart, _is_setup, and @@ -2661,12 +2722,18 @@ sub _items_cust_bill_pkg { || $discount_show_always || $cust_bill_pkg->recur_show_zero; push @b, { + 'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref 'description' => $description, 'amount' => sprintf("%.2f", $cust_bill_pkg->setup), + 'preref_html' => ( $opt{preref_callback} + ? &{ $opt{preref_callback} }( $cust_bill_pkg ) + : '' + ), }; } if ( $cust_bill_pkg->recur != 0 ) { push @b, { + 'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref 'description' => "$desc (". $cust_bill_pkg->part_pkg->freq_pretty.")", 'amount' => sprintf("%.2f", $cust_bill_pkg->recur), }; diff --git a/conf/quotation_html b/conf/quotation_html index 68d373f04..5458774e1 100644 --- a/conf/quotation_html +++ b/conf/quotation_html @@ -155,7 +155,11 @@ $OUT .= ( ($line->{'ref'} && $line->{'ref'} ne $lastref) ? '' : '_more' ). '">'. ''. - ( $line->{'ref'} ne $lastref ? $line->{'ref'} : '' ). ''. + ( $line->{'ref'} ne $lastref + ? $line->{'preref_html'}. $line->{'ref'} + : '' + ). + ''. ''. $line->{'description'}. ''. ( $unitprices ? ''. $line->{'unit_amount'}. ''. diff --git a/httemplate/misc/delete-quotation_pkg.html b/httemplate/misc/delete-quotation_pkg.html new file mode 100644 index 000000000..5a44d3728 --- /dev/null +++ b/httemplate/misc/delete-quotation_pkg.html @@ -0,0 +1,21 @@ +% if ( $error ) { +% errorpage($error); +% } else { +<% $cgi->redirect($p. "view/quotation.html?". $quotationnum) %> +% } +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Generate quotation'); #separate ACL for editing it later? too silly for us yet + +#untaint quotationpkgnum +my($query) = $cgi->keywords; +$query =~ /^(\d+)$/ or die "Illegal quotationpkgnum"; +my $quotationpkgnum = $1; + +my $quotation_pkg = qsearchs('quotation_pkg',{'quotationpkgnum'=>$quotationpkgnum}); +my $quotationnum = $quotation_pkg->quotationnum; + +my $error = $quotation_pkg->delete; + + diff --git a/httemplate/view/quotation.html b/httemplate/view/quotation.html index a88acf82b..ae9c4aa8c 100755 --- a/httemplate/view/quotation.html +++ b/httemplate/view/quotation.html @@ -1,5 +1,12 @@ <& /elements/header.html, mt('Quotation View'), $menubar &> + + %#XXX link to order... <%doc> @@ -38,7 +45,7 @@ XXX resending quotations % } % if ( $conf->exists('quotation_html') ) { - <% join('', $quotation->print_html() ) %> + <% join('', $quotation->print_html( preref_callback=>$preref_callback )) %> % } else { % die "quotation_html config missing"; % } @@ -87,5 +94,17 @@ my $link = "quotationnum=$quotationnum"; #$link .= ';template='. uri_escape($template) if $template; #$link .= ';notice_name='. $notice_name if $notice_name; +my $preref_callback = sub { + areyousure_link("${p}misc/delete-quotation_pkg.html?". shift->quotationpkgnum, + emt('Are you sure you want to remove this package from the quotation?'), + emt('Remove this package'), #tooltip + qq(), #link + ); +}; + +sub areyousure_link { + my ($url,$msg,$title,$label) = (shift,shift,shift,shift); + ''.$label.''; +} -- 2.11.0