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