quotation reports, RT#16996
[freeside.git] / httemplate / search / quotation.html
diff --git a/httemplate/search/quotation.html b/httemplate/search/quotation.html
new file mode 100755 (executable)
index 0000000..259c85c
--- /dev/null
@@ -0,0 +1,268 @@
+<& elements/search.html,
+                 'title'       => emt('Quotation Search Results'),
+                 'html_init'   => $html_init,
+                 'menubar'     => $menubar,
+                 'name'        => 'quotations',
+                 'query'       => $sql_query,
+                 'count_query' => $count_query,
+                 'count_addl'  => $count_addl,
+                 'redirect'    => $link,
+                 'header'      => [ emt('Quotation #'),
+                                    emt('Setup'),
+                                    emt('Recurring'),
+                                    emt('Date'),
+                                    emt('Prospect'),
+                                    emt('Customer'),
+                                  ],
+                 'fields'      => [
+                   'quotationnum',
+                   sub { $money_char. shift->total_setup },
+                   sub { $money_char. shift->total_recur },
+                   sub { time2str('%b %d %Y', shift->_date ) },
+                   sub { my $prospect_main = shift->prospect_main;
+                         $prospect_main ? $prospect_main->name : '';
+                       },
+                   sub { my $cust_main = shift->cust_main;
+                         $cust_main ? $cust_main->name : '';
+                       },
+                   #\&FS::UI::Web::cust_fields,
+                 ],
+                 'sort_fields' => [
+                   'quotationnum',
+                   '', #FS::quotation->total_setup_sql,
+                   '', #FS::quotation->total_recur_sql,
+                   '_date',
+                   '',
+                   '',
+                 ],
+                 'align' => 'rrrrll', #.FS::UI::Web::cust_aligns(),
+                 'links' => [
+                   $link,
+                   $link,
+                   $link,
+                   $link,
+                   $prospect_link,
+                   $cust_link,
+                   #( map { $_ ne 'Cust. Status' ? $clink : '' }
+                   #      FS::UI::Web::cust_header()
+                   #),
+                 ],
+#                 'color' => [ 
+#                              '',
+#                              '',
+#                              '',
+#                              '',
+#                              '',
+#                              FS::UI::Web::cust_colors(),
+#                            ],
+#                 'style' => [ 
+#                              '',
+#                              '',
+#                              '',
+#                              '',
+#                              '',
+#                              FS::UI::Web::cust_styles(),
+#                            ],
+&>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+  unless $curuser->access_right('List quotations');
+
+my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
+my $join_cust_main = 'LEFT JOIN cust_main ON ( quotation.custnum = cust_main.custnum )';
+
+#here is the agent virtualization
+my $agentnums_sql = ' (    '. $curuser->agentnums_sql( table=>'prospect_main' ).
+                    '   OR '. $curuser->agentnums_sql( table=>'cust_main' ).
+                    ' )    ';
+
+my( $count_query, $sql_query );
+my $count_addl = '';
+my %search;
+
+#if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
+#
+#  my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
+#  
+#  $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
+#
+#  $sql_query = {
+#    'table'     => 'quotation',
+#    'addl_from' => "$join_prospect_main $join_cust_main",
+#    'hashref'   => {},
+#    'extra_sql' => $where,
+#  };
+#
+#} else {
+
+  #some false laziness w/cust_bill::re_X
+  my $orderby = 'ORDER BY quotation._date';
+
+  if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+    $search{'agentnum'} = $1;
+  }
+
+#  if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
+#    $search{'refnum'} = $1;
+#  }
+
+  if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
+    $search{'prospectnum'} = $1;
+  }
+
+  if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
+    $search{'custnum'} = $1;
+  }
+
+  # begin/end/beginning/ending
+  my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
+  $search{'_date'} = [ $beginning, $ending ]
+    unless $beginning == 0 && $ending == 4294967295;
+
+  if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
+    $search{'quotationnum_min'} = $1;
+  }
+  if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
+    $search{'quotationnum_max'} = $1;
+  }
+
+  #amounts
+  $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
+    foreach qw( total_setup total_recur );
+
+#  my($query) = $cgi->keywords;
+#  if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
+#    $search{'open'} = 1 if $1;
+#    ($search{'days'}, my $field) = ($2, $3);
+#    $field = "_date" if $field eq 'date';
+#    $orderby = "ORDER BY cust_bill.$field";
+#  }
+
+#  if ( $cgi->param('newest_percust') ) {
+#    $search{'newest_percust'} = 1;
+#    $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
+#  }
+
+  my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
+
+  unless ( $count_query ) {
+    $count_query = 'SELECT COUNT(*)';
+  }
+  $count_query .=  " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
+
+  $sql_query = {
+    'table'     => 'quotation',
+    'addl_from' => "$join_prospect_main $join_cust_main",
+    'hashref'   => {},
+    'select'    => join(', ',
+                     'quotation.*',
+                     #( map "cust_main.$_", qw(custnum last first company) ),
+                     'prospect_main.prospectnum as prospect_main_prospectnum',
+                     'cust_main.custnum as cust_main_custnum',
+                     #FS::UI::Web::cust_sql_fields(),
+                   ),
+    'extra_sql' => $extra_sql,
+    'order_by'  => $orderby,
+  };
+
+#}
+
+my $link  = [ "${p}view/quotation.html?", 'quotationnum', ];
+my $prospect_link = sub {
+  my $quotation = shift;
+  $quotation->prospect_main_prospectnum
+    ? [ "${p}view/prospect_main.html?", 'prospectnum' ]
+    : '';
+};
+
+my $cust_link = sub {
+  my $quotation = shift;
+  $quotation->cust_main_custnum
+    ? [ "${p}view/cust_main.cgi?", 'custnum' ]
+    : '';
+};
+
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
+
+my $html_init = join("\n", map {
+ ( my $action = $_ ) =~ s/_$//;
+ include('/elements/progress-init.html',
+           $_.'form',
+           [ keys %search ],
+           "../misc/${_}invoices.cgi",
+           { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
+           $_, #key
+        ),
+ qq!<FORM NAME="${_}form">!,
+ ( map { my $f = $_;
+         my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
+         map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
+       }
+       keys %search
+ ),
+ qq!</FORM>!
+} qw( print_ email_ fax_ ftp_ spool_ ) ). 
+
+'<SCRIPT TYPE="text/javascript">
+
+function confirm_print_process() {
+  if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
+    return;
+  }
+  print_process();
+}
+function confirm_email_process() {
+  if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
+    return;
+  }
+  email_process();
+}
+function confirm_fax_process() {
+  if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
+    return;
+  }
+  fax_process();
+}
+function confirm_ftp_process() {
+  if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
+    return;
+  }
+  ftp_process();
+}
+function confirm_spool_process() {
+  if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
+    return;
+  }
+  spool_process();
+}
+
+</SCRIPT>';
+
+my $menubar = [];
+
+#if ( $curuser->access_right('Resend quotations') ) {
+#
+#  push @$menubar, emt('Print these invoices') =>
+#                    "javascript:confirm_print_process()",
+#                  emt('Email these invoices') =>
+#                    "javascript:confirm_email_process()";
+#
+#  push @$menubar, emt('Fax these invoices') =>
+#                    "javascript:confirm_fax_process()"
+#    if $conf->exists('hylafax');
+#
+#  push @$menubar, emt('FTP these invoices') =>
+#                    "javascript:confirm_ftp_process()"
+#    if $conf->exists('cust_bill-ftpformat');
+#
+#  push @$menubar, emt('Spool these invoices') =>
+#                    "javascript:confirm_spool_process()"
+#    if $conf->exists('cust_bill-spoolformat');
+#
+#}
+
+</%init>