c25dc3e08fccfea18d4b8162038b25ac77e20c91
[freeside.git] / httemplate / view / cust_bill.cgi
1 <& /elements/header.html, mt('Invoice View'), menubar(
2   emt("View this customer (#[_1])",$display_custnum) => "${p}view/cust_main.cgi?$custnum",
3 ) &>
4
5 <SCRIPT TYPE="text/javascript">
6 function areyousure(href, message) {
7   if (confirm(message) == true)
8     window.location.href = href;
9 }
10 </SCRIPT>
11
12 % if ( !$cust_bill->closed ) { # otherwise allow no changes
13 %   my $can_delete = $conf->exists('deleteinvoices')
14 %                    && $curuser->access_right('Delete invoices');
15 %   my $can_void = $curuser->access_right('Void invoices');
16 %   if ( $can_void ) {
17     <& /elements/popup_link.html,
18       'label'       => emt('Void this invoice'),
19       'actionlabel' => emt('Void this invoice'),
20       'action'      => $p.'misc/void-cust_bill.html?invnum='.$invnum,
21     &>
22 %   }
23 %   if ( $can_void and $can_delete ) {
24   &nbsp;|&nbsp;
25 %   }
26 %   if ( $can_delete ) {
27     <A href="" onclick="areyousure(\
28       '<%$p%>misc/delete-cust_bill.html?<% $invnum %>',\
29       <% mt('Are you sure you want to delete this invoice?') |js_string %>)"\
30     TITLE = "<% mt('Delete this invoice from the database completely') |h %>">\
31     <% emt('Delete this invoice') |h %></A>
32 %   }
33 %   if ( $can_void or $can_delete ) {
34   <BR><BR>
35 %   }
36 % }
37
38 % if ( $cust_bill->owed > 0
39 %      && scalar( grep $payby{$_}, qw(BILL CASH WEST MCRD MCHK) )
40 %      && $curuser->access_right(['Post payment', 'Post check payment', 'Post cash payment'])
41 %      && ! $conf->exists('pkg-balances')
42 %    )
43 % {
44 %     my $s = 0;
45
46       <% mt('Post') |h %> 
47
48 %     if ( $payby{'BILL'} && $curuser->access_right(['Post payment', 'Post check payment']) ) { 
49           <% $s++ ? ' | ' : '' %>
50           <A HREF="<% $p %>edit/cust_pay.cgi?payby=BILL;invnum=<% $invnum %>"><% mt('check') |h %></A>
51 %     } 
52
53 %     if ( $payby{'CASH'} && $curuser->access_right(['Post payment', 'Post cash payment']) ) { 
54           <% $s++ ? ' | ' : '' %>
55           <A HREF="<% $p %>edit/cust_pay.cgi?payby=CASH;invnum=<% $invnum %>"><% mt('cash') |h %></A>
56 %     } 
57
58 %     if ( $payby{'WEST'} && $curuser->access_right(['Post payment']) ) { 
59           <% $s++ ? ' | ' : '' %>
60           <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;invnum=<% $invnum %>"><% mt('Western Union') |h %></A>
61 %     } 
62
63 %     if ( $payby{'MCRD'} && $curuser->access_right(['Post payment']) ) { 
64           <% $s++ ? ' | ' : '' %>
65           <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;invnum=<% $invnum %>"><% mt('manual credit card') |h %></A>
66 %     } 
67
68 %     if ( $payby{'MCHK'} && $curuser->access_right(['Post payment']) ) { 
69           <% $s++ ? ' | ' : '' %>
70           <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCHK;invnum=<% $invnum %>"><% mt('manual electronic check') |h %></A>
71 %     } 
72
73       <% mt('payment against this invoice') |h %><BR><BR>
74
75 % } 
76
77 % if ( $conf->exists('cust_bill-enable_promised_date') ) {
78 %   my $onclick = include('/elements/popup_link_onclick.html',
79 %      'action'      => $p.'misc/cust_bill-promised_date.html?'.$invnum,
80 %      'actionlabel' => emt('Set promised payment date'),
81 %      'width'       => 320,
82 %      'height'      => 240,
83 %   );
84 %   $onclick = '<A HREF="#" onclick="'.$onclick.'">';
85 %   if ( $cust_bill->promised_date ) {
86 %     my $date_format = $conf->config('date_format') || '%b %o, %Y';
87       <% mt('Payment promised by [_1]', 
88             time2str($date_format, $cust_bill->promised_date) ) %>
89       (&nbsp;<% $onclick %><% mt('change') |h %></A>&nbsp;)
90       <BR><BR>
91 %   }
92 %   elsif ( $cust_bill->owed > 0 ) {
93     <% $onclick %><% mt('Set promised payment date' ) |h %></A>
94     <BR><BR>
95 %   }
96 % }
97
98 % if ( $curuser->access_right('Resend invoices') ) {
99         <A HREF="<% $p %>misc/send-invoice.cgi?method=print;<% $link %>"><% mt('Print this invoice') |h %></A>
100 % }
101
102 % if ( $conf->exists('support-key')
103 %        && $curuser->access_right('Print and mail invoices')
104 %    )
105 % {
106         | <& /elements/popup_link.html,
107                'action'      => $p."misc/post_fsinc-invoice.cgi?$link",
108                'label'       => 'Print and mail this invoice online',
109                'actionlabel' => 'Invoice printing and mailing',
110           &>
111 % }
112
113 % if ( $curuser->access_right('Resend invoices') ) {
114
115 %   if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
116         | <A HREF="<% $p %>misc/send-invoice.cgi?method=email;<% $link %>"><% mt('Re-email this invoice') |h %></A>
117 %   } 
118
119 %   if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
120         | <A HREF="<% $p %>misc/send-invoice.cgi?method=fax;<% $link %>"><% mt('Re-fax this invoice') |h %></A>
121 %   } 
122
123 % }
124
125 % if (    $curuser->access_right('Resend invoices')
126 %      || $curuser->access_right('Print and mail invoices') ) {
127         <BR><BR>
128 % } 
129
130 % my $br = 0;
131 % if ( $conf->exists('invoice_latex') ) {
132
133   <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $link %>"><% mt('View typeset invoice PDF') |h %></A>
134
135 %   $br++;
136 % } 
137
138 % if ( $cust_bill->num_cust_event ) {
139 <% $br ? '|' : '' %>
140 <A HREF="<%$p%>search/cust_event.html?invnum=<% $cust_bill->invnum %>"><% mt('View invoice events') |h %></A> 
141 %   $br++;
142 % }
143
144 % if ( $cust_bill->num_cust_bill_event ) { $br++;
145 <A HREF="<%$p%>search/cust_bill_event.cgi?invnum=<% $cust_bill->invnum %>">( <% mt('View deprecated, old-style invoice events') |h %> )</A> 
146 % }
147
148 % my @modes = grep {! $_->disabled} 
149 %   $cust_bill->cust_main->agent->invoice_modes;
150 % if ( @modes || $include_statement_template ) {
151 <% $br ? '|' : '' %>
152 <% mt('View as:') %>
153 <FORM STYLE="display:inline" ACTION="<% $cgi->url %>" METHOD="GET">
154 <INPUT NAME="invnum" VALUE="<% $invnum %>" TYPE="hidden">
155 <& /elements/select-table.html,
156   table       => 'invoice_mode',
157   field       => 'mode',
158   curr_value  => scalar($cgi->param('mode')),
159   records     => \@modes,
160   name_col    => 'modename',
161   onchange    => 'change_invoice_mode',
162   empty_label => '(default)',
163   $include_statement_template ? (
164     'post_options' => [ 'statement', '(statement)' ]
165   ) : ()
166 &>
167 <SCRIPT TYPE="text/javascript">
168 function change_invoice_mode(obj) {
169   obj.form.submit();
170 }
171 </SCRIPT>
172 % }
173
174 <BR><BR>
175
176 % if ( $conf->exists('invoice_html') && ! $cgi->param('plaintext') ) { 
177   <% join('', $cust_bill->print_html(\%opt) ) %>
178 % } else { 
179   <PRE><% join('', $cust_bill->print_text(\%opt) ) |h %></PRE>
180 % } 
181
182 <& /elements/footer.html &>
183 <%init>
184
185 my $curuser = $FS::CurrentUser::CurrentUser;
186
187 die "access denied"
188   unless $curuser->access_right('View invoices');
189
190 my $conf = FS::Conf->new;
191
192 my( $invnum, $mode, $template, $notice_name, $no_coupon );
193 my($query) = $cgi->keywords;
194 if ( $query =~ /^((.+)-)?(\d+)$/ ) {
195   $template = $2;
196   $invnum = $3;
197   $notice_name = 'Invoice';
198 } else {
199   $invnum = $cgi->param('invnum');
200   $template = $cgi->param('template');
201   $notice_name = $cgi->param('notice_name');
202   $mode = $cgi->param('mode');
203 }
204
205 if ($mode eq 'statement') {
206   $mode = undef;
207   $template = 'statement';
208   $notice_name = 'Statement';
209   $no_coupon = 1;
210 }
211
212 my $include_statement_template = $conf->config('payment_receipt_statement_mode') ? 0 : 1;
213
214 my %opt = (
215   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
216   'template'      => $template,
217   'notice_name'   => $notice_name,
218 );
219
220 $opt{'barcode_img'} = 1 if $conf->exists('invoice-barcode');
221
222 my @payby =  grep /\w/, $conf->config('payby');
223 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
224 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
225   unless @payby;
226 my %payby = map { $_=>1 } @payby;
227
228 my $cust_bill = qsearchs({
229   'select'    => 'cust_bill.*',
230   'table'     => 'cust_bill',
231   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
232   'hashref'   => { 'invnum' => $invnum },
233   'extra_sql' => ' AND '. $curuser->agentnums_sql,
234 });
235 # if we're asked for a voided invnum, redirect appropriately
236 if (!$cust_bill and FS::cust_bill_void->row_exists("invnum = $invnum") ) {
237   $m->clear_buffer;
238   my $url = $p.'view/cust_bill_void.html?'.$cgi->query_string;
239   $m->print( $cgi->redirect($url) );
240   $m->abort;
241 }
242 die "Invoice #$invnum not found!" unless $cust_bill;
243
244 $cust_bill->set('mode' => $mode);
245
246 my $custnum = $cust_bill->custnum;
247 my $display_custnum = $cust_bill->cust_main->display_custnum;
248
249 my $link = "invnum=$invnum";
250 $link .= ';mode=' . $mode if $mode;
251 $link .= ';template='. uri_escape($template) if $template;
252 $link .= ';notice_name='. $notice_name if $notice_name;
253 $link .= ';no_coupon=1' if $no_coupon;
254
255 </%init>