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