disable quotations without fully-qualifying all other searches, RT#20688, RT#22232
[freeside.git] / httemplate / search / quotation.html
1 <& elements/search.html,
2                  'title'              => emt('Quotation Search Results'),
3                  'html_init'          => $html_init,
4                  'menubar'            => $menubar,
5                  'name'               => 'quotations',
6                  'query'              => $sql_query,
7                  'count_query'        => $count_query,
8                  'count_addl'         => $count_addl,
9                  'redirect'           => $link,
10                  'disableable'        => 1,
11                  'disabled_statuspos' => 1,
12                  'header'             => [ emt('Quotation #'),
13                                            emt('Setup'),
14                                            emt('Recurring'),
15                                            emt('Date'),
16                                            emt('Prospect'),
17                                            emt('Customer'),
18                                          ],
19                  'fields'             => [
20                    'quotationnum',
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 : '';
26                        },
27                    sub { my $cust_main = shift->cust_main;
28                          $cust_main ? $cust_main->name : '';
29                        },
30                    #\&FS::UI::Web::cust_fields,
31                  ],
32                  'sort_fields'        => [
33                    'quotationnum',
34                    '', #FS::quotation->total_setup_sql,
35                    '', #FS::quotation->total_recur_sql,
36                    '_date',
37                    '',
38                    '',
39                  ],
40                  'align' => 'rrrrll', #.FS::UI::Web::cust_aligns(),
41                  'links' => [
42                    $link,
43                    $link,
44                    $link,
45                    $link,
46                    $prospect_link,
47                    $cust_link,
48                    #( map { $_ ne 'Cust. Status' ? $cust_link : '' }
49                    #      FS::UI::Web::cust_header()
50                    #),
51                  ],
52 #                 'color' => [ 
53 #                              '',
54 #                              '',
55 #                              '',
56 #                              '',
57 #                              '',
58 #                              FS::UI::Web::cust_colors(),
59 #                            ],
60 #                 'style' => [ 
61 #                              '',
62 #                              '',
63 #                              '',
64 #                              '',
65 #                              '',
66 #                              FS::UI::Web::cust_styles(),
67 #                            ],
68 &>
69 <%init>
70
71 my $curuser = $FS::CurrentUser::CurrentUser;
72
73 die "access denied"
74   unless $curuser->access_right('List quotations');
75
76 local($FS::Record::qsearch_qualify_columns) = 1;
77
78 my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
79 my $join_cust_main = FS::UI::Web::join_cust_main('quotation');
80
81 #here is the agent virtualization
82 my $agentnums_sql = ' (    '. $curuser->agentnums_sql( table=>'prospect_main' ).
83                     '   OR '. $curuser->agentnums_sql( table=>'cust_main' ).
84                     ' )    ';
85
86 my( $count_query, $sql_query );
87 my $count_addl = '';
88 my %search;
89
90 #if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
91 #
92 #  my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
93 #  
94 #  $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
95 #
96 #  $sql_query = {
97 #    'table'     => 'quotation',
98 #    'addl_from' => "$join_prospect_main $join_cust_main",
99 #    'hashref'   => {},
100 #    'extra_sql' => $where,
101 #  };
102 #
103 #} else {
104
105   #some false laziness w/cust_bill::re_X
106   my $orderby = 'ORDER BY quotation._date';
107
108   if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
109     $search{'agentnum'} = $1;
110   }
111
112 #  if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
113 #    $search{'refnum'} = $1;
114 #  }
115
116   if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
117     $search{'prospectnum'} = $1;
118   }
119
120   if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
121     $search{'custnum'} = $1;
122   }
123
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;
128
129   if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
130     $search{'quotationnum_min'} = $1;
131   }
132   if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
133     $search{'quotationnum_max'} = $1;
134   }
135
136   #amounts
137   $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
138     foreach qw( total_setup total_recur );
139
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";
146 #  }
147
148 #  if ( $cgi->param('newest_percust') ) {
149 #    $search{'newest_percust'} = 1;
150 #    $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
151 #  }
152
153   my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
154
155   unless ( $count_query ) {
156     $count_query = 'SELECT COUNT(*)';
157   }
158   $count_query .=  " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
159
160   $sql_query = {
161     'table'     => 'quotation',
162     'addl_from' => "$join_prospect_main $join_cust_main",
163     'hashref'   => {},
164     'select'    => join(', ',
165                      'quotation.*',
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(),
170                    ),
171     'extra_sql' => $extra_sql,
172     'order_by'  => $orderby,
173   };
174
175 #}
176
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' ]
182     : '';
183 };
184
185 my $cust_link = sub {
186   my $quotation = shift;
187   $quotation->cust_main_custnum
188     ? [ "${p}view/cust_main.cgi?", 'custnum' ]
189     : '';
190 };
191
192 my $conf = new FS::Conf;
193 my $money_char = $conf->config('money_char') || '$';
194
195 my $html_init = join("\n", map {
196  ( my $action = $_ ) =~ s/_$//;
197  include('/elements/progress-init.html',
198            $_.'form',
199            [ keys %search ],
200            "../misc/${_}invoices.cgi",
201            { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
202            $_, #key
203         ),
204  qq!<FORM NAME="${_}form">!,
205  ( map { my $f = $_;
206          my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
207          map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
208        }
209        keys %search
210  ),
211  qq!</FORM>!
212 } qw( print_ email_ fax_ ftp_ spool_ ) ). 
213
214 '<SCRIPT TYPE="text/javascript">
215
216 function confirm_print_process() {
217   if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
218     return;
219   }
220   print_process();
221 }
222 function confirm_email_process() {
223   if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
224     return;
225   }
226   email_process();
227 }
228 function confirm_fax_process() {
229   if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
230     return;
231   }
232   fax_process();
233 }
234 function confirm_ftp_process() {
235   if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
236     return;
237   }
238   ftp_process();
239 }
240 function confirm_spool_process() {
241   if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
242     return;
243   }
244   spool_process();
245 }
246
247 </SCRIPT>';
248
249 my $menubar = [];
250
251 #if ( $curuser->access_right('Resend quotations') ) {
252 #
253 #  push @$menubar, emt('Print these invoices') =>
254 #                    "javascript:confirm_print_process()",
255 #                  emt('Email these invoices') =>
256 #                    "javascript:confirm_email_process()";
257 #
258 #  push @$menubar, emt('Fax these invoices') =>
259 #                    "javascript:confirm_fax_process()"
260 #    if $conf->exists('hylafax');
261 #
262 #  push @$menubar, emt('FTP these invoices') =>
263 #                    "javascript:confirm_ftp_process()"
264 #    if $conf->exists('cust_bill-ftpformat');
265 #
266 #  push @$menubar, emt('Spool these invoices') =>
267 #                    "javascript:confirm_spool_process()"
268 #    if $conf->exists('cust_bill-spoolformat');
269 #
270 #}
271
272 </%init>