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