summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authormark <mark>2011-12-08 21:13:17 +0000
committermark <mark>2011-12-08 21:13:17 +0000
commitce1b61e7d65317a74f680afb4cb8d8306e14fa5f (patch)
tree5adb1b9b7b6afc37ebc03bc29aa32fabb8cb373e /FS
parentd8d63a28503d40743425dceda7e0b744739eeb2a (diff)
promised payment date for invoices, #13554
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Conf.pm7
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/cust_bill.pm11
-rw-r--r--FS/FS/cust_bill_ApplicationCommon.pm11
-rw-r--r--FS/FS/part_event/Condition/cust_bill_past_promised.pm48
5 files changed, 78 insertions, 0 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 3987fac..fcdcd57 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4681,6 +4681,13 @@ and customer address. Include units.',
'description' => 'An alternate ordering of fields for the New Customer and Edit Customer screens.',
'type' => 'checkbox',
},
+
+ {
+ 'key' => 'cust_bill-enable_promised_date',
+ 'section' => 'UI',
+ 'description' => 'Enable display/editing of the "promised payment date" field on invoices.',
+ 'type' => 'checkbox',
+ },
{
'key' => 'available-locales',
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 51daf44..18df708 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -532,6 +532,7 @@ sub tables_hashref {
'closed', 'char', 'NULL', 1, '', '', #not yet used much
'statementnum', 'int', 'NULL', '', '', '', #invoice aggregate statements
'agent_invid', 'int', 'NULL', '', '', '', #(varchar?) importing legacy
+ 'promised_date', @date_type, '', '',
],
'primary_key' => 'invnum',
'unique' => [ [ 'custnum', 'agent_invid' ] ], #agentnum? huh
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index ef6dc7b..41ff6aa 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -144,6 +144,8 @@ Specific use cases
=item agent_invid - legacy invoice number
+=item promised_date - customer promised payment date, for collection
+
=back
=head1 METHODS
@@ -5622,6 +5624,15 @@ sub search_sql_where {
}
+ #promised_date - also has an option to accept nulls
+ if ( $param->{promised_date} ) {
+ my($beginning, $ending, $null) = @{$param->{promised_date}};
+
+ push @search, "(( cust_bill.promised_date >= $beginning AND ".
+ "cust_bill.promised_date < $ending )" .
+ ($null ? ' OR cust_bill.promised_date IS NULL ) ' : ')');
+ }
+
#agent virtualization
my $curuser = $FS::CurrentUser::CurrentUser;
if ( $curuser->username eq 'fs_queue'
diff --git a/FS/FS/cust_bill_ApplicationCommon.pm b/FS/FS/cust_bill_ApplicationCommon.pm
index afb90f4..cadb8a7 100644
--- a/FS/FS/cust_bill_ApplicationCommon.pm
+++ b/FS/FS/cust_bill_ApplicationCommon.pm
@@ -435,6 +435,17 @@ sub apply_to_lineitems {
}
+ # unset promised payment date if there is one
+ my $cust_bill = $self->cust_bill;
+ if ( $cust_bill->promised_date and $cust_bill->owed <= 0 ) {
+ $cust_bill->set('promised_date', '');
+ my $error = $cust_bill->replace;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
#everything should always be applied to line items in full now... sanity check
$applied = sprintf('%.2f', $applied);
unless ( $applied == $self->amount ) {
diff --git a/FS/FS/part_event/Condition/cust_bill_past_promised.pm b/FS/FS/part_event/Condition/cust_bill_past_promised.pm
new file mode 100644
index 0000000..e861cb4
--- /dev/null
+++ b/FS/FS/part_event/Condition/cust_bill_past_promised.pm
@@ -0,0 +1,48 @@
+package FS::part_event::Condition::cust_bill_past_promised;
+
+use strict;
+use FS::cust_bill;
+use Time::Local 'timelocal';
+
+use base qw( FS::part_event::Condition );
+
+sub description {
+ 'Promised payment date has passed',
+}
+
+sub eventtable_hashref {
+ { 'cust_main' => 0,
+ 'cust_bill' => 1,
+ 'cust_pkg' => 0,
+ };
+}
+
+sub option_fields {
+ (
+ 'delay' => { label => 'Delay additional days',
+ type => 'text',
+ value => '0',
+ },
+ );
+}
+
+sub condition {
+ # always return true if there is no promised_date
+ my($self, $cust_bill, %opt) = @_;
+
+ my $delay = $self->option('delay') || 0;
+ my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($opt{'time'}))[0..5];
+ my $as_of = timelocal(0,0,0,$mday,$mon,$year) - $delay * 86400;
+ $as_of >= ($cust_bill->promised_date || 0);
+}
+
+sub condition_sql {
+ my( $class, $table, %opt ) = @_;
+ return 'true' if $opt{'driver_name'} ne 'Pg';
+ my $delay = $class->condition_sql_option_integer('delay', 'Pg');
+ my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($opt{'time'}))[0..5];
+ my $as_of = timelocal(0,0,0,$mday,$mon,$year) . " - ($delay * 86400)";
+ "(cust_bill.promised_date IS NULL OR $as_of >= cust_bill.promised_date)";
+}
+
+1;