quotations look like they belong to customers
[freeside.git] / httemplate / view / quotation.html
index 2c2c6b7..cabf30a 100755 (executable)
+% if ( $quotation->custnum ) {
+<& /elements/header-cust_main.html, view=>'quotations', custnum=>$quotation->custnum &>
+<h2>Quotation #<% $quotationnum %></h2>
+% } else { #eventually, header-prospect_main.html
 <& /elements/header.html, mt('Quotation View'), $menubar &>
+<& /elements/init_overlib.html &>
 
-%#XXX link to order...
-
-<%doc>
-
-XXX resending quotations
-
-% if ( $curuser->access_right('Resend invoices') ) {
-
-    <A HREF="<% $p %>misc/send-invoice.cgi?method=print;<% $link %>"><% mt('Re-print this invoice') |h %></A>
-
-%   if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
-        | <A HREF="<% $p %>misc/send-invoice.cgi?method=email;<% $link %>"><% mt('Re-email this invoice') |h %></A>
-%   } 
-
-%   if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
-        | <A HREF="<% $p %>misc/send-invoice.cgi?method=fax;<% $link %>"><% mt('Re-fax this invoice') |h %></A>
-%   } 
+<SCRIPT TYPE="text/javascript">
+function areyousure(href, message) {
+  if (confirm(message) == true)
+    window.location.href = href;
+}
+</SCRIPT>
+
+% }
+
+% unless ( $quotation->disabled eq 'Y' ) {
+
+%   my $inrow = 0;
+%   if ( $curuser->access_right('Order customer package') ) {
+      <& /elements/order_pkg_link.html,
+           'label'       => emt('Add package'),
+           'actionlabel' => emt('Add package'),
+           map { $_ => $quotation->$_ } qw( quotationnum custnum prospectnum )
+      &>
+%     $inrow++;
+%   }
+
+%   if ( $curuser->access_right('One-time charge') ) {
+      <% $inrow ? ' | ' : '' %>
+%     my $query = 'quotationnum=' . $quotation->get('quotationnum');
+%     if ($quotation->custnum) {
+%       $query .= ';custnum=' . $quotation->custnum;
+%     } else {
+%       $query .= ';prospectnum=' . $quotation->prospectnum;
+%     }
+      <A HREF="<% $fsurl . 'edit/quick-charge.html?' . $query %>"><% emt('One-time charge') %></A>
+%     $inrow++;
+%   }
+
+%   if ( $can_generate_quotation ) {
+      <% $inrow ? ' | ' : '' %>
+      <A HREF="<%$p%>edit/quotation.html?quotationnum=<% $quotation->quotationnum %>">Edit quotation fields</A>
+%     $inrow++;
+%   }
+
+    <% $inrow ? '<BR><BR>' : '' %>
+
+%   if ( 1 ) { #if ( $curuser->access_right('Send quotations') )
+
+      <& /elements/popup_link.html,
+           'action'      => "${p}misc/email-quotation.html".
+                              "?quotationnum=$quotationnum",
+           'label'       => emt('Email this quotation'),
+           'actionlabel' => emt('Select recipients'),
+           #'width'       => 540,
+           #'height'      => 336,
+      &>
+
+%#      <A HREF="<% $p %>misc/send-invoice.cgi?method=print;<% $link %>"><% mt('Re-print this invoice') |h %></A>
+
+%#%     if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
+%#           | <A HREF="<% $p %>misc/send-invoice.cgi?method=fax;<% $link %>"><% mt('Re-fax this invoice') |h %></A>
+%#%     } 
+
+%   }
+
+%   if ( $conf->exists('quotation_latex') ) { 
+      | <A HREF="<% $p %>view/quotation-pdf.cgi?<% $link %>"><% mt('View typeset quotation PDF') |h %></A>
+%   }
 
     <BR><BR>
 
-% } 
-
-XXX view typset quotation
-
-% if ( $conf->exists('invoice_latex') ) { 
-
-  <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $link %>"><% mt('View typeset invoice PDF') |h %></A>
+%   if ( $curuser->access_right('New customer') && $quotation->quotation_pkg ) {
+%     # if we end up with more than one option, combine these links and add an interstitial screen
+      <A HREF="<%$p%>edit/process/quotation_convert.html?quotationnum=<% $quotation->quotationnum %>">Place order</A>
+      | <A HREF="<%$p%>edit/process/quotation_convert.html?quotationnum=<% $quotation->quotationnum %>&onhold=1">Order on hold</A>
+      <BR><BR>
+%   }
+
+% }
+
+% if ( $curuser->access_right('Disable quotation') ) {
+%   if ( $quotation->disabled eq 'Y' ) {
+      <A HREF="<%$p%>misc/enable-quotation.html?quotationnum=<% $quotation->quotationnum %>" TITLE="<% emt('Enable this quotation') %>"><% emt('Enable this quotation') %></A>
+%   } else {
+      <% areyousure_link(
+           "${p}misc/disable-quotation.html?quotationnum=". $quotation->quotationnum,
+           emt('Are you sure you want to disable this quotation?'),
+           emt('Disable this quotation'), #tooltip
+           emt('Disable this quotation'), #link
+      ) %>
+%   }
   <BR><BR>
-% } 
-
-XXX actually show the quotation
-
-% if ( $conf->exists('invoice_html') ) { 
-  <% join('', $cust_bill->print_html(\%opt) ) %>
+% }
+
+% if ( $error ) {
+<DIV CLASS="error"><% emt('Error calculating quotation: [_1]', $error) %></DIV>
+% }
+
+% my $close_date = $quotation->close_date;
+% my $confidence = $quotation->confidence;
+% if ($close_date or length($confidence)) {
+<TABLE>
+%   if ($close_date) {
+<TR>
+  <TH STYLE="text-align: right;">Close Date:</TH>
+  <TD><% time2str($conf->config('date_format') || '%m/%d/%Y',$close_date) %></TD>
+</TR>
+%   }
+%   if (length($confidence)) {
+<TR><TH STYLE="text-align: right;">Confidence:</TH><TD><% $confidence %>%</TD></TR>
+%   }
+</TABLE>
+% }
+
+% if ( $conf->exists('quotation_html') ) { 
+    <% join('', $quotation->print_html( preref_callback=>$preref_callback )) %>
 % } else { 
-  <PRE><% join('', $cust_bill->print_text(\%opt) ) %></PRE>
-% } 
-
-</%doc>
-
-<& /elements/footer.html &>
+%   die "quotation_html config missing";
+% }
+% #plaintext quotations? <PRE><% join('', $quotation->print_text() ) %></PRE>
+
+% if ( $quotation->custnum ) {
+  <& /elements/footer-cust_main.html &>
+% } else {
+  <& /elements/footer.html &>
+% }
 <%init>
 
 my $curuser = $FS::CurrentUser::CurrentUser;
@@ -48,6 +133,8 @@ my $curuser = $FS::CurrentUser::CurrentUser;
 #die "access denied"
 #  unless $curuser->access_right('View quotations');
 
+my $can_generate_quotation = $curuser->access_right('Generate quotation');
+
 my $quotationnum;
 my($query) = $cgi->keywords;
 if ( $query =~ /^(\d+)$/ ) {
@@ -56,7 +143,7 @@ if ( $query =~ /^(\d+)$/ ) {
   $quotationnum = $cgi->param('quotationnum');
 }
 
-#my $conf = new FS::Conf;
+my $conf = new FS::Conf;
 
 my $quotation = qsearchs({
   'select'    => 'quotation.*',
@@ -67,15 +154,37 @@ my $quotation = qsearchs({
 });
 die "Quotation #$quotationnum not found!" unless $quotation;
 
-if ( my $custnum = $quotation->custnum ) {
-  my $display_custnum = $quotation->cust_main->display_custnum;
-  $menubar = menubar(
-    emt("View this customer (#[_1])",$display_custnum) => "${p}view/cust_main.cgi?$custnum",
-  );
-} elsif ( my $prospectnum = $quotation->prospectnum ) {
-  $menubar = menubar(
-    emt("View this prospect (#[_1])",$prospectnum) => "${p}view/prospect_main.html?$prospectnum",
-  );
+my $error = $quotation->estimate;
+
+my $menubar = menubar( $quotation->cust_or_prospect_label_link($p) );
+
+my $link = "quotationnum=$quotationnum";
+#$link .= ';template='. uri_escape($template) if $template;
+#$link .= ';notice_name='. $notice_name if $notice_name;
+
+my $preref_callback = sub {
+  my $quotation_pkg = shift;
+  $can_generate_quotation ?
+  areyousure_link("${p}misc/delete-quotation_pkg.html?". $quotation_pkg->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
+                 ) .
+  include('/elements/popup_link.html',
+    action      => "${p}edit/quotation_pkg_detail.html?pkgnum=" .
+                   $quotation_pkg->quotationpkgnum,
+    html_label  => qq(<IMG SRC="${p}images/Actions-document-edit-icon.png">),
+    title       => emt('Edit quotation details'),
+    actionlabel => emt('Edit quotation details'),
+    color       => '#333399',
+    width       => 763,
+  )
+  : '';
+};
+
+sub areyousure_link {
+    my ($url,$msg,$title,$label) = (shift,shift,shift,shift);
+    '<A HREF="javascript:areyousure(\''.$url.'\',\''.$msg.'\')" TITLE="'.$title.'">'.$label.'</A>';
 }
 
 </%init>