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