Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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) )
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       <% mt('payment against this invoice') |h %><BR><BR>
58
59 % } 
60
61 % if ( $conf->exists('cust_bill-enable_promised_date') ) {
62 %   my $onclick = include('/elements/popup_link_onclick.html',
63 %      'action'      => $p.'misc/cust_bill-promised_date.html?'.$invnum,
64 %      'actionlabel' => emt('Set promised payment date'),
65 %      'width'       => 320,
66 %      'height'      => 240,
67 %   );
68 %   $onclick = '<A HREF="#" onclick="'.$onclick.'">';
69 %   if ( $cust_bill->promised_date ) {
70 %     my $date_format = $conf->config('date_format') || '%b %o, %Y';
71       <% mt('Payment promised by [_1]', 
72             time2str($date_format, $cust_bill->promised_date) ) %>
73       (&nbsp;<% $onclick %><% mt('change') |h %></A>&nbsp;)
74       <BR><BR>
75 %   }
76 %   elsif ( $cust_bill->owed > 0 ) {
77     <% $onclick %><% mt('Set promised payment date' ) |h %></A>
78     <BR><BR>
79 %   }
80 % }
81
82 % if ( $curuser->access_right('Resend invoices') ) {
83
84     <A HREF="<% $p %>misc/send-invoice.cgi?method=print;<% $link %>"><% mt('Re-print this invoice') |h %></A>
85
86 %   if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
87         | <A HREF="<% $p %>misc/send-invoice.cgi?method=email;<% $link %>"><% mt('Re-email this invoice') |h %></A>
88 %   } 
89
90 %   if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
91         | <A HREF="<% $p %>misc/send-invoice.cgi?method=fax;<% $link %>"><% mt('Re-fax this invoice') |h %></A>
92 %   } 
93
94     <BR><BR>
95
96 % } 
97
98 % if ( $conf->exists('invoice_latex') ) { 
99
100   <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $link %>"><% mt('View typeset invoice PDF') |h %></A>
101   <BR><BR>
102 % } 
103
104 % my $br = 0;
105 % if ( $cust_bill->num_cust_event ) { $br++;
106 <A HREF="<%$p%>search/cust_event.html?invnum=<% $cust_bill->invnum %>">( <% mt('View invoice events') |h %> )</A> 
107 % }
108
109 % if ( $cust_bill->num_cust_bill_event ) { $br++;
110 <A HREF="<%$p%>search/cust_bill_event.cgi?invnum=<% $cust_bill->invnum %>">( <% mt('View deprecated, old-style invoice events') |h %> )</A> 
111 % }
112
113 % my @modes = grep {! $_->disabled} 
114 %   $cust_bill->cust_main->agent->invoice_modes;
115 % if ( @modes ) {
116 ( <% mt('View as:') %>
117 <FORM STYLE="display:inline" ACTION="<% $cgi->url %>" METHOD="GET">
118 <INPUT NAME="invnum" VALUE="<% $invnum %>" TYPE="hidden">
119 <& /elements/select-table.html,
120   table       => 'invoice_mode',
121   field       => 'mode',
122   curr_value  => scalar($cgi->param('mode')),
123   records     => \@modes,
124   name_col    => 'modename',
125   onchange    => 'change_invoice_mode',
126   empty_label => '(default)',
127 &> )
128 <SCRIPT TYPE="text/javascript">
129 function change_invoice_mode(obj) {
130   obj.form.submit();
131 }
132 </SCRIPT>
133 % $br++;
134 % }
135
136 <% $br ? '<BR><BR>' : '' %>
137
138 % if ( $conf->exists('invoice_html') ) { 
139   <% join('', $cust_bill->print_html(\%opt) ) %>
140 % } else { 
141   <PRE><% join('', $cust_bill->print_text(\%opt) ) %></PRE>
142 % } 
143
144 <& /elements/footer.html &>
145 <%init>
146
147 my $curuser = $FS::CurrentUser::CurrentUser;
148
149 die "access denied"
150   unless $curuser->access_right('View invoices');
151
152 my $conf = FS::Conf->new;
153
154 my( $invnum, $mode, $template, $notice_name );
155 my($query) = $cgi->keywords;
156 if ( $query =~ /^((.+)-)?(\d+)$/ ) {
157   $template = $2;
158   $invnum = $3;
159   $notice_name = 'Invoice';
160 } else {
161   $invnum = $cgi->param('invnum');
162   $template = $cgi->param('template');
163   $notice_name = $cgi->param('notice_name');
164   $mode = $cgi->param('mode');
165 }
166
167 my %opt = (
168   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
169   'template'      => $template,
170   'notice_name'   => $notice_name,
171 );
172
173 $opt{'barcode_img'} = 1 if $conf->exists('invoice-barcode');
174
175 my @payby =  grep /\w/, $conf->config('payby');
176 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
177 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
178   unless @payby;
179 my %payby = map { $_=>1 } @payby;
180
181 my $cust_bill = qsearchs({
182   'select'    => 'cust_bill.*',
183   'table'     => 'cust_bill',
184   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
185   'hashref'   => { 'invnum' => $invnum },
186   'extra_sql' => ' AND '. $curuser->agentnums_sql,
187 });
188 die "Invoice #$invnum not found!" unless $cust_bill;
189
190 $cust_bill->set('mode' => $mode);
191
192 my $custnum = $cust_bill->custnum;
193 my $display_custnum = $cust_bill->cust_main->display_custnum;
194
195 my $link = "invnum=$invnum";
196 $link .= ';mode=' . $mode if $mode;
197 $link .= ';template='. uri_escape($template) if $template;
198 $link .= ';notice_name='. $notice_name if $notice_name;
199
200 </%init>