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 'quotation_description',
28 sub { my $quotation = shift;
29 $quotation->close_date ? time2str('%b %d %Y', $quotation->close_date) : '';
31 sub { my $quotation = shift;
32 length($quotation->confidence) ? $quotation->confidence . '%' : '';
34 sub { my $prospect_main = shift->prospect_main;
35 $prospect_main ? $prospect_main->name : '';
37 sub { my $cust_main = shift->cust_main;
38 $cust_main ? encode_entities($cust_main->name) : '';
40 #\&FS::UI::Web::cust_fields,
44 '', #FS::quotation->total_setup_sql,
45 '', #FS::quotation->total_recur_sql,
47 'quotation_description',
53 'align' => 'rrrrlrrll', #.FS::UI::Web::cust_aligns(),
64 #( map { $_ ne 'Cust. Status' ? $cust_link : '' }
65 # FS::UI::Web::cust_header()
74 # FS::UI::Web::cust_colors(),
82 # FS::UI::Web::cust_styles(),
87 my $curuser = $FS::CurrentUser::CurrentUser;
90 unless $curuser->access_right('List quotations');
92 local($FS::Record::qsearch_qualify_columns) = 1;
94 my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
95 my $join_cust_main = FS::UI::Web::join_cust_main('quotation');
97 #here is the agent virtualization
98 my $agentnums_sql = ' ( '. $curuser->agentnums_sql( table=>'prospect_main' ).
99 ' OR '. $curuser->agentnums_sql( table=>'cust_main' ).
102 my( $count_query, $sql_query );
106 #if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
108 # my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
110 # $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
113 # 'table' => 'quotation',
114 # 'addl_from' => "$join_prospect_main $join_cust_main",
116 # 'extra_sql' => $where,
121 #some false laziness w/cust_bill::re_X
122 my $orderby = 'ORDER BY quotation._date';
124 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
125 $search{'agentnum'} = $1;
128 # if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
129 # $search{'refnum'} = $1;
132 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
133 $search{'prospectnum'} = $1;
136 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
137 $search{'custnum'} = $1;
140 # begin/end/beginning/ending
141 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
142 $search{'_date'} = [ $beginning, $ending ]
143 unless $beginning == 0 && $ending == 4294967295;
145 if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
146 $search{'quotationnum_min'} = $1;
148 if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
149 $search{'quotationnum_max'} = $1;
153 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
154 foreach qw( total_setup total_recur );
156 # my($query) = $cgi->keywords;
157 # if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
158 # $search{'open'} = 1 if $1;
159 # ($search{'days'}, my $field) = ($2, $3);
160 # $field = "_date" if $field eq 'date';
161 # $orderby = "ORDER BY cust_bill.$field";
164 # if ( $cgi->param('newest_percust') ) {
165 # $search{'newest_percust'} = 1;
166 # $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
169 my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
171 unless ( $count_query ) {
172 $count_query = 'SELECT COUNT(*)';
174 $count_query .= " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
177 'table' => 'quotation',
178 'addl_from' => "$join_prospect_main $join_cust_main",
180 'select' => join(', ',
182 #( map "cust_main.$_", qw(custnum last first company) ),
183 'prospect_main.prospectnum as prospect_main_prospectnum',
184 'cust_main.custnum as cust_main_custnum',
185 #FS::UI::Web::cust_sql_fields(),
187 'extra_sql' => $extra_sql,
188 'order_by' => $orderby,
193 my $link = [ "${p}view/quotation.html?", 'quotationnum', ];
194 my $prospect_link = sub {
195 my $quotation = shift;
196 $quotation->prospect_main_prospectnum
197 ? [ "${p}view/prospect_main.html?", 'prospectnum' ]
201 my $cust_link = sub {
202 my $quotation = shift;
203 $quotation->cust_main_custnum
204 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
208 my $conf = new FS::Conf;
209 my $money_char = $conf->config('money_char') || '$';
211 my $html_init = join("\n", map {
212 ( my $action = $_ ) =~ s/_$//;
213 include('/elements/progress-init.html',
216 "../misc/${_}invoices.cgi",
217 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
220 qq!<FORM NAME="${_}form">!,
222 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
223 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
228 } qw( print_ email_ fax_ ftp_ spool_ ) ).
230 '<SCRIPT TYPE="text/javascript">
232 function confirm_print_process() {
233 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
238 function confirm_email_process() {
239 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
244 function confirm_fax_process() {
245 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
250 function confirm_ftp_process() {
251 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
256 function confirm_spool_process() {
257 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
267 #if ( $curuser->access_right('Resend quotations') ) {
269 # push @$menubar, emt('Print these invoices') =>
270 # "javascript:confirm_print_process()",
271 # emt('Email these invoices') =>
272 # "javascript:confirm_email_process()";
274 # push @$menubar, emt('Fax these invoices') =>
275 # "javascript:confirm_fax_process()"
276 # if $conf->exists('hylafax');
278 # push @$menubar, emt('FTP these invoices') =>
279 # "javascript:confirm_ftp_process()"
280 # if $conf->exists('cust_bill-ftpformat');
282 # push @$menubar, emt('Spool these invoices') =>
283 # "javascript:confirm_spool_process()"
284 # if $conf->exists('cust_bill-spoolformat');