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) : '';
33 sub { my $quot = shift;
34 $quot->close_date ? time2str('%b %d %Y', $quot->close_date) : '';
36 #\&FS::UI::Web::cust_fields,
40 '', #FS::quotation->total_setup_sql,
41 '', #FS::quotation->total_recur_sql,
48 'align' => 'rrrrllrr', #.FS::UI::Web::cust_aligns(),
58 #( map { $_ ne 'Cust. Status' ? $cust_link : '' }
59 # FS::UI::Web::cust_header()
68 # FS::UI::Web::cust_colors(),
76 # FS::UI::Web::cust_styles(),
81 my $curuser = $FS::CurrentUser::CurrentUser;
84 unless $curuser->access_right('List quotations');
86 local($FS::Record::qsearch_qualify_columns) = 1;
88 my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
89 my $join_cust_main = FS::UI::Web::join_cust_main('quotation');
91 #here is the agent virtualization
92 my $agentnums_sql = ' ( '. $curuser->agentnums_sql( table=>'prospect_main' ).
93 ' OR '. $curuser->agentnums_sql( table=>'cust_main' ).
96 my( $count_query, $sql_query );
100 #if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
102 # my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
104 # $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
107 # 'table' => 'quotation',
108 # 'addl_from' => "$join_prospect_main $join_cust_main",
110 # 'extra_sql' => $where,
115 #some false laziness w/cust_bill::re_X
116 my $orderby = 'ORDER BY quotation._date';
118 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
119 $search{'agentnum'} = $1;
122 # if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
123 # $search{'refnum'} = $1;
126 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
127 $search{'prospectnum'} = $1;
130 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
131 $search{'custnum'} = $1;
134 # begin/end/beginning/ending
135 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
136 $search{'_date'} = [ $beginning, $ending ]
137 unless $beginning == 0 && $ending == 4294967295;
139 if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
140 $search{'quotationnum_min'} = $1;
142 if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
143 $search{'quotationnum_max'} = $1;
147 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
148 foreach qw( total_setup total_recur );
150 # my($query) = $cgi->keywords;
151 # if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
152 # $search{'open'} = 1 if $1;
153 # ($search{'days'}, my $field) = ($2, $3);
154 # $field = "_date" if $field eq 'date';
155 # $orderby = "ORDER BY cust_bill.$field";
158 # if ( $cgi->param('newest_percust') ) {
159 # $search{'newest_percust'} = 1;
160 # $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
163 my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
165 unless ( $count_query ) {
166 $count_query = 'SELECT COUNT(*)';
168 $count_query .= " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
171 'table' => 'quotation',
172 'addl_from' => "$join_prospect_main $join_cust_main",
174 'select' => join(', ',
176 #( map "cust_main.$_", qw(custnum last first company) ),
177 'prospect_main.prospectnum as prospect_main_prospectnum',
178 'cust_main.custnum as cust_main_custnum',
179 #FS::UI::Web::cust_sql_fields(),
181 'extra_sql' => $extra_sql,
182 'order_by' => $orderby,
187 my $link = [ "${p}view/quotation.html?", 'quotationnum', ];
188 my $prospect_link = sub {
189 my $quotation = shift;
190 $quotation->prospect_main_prospectnum
191 ? [ "${p}view/prospect_main.html?", 'prospectnum' ]
195 my $cust_link = sub {
196 my $quotation = shift;
197 $quotation->cust_main_custnum
198 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
202 my $conf = new FS::Conf;
203 my $money_char = $conf->config('money_char') || '$';
205 my $html_init = join("\n", map {
206 ( my $action = $_ ) =~ s/_$//;
207 include('/elements/progress-init.html',
210 "../misc/${_}invoices.cgi",
211 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
214 qq!<FORM NAME="${_}form">!,
216 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
217 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
222 } qw( print_ email_ fax_ ftp_ spool_ ) ).
224 '<SCRIPT TYPE="text/javascript">
226 function confirm_print_process() {
227 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
232 function confirm_email_process() {
233 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
238 function confirm_fax_process() {
239 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
244 function confirm_ftp_process() {
245 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
250 function confirm_spool_process() {
251 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
261 #if ( $curuser->access_right('Resend quotations') ) {
263 # push @$menubar, emt('Print these invoices') =>
264 # "javascript:confirm_print_process()",
265 # emt('Email these invoices') =>
266 # "javascript:confirm_email_process()";
268 # push @$menubar, emt('Fax these invoices') =>
269 # "javascript:confirm_fax_process()"
270 # if $conf->exists('hylafax');
272 # push @$menubar, emt('FTP these invoices') =>
273 # "javascript:confirm_ftp_process()"
274 # if $conf->exists('cust_bill-ftpformat');
276 # push @$menubar, emt('Spool these invoices') =>
277 # "javascript:confirm_spool_process()"
278 # if $conf->exists('cust_bill-spoolformat');