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 #'),
21 sub { $money_char. shift->total_setup },
22 sub { $money_char. shift->total_recur },
23 sub { time2str('%b %d %Y', shift->_date ) },
24 sub { my $prospect_main = shift->prospect_main;
25 $prospect_main ? $prospect_main->name : '';
27 sub { my $cust_main = shift->cust_main;
28 $cust_main ? $cust_main->name : '';
30 #\&FS::UI::Web::cust_fields,
34 '', #FS::quotation->total_setup_sql,
35 '', #FS::quotation->total_recur_sql,
40 'align' => 'rrrrll', #.FS::UI::Web::cust_aligns(),
48 #( map { $_ ne 'Cust. Status' ? $cust_link : '' }
49 # FS::UI::Web::cust_header()
58 # FS::UI::Web::cust_colors(),
66 # FS::UI::Web::cust_styles(),
71 my $curuser = $FS::CurrentUser::CurrentUser;
74 unless $curuser->access_right('List quotations');
76 local($FS::Record::qsearch_qualify_columns) = 1;
78 my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
79 my $join_cust_main = FS::UI::Web::join_cust_main('quotation');
81 #here is the agent virtualization
82 my $agentnums_sql = ' ( '. $curuser->agentnums_sql( table=>'prospect_main' ).
83 ' OR '. $curuser->agentnums_sql( table=>'cust_main' ).
86 my( $count_query, $sql_query );
90 #if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
92 # my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
94 # $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
97 # 'table' => 'quotation',
98 # 'addl_from' => "$join_prospect_main $join_cust_main",
100 # 'extra_sql' => $where,
105 #some false laziness w/cust_bill::re_X
106 my $orderby = 'ORDER BY quotation._date';
108 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
109 $search{'agentnum'} = $1;
112 # if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
113 # $search{'refnum'} = $1;
116 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
117 $search{'prospectnum'} = $1;
120 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
121 $search{'custnum'} = $1;
124 # begin/end/beginning/ending
125 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
126 $search{'_date'} = [ $beginning, $ending ]
127 unless $beginning == 0 && $ending == 4294967295;
129 if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
130 $search{'quotationnum_min'} = $1;
132 if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
133 $search{'quotationnum_max'} = $1;
137 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
138 foreach qw( total_setup total_recur );
140 # my($query) = $cgi->keywords;
141 # if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
142 # $search{'open'} = 1 if $1;
143 # ($search{'days'}, my $field) = ($2, $3);
144 # $field = "_date" if $field eq 'date';
145 # $orderby = "ORDER BY cust_bill.$field";
148 # if ( $cgi->param('newest_percust') ) {
149 # $search{'newest_percust'} = 1;
150 # $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
153 my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
155 unless ( $count_query ) {
156 $count_query = 'SELECT COUNT(*)';
158 $count_query .= " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
161 'table' => 'quotation',
162 'addl_from' => "$join_prospect_main $join_cust_main",
164 'select' => join(', ',
166 #( map "cust_main.$_", qw(custnum last first company) ),
167 'prospect_main.prospectnum as prospect_main_prospectnum',
168 'cust_main.custnum as cust_main_custnum',
169 #FS::UI::Web::cust_sql_fields(),
171 'extra_sql' => $extra_sql,
172 'order_by' => $orderby,
177 my $link = [ "${p}view/quotation.html?", 'quotationnum', ];
178 my $prospect_link = sub {
179 my $quotation = shift;
180 $quotation->prospect_main_prospectnum
181 ? [ "${p}view/prospect_main.html?", 'prospectnum' ]
185 my $cust_link = sub {
186 my $quotation = shift;
187 $quotation->cust_main_custnum
188 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
192 my $conf = new FS::Conf;
193 my $money_char = $conf->config('money_char') || '$';
195 my $html_init = join("\n", map {
196 ( my $action = $_ ) =~ s/_$//;
197 include('/elements/progress-init.html',
200 "../misc/${_}invoices.cgi",
201 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
204 qq!<FORM NAME="${_}form">!,
206 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
207 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
212 } qw( print_ email_ fax_ ftp_ spool_ ) ).
214 '<SCRIPT TYPE="text/javascript">
216 function confirm_print_process() {
217 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
222 function confirm_email_process() {
223 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
228 function confirm_fax_process() {
229 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
234 function confirm_ftp_process() {
235 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
240 function confirm_spool_process() {
241 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
251 #if ( $curuser->access_right('Resend quotations') ) {
253 # push @$menubar, emt('Print these invoices') =>
254 # "javascript:confirm_print_process()",
255 # emt('Email these invoices') =>
256 # "javascript:confirm_email_process()";
258 # push @$menubar, emt('Fax these invoices') =>
259 # "javascript:confirm_fax_process()"
260 # if $conf->exists('hylafax');
262 # push @$menubar, emt('FTP these invoices') =>
263 # "javascript:confirm_ftp_process()"
264 # if $conf->exists('cust_bill-ftpformat');
266 # push @$menubar, emt('Spool these invoices') =>
267 # "javascript:confirm_spool_process()"
268 # if $conf->exists('cust_bill-spoolformat');