summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Report/Tax.pm48
-rw-r--r--FS/FS/cust_main/Billing_Batch.pm9
-rw-r--r--FS/FS/cust_main/Billing_Realtime.pm5
-rw-r--r--FS/FS/cust_pay_pending.pm2
-rw-r--r--FS/FS/queue.pm20
5 files changed, 69 insertions, 15 deletions
diff --git a/FS/FS/Report/Tax.pm b/FS/FS/Report/Tax.pm
index 93fc64435..f1f6be38e 100644
--- a/FS/FS/Report/Tax.pm
+++ b/FS/FS/Report/Tax.pm
@@ -475,11 +475,7 @@ sub report_internal {
if ( $agentnum ) {
$outside_where .= " AND cust_main.agentnum = $agentnum";
}
- my $sql_outside = "SELECT SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)
- FROM cust_bill_pkg
- $join_cust_pkg
- $outside_where
- AND $nottax
+ $outside_where .= "
AND NOT EXISTS(
SELECT 1 FROM cust_tax_exempt_pkg
JOIN cust_main_county USING (taxnum)
@@ -492,10 +488,37 @@ sub report_internal {
JOIN cust_main_county USING (taxnum)
WHERE cust_bill_pkg_tax_location.taxable_billpkgnum = cust_bill_pkg.billpkgnum
AND COALESCE(cust_main_county.taxname,'Tax') = $taxname
+ )";
+ my $sql_outside = "SELECT SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)
+ FROM cust_bill_pkg
+ $join_cust_pkg
+ $outside_where
+ AND $nottax
+ ";
+ warn "\nOUT_SALES:\n$sql_outside\n" if $DEBUG;
+ my $out_sales = FS::Record->scalar_sql($sql_outside);
+
+ # and out-of-region credit applications, also (excluding those applied
+ # to out-of-region sales _or taxes_)
+ if ( $opt{credit_date} eq 'cust_credit_bill' ) {
+ $outside_where =~ s/cust_bill._date/cust_credit_bill._date/g;
+ }
+
+ $sql_outside = "SELECT SUM(cust_credit_bill_pkg.amount)
+ FROM cust_credit_bill_pkg
+ JOIN cust_bill_pkg USING (billpkgnum)
+ $join_cust_pkg
+ JOIN cust_credit_bill USING (creditbillnum)
+ $outside_where
+ AND NOT EXISTS(
+ SELECT 1 FROM cust_bill_pkg_tax_location
+ JOIN cust_main_county USING (taxnum)
+ WHERE cust_bill_pkg_tax_location.billpkgnum = cust_bill_pkg.billpkgnum
+ AND COALESCE(cust_main_county.taxname,'Tax') = $taxname
)
";
- warn "\nOUTSIDE:\n$sql_outside\n" if $DEBUG;
- my $total_outside = FS::Record->scalar_sql($sql_outside);
+ warn "\nOUT_CREDIT:\n$sql_outside\n" if $DEBUG;
+ my $out_credit = FS::Record->scalar_sql($sql_outside);
my %taxrates;
foreach my $tax (
@@ -509,11 +532,12 @@ sub report_internal {
# return the data
bless {
- 'opt' => \%opt,
- 'data' => \%data,
- 'total' => \%total,
- 'taxrates' => \%taxrates,
- 'outside' => $total_outside,
+ 'opt' => \%opt,
+ 'data' => \%data,
+ 'total' => \%total,
+ 'taxrates' => \%taxrates,
+ 'out_sales' => $out_sales,
+ 'out_credit' => $out_credit,
}, $class;
}
diff --git a/FS/FS/cust_main/Billing_Batch.pm b/FS/FS/cust_main/Billing_Batch.pm
index 0cf2beeda..cdaf2938f 100644
--- a/FS/FS/cust_main/Billing_Batch.pm
+++ b/FS/FS/cust_main/Billing_Batch.pm
@@ -48,7 +48,13 @@ sub batch_card {
}else{
$amount = sprintf("%.2f", $self->balance - $self->in_transit_payments);
}
- return '' unless $amount > 0;
+ if ($amount <= 0) {
+ warn(sprintf("Customer balance %.2f - in transit amount %.2f is <= 0.\n",
+ $self->balance,
+ $self->in_transit_payments
+ ));
+ return;
+ }
my $invnum = delete $options{invnum};
@@ -218,6 +224,7 @@ sub in_transit_payments {
foreach my $cust_pay_batch ( qsearch('cust_pay_batch', {
'batchnum' => $pay_batch->batchnum,
'custnum' => $self->custnum,
+ 'status' => '',
} ) ) {
$in_transit_payments += $cust_pay_batch->amount;
}
diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm
index c2ce680a1..7a204073b 100644
--- a/FS/FS/cust_main/Billing_Realtime.pm
+++ b/FS/FS/cust_main/Billing_Realtime.pm
@@ -955,6 +955,8 @@ sub _realtime_bop_result {
return $e;
}
+ $cust_pay_pending->set('jobnum','');
+
}
if ( $options{'paynum_ref'} ) {
@@ -1063,8 +1065,9 @@ sub _realtime_bop_result {
if ( $placeholder ) {
my $error = $placeholder->depended_delete;
$error ||= $placeholder->delete;
+ $cust_pay_pending->set('jobnum','');
warn "error removing provisioning jobs after declined paypendingnum ".
- $cust_pay_pending->paypendingnum. ": $error\n";
+ $cust_pay_pending->paypendingnum. ": $error\n" if $error;
} else {
my $e = "error finding job $jobnum for declined paypendingnum ".
$cust_pay_pending->paypendingnum. "\n";
diff --git a/FS/FS/cust_pay_pending.pm b/FS/FS/cust_pay_pending.pm
index 63274b184..1a5420385 100644
--- a/FS/FS/cust_pay_pending.pm
+++ b/FS/FS/cust_pay_pending.pm
@@ -393,6 +393,8 @@ sub approve {
warn $e;
return $e;
}
+
+ $self->set('jobnum','');
}
if ( $opt{'paynum_ref'} ) {
diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm
index 67d124d02..a0654a13c 100644
--- a/FS/FS/queue.pm
+++ b/FS/FS/queue.pm
@@ -206,9 +206,27 @@ sub delete {
}
}
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ foreach my $cust_pay_pending (qsearch('cust_pay_pending',{ jobnum => $self->jobnum })) {
+ $cust_pay_pending->set('jobnum','');
+ my $error = $cust_pay_pending->replace();
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
my $error = $self->SUPER::delete;
- return $error if $error;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
unlink $reportname if $reportname;
'';