[Astpp-commit] SF.net SVN: astpp:[2267] trunk
Brought to you by:
darrenkw
|
From: <dar...@us...> - 2009-10-01 04:43:55
|
Revision: 2267
http://astpp.svn.sourceforge.net/astpp/?rev=2267&view=rev
Author: darrenkw
Date: 2009-10-01 04:43:47 +0000 (Thu, 01 Oct 2009)
Log Message:
-----------
Committed code to allow viewing invoices in HTML. The html is stored in a template and can easily be modified to suit your requirements.
Modified Paths:
--------------
trunk/scripts/astpp-common.pl
trunk/templates/invoice.tpl
trunk/web_interface/astpp-admin.cgi
Modified: trunk/scripts/astpp-common.pl
===================================================================
--- trunk/scripts/astpp-common.pl 2009-10-01 03:21:35 UTC (rev 2266)
+++ trunk/scripts/astpp-common.pl 2009-10-01 04:43:47 UTC (rev 2267)
@@ -324,8 +324,22 @@
return $trunkdata;
}
+sub get_invoice() {
+ my ( $astpp_db, $invoiceid ) = @_;
+ my ( $sql, $invoicedata );
+ $sql =
+ $astpp_db->prepare(
+ "SELECT * FROM invoice_list_view WHERE invoiceid = " . $astpp_db->quote($invoiceid) );
+ $sql->execute;
+ $invoicedata = $sql->fetchrow_hashref;
+ $sql->finish;
+ return $invoicedata;
+}
+
# This is used by calling cards as well as lcr. Pass on the phone number as well as the trunk to use. It will return the dialstring
# for Asterisk(tm).
+# This is used by calling cards as well as lcr. Pass on the phone number as well as the trunk to use. It will return the dialstring
+# for Asterisk(tm).
sub get_dial_string() {
my ( $astpp_db, $route, $phone ) = @_;
my ( $sql, $trunkdata, $dialstring );
@@ -1655,8 +1669,20 @@
$sql->execute;
$accountdata = $sql->fetchrow_hashref;
$sql->finish;
+ }
+ if ($accountdata) {
+ return $accountdata;
+ } else {
+ $sql =
+ $astpp_db->prepare( "SELECT * FROM accounts WHERE accountid = "
+ . $astpp_db->quote($accountno)
+ . " AND status = 1" );
+ $sql->execute;
+ $accountdata = $sql->fetchrow_hashref;
+ $sql->finish;
return $accountdata;
}
+
}
@@ -1681,8 +1707,20 @@
$sql->execute;
$accountdata = $sql->fetchrow_hashref;
$sql->finish;
+ }
+ if ($accountdata) {
+ return $accountdata;
+ } else {
+ $sql =
+ $astpp_db->prepare( "SELECT * FROM accounts WHERE accountid = "
+ . $astpp_db->quote($accountno)
+ . " AND status = 1" );
+ $sql->execute;
+ $accountdata = $sql->fetchrow_hashref;
+ $sql->finish;
return $accountdata;
}
+
}
# Go looking for account by CC number.
Modified: trunk/templates/invoice.tpl
===================================================================
--- trunk/templates/invoice.tpl 2009-10-01 03:21:35 UTC (rev 2266)
+++ trunk/templates/invoice.tpl 2009-10-01 04:43:47 UTC (rev 2267)
@@ -1,14 +1,76 @@
+<div align="center">
+ <table width="100%" border="0">
+ <tr>
+ <td width="50%">VOIP Wholesale Company</td>
+ <td><div align="right">www.astpp.org</div></td>
+ </tr>
+ <tr>
+ <td width="50%">123 Street</td>
+ <td><div align="right">(800) 555-1212</div></td>
+ </tr>
+ <tr>
+ <td width="50%">City, Province</td>
+ <td><div align="right">su...@as...</div></td>
+ </tr>
+ <tr>
+ <td width="50%">Canada</td>
+ <td><div align="right"></div></td>
+ </tr>
+ </table>
+ <hr />
+ <p>I N V O I C E
+</p>
+</div>
-
-<table class="default">
+<div align="left">
+<table border="0">
+<tr><td>
+To:
+</td></tr>
+<tr><td>
+<TMPL_VAR NAME="firstname"> <TMPL_VAR NAME="lastname">
+</td></tr>
+<tr><td>
+<TMPL_VAR NAME="company_name">
+</td></tr>
+<tr><td>
+<TMPL_VAR NAME="address_1">
+</td></tr>
+<tr><td>
+<TMPL_VAR NAME="address_2">
+</td></tr>
+<tr><td>
+<TMPL_VAR NAME="address_3">
+</td></tr>
+<tr><td>
+<TMPL_VAR NAME="city">, <TMPL_VAR NAME="province"> <TMPL_VAR NAME="postal_code">
+</td></tr>
+<tr><td>
+<TMPL_VAR NAME="country"></pre>
+</td></tr>
+</table>
+</div>
+<table width="100%" border="1" cellspacing="0">
+ <tr>
+ <td width="33.3%"><div align="center">Account ID</div></td>
+ <td width="33.3%"><div align="center">Invoice Number</div></td>
+ <td width="33.3%"><div align="center">Invoice Date</div></td>
+ </tr>
+ <tr>
+ <td><div align="center"><TMPL_VAR NAME="accountid"></div></td>
+ <td><div align="center"><TMPL_VAR NAME="invoiceid"></div></td>
+ <td><div align="center"><TMPL_VAR NAME="invoicedate"></div></td>
+ </tr>
+</table>
+<p> </p>
+<table width="100%" class="default">
<tr class="header">
- <td>Date & Time</td>
- <td>Caller*ID</td>
- <td>Called Number</td>
- <td>Disposition</td>
- <td>Billable Seconds</td>
- <td>Charge</td>
- <td>Notes</td>
+ <td width="20%">Date & Time</td>
+ <td width="20%">Caller*ID</td>
+ <td width="20%">Called Number</td>
+ <td width="20%">Disposition</td>
+ <td width="10%">Duration</td>
+ <td width="10%">Charge</td>
</tr>
<TMPL_LOOP NAME="invoice_cdr_list">
<TR>
@@ -17,9 +79,24 @@
<TD><TMPL_VAR NAME="callednum"></TD>
<TD><TMPL_VAR NAME="disposition"></TD>
<TD><TMPL_VAR NAME="billseconds"></TD>
- <TD><TMPL_VAR NAME="charge"></TD>
- <TD><TMPL_VAR NAME="notes"></TD>
+ <TD><div align="right"><TMPL_VAR NAME="charge"></div></TD>
</TR>
</TMPL_LOOP>
</table>
-
+<br>
+<table width="100%" class="default">
+ <tr class="header">
+ <td width="40%"></td>
+ <td width="20%">Title</td>
+ <td width="20%">Text</td>
+ <td width="20%">Fee</td>
+ </tr>
+ <TMPL_LOOP NAME="invoice_total_list">
+ <TR>
+ <TD></td>
+ <TD><TMPL_VAR NAME="title"></TD>
+ <TD><TMPL_VAR NAME="text"></TD>
+ <TD><div align="right"><TMPL_VAR NAME="value"></div></TD>
+ </TR>
+ </TMPL_LOOP>
+</table>
Modified: trunk/web_interface/astpp-admin.cgi
===================================================================
--- trunk/web_interface/astpp-admin.cgi 2009-10-01 03:21:35 UTC (rev 2266)
+++ trunk/web_interface/astpp-admin.cgi 2009-10-01 04:43:47 UTC (rev 2267)
@@ -428,6 +428,8 @@
return &build_view_cdrs() if $params->{mode} eq gettext("View CDRs");
return &build_configuration()
if $params->{mode} eq gettext("Configuration");
+ return &build_view_invoice()
+ if $params->{mode} eq gettext("View Invoice");
return &build_add_callshop()
if $params->{mode} eq gettext("Create CallShop");
@@ -2394,6 +2396,61 @@
return $status;
}
+sub build_view_invoice() {
+ my ($tmp,$sql,$body, $status, @cdr_list,@total_list);
+ my $template = HTML::Template->new(
+ filename => '/var/lib/astpp/templates/invoice.tpl',
+ die_on_bad_params => $config->{template_die_on_bad_params}
+ );
+ return gettext("Database is NOT configured!") . " \n" unless $astpp_db;
+ return gettext("No Invoice Selected!") . " \n" unless $params->{invoiceid};
+ $params->{format} = "html" if !$params->{format};
+
+ $tmp = "SELECT * FROM cdrs WHERE invoiceid = "
+ . $astpp_db->quote($params->{invoiceid});
+ $sql = $astpp_db->prepare($tmp);
+ $sql->execute;
+
+ while ( my $cdr = $sql->fetchrow_hashref ) {
+ $cdr->{charge} = ($cdr->{debit} - $cdr->{credit}) / 10000;
+ $cdr->{charge} = sprintf( "%." . $config->{decimalpoints} . "f", $cdr->{charge} );
+ push( @cdr_list, $cdr );
+ }
+ $template->param( invoice_cdr_list => \@cdr_list );
+
+ $tmp = "SELECT * FROM invoices_total WHERE invoices_id = "
+ . $astpp_db->quote($params->{invoiceid})
+ . " ORDER BY sort_order";
+ $sql = $astpp_db->prepare($tmp);
+ $sql->execute;
+
+ while ( my $total = $sql->fetchrow_hashref ) {
+# $cdr->{charge} = ($cdr->{debit} - $cdr->{credit}) / 10000;
+# $cdr->{charge} = sprintf( "%." . $config->{decimalpoints} . "f", $cdr->{charge} );
+ push( @total_list, $total );
+ }
+ $template->param( invoice_total_list => \@total_list );
+
+ my $invoicedata = &get_invoice( $astpp_db, $params->{invoiceid});
+ $template->param( invoiceid => $invoicedata->{invoiceid} );
+ $template->param( invoicedate => $invoicedata->{date} );
+ $template->param( accountid => $invoicedata->{accountid} );
+
+ my $accountinfo = &get_account_including_closed( $astpp_db, $invoicedata->{accountid} );
+ $template->param( first_name => $accountinfo->{first_name} );
+ $template->param( last_name => $accountinfo->{last_name} );
+ $template->param( company => $accountinfo->{company} );
+ $template->param( address_1 => $accountinfo->{address_1} );
+ $template->param( address_2 => $accountinfo->{address_2} );
+ $template->param( address_3 => $accountinfo->{address_3} );
+ $template->param( city => $accountinfo->{city} );
+ $template->param( province => $accountinfo->{province} );
+ $template->param( country => $accountinfo->{country} );
+ $template->param( postal_code => $accountinfo->{postal_code} );
+
+ return $template->output;
+}
+
sub build_create_account() {
my ( @pricelists, $status, $body );
my $template = HTML::Template->new(
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|