use FS::reason;
use FS::reason_type;
use FS::L10N;
+use FS::Misc::Savepoint;
$DEBUG = 0;
$me = '[FS::cust_bill]';
sub table { 'cust_bill'; }
sub template_conf { 'invoice_'; }
-sub has_sections {
- my $self = shift;
- my $agentnum = $self->cust_main->agentnum;
- my $tc = $self->template_conf;
-
- $self->conf->exists($tc.'sections', $agentnum) ||
- $self->conf->exists($tc.'sections_by_location', $agentnum);
-}
-
# should be the ONLY occurrence of "Invoice" in invoice rendering code.
# (except email_subject and invnum_date_pretty)
sub notice_name {
}
-=item void [ REASON ]
+=item void [ REASON [ , REPROCESS_CDRS ] ]
Voids this invoice: deletes the invoice and adds a record of the voided invoice
to the FS::cust_bill_void table (and related tables starting from
sub void {
my $self = shift;
my $reason = scalar(@_) ? shift : '';
+ my $reprocess_cdrs = scalar(@_) ? shift : '';
unless (ref($reason) || !$reason) {
$reason = FS::reason->new_or_existing(
}
foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) {
- my $error = $cust_bill_pkg->void($reason);
+ my $error = $cust_bill_pkg->void($reason, $reprocess_cdrs);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
sub cust_bill_pkg {
my $self = shift;
qsearch(
- { 'table' => 'cust_bill_pkg',
+ {
+ 'select' => 'cust_bill_pkg.*, pkg_category.categoryname',
+ 'table' => 'cust_bill_pkg',
+ 'addl_from' => ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN part_pkg USING ( pkgpart ) '.
+ ' LEFT JOIN pkg_class USING ( classnum ) '.
+ ' LEFT JOIN pkg_category USING ( categorynum ) ',
'hashref' => { 'invnum' => $self->invnum },
'order_by' => 'ORDER BY billpkgnum', #important? otherwise we could use
# the AUTLOADED FK search. or should
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ my $savepoint_label = 'cust_bill__apply_payments_and_credits';
+ savepoint_create( $savepoint_label );
+
$self->select_for_update; #mutex
my @payments = grep { $_->unapplied > 0 }
my $error = $app->insert(%options);
if ( $error ) {
+ savepoint_rollback_and_release( $savepoint_label );
$dbh->rollback if $oldAutoCommit;
return "Error inserting ". $app->table. " record: $error";
}
}
+ savepoint_release( $savepoint_label );
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
''; #no error
sub send_csv {
my($self, %opt) = @_;
+ if ( $FS::Misc::DISABLE_ALL_NOTICES ) {
+ warn 'send_csv() disabled by $FS::Misc::DISABLE_ALL_NOTICES' if $DEBUG;
+ return;
+ }
+
#create file(s)
my $spooldir = "/usr/local/etc/freeside/export.". datasrc. "/cust_bill";
sub spool_csv {
my($self, %opt) = @_;
+ if ( $FS::Misc::DISABLE_ALL_NOTICES ) {
+ warn 'spool_csv() disabled by $FS::Misc::DISABLE_ALL_NOTICES' if $DEBUG;
+ return;
+ }
+
my $time = $opt{'time'} || time;
my $cust_main = $self->cust_main;
}
-=sub _items_usage_class_summary OPTIONS
+=item _items_usage_class_summary OPTIONS
Returns a list of detail items summarizing the usage charges on this
invoice. Each one will have 'amount', 'description' (the usage charge name),
return @l;
}
-=sub _items_previous()
+=item _items_previous()
Returns an array of hashrefs, each hashref representing a line-item on
the current bill for previous unpaid invoices.
}
-=sub _items_previous_total
+=item _items_previous_total
Return sum of amounts from all items returned by _items_previous
Results will vary based on invoicing conf flags
}
}
-=sub _items_credits()
+=item _items_credits()
Return array of hashrefs containing credits to be shown as line-items
when rendering this bill.
@return;
}
-=sub _items_credits_total
+=item _items_credits_total
Return the total of al items from _items_credits
Will vary based on invoice display conf flag
-=sub _items_credits_postbill()
+=item _items_credits_postbill()
Returns an array of hashrefs for credits where
- Credit issued after this invoice
}} @cust_credit_bill;
}
-=sub _items_payments_postbill()
+=item _items_payments_postbill()
Returns an array of hashrefs for payments where
- Payment occured after this invoice
}} @cust_bill_pay;
}
-=sub _items_payments()
+=item _items_payments()
Return array of hashrefs containing payments to be shown as line-items
when rendering this bill.
if ($self->conf->exists('previous_balance-payments_since')) {
if ($template eq 'statement') {
-print "\nCASE 3\n";
# Case 3 (see above)
# Return payments timestamped between the previous and following bills
} else {
# Case 2 (see above)
# Return payments timestamped between this and the previous bill
-print "\nCASE 2\n";
+
my $date_start = 0;
my $date_end = $self->_date;
return @{ $self->get('_items_payments') };
}
-=sub _items_payments_total
+=item _items_payments_total
Return a total of all records returned by _items_payments
Results vary based on invoicing conf flags
return @return;
}
-=sub _items_total()
+=item _items_total()
Generate the line-items to be shown on the bill in the "Totals" section
return map{ sprintf('%.2f',$_) } @aging_balances;
}
+=item has_call_details
+
+Returns true if this invoice has call details.
+
+=cut
+
+sub has_call_details {
+ my $self = shift;
+ $self->scalar_sql("
+ SELECT 1 FROM cust_bill_pkg_detail
+ LEFT JOIN cust_bill_pkg USING (billpkgnum)
+ WHERE cust_bill_pkg_detail.format = 'C'
+ AND cust_bill_pkg.invnum = ?
+ LIMIT 1
+ ", $self->invnum);
+}
+
=item call_details [ OPTION => VALUE ... ]
Returns an array of CSV strings representing the call details for this invoice