cf0c3190a66e61b4c51a4d57378d923c265139c4
[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 %      && $curuser->access_right(['Post payment', 'Post check payment', 'Post cash payment'])
40 %      && ! $conf->exists('pkg-balances')
41 %    )
42 % {
43 %     my $s = 0;
44
45       <% mt('Post') |h %> 
46
47 %     if ( $curuser->access_right(['Post payment', 'Post check payment']) ) { 
48           <% $s++ ? ' | ' : '' %>
49           <A HREF="<% $p %>edit/cust_pay.cgi?payby=BILL;invnum=<% $invnum %>"><% mt('check') |h %></A>
50 %     } 
51
52 %     if ( $curuser->access_right(['Post payment', 'Post cash payment']) ) { 
53           <% $s++ ? ' | ' : '' %>
54           <A HREF="<% $p %>edit/cust_pay.cgi?payby=CASH;invnum=<% $invnum %>"><% mt('cash') |h %></A>
55 %     } 
56
57 %#  %     if ( $payby{'WEST'} && $curuser->access_right(['Post payment']) ) { 
58 %#            <% $s++ ? ' | ' : '' %>
59 %#            <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;invnum=<% $invnum %>"><% mt('Western Union') |h %></A>
60 %#  %     } 
61 %#  
62 %#  %     if ( $payby{'MCRD'} && $curuser->access_right(['Post payment']) ) { 
63 %#            <% $s++ ? ' | ' : '' %>
64 %#            <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;invnum=<% $invnum %>"><% mt('manual credit card') |h %></A>
65 %#  %     } 
66 %#  
67 %#  %     if ( $payby{'MCHK'} && $curuser->access_right(['Post payment']) ) { 
68 %#            <% $s++ ? ' | ' : '' %>
69 %#            <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCHK;invnum=<% $invnum %>"><% mt('manual electronic check') |h %></A>
70 %#  %     } 
71
72       <% mt('payment against this invoice') |h %><BR><BR>
73
74 % } 
75
76 % if ( $conf->exists('cust_bill-enable_promised_date') ) {
77 %   my $onclick = include('/elements/popup_link_onclick.html',
78 %      'action'      => $p.'misc/cust_bill-promised_date.html?'.$invnum,
79 %      'actionlabel' => emt('Set promised payment date'),
80 %      'width'       => 320,
81 %      'height'      => 240,
82 %   );
83 %   $onclick = '<A HREF="#" onclick="'.$onclick.'">';
84 %   if ( $cust_bill->promised_date ) {
85 %     my $date_format = $conf->config('date_format') || '%b %o, %Y';
86       <% mt('Payment promised by [_1]', 
87             time2str($date_format, $cust_bill->promised_date) ) %>
88       (&nbsp;<% $onclick %><% mt('change') |h %></A>&nbsp;)
89       <BR><BR>
90 %   }
91 %   elsif ( $cust_bill->owed > 0 ) {
92     <% $onclick %><% mt('Set promised payment date' ) |h %></A>
93     <BR><BR>
94 %   }
95 % }
96
97 % if ( $curuser->access_right('Resend invoices') ) {
98
99     <A HREF="<% $p %>misc/send-invoice.cgi?method=print;<% $link %>"><% mt('Re-print this invoice') |h %></A>
100
101 %   if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
102         | <A HREF="<% $p %>misc/send-invoice.cgi?method=email;<% $link %>"><% mt('Re-email this invoice') |h %></A>
103 %   } 
104
105 %   if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
106         | <A HREF="<% $p %>misc/send-invoice.cgi?method=fax;<% $link %>"><% mt('Re-fax this invoice') |h %></A>
107 %   } 
108
109     <BR><BR>
110
111 % } 
112
113 % my $br = 0;
114 % if ( $conf->exists('invoice_latex') ) {
115
116   <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $link %>"><% mt('View typeset invoice PDF') |h %></A>
117
118 %   $br++;
119 % } 
120
121 % if ( $cust_bill->num_cust_event ) {
122 <% $br ? '|' : '' %>
123 <A HREF="<%$p%>search/cust_event.html?invnum=<% $cust_bill->invnum %>"><% mt('View invoice events') |h %></A> 
124 %   $br++;
125 % }
126
127 % my @modes = grep {! $_->disabled} 
128 %   $cust_bill->cust_main->agent->invoice_modes;
129 % if ( @modes || $include_statement_template ) {
130 <% $br ? '|' : '' %>
131 <% mt('View as:') %>
132 <FORM STYLE="display:inline" ACTION="<% $cgi->url %>" METHOD="GET">
133 <INPUT NAME="invnum" VALUE="<% $invnum %>" TYPE="hidden">
134 <& /elements/select-table.html,
135   table       => 'invoice_mode',
136   field       => 'mode',
137   curr_value  => scalar($cgi->param('mode')),
138   records     => \@modes,
139   name_col    => 'modename',
140   onchange    => 'change_invoice_mode',
141   empty_label => '(default)',
142   $include_statement_template ? (
143     'post_options' => [ 'statement', '(statement)' ]
144   ) : ()
145 &>
146 <SCRIPT TYPE="text/javascript">
147 function change_invoice_mode(obj) {
148   obj.form.submit();
149 }
150 </SCRIPT>
151 % }
152
153 <BR><BR>
154
155 % if ( $conf->exists('invoice_html') && ! $cgi->param('plaintext') ) { 
156   <% join('', $cust_bill->print_html(\%opt) ) %>
157 % } else { 
158   <PRE><% join('', $cust_bill->print_text(\%opt) ) |h %></PRE>
159 % } 
160
161 <& /elements/footer.html &>
162 <%init>
163
164 my $curuser = $FS::CurrentUser::CurrentUser;
165
166 die "access denied"
167   unless $curuser->access_right('View invoices');
168
169 my $conf = FS::Conf->new;
170
171 my( $invnum, $mode, $template, $notice_name, $no_coupon );
172 my($query) = $cgi->keywords;
173 if ( $query =~ /^((.+)-)?(\d+)$/ ) {
174   $template = $2;
175   $invnum = $3;
176   $notice_name = 'Invoice';
177 } else {
178   $invnum = $cgi->param('invnum');
179   $template = $cgi->param('template');
180   $notice_name = $cgi->param('notice_name');
181   $mode = $cgi->param('mode');
182 }
183
184 if ($mode eq 'statement') {
185   $mode = undef;
186   $template = 'statement';
187   $notice_name = 'Statement';
188   $no_coupon = 1;
189 }
190
191 my $include_statement_template = $conf->config('payment_receipt_statement_mode') ? 0 : 1;
192
193 my %opt = (
194   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
195   'template'      => $template,
196   'notice_name'   => $notice_name,
197 );
198
199 $opt{'barcode_img'} = 1 if $conf->exists('invoice-barcode');
200
201 my $cust_bill = qsearchs({
202   'select'    => 'cust_bill.*',
203   'table'     => 'cust_bill',
204   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
205   'hashref'   => { 'invnum' => $invnum },
206   'extra_sql' => ' AND '. $curuser->agentnums_sql,
207 });
208 # if we're asked for a voided invnum, redirect appropriately
209 if (!$cust_bill and FS::cust_bill_void->row_exists("invnum = $invnum") ) {
210   $m->clear_buffer;
211   my $url = $p.'view/cust_bill_void.html?'.$cgi->query_string;
212   $m->print( $cgi->redirect($url) );
213   $m->abort;
214 }
215 die "Invoice #$invnum not found!" unless $cust_bill;
216
217 $cust_bill->set('mode' => $mode);
218
219 my $custnum = $cust_bill->custnum;
220 my $display_custnum = $cust_bill->cust_main->display_custnum;
221
222 my $link = "invnum=$invnum";
223 $link .= ';mode=' . $mode if $mode;
224 $link .= ';template='. uri_escape($template) if $template;
225 $link .= ';notice_name='. $notice_name if $notice_name;
226 $link .= ';no_coupon=1' if $no_coupon;
227
228 </%init>