[freeside-commits] freeside/FS/FS Conf.pm, 1.320, 1.321 Schema.pm, 1.166, 1.167 Upgrade.pm, 1.30, 1.31 cust_bill.pm, 1.256, 1.257 cust_bill_pkg.pm, 1.40, 1.41 cust_bill_pkg_display.pm, 1.1, 1.2 cust_main.pm, 1.456, 1.457 pkg_category.pm, 1.1, 1.2
Jeff Finucane,420,,
jeff at wavetail.420.am
Sun Oct 4 17:49:36 PDT 2009
- Previous message: [freeside-commits] freeside/conf invoice_htmlsummary, NONE, 1.1 invoice_latexsummary, NONE, 1.1 invoice_html, 1.29, 1.30 invoice_latex, 1.37, 1.38
- Next message: [freeside-commits] freeside/FS/FS/part_event/Action cust_bill_fee_percent.pm, 1.6, 1.7 fee.pm, 1.6, 1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv31511/FS/FS
Modified Files:
Conf.pm Schema.pm Upgrade.pm cust_bill.pm cust_bill_pkg.pm
cust_bill_pkg_display.pm cust_main.pm pkg_category.pm
Log Message:
leading summary page invoices #RT5086
Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.320
retrieving revision 1.321
diff -u -d -r1.320 -r1.321
--- Conf.pm 4 Oct 2009 02:04:49 -0000 1.320
+++ Conf.pm 5 Oct 2009 00:49:33 -0000 1.321
@@ -892,6 +892,13 @@
},
{
+ 'key' => 'invoice_usesummary',
+ 'section' => 'billing',
+ 'description' => 'Indicates that html and latex invoices should be in summary style and make use of invoice_latexsummary.',
+ 'type' => 'checkbox',
+ },
+
+ {
'key' => 'invoice_template',
'section' => 'billing',
'description' => 'Text template file for invoices. Used if no invoice_html template is defined, and also seen by users using non-HTML capable mail clients. See the <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Plaintext_invoice_templates">billing documentation</a> for details.',
@@ -923,6 +930,14 @@
},
{
+ 'key' => 'invoice_htmlsummary',
+ 'section' => 'billing',
+ 'description' => 'Summary initial page for HTML invoices.',
+ 'type' => 'textarea',
+ 'per_agent' => 1,
+ },
+
+ {
'key' => 'invoice_htmlreturnaddress',
'section' => 'billing',
'description' => 'Return address for HTML invoices. Defaults to the same data in invoice_latexreturnaddress if not specified.',
@@ -953,6 +968,14 @@
},
{
+ 'key' => 'invoice_latexsummary',
+ 'section' => 'billing',
+ 'description' => 'Summary initial page for LaTeX typeset PostScript invoices.',
+ 'type' => 'textarea',
+ 'per_agent' => 1,
+ },
+
+ {
'key' => 'invoice_latexcoupon',
'section' => 'billing',
'description' => 'Remittance coupon for LaTeX typeset PostScript invoices.',
@@ -1005,6 +1028,25 @@
'type' => 'checkbox',
},
+ {
+ 'key' => 'finance_pkgclass',
+ 'section' => 'billing',
+ 'description' => 'The package class for finance charges',
+ 'type' => 'select-sub',
+ 'options_sub' => sub { require FS::Record;
+ require FS::pkg_class;
+ map { $_->classnum => $_->classname }
+ FS::Record::qsearch('pkg_class', {} );
+ },
+ 'option_sub' => sub { require FS::Record;
+ require FS::pkg_class;
+ my $pkg_class = FS::Record::qsearchs(
+ 'pkg_class', { 'classnum'=>shift }
+ );
+ $pkg_class ? $pkg_class->classname : '';
+ },
+ },
+
{
'key' => 'separate_usage',
'section' => 'billing',
Index: Upgrade.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Upgrade.pm,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- Upgrade.pm 23 Apr 2009 20:34:13 -0000 1.30
+++ Upgrade.pm 5 Oct 2009 00:49:33 -0000 1.31
@@ -135,6 +135,9 @@
#change recur_flat and enable_prorate
'part_pkg_option' => [],
+ #add weights to pkg_category
+ 'pkg_category' => [],
+
;
\%hash;
Index: cust_bill_pkg_display.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill_pkg_display.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cust_bill_pkg_display.pm 12 Sep 2008 02:28:45 -0000 1.1
+++ cust_bill_pkg_display.pm 5 Oct 2009 00:49:34 -0000 1.2
@@ -52,7 +52,12 @@
if ( defined($value) ) {
$self->setfield('section', $value);
} else {
- $self->getfield('section') || $self->cust_bill_pkg->part_pkg->categoryname;
+ my $section = $self->getfield('section');
+ unless ($section) {
+ my $part_pkg = $self->cust_bill_pkg->part_pkg;
+ $section = $part_pkg->categoryname if $part_pkg;
+ }
+ $section;
}
}
Index: pkg_category.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/pkg_category.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pkg_category.pm 19 Jun 2008 03:18:15 -0000 1.1
+++ pkg_category.pm 5 Oct 2009 00:49:34 -0000 1.2
@@ -1,11 +1,13 @@
package FS::pkg_category;
use strict;
-use vars qw( @ISA );
-use FS::Record qw( qsearch );
+use vars qw( @ISA $me $DEBUG );
+use FS::Record qw( qsearch dbh );
use FS::part_pkg;
@ISA = qw( FS::Record );
+$DEBUG = 0;
+$me = '[FS::pkg_category]';
=head1 NAME
@@ -95,10 +97,39 @@
$self->ut_numbern('categorynum')
or $self->ut_text('categoryname')
+ or $self->ut_snumber('weight')
or $self->SUPER::check;
}
+# _ upgrade_data
+#
+# Used by FS::Upgrade to migrate to a new database.
+#
+#
+
+sub _upgrade_data {
+ my ($class, %opts) = @_;
+ my $dbh = dbh;
+
+ warn "$me upgrading $class\n" if $DEBUG;
+
+ my @pkg_category =
+ qsearch('pkg_category', { weight => { op => '!=', value => '' } } );
+
+ unless( scalar(@pkg_category) ) {
+ my @pkg_category = qsearch('pkg_category', {} );
+ my $weight = 0;
+ foreach ( sort { $a->description cmp $b->description } @pkg_category ) {
+ $_->weight($weight);
+ my $error = $_->replace;
+ die "error setting pkg_category weight: $error\n" if $error;
+ $weight += 10;
+ }
+ }
+ '';
+}
+
=back
=head1 BUGS
Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.256
retrieving revision 1.257
diff -u -d -r1.256 -r1.257
--- cust_bill.pm 4 Oct 2009 02:04:49 -0000 1.256
+++ cust_bill.pm 5 Oct 2009 00:49:33 -0000 1.257
@@ -1968,6 +1968,7 @@
'smallfooter' => sub { map "$_", @_ },
'returnaddress' => sub { map "$_", @_ },
'coupon' => sub { map "$_", @_ },
+ 'summary' => sub { map "$_", @_ },
},
'html' => {
'notes' =>
@@ -2001,6 +2002,7 @@
} @_
},
'coupon' => sub { "" },
+ 'summary' => sub { "" },
},
'template' => {
'notes' =>
@@ -2031,6 +2033,7 @@
} @_
},
'coupon' => sub { "" },
+ 'summary' => sub { "" },
},
);
@@ -2147,6 +2150,14 @@
'unitprices' => $conf->exists('invoice-unitprice'),
);
+ $invoice_data{finance_section} = '';
+ if ( $conf->config('finance_pkgclass') ) {
+ my $pkg_class =
+ qsearchs('pkg_class', { classnum => $conf->config('finance_pkgclass') });
+ $invoice_data{finance_section} = $pkg_class->categoryname;
+ }
+ $invoice_data{finance_amount} = '0.00';
+
my $countrydefault = $conf->config('countrydefault') || 'US';
my $prefix = $cust_main->has_ship_address ? 'ship_' : '';
foreach ( qw( contact company address1 address2 city state zip country fax) ){
@@ -2193,11 +2204,19 @@
# my( $cr_total, @cr_cust_credit ) = $self->cust_credit; #credits
#my $balance_due = $self->owed + $pr_total - $cr_total;
my $balance_due = $self->owed + $pr_total;
+ $invoice_data{'true_previous_balance'} = sprintf("%.2f", $self->previous_balance);
+ $invoice_data{'balance_adjustments'} = sprintf("%.2f", $self->previous_balance - $self->billing_balance);
$invoice_data{'previous_balance'} = sprintf("%.2f", $pr_total);
$invoice_data{'balance'} = sprintf("%.2f", $balance_due);
my $agentnum = $self->cust_main->agentnum;
+ my $summarypage = '';
+ if ( $conf->exists('invoice_usesummary', $agentnum) ) {
+ $summarypage = 1;
+ }
+ $invoice_data{'summarypage'} = $summarypage;
+
#do variable substitution in notes, footer, smallfooter
foreach my $include (qw( notes footer smallfooter coupon )) {
@@ -2257,6 +2276,7 @@
'template' => '',
);
my $other_money_char = $other_money_chars{$format};
+ $invoice_data{'dollar'} = $other_money_char;
my @detail_items = ();
my @total_items = ();
@@ -2271,21 +2291,27 @@
my $previous_section = { 'description' => 'Previous Charges',
'subtotal' => $other_money_char.
sprintf('%.2f', $pr_total),
+ 'summarized' => $summarypage ? 'Y' : '',
};
my $taxtotal = 0;
my $tax_section = { 'description' => 'Taxes, Surcharges, and Fees',
- 'subtotal' => $taxtotal }; # adjusted below
+ 'subtotal' => $taxtotal, # adjusted below
+ 'summarized' => $summarypage ? 'Y' : '',
+ };
my $adjusttotal = 0;
my $adjust_section = { 'description' => 'Credits, Payments, and Adjustments',
- 'subtotal' => 0 }; # adjusted below
+ 'subtotal' => 0, # adjusted below
+ 'summarized' => $summarypage ? 'Y' : '',
+ };
my $unsquelched = $params{unsquelch_cdr} || $cust_main->squelch_cdr ne 'Y';
my $multisection = $conf->exists('invoice_sections', $cust_main->agentnum);
my $late_sections = [];
if ( $multisection ) {
- push @sections, $self->_items_sections( $late_sections );
+ push @sections,
+ $self->_items_sections( $late_sections, $summarypage, $escape_function );
}else{
push @sections, { 'description' => '', 'subtotal' => '' };
}
@@ -2330,6 +2356,10 @@
foreach my $section (@sections, @$late_sections) {
+ $invoice_data{finance_amount} = sprintf('%.2f', $section->{'subtotal'} )
+ if ( $invoice_data{finance_section} &&
+ $section->{'description'} eq $invoice_data{finance_section} );
+
$section->{'subtotal'} = $other_money_char.
sprintf('%.2f', $section->{'subtotal'})
if $multisection;
@@ -2346,6 +2376,7 @@
$options{'escape_function'} = $escape_function;
$options{'format_function'} = sub { () } unless $unsquelched;
$options{'unsquelched'} = $unsquelched;
+ $options{'summary_page'} = $summarypage;
foreach my $line_item ( $self->_items_pkg(%options) ) {
my $detail = {
@@ -2384,6 +2415,9 @@
}
+ $invoice_data{current_less_finance} =
+ sprintf('%.2f', $self->charged - $invoice_data{finance_amount} );
+
if ( $multisection && !$conf->exists('disable_previous_balance') ) {
unshift @sections, $previous_section if $pr_total;
}
@@ -2555,7 +2589,11 @@
$total->{'total_item'} = &$embolden_function($self->balance_due_msg);
$total->{'total_amount'} =
&$embolden_function(
- $other_money_char. sprintf('%.2f', $self->owed + $pr_total )
+ $other_money_char. sprintf('%.2f', $summarypage
+ ? $self->charged +
+ $self->billing_balance
+ : $self->owed + $pr_total
+ )
);
if ( $multisection ) {
$adjust_section->{'posttotal'} = $total->{'total_item'}. ' '.
@@ -2574,6 +2612,49 @@
if $unsquelched;
}
+ my @includelist = ();
+ push @includelist, 'summary' if $summarypage;
+ foreach my $include ( @includelist ) {
+
+ my $inc_file = $conf->key_orbase("invoice_${format}$include", $template);
+ my @inc_src;
+
+ if ( length( $conf->config($inc_file, $agentnum) ) ) {
+
+ @inc_src = $conf->config($inc_file, $agentnum);
+
+ } else {
+
+ $inc_file = $conf->key_orbase("invoice_latex$include", $template);
+
+ my $convert_map = $convert_maps{$format}{$include};
+
+ @inc_src = map { s/\[\@--/$delimiters{$format}[0]/g;
+ s/--\@\]/$delimiters{$format}[1]/g;
+ $_;
+ }
+ &$convert_map( $conf->config($inc_file, $agentnum) );
+
+ }
+
+ my $inc_tt = new Text::Template (
+ TYPE => 'ARRAY',
+ SOURCE => [ map "$_\n", @inc_src ],
+ DELIMITERS => $delimiters{$format},
+ ) or die "Can't create new Text::Template object: $Text::Template::ERROR";
+
+ unless ( $inc_tt->compile() ) {
+ my $error = "Can't compile $inc_file template: $Text::Template::ERROR\n";
+ warn $error. "Template:\n". join('', map "$_\n", @inc_src);
+ die $error;
+ }
+
+ $invoice_data{$include} = $inc_tt->fill_in( HASH => \%invoice_data );
+
+ $invoice_data{$include} =~ s/\n+$//
+ if ($format eq 'latex');
+ }
+
$invoice_lines = 0;
my $wasfunc = 0;
foreach ( grep /invoice_lines\(\d*\)/, @invoice_template ) { #kludgy
@@ -2850,21 +2931,30 @@
sub _items_sections {
my $self = shift;
my $late = shift;
+ my $summarypage = shift;
+ my $escape = shift;
my %s = ();
my %l = ();
+ my %not_tax = ();
foreach my $cust_bill_pkg ( $self->cust_bill_pkg )
{
- if ( $cust_bill_pkg->pkgnum > 0 ) {
+
my $usage = $cust_bill_pkg->usage;
foreach my $display ($cust_bill_pkg->cust_bill_pkg_display) {
+ next if ( $display->summary && $summarypage );
+
my $desc = $display->section;
my $type = $display->type;
- if ( $display->post_total ) {
+ if ( $cust_bill_pkg->pkgnum > 0 ) {
+ $not_tax{$desc} = 1;
+ }
+
+ if ( $display->post_total && !$summarypage ) {
if (! $type || $type eq 'S') {
$l{$desc} += $cust_bill_pkg->setup
if ( $cust_bill_pkg->setup != 0 );
@@ -2908,16 +2998,29 @@
}
- }
-
}
- push @$late, map { { 'description' => $_,
+ my %cache = map { $_->categoryname => $_ }
+ qsearch( 'pkg_category', {disabled => 'Y'} );
+ $cache{$_->categoryname} = $_
+ foreach qsearch( 'pkg_category', {disabled => ''} );
+
+ push @$late, map { { 'description' => &{$escape}($_),
'subtotal' => $l{$_},
'post_total' => 1,
- } } sort keys %l;
+ } }
+ sort { $cache{$a}->weight <=> $cache{$b}->weight } keys %l;
- map { {'description' => $_, 'subtotal' => $s{$_}} } sort keys %s;
+ map { { 'description' => &{$escape}($_),
+ 'subtotal' => $s{$_},
+ 'summarized' => $not_tax{$_} ? '' : 'Y',
+ 'tax_section' => $not_tax{$_} ? '' : 'Y',
+ } }
+ sort { $cache{$a}->weight <=> $cache{$b}->weight }
+ ( $summarypage
+ ? ( grep { exists($s{$_}) || !$cache{$_}->disabled } keys %cache )
+ : ( keys %s )
+ );
}
@@ -2999,6 +3102,7 @@
my $format_function = $opt{format_function} || '';
my $unsquelched = $opt{unsquelched} || '';
my $section = $opt{section}->{description} if $opt{section};
+ my $summary_page = $opt{summary_page} || '';
my @b = ();
my ($s, $r, $u) = ( undef, undef, undef );
@@ -3018,6 +3122,7 @@
? $_->section eq $section
: 1
}
+ grep { $_->summary || !$summary_page }
$cust_bill_pkg->cust_bill_pkg_display
)
{
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -d -r1.166 -r1.167
--- Schema.pm 1 Oct 2009 23:01:10 -0000 1.166
+++ Schema.pm 5 Oct 2009 00:49:33 -0000 1.167
@@ -394,6 +394,8 @@
'custnum', 'int', '', '', '', '',
'_date', @date_type, '', '',
'charged', @money_type, '', '',
+ 'previous_balance', @money_typen, '', '', #eventually not nullable
+ 'billing_balance', @money_typen, '', '', #eventually not nullable
'printed', 'int', '', '', '', '',
'closed', 'char', 'NULL', 1, '', '',
'statementnum', 'int', 'NULL', '', '', '',
@@ -2073,6 +2075,7 @@
'columns' => [
'categorynum', 'serial', '', '', '', '',
'categoryname', 'varchar', '', $char_d, '', '',
+ 'weight', 'int', 'NULL', '', '', '',
'disabled', 'char', 'NULL', 1, '', '',
],
'primary_key' => 'categorynum',
Index: cust_bill_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill_pkg.pm,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- cust_bill_pkg.pm 4 Oct 2009 02:04:49 -0000 1.40
+++ cust_bill_pkg.pm 5 Oct 2009 00:49:34 -0000 1.41
@@ -361,7 +361,10 @@
if ( $self->pkgpart_override ) {
qsearchs('part_pkg', { 'pkgpart' => $self->pkgpart_override } );
} else {
- $self->cust_pkg->part_pkg;
+ my $part_pkg;
+ my $cust_pkg = $self->cust_pkg;
+ $part_pkg = $cust_pkg->part_pkg if $cust_pkg;
+ $part_pkg;
}
}
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.456
retrieving revision 1.457
diff -u -d -r1.456 -r1.457
--- cust_main.pm 1 Oct 2009 23:48:55 -0000 1.456
+++ cust_main.pm 5 Oct 2009 00:49:34 -0000 1.457
@@ -2717,6 +2717,23 @@
$tax = sprintf('%.2f', $tax );
$total_setup = sprintf('%.2f', $total_setup+$tax );
+ my $pkg_category = qsearchs( 'pkg_category', { 'categoryname' => $taxname,
+ 'disabled' => '',
+ },
+ );
+
+ my @display = ();
+ if ( $pkg_category and
+ $conf->config('invoice_latexsummary') ||
+ $conf->config('invoice_htmlsummary')
+ )
+ {
+
+ my %hash = ( 'section' => $pkg_category->categoryname );
+ push @display, new FS::cust_bill_pkg_display { type => 'S', %hash };
+
+ }
+
push @cust_bill_pkg, new FS::cust_bill_pkg {
'pkgnum' => 0,
'setup' => $tax,
@@ -2724,6 +2741,7 @@
'sdate' => '',
'edate' => '',
'itemdesc' => $taxname,
+ 'display' => \@display,
'cust_bill_pkg_tax_location' => \@cust_bill_pkg_tax_location,
'cust_bill_pkg_tax_rate_location' => \@cust_bill_pkg_tax_rate_location,
};
@@ -2761,11 +2779,24 @@
my $charged = sprintf('%.2f', $total_setup + $total_recur );
+ my @cust_bill = $self->cust_bill;
+ my $balance = $self->balance;
+ my $previous_balance = scalar(@cust_bill)
+ ? $cust_bill[$#cust_bill]->billing_balance
+ : 0;
+
+ $previous_balance += $cust_bill[$#cust_bill]->charged
+ if scalar(@cust_bill);
+ #my $balance_adjustments =
+ # sprintf('%.2f', $balance - $prior_prior_balance - $prior_charged);
+
#create the new invoice
my $cust_bill = new FS::cust_bill ( {
- 'custnum' => $self->custnum,
- '_date' => ( $invoice_time ),
- 'charged' => $charged,
+ 'custnum' => $self->custnum,
+ '_date' => ( $invoice_time ),
+ 'charged' => $charged,
+ 'billing_balance' => $balance,
+ 'previous_balance' => $previous_balance,
} );
$error = $cust_bill->insert;
if ( $error ) {
- Previous message: [freeside-commits] freeside/conf invoice_htmlsummary, NONE, 1.1 invoice_latexsummary, NONE, 1.1 invoice_html, 1.29, 1.30 invoice_latex, 1.37, 1.38
- Next message: [freeside-commits] freeside/FS/FS/part_event/Action cust_bill_fee_percent.pm, 1.6, 1.7 fee.pm, 1.6, 1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list