delete packages from quotations, RT#30313
authorIvan Kohler <ivan@freeside.biz>
Fri, 7 Nov 2014 00:48:16 +0000 (16:48 -0800)
committerIvan Kohler <ivan@freeside.biz>
Fri, 7 Nov 2014 00:48:16 +0000 (16:48 -0800)
FS/FS/Template_Mixin.pm
conf/quotation_html
httemplate/misc/delete-quotation_pkg.html [new file with mode: 0644]
httemplate/view/quotation.html

index ce7efca..f70ac3c 100644 (file)
@@ -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<format> 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<perlfunc/"time">.  Also see
 L<Time::Local> and L<Date::Parse> 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),
           };
index 68d373f..5458774 100644 (file)
               $OUT .=  ( ($line->{'ref'} && $line->{'ref'} ne $lastref) ? '' : '_more' ).
                        '">'.
                        '<td align="center">'. 
-                       ( $line->{'ref'} ne $lastref ? $line->{'ref'} : '' ). '</td>'.
+                         ( $line->{'ref'} ne $lastref
+                             ? $line->{'preref_html'}. $line->{'ref'}
+                             : ''
+                         ).
+                       '</td>'.
                        '<td align="left">'. $line->{'description'}. '</td>'.
                        ( $unitprices 
                            ? '<td align="left">'. $line->{'unit_amount'}. '</td>'.
diff --git a/httemplate/misc/delete-quotation_pkg.html b/httemplate/misc/delete-quotation_pkg.html
new file mode 100644 (file)
index 0000000..5a44d37
--- /dev/null
@@ -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;
+
+</%init>
index a88acf8..ae9c4aa 100755 (executable)
@@ -1,5 +1,12 @@
 <& /elements/header.html, mt('Quotation View'), $menubar &>
 
+<SCRIPT TYPE="text/javascript">
+function areyousure(href, message) {
+  if (confirm(message) == true)
+    window.location.href = href;
+}
+</SCRIPT>
+
 %#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(<img src="${p}images/cross.png">), #link
+                 );
+};
+
+sub areyousure_link {
+    my ($url,$msg,$title,$label) = (shift,shift,shift,shift);
+    '<A HREF="javascript:areyousure(\''.$url.'\',\''.$msg.'\')" TITLE="'.$title.'">'.$label.'</A>';
+}
 
 </%init>