use Text::CSV_XS;
use FS::Record qw( qsearch qsearchs dbh );
use FS::cust_pkg;
-use FS::cust_bill;
use FS::cust_bill_pkg_detail;
use FS::cust_bill_pkg_display;
use FS::cust_bill_pkg_discount;
|| $self->ut_snumber('pkgnum')
|| $self->ut_number('invnum')
|| $self->ut_money('setup')
+ || $self->ut_moneyn('unitsetup')
+ || $self->ut_currencyn('setup_billed_currency')
+ || $self->ut_moneyn('setup_billed_amount')
|| $self->ut_money('recur')
+ || $self->ut_moneyn('unitrecur')
+ || $self->ut_currencyn('recur_billed_currency')
+ || $self->ut_moneyn('recur_billed_amount')
|| $self->ut_numbern('sdate')
|| $self->ut_numbern('edate')
|| $self->ut_textn('itemdesc')
Returns the invoice (see L<FS::cust_bill>) for this invoice line item.
-=cut
-
-sub cust_bill {
- my $self = shift;
- qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
-}
-
=item previous_cust_bill_pkg
Returns the previous cust_bill_pkg for this package, if any.
sub paid_sql {
my ($class, $start, $end, %opt) = @_;
- my $s = $start ? "AND cust_bill_pay._date <= $start" : '';
- my $e = $end ? "AND cust_bill_pay._date > $end" : '';
+ my $s = $start ? "AND cust_pay._date <= $start" : '';
+ my $e = $end ? "AND cust_pay._date > $end" : '';
my $setuprecur =
$opt{setuprecur} =~ /^s/ ? 'setup' :
$opt{setuprecur} =~ /^r/ ? 'recur' :
my $paid = "( SELECT COALESCE(SUM(cust_bill_pay_pkg.amount),0)
FROM cust_bill_pay_pkg JOIN cust_bill_pay USING (billpaynum)
+ JOIN cust_pay USING (paynum)
WHERE cust_bill_pay_pkg.billpkgnum = cust_bill_pkg.billpkgnum
$s $e $setuprecur )";
sub credited_sql {
my ($class, $start, $end, %opt) = @_;
- my $s = $start ? "AND cust_credit_bill._date <= $start" : '';
- my $e = $end ? "AND cust_credit_bill._date > $end" : '';
+ my $s = $start ? "AND cust_credit._date <= $start" : '';
+ my $e = $end ? "AND cust_credit._date > $end" : '';
my $setuprecur =
$opt{setuprecur} =~ /^s/ ? 'setup' :
$opt{setuprecur} =~ /^r/ ? 'recur' :
my $credited = "( SELECT COALESCE(SUM(cust_credit_bill_pkg.amount),0)
FROM cust_credit_bill_pkg JOIN cust_credit_bill USING (creditbillnum)
+ JOIN cust_credit USING (crednum)
WHERE cust_credit_bill_pkg.billpkgnum = cust_bill_pkg.billpkgnum
$s $e $setuprecur )";
delete @hash{qw(censustract censusyear latitude longitude coord_auto)};
$hash{custnum} = $h_cust_main->custnum;
- my $tax_loc = FS::cust_location->new_or_existing(\%hash);
- if ( !$tax_loc->locationnum ) {
- $tax_loc->disabled('Y');
- my $error = $tax_loc->insert;
- if ( $error ) {
- warn "couldn't create historical location record for cust#".
- $h_cust_main->custnum.": $error\n";
- next INVOICE;
- }
+ my $tax_loc = FS::cust_location->new(\%hash);
+ my $error = $tax_loc->find_or_insert || $tax_loc->disable_if_unused;
+ if ( $error ) {
+ warn "couldn't create historical location record for cust#".
+ $h_cust_main->custnum.": $error\n";
+ next INVOICE;
}
my $exempt_cust = 1 if $h_cust_main->tax;