use FS::cust_bill_pay_batch;
use FS::part_bill_event;
use FS::payby;
+use FS::bill_batch;
+use FS::cust_bill_batch;
@ISA = qw( FS::cust_main_Mixin FS::Record );
'notice_name' => $notice_name,
);
- do_print $self->lpr_data(\%opt);
+ if($conf->exists('invoice_print_pdf')) {
+ # Add the invoice to the current batch.
+ $self->batch_invoice(\%opt);
+ }
+ else {
+ do_print $self->lpr_data(\%opt);
+ }
}
=item fax_invoice HASHREF | [ TEMPLATE ]
}
+=item batch_invoice [ HASHREF ]
+
+Place this invoice into the open batch (see C<FS::bill_batch>). If there
+isn't an open batch, one will be created.
+
+=cut
+
+sub batch_invoice {
+ my ($self, $opt) = @_;
+ my $batch = FS::bill_batch->get_open_batch;
+ my $cust_bill_batch = FS::cust_bill_batch->new({
+ batchnum => $batch->batchnum,
+ invnum => $self->invnum,
+ });
+ return $cust_bill_batch->insert($opt);
+}
+
=item ftp_invoice [ TEMPLATENAME ]
Sends this invoice data via FTP.
=cut
sub owed_sql {
- my $class = shift;
- my ($start, $end) = @_;
+ my ($class, $start, $end) = @_;
'charged - '.
$class->paid_sql($start, $end). ' - '.
$class->credited_sql($start, $end);
=cut
sub net_sql {
- my $class = shift;
- my ($start, $end) = @_;
+ my ($class, $start, $end) = @_;
'charged - '. $class->credited_sql($start, $end);
}
sub paid_sql {
my ($class, $start, $end) = @_;
$start &&= "AND cust_bill_pay._date <= $start";
- $end &&= "AND cust_bill_pay._date > $end";
+ $end &&= "AND cust_bill_pay._date > $end";
+ $start = '' unless defined($start);
+ $end = '' unless defined($end);
"( SELECT COALESCE(SUM(amount),0) FROM cust_bill_pay
WHERE cust_bill.invnum = cust_bill_pay.invnum $start $end )";
}
=cut
sub credited_sql {
- my ($class, $start, $end) = shift;
+ my ($class, $start, $end) = @_;
$start &&= "AND cust_credit_bill._date <= $start";
- $end &&= "AND cust_credit_bill._date > $end";
+ $end &&= "AND cust_credit_bill._date > $end";
+ $start = '' unless defined($start);
+ $end = '' unless defined($end);
"( SELECT COALESCE(SUM(amount),0) FROM cust_credit_bill
WHERE cust_bill.invnum = cust_credit_bill.invnum $start $end )";
}