From ea1d9968a9439272b58593e6b2ccbb3869002b20 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 20 Oct 2003 04:25:18 +0000 Subject: [PATCH] daily/weekly billing --- FS/FS/cust_main.pm | 22 +++++++++++++-- FS/FS/part_pkg.pm | 10 ++++++- FS/bin/freeside-setup | 2 +- httemplate/docs/upgrade10.html | 64 +++++++++++++++++++++++++++++++++++++++++- httemplate/edit/part_pkg.cgi | 51 +++++++++++++++++++++++++++++---- 5 files changed, 137 insertions(+), 12 deletions(-) diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 58cfc0c76..0283e3d04 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1089,7 +1089,7 @@ sub bill { #bill recurring fee my $recur = 0; my $sdate; - if ( $part_pkg->getfield('freq') > 0 && + if ( $part_pkg->getfield('freq') ne '0' && ! $cust_pkg->getfield('susp') && ( $cust_pkg->getfield('bill') || 0 ) <= $time ) { @@ -1127,8 +1127,19 @@ sub bill { $cust_pkg->last_bill($sdate) if $cust_pkg->dbdef_table->column('last_bill'); - $mon += $part_pkg->freq; - until ( $mon < 12 ) { $mon -= 12; $year++; } + if ( $part_pkg->freq =~ /^\d+$/ ) { + $mon += $part_pkg->freq; + until ( $mon < 12 ) { $mon -= 12; $year++; } + } elsif ( $part_pkg->freq =~ /^(\d+)w$/ ) { + my $weeks = $1; + $mday += $weeks * 7; + } elsif ( $part_pkg->freq =~ /^(\d+)d$/ ) { + my $days = $1; + $mday += $days; + } else { + $dbh->rollback if $oldAutoCommit; + return "unparsable frequency: ". $part_pkg->freq; + } $cust_pkg->setfield('bill', timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year)); $cust_pkg_mod_flag = 1; @@ -1208,6 +1219,11 @@ sub bill { my ($mon,$year) = (localtime($sdate) )[4,5]; $mon++; my $freq = $part_pkg->freq || 1; + if ( $freq !~ /(\d+)$/ ) { + $dbh->rollback if $oldAutoCommit; + return "daily/weekly package definitions not (yet?)". + " compatible with monthly tax exemptions"; + } my $taxable_per_month = sprintf("%.2f", $taxable_charged / $freq ); foreach my $which_month ( 1 .. $freq ) { my %hash = ( diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 12ee804ff..695d48ceb 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -229,11 +229,19 @@ sub check { } + if ( $self->dbdef_table->column('freq')->type =~ /(int)/i ) { + my $error = $self->ut_number('freq'); + return $error if $error; + } else { + $self->freq =~ /^(\d+[dw]?)$/ + or return "Illegal or empty freq: ". $self->freq; + $self->freq($1); + } + $self->ut_numbern('pkgpart') || $self->ut_text('pkg') || $self->ut_text('comment') || $self->ut_anything('setup') - || $self->ut_number('freq') || $self->ut_anything('recur') || $self->ut_alphan('plan') || $self->ut_anything('plandata') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index b7b45dc63..375a63c2f 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -678,7 +678,7 @@ sub tables_hash_hack { 'pkg', 'varchar', '', $char_d, 'comment', 'varchar', '', $char_d, 'setup', @perl_type, - 'freq', 'int', '', '', #billing frequency (months) + 'freq', 'varchar', '', $char_d, #billing frequency 'recur', @perl_type, 'setuptax', 'char', 'NULL', 1, 'recurtax', 'char', 'NULL', 1, diff --git a/httemplate/docs/upgrade10.html b/httemplate/docs/upgrade10.html index 4a6baa59b..446090503 100644 --- a/httemplate/docs/upgrade10.html +++ b/httemplate/docs/upgrade10.html @@ -62,6 +62,68 @@ CREATE TABLE svc_broadband ( PRIMARY KEY (svcnum) ); +CREATE TABLE acct_snarf ( + snarfnum serial, + svcnum int NOT NULL, + machine varchar(255) NULL, + protocol varchar(80) NULL, + username varchar(80) NULL, + _password varchar(80) NULL, + PRIMARY KEY (snarfnum) +); +CREATE INDEX acct_snarf1 ON acct_snarf ( svcnum ); + +CREATE TABLE part_pkg_temp ( + pkgpart serial NOT NULL, + pkg varchar(80) NOT NULL, + "comment" varchar(80) NOT NULL, + setup text NULL, + freq varchar(80) NOT NULL, + recur text NULL, + setuptax char(1) NULL, + recurtax char(1) NULL, + plan varchar(80) NULL, + plandata text NULL, + disabled char(1) NULL, + taxclass varchar(80) NULL, + PRIMARY KEY (pkgpart), +); +INSERT INTO part_pkg_temp SELECT * from part_pkg; +DROP TABLE part_pkg; +ALTER TABLE part_pkg_temp RENAME TO part_pkg; +ALTER TABLE part_pkg DROP CONSTRAINT part_pkg_temp_pkey; +ALTER TABLE part_pkg ADD PRIMARY KEY (pkgpart); +CREATE INDEX part_pkg1 ON part_pkg(disabled); +select setval('public.part_pkg_temp_pkgpart_seq', ( select max(pkgpart) from part_pkg) ); #? + +CREATE TABLE h_part_pkg_temp ( + historynum serial NOT NULL, + history_date int, + history_user varchar(80) NOT NULL, + history_action varchar(80) NOT NULL, + pkgpart int NOT NULL, + pkg varchar(80) NOT NULL, + "comment" varchar(80) NOT NULL, + setup text NULL, + freq varchar(80) NOT NULL, + recur text NULL, + setuptax char(1) NULL, + recurtax char(1) NULL, + plan varchar(80) NULL, + plandata text NULL, + disabled char(1) NULL, + taxclass varchar(80) NULL, + PRIMARY KEY (historynum) +); +INSERT INTO h_part_pkg_temp SELECT * from h_part_pkg; +DROP TABLE h_part_pkg; +ALTER TABLE h_part_pkg_temp RENAME TO h_part_pkg; +ALTER TABLE h_part_pkg DROP CONSTRAINT h_part_pkg_temp_pkey; +ALTER TABLE h_part_pkg ADD PRIMARY KEY (historynum); +CREATE INDEX h_part_pkg1 ON h_part_pkg(disabled); +select setval('public.h_part_pkg_temp_historynum_seq', ( select max(historynum) from h_part_pkg) ); + + DROP INDEX cust_bill_pkg1; ALTER TABLE cust_bill_pkg ADD itemdesc varchar(80) NULL; @@ -106,7 +168,7 @@ optionally: mandatory again: dbdef-create username -create-history-tables username cust_bill_pkg_detail router part_svc_router addr_block svc_broadband +create-history-tables username cust_bill_pkg_detail router part_svc_router addr_block svc_broadband acct_snarf dbdef-create username apache - fix sections to include .html also diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index dee356250..daa5b7483 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -66,12 +66,51 @@ print '
'; #print qq!!, print "Package Part #", $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)"; -print ntable("#cccccc",2), <Package (customer-visible) -Comment (customer-hidden) -Frequency (months) of recurring fee  0=no recurring fee, 1=monthly, 3=quarterly, 12=yearly -Setup fee tax exempt -END +my %freq; +tie %freq, 'Tie::IxHash', + '0' => '(no recurring fee)', + '1d' => 'daily', + '1w' => 'weekly', + '2w' => 'biweekly (every 2 weeks)', + '1' => 'monthly', + '2' => 'bimonthly (every 2 months)', + '3' => 'quarterly (every 3 months)', + '6' => 'semiannually (every 6 months)', + '12' => 'annually', + '24' => 'biannually (every 2 years)', +; +if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) { + delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq; +} + +%> +<%= ntable("#cccccc",2) %> + + Package (customer-visible) + + + + + + Comment (customer-hidden) + + + + + + Recurring fee frequency + + + + + + Setup fee tax exempt + +<% print '{setuptax} eq "Y"; -- 2.11.0