1 <& elements/search.html,
2 'title' => emt('Quotation Search Results'),
3 'html_init' => $html_init,
5 'name' => 'quotations',
7 'count_query' => $count_query,
8 'count_addl' => $count_addl,
11 'disabled_statuspos' => 1,
12 'header' => [ emt('Quotation #'),
24 sub { $money_char. shift->total_setup },
25 sub { $money_char. shift->total_recur },
26 sub { time2str('%b %d %Y', shift->_date ) },
27 sub { my $prospect_main = shift->prospect_main;
28 $prospect_main ? $prospect_main->name : '';
30 sub { my $cust_main = shift->cust_main;
31 $cust_main ? encode_entities($cust_main->name) : '';
33 sub { my $quotation = shift;
34 length($quotation->confidence) ? $quotation->confidence . '%' : '';
36 sub { my $quotation = shift;
37 $quotation->close_date ? time2str('%b %d %Y', $quotation->close_date) : '';
39 'quotation_description',
40 #\&FS::UI::Web::cust_fields,
44 '', #FS::quotation->total_setup_sql,
45 '', #FS::quotation->total_recur_sql,
52 'align' => 'rrrrllrr', #.FS::UI::Web::cust_aligns(),
62 #( map { $_ ne 'Cust. Status' ? $cust_link : '' }
63 # FS::UI::Web::cust_header()
72 # FS::UI::Web::cust_colors(),
80 # FS::UI::Web::cust_styles(),
85 my $curuser = $FS::CurrentUser::CurrentUser;
88 unless $curuser->access_right('List quotations');
90 local($FS::Record::qsearch_qualify_columns) = 1;
92 my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
93 my $join_cust_main = FS::UI::Web::join_cust_main('quotation');
95 #here is the agent virtualization
96 my $agentnums_sql = ' ( '. $curuser->agentnums_sql( table=>'prospect_main' ).
97 ' OR '. $curuser->agentnums_sql( table=>'cust_main' ).
100 my( $count_query, $sql_query );
104 #if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
106 # my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
108 # $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
111 # 'table' => 'quotation',
112 # 'addl_from' => "$join_prospect_main $join_cust_main",
114 # 'extra_sql' => $where,
119 #some false laziness w/cust_bill::re_X
120 my $orderby = 'ORDER BY quotation._date';
122 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
123 $search{'agentnum'} = $1;
126 # if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
127 # $search{'refnum'} = $1;
130 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
131 $search{'prospectnum'} = $1;
134 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
135 $search{'custnum'} = $1;
138 # begin/end/beginning/ending
139 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
140 $search{'_date'} = [ $beginning, $ending ]
141 unless $beginning == 0 && $ending == 4294967295;
143 if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
144 $search{'quotationnum_min'} = $1;
146 if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
147 $search{'quotationnum_max'} = $1;
151 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
152 foreach qw( total_setup total_recur );
154 # my($query) = $cgi->keywords;
155 # if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
156 # $search{'open'} = 1 if $1;
157 # ($search{'days'}, my $field) = ($2, $3);
158 # $field = "_date" if $field eq 'date';
159 # $orderby = "ORDER BY cust_bill.$field";
162 # if ( $cgi->param('newest_percust') ) {
163 # $search{'newest_percust'} = 1;
164 # $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
167 my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
169 unless ( $count_query ) {
170 $count_query = 'SELECT COUNT(*)';
172 $count_query .= " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
175 'table' => 'quotation',
176 'addl_from' => "$join_prospect_main $join_cust_main",
178 'select' => join(', ',
180 #( map "cust_main.$_", qw(custnum last first company) ),
181 'prospect_main.prospectnum as prospect_main_prospectnum',
182 'cust_main.custnum as cust_main_custnum',
183 #FS::UI::Web::cust_sql_fields(),
185 'extra_sql' => $extra_sql,
186 'order_by' => $orderby,
191 my $link = [ "${p}view/quotation.html?", 'quotationnum', ];
192 my $prospect_link = sub {
193 my $quotation = shift;
194 $quotation->prospect_main_prospectnum
195 ? [ "${p}view/prospect_main.html?", 'prospectnum' ]
199 my $cust_link = sub {
200 my $quotation = shift;
201 $quotation->cust_main_custnum
202 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
206 my $conf = new FS::Conf;
207 my $money_char = $conf->config('money_char') || '$';
209 my $html_init = join("\n", map {
210 ( my $action = $_ ) =~ s/_$//;
211 include('/elements/progress-init.html',
214 "../misc/${_}invoices.cgi",
215 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
218 qq!<FORM NAME="${_}form">!,
220 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
221 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
226 } qw( print_ email_ fax_ ftp_ spool_ ) ).
228 '<SCRIPT TYPE="text/javascript">
230 function confirm_print_process() {
231 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
236 function confirm_email_process() {
237 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
242 function confirm_fax_process() {
243 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
248 function confirm_ftp_process() {
249 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
254 function confirm_spool_process() {
255 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
265 #if ( $curuser->access_right('Resend quotations') ) {
267 # push @$menubar, emt('Print these invoices') =>
268 # "javascript:confirm_print_process()",
269 # emt('Email these invoices') =>
270 # "javascript:confirm_email_process()";
272 # push @$menubar, emt('Fax these invoices') =>
273 # "javascript:confirm_fax_process()"
274 # if $conf->exists('hylafax');
276 # push @$menubar, emt('FTP these invoices') =>
277 # "javascript:confirm_ftp_process()"
278 # if $conf->exists('cust_bill-ftpformat');
280 # push @$menubar, emt('Spool these invoices') =>
281 # "javascript:confirm_spool_process()"
282 # if $conf->exists('cust_bill-spoolformat');