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,
10 'header' => [ emt('Quotation #'),
19 sub { $money_char. shift->total_setup },
20 sub { $money_char. shift->total_recur },
21 sub { time2str('%b %d %Y', shift->_date ) },
22 sub { my $prospect_main = shift->prospect_main;
23 $prospect_main ? $prospect_main->name : '';
25 sub { my $cust_main = shift->cust_main;
26 $cust_main ? $cust_main->name : '';
28 #\&FS::UI::Web::cust_fields,
32 '', #FS::quotation->total_setup_sql,
33 '', #FS::quotation->total_recur_sql,
38 'align' => 'rrrrll', #.FS::UI::Web::cust_aligns(),
46 #( map { $_ ne 'Cust. Status' ? $clink : '' }
47 # FS::UI::Web::cust_header()
56 # FS::UI::Web::cust_colors(),
64 # FS::UI::Web::cust_styles(),
69 my $curuser = $FS::CurrentUser::CurrentUser;
72 unless $curuser->access_right('List quotations');
74 my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
75 my $join_cust_main = FS::UI::Web::join_cust_main('quotation');
77 #here is the agent virtualization
78 my $agentnums_sql = ' ( '. $curuser->agentnums_sql( table=>'prospect_main' ).
79 ' OR '. $curuser->agentnums_sql( table=>'cust_main' ).
82 my( $count_query, $sql_query );
86 #if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
88 # my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
90 # $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
93 # 'table' => 'quotation',
94 # 'addl_from' => "$join_prospect_main $join_cust_main",
96 # 'extra_sql' => $where,
101 #some false laziness w/cust_bill::re_X
102 my $orderby = 'ORDER BY quotation._date';
104 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
105 $search{'agentnum'} = $1;
108 # if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
109 # $search{'refnum'} = $1;
112 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
113 $search{'prospectnum'} = $1;
116 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
117 $search{'custnum'} = $1;
120 # begin/end/beginning/ending
121 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
122 $search{'_date'} = [ $beginning, $ending ]
123 unless $beginning == 0 && $ending == 4294967295;
125 if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
126 $search{'quotationnum_min'} = $1;
128 if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
129 $search{'quotationnum_max'} = $1;
133 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
134 foreach qw( total_setup total_recur );
136 # my($query) = $cgi->keywords;
137 # if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
138 # $search{'open'} = 1 if $1;
139 # ($search{'days'}, my $field) = ($2, $3);
140 # $field = "_date" if $field eq 'date';
141 # $orderby = "ORDER BY cust_bill.$field";
144 # if ( $cgi->param('newest_percust') ) {
145 # $search{'newest_percust'} = 1;
146 # $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
149 my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
151 unless ( $count_query ) {
152 $count_query = 'SELECT COUNT(*)';
154 $count_query .= " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
157 'table' => 'quotation',
158 'addl_from' => "$join_prospect_main $join_cust_main",
160 'select' => join(', ',
162 #( map "cust_main.$_", qw(custnum last first company) ),
163 'prospect_main.prospectnum as prospect_main_prospectnum',
164 'cust_main.custnum as cust_main_custnum',
165 #FS::UI::Web::cust_sql_fields(),
167 'extra_sql' => $extra_sql,
168 'order_by' => $orderby,
173 my $link = [ "${p}view/quotation.html?", 'quotationnum', ];
174 my $prospect_link = sub {
175 my $quotation = shift;
176 $quotation->prospect_main_prospectnum
177 ? [ "${p}view/prospect_main.html?", 'prospectnum' ]
181 my $cust_link = sub {
182 my $quotation = shift;
183 $quotation->cust_main_custnum
184 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
188 my $conf = new FS::Conf;
189 my $money_char = $conf->config('money_char') || '$';
191 my $html_init = join("\n", map {
192 ( my $action = $_ ) =~ s/_$//;
193 include('/elements/progress-init.html',
196 "../misc/${_}invoices.cgi",
197 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
200 qq!<FORM NAME="${_}form">!,
202 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
203 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
208 } qw( print_ email_ fax_ ftp_ spool_ ) ).
210 '<SCRIPT TYPE="text/javascript">
212 function confirm_print_process() {
213 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
218 function confirm_email_process() {
219 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
224 function confirm_fax_process() {
225 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
230 function confirm_ftp_process() {
231 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
236 function confirm_spool_process() {
237 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
247 #if ( $curuser->access_right('Resend quotations') ) {
249 # push @$menubar, emt('Print these invoices') =>
250 # "javascript:confirm_print_process()",
251 # emt('Email these invoices') =>
252 # "javascript:confirm_email_process()";
254 # push @$menubar, emt('Fax these invoices') =>
255 # "javascript:confirm_fax_process()"
256 # if $conf->exists('hylafax');
258 # push @$menubar, emt('FTP these invoices') =>
259 # "javascript:confirm_ftp_process()"
260 # if $conf->exists('cust_bill-ftpformat');
262 # push @$menubar, emt('Spool these invoices') =>
263 # "javascript:confirm_spool_process()"
264 # if $conf->exists('cust_bill-spoolformat');