disable quotations, 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 my $join_prospect_main = 'LEFT JOIN prospect_main USING ( prospectnum )';
77 my $join_cust_main = FS::UI::Web::join_cust_main('quotation');
78
79 #here is the agent virtualization
80 my $agentnums_sql = ' (    '. $curuser->agentnums_sql( table=>'prospect_main' ).
81                     '   OR '. $curuser->agentnums_sql( table=>'cust_main' ).
82                     ' )    ';
83
84 my( $count_query, $sql_query );
85 my $count_addl = '';
86 my %search;
87
88 #if ( $cgi->param('quotationnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
89 #
90 #  my $where = "WHERE quotationnum = $2 AND $agentnums_sql";
91 #  
92 #  $count_query = "SELECT COUNT(*) FROM quotation $join_prospect_main $join_cust_main $where";
93 #
94 #  $sql_query = {
95 #    'table'     => 'quotation',
96 #    'addl_from' => "$join_prospect_main $join_cust_main",
97 #    'hashref'   => {},
98 #    'extra_sql' => $where,
99 #  };
100 #
101 #} else {
102
103   #some false laziness w/cust_bill::re_X
104   my $orderby = 'ORDER BY quotation._date';
105
106   if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
107     $search{'agentnum'} = $1;
108   }
109
110 #  if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
111 #    $search{'refnum'} = $1;
112 #  }
113
114   if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
115     $search{'prospectnum'} = $1;
116   }
117
118   if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
119     $search{'custnum'} = $1;
120   }
121
122   # begin/end/beginning/ending
123   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
124   $search{'_date'} = [ $beginning, $ending ]
125     unless $beginning == 0 && $ending == 4294967295;
126
127   if ( $cgi->param('quotationnum_min') =~ /^\s*(\d+)\s*$/ ) {
128     $search{'quotationnum_min'} = $1;
129   }
130   if ( $cgi->param('quotationnum_max') =~ /^\s*(\d+)\s*$/ ) {
131     $search{'quotationnum_max'} = $1;
132   }
133
134   #amounts
135   $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
136     foreach qw( total_setup total_recur );
137
138 #  my($query) = $cgi->keywords;
139 #  if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
140 #    $search{'open'} = 1 if $1;
141 #    ($search{'days'}, my $field) = ($2, $3);
142 #    $field = "_date" if $field eq 'date';
143 #    $orderby = "ORDER BY cust_bill.$field";
144 #  }
145
146 #  if ( $cgi->param('newest_percust') ) {
147 #    $search{'newest_percust'} = 1;
148 #    $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
149 #  }
150
151   my $extra_sql = ' WHERE '. FS::quotation->search_sql_where( \%search );
152
153   unless ( $count_query ) {
154     $count_query = 'SELECT COUNT(*)';
155   }
156   $count_query .=  " FROM quotation $join_prospect_main $join_cust_main $extra_sql";
157
158   $sql_query = {
159     'table'     => 'quotation',
160     'addl_from' => "$join_prospect_main $join_cust_main",
161     'hashref'   => {},
162     'select'    => join(', ',
163                      'quotation.*',
164                      #( map "cust_main.$_", qw(custnum last first company) ),
165                      'prospect_main.prospectnum as prospect_main_prospectnum',
166                      'cust_main.custnum as cust_main_custnum',
167                      #FS::UI::Web::cust_sql_fields(),
168                    ),
169     'extra_sql' => $extra_sql,
170     'order_by'  => $orderby,
171   };
172
173 #}
174
175 my $link  = [ "${p}view/quotation.html?", 'quotationnum', ];
176 my $prospect_link = sub {
177   my $quotation = shift;
178   $quotation->prospect_main_prospectnum
179     ? [ "${p}view/prospect_main.html?", 'prospectnum' ]
180     : '';
181 };
182
183 my $cust_link = sub {
184   my $quotation = shift;
185   $quotation->cust_main_custnum
186     ? [ "${p}view/cust_main.cgi?", 'custnum' ]
187     : '';
188 };
189
190 my $conf = new FS::Conf;
191 my $money_char = $conf->config('money_char') || '$';
192
193 my $html_init = join("\n", map {
194  ( my $action = $_ ) =~ s/_$//;
195  include('/elements/progress-init.html',
196            $_.'form',
197            [ keys %search ],
198            "../misc/${_}invoices.cgi",
199            { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
200            $_, #key
201         ),
202  qq!<FORM NAME="${_}form">!,
203  ( map { my $f = $_;
204          my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
205          map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
206        }
207        keys %search
208  ),
209  qq!</FORM>!
210 } qw( print_ email_ fax_ ftp_ spool_ ) ). 
211
212 '<SCRIPT TYPE="text/javascript">
213
214 function confirm_print_process() {
215   if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
216     return;
217   }
218   print_process();
219 }
220 function confirm_email_process() {
221   if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
222     return;
223   }
224   email_process();
225 }
226 function confirm_fax_process() {
227   if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
228     return;
229   }
230   fax_process();
231 }
232 function confirm_ftp_process() {
233   if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
234     return;
235   }
236   ftp_process();
237 }
238 function confirm_spool_process() {
239   if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
240     return;
241   }
242   spool_process();
243 }
244
245 </SCRIPT>';
246
247 my $menubar = [];
248
249 #if ( $curuser->access_right('Resend quotations') ) {
250 #
251 #  push @$menubar, emt('Print these invoices') =>
252 #                    "javascript:confirm_print_process()",
253 #                  emt('Email these invoices') =>
254 #                    "javascript:confirm_email_process()";
255 #
256 #  push @$menubar, emt('Fax these invoices') =>
257 #                    "javascript:confirm_fax_process()"
258 #    if $conf->exists('hylafax');
259 #
260 #  push @$menubar, emt('FTP these invoices') =>
261 #                    "javascript:confirm_ftp_process()"
262 #    if $conf->exists('cust_bill-ftpformat');
263 #
264 #  push @$menubar, emt('Spool these invoices') =>
265 #                    "javascript:confirm_spool_process()"
266 #    if $conf->exists('cust_bill-spoolformat');
267 #
268 #}
269
270 </%init>