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 #'),
23 sub { $money_char. shift->total_setup },
24 sub { $money_char. shift->total_recur },
25 sub { time2str('%b %d %Y', shift->_date ) },
26 sub { my $prospect_main = shift->prospect_main;
27 $prospect_main ? $prospect_main->name : '';
29 sub { my $cust_main = shift->cust_main;
30 $cust_main ? encode_entities($cust_main->name) : '';
32 sub { my $quotation = shift;
33 length($quotation->confidence) ? $quotation->confidence . '%' : '';
35 sub { my $quotation = shift;
36 $quotation->close_date ? time2str('%b %d %Y', $quotation->close_date) : '';
38 #\&FS::UI::Web::cust_fields,
42 '', #FS::quotation->total_setup_sql,
43 '', #FS::quotation->total_recur_sql,
50 'align' => 'rrrrllrr', #.FS::UI::Web::cust_aligns(),
60 #( map { $_ ne 'Cust. Status' ? $cust_link : '' }
61 # FS::UI::Web::cust_header()
70 # FS::UI::Web::cust_colors(),
78 # FS::UI::Web::cust_styles(),
83 my $curuser = $FS::CurrentUser::CurrentUser;
86 unless $curuser->access_right('List quotations');
88 local($FS::Record::qsearch_qualify_columns) = 1;
90 my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
91 my $join_cust_main = FS::UI::Web::join_cust_main('quotation');
93 #here is the agent virtualization
94 my $agentnums_sql = ' ( '. $curuser->agentnums_sql( table=>'prospect_main' ).
95 ' OR '. $curuser->agentnums_sql( table=>'cust_main' ).
98 my( $count_query, $sql_query );
102 #if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
104 # my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
106 # $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
109 # 'table' => 'quotation',
110 # 'addl_from' => "$join_prospect_main $join_cust_main",
112 # 'extra_sql' => $where,
117 #some false laziness w/cust_bill::re_X
118 my $orderby = 'ORDER BY quotation._date';
120 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
121 $search{'agentnum'} = $1;
124 # if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
125 # $search{'refnum'} = $1;
128 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
129 $search{'prospectnum'} = $1;
132 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
133 $search{'custnum'} = $1;
136 # begin/end/beginning/ending
137 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
138 $search{'_date'} = [ $beginning, $ending ]
139 unless $beginning == 0 && $ending == 4294967295;
141 if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
142 $search{'quotationnum_min'} = $1;
144 if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
145 $search{'quotationnum_max'} = $1;
149 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
150 foreach qw( total_setup total_recur );
152 # my($query) = $cgi->keywords;
153 # if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
154 # $search{'open'} = 1 if $1;
155 # ($search{'days'}, my $field) = ($2, $3);
156 # $field = "_date" if $field eq 'date';
157 # $orderby = "ORDER BY cust_bill.$field";
160 # if ( $cgi->param('newest_percust') ) {
161 # $search{'newest_percust'} = 1;
162 # $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
165 my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
167 unless ( $count_query ) {
168 $count_query = 'SELECT COUNT(*)';
170 $count_query .= " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
173 'table' => 'quotation',
174 'addl_from' => "$join_prospect_main $join_cust_main",
176 'select' => join(', ',
178 #( map "cust_main.$_", qw(custnum last first company) ),
179 'prospect_main.prospectnum as prospect_main_prospectnum',
180 'cust_main.custnum as cust_main_custnum',
181 #FS::UI::Web::cust_sql_fields(),
183 'extra_sql' => $extra_sql,
184 'order_by' => $orderby,
189 my $link = [ "${p}view/quotation.html?", 'quotationnum', ];
190 my $prospect_link = sub {
191 my $quotation = shift;
192 $quotation->prospect_main_prospectnum
193 ? [ "${p}view/prospect_main.html?", 'prospectnum' ]
197 my $cust_link = sub {
198 my $quotation = shift;
199 $quotation->cust_main_custnum
200 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
204 my $conf = new FS::Conf;
205 my $money_char = $conf->config('money_char') || '$';
207 my $html_init = join("\n", map {
208 ( my $action = $_ ) =~ s/_$//;
209 include('/elements/progress-init.html',
212 "../misc/${_}invoices.cgi",
213 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
216 qq!<FORM NAME="${_}form">!,
218 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
219 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
224 } qw( print_ email_ fax_ ftp_ spool_ ) ).
226 '<SCRIPT TYPE="text/javascript">
228 function confirm_print_process() {
229 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
234 function confirm_email_process() {
235 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
240 function confirm_fax_process() {
241 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
246 function confirm_ftp_process() {
247 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
252 function confirm_spool_process() {
253 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
263 #if ( $curuser->access_right('Resend quotations') ) {
265 # push @$menubar, emt('Print these invoices') =>
266 # "javascript:confirm_print_process()",
267 # emt('Email these invoices') =>
268 # "javascript:confirm_email_process()";
270 # push @$menubar, emt('Fax these invoices') =>
271 # "javascript:confirm_fax_process()"
272 # if $conf->exists('hylafax');
274 # push @$menubar, emt('FTP these invoices') =>
275 # "javascript:confirm_ftp_process()"
276 # if $conf->exists('cust_bill-ftpformat');
278 # push @$menubar, emt('Spool these invoices') =>
279 # "javascript:confirm_spool_process()"
280 # if $conf->exists('cust_bill-spoolformat');