SELECT SUM(charged)
FROM cust_bill
LEFT JOIN cust_main USING ( custnum )
- WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
- . (%opt ? $self->for_custnum(%opt) : '')
+ WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum).
+ $self->for_opts(%opt)
);
}
sub netsales { #net sales
my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
- $self->invoiced($speriod,$eperiod,$agentnum,%opt)
- - $self->netcredits($speriod,$eperiod,$agentnum,%opt);
+ $self->invoiced( $speriod, $eperiod, $agentnum, %opt)
+ - $self->netcredits($speriod, $eperiod, $agentnum, %opt);
}
=item cashflow: payments - refunds
=cut
sub netcashflow {
- my( $self, $speriod, $eperiod, $agentnum ) = @_;
+ my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
- $self->receipts($speriod, $eperiod, $agentnum)
- - $self->netrefunds( $speriod, $eperiod, $agentnum);
+ $self->receipts( $speriod, $eperiod, $agentnum, %opt)
+ - $self->netrefunds( $speriod, $eperiod, $agentnum, %opt);
}
=item payments: The sum of payments received in the period.
SELECT SUM(paid)
FROM cust_pay
LEFT JOIN cust_main USING ( custnum )
- WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
- . (%opt ? $self->for_custnum(%opt) : '')
+ WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum).
+ $self->for_opts(%opt)
);
}
=cut
sub credits {
- my( $self, $speriod, $eperiod, $agentnum ) = @_;
+ my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
$self->scalar_sql("
SELECT SUM(amount)
FROM cust_credit
LEFT JOIN cust_main USING ( custnum )
- WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
+ WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum).
+ $self->for_opts(%opt)
);
}
SELECT SUM(refund)
FROM cust_refund
LEFT JOIN cust_main USING ( custnum )
- WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
- . (%opt ? $self->for_custnum(%opt) : '')
+ WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum).
+ $self->for_opts(%opt)
);
}
$eperiod,
$agentnum,
'cust_bill._date'
- )
- . (%opt ? $self->for_custnum(%opt) : '')
+ ).
+ $self->for_opts(%opt)
);
}
=cut
sub receipts { #net payments
- my( $self, $speriod, $eperiod, $agentnum ) = @_;
+ my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
$self->scalar_sql("
SELECT SUM(cust_bill_pay.amount)
FROM cust_bill_pay
$eperiod,
$agentnum,
'cust_bill._date'
- )
+ ).
+ $self->for_opts(%opt)
);
}
=cut
sub netrefunds {
- my( $self, $speriod, $eperiod, $agentnum ) = @_;
+ my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
$self->scalar_sql("
SELECT SUM(cust_credit_refund.amount)
FROM cust_credit_refund
$eperiod,
$agentnum,
'cust_credit._date'
- )
+ ).
+ $self->for_opts(%opt)
);
}
$sql;
}
-sub for_custnum {
+sub for_opts {
my ( $self, %opt ) = @_;
- return '' unless $opt{'custnum'};
- $opt{'custnum'} =~ /^\d+$/ ? " and custnum = $opt{custnum} " : '';
+ my $sql = '';
+ if ( $opt{'custnum'} =~ /^(\d+)$/ ) {
+ $sql .= " and custnum = $1 ";
+ }
+ if ( $opt{'refnum'} =~ /^(\d+)$/ ) {
+ $sql .= " and refnum = $1 ";
+ }
+ $sql;
}
sub with_classnum {
'end_year' => 2020,
#opt
'agentnum' => 54
+ 'refnum' => 54
'params' => [ [ 'paramsfor', 'item_one' ], [ 'item', 'two' ] ], # ...
'remove_empty' => 1, #collapse empty rows, default 0
'item_labels' => [ ], #useful with remove_empty
}
my $agentnum = $self->{'agentnum'};
+ my $refnum = $self->{'refnum'};
if ( $projecting ) {
my $item = $items[$i];
my @param = $self->{'params'} ? @{ $self->{'params'}[$i] }: ();
push @param, 'project', $projecting;
+ push @param, 'refnum' => $refnum if $refnum;
my $value = $self->$item($speriod, $eperiod, $agentnum, @param);
push @{$data{data}->[$col]}, $value;
$item = $items[$i+1];
@param = $self->{'params'} ? @{ $self->{'params'}[++$i] }: ();
push @param, 'project', $projecting;
+ push @param, 'refnum' => $refnum if $refnum;
$value = $self->$item($speriod, $eperiod, $agentnum, @param);
push @{$data{data}->[$col++]}, $value;
}
my $item = $items[$i];
my @param = $self->{'params'} ? @{ $self->{'params'}[$col] }: ();
push @param, 'project', $projecting;
+ push @param, 'refnum' => $refnum if $refnum;
my $value = $self->$item($speriod, $eperiod, $agentnum, @param);
push @{$data{data}->[$col++]}, $value;
}
push @search, "cust_main.agentnum = $1";
}
- #agentnum
+ #refnum
+ if ( $param->{'refnum'} =~ /^(\d+)$/ ) {
+ push @search, "cust_main.refnum = $1";
+ }
+
+ #custnum
if ( $param->{'custnum'} =~ /^(\d+)$/ ) {
push @search, "cust_bill.custnum = $1";
}
<% include('elements/monthly.html',
- 'title' => $agentname.
+ 'title' => $agentname. $referralname.
'Sales, Credits and Receipts Summary',
'items' => \@items,
'labels' => \%label,
'colors' => \%color,
'links' => \%link,
'agentnum' => $agentnum,
+ 'refnum' => $refnum,
'nototal' => scalar($cgi->param('12mo')),
)
%>
$agent = qsearchs('agent', { 'agentnum' => $agentnum } );
die "agentnum $agentnum not found!" unless $agent;
}
-
my $agentname = $agent ? $agent->agent.' ' : '';
+my( $refnum, $part_referral ) = ('', '');
+if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ $refnum = $1;
+ $part_referral = qsearchs('part_referral', { 'refnum' => $refnum } );
+ die "refnum $refnum not found!" unless $part_referral;
+}
+my $referralname = $part_referral ? $part_referral->referral.' ' : '';
+
+
my @items = qw( invoiced netsales
credits netcredits
payments receipts
$color{$_.'_12mo'} = $color{$_}
foreach keys %color;
+my $ar = "agentnum=$agentnum;refnum=$refnum";
+
my %link = (
- 'invoiced' => "${p}search/cust_bill.html?agentnum=$agentnum;",
- 'netsales' => "${p}search/cust_bill.html?agentnum=$agentnum;net=1;",
- 'credits' => "${p}search/cust_credit.html?agentnum=$agentnum;",
- 'netcredits' => "${p}search/cust_credit_bill.html?agentnum=$agentnum;",
- 'payments' => "${p}search/cust_pay.html?magic=_date;agentnum=$agentnum;",
- 'receipts' => "${p}search/cust_bill_pay.html?agentnum=$agentnum;",
- 'refunds' => "${p}search/cust_refund.html?magic=_date;agentnum=$agentnum;",
- 'netrefunds' => "${p}search/cust_credit_refund.html?agentnum=$agentnum;",
+ 'invoiced' => "${p}search/cust_bill.html?$ar;",
+ 'netsales' => "${p}search/cust_bill.html?$ar;net=1;",
+ 'credits' => "${p}search/cust_credit.html?$ar;",
+ 'netcredits' => "${p}search/cust_credit_bill.html?$ar;",
+ 'payments' => "${p}search/cust_pay.html?magic=_date;$ar;",
+ 'receipts' => "${p}search/cust_bill_pay.html?$ar;",
+ 'refunds' => "${p}search/cust_refund.html?magic=_date;$ar;",
+ 'netrefunds' => "${p}search/cust_credit_refund.html?$ar;",
);
# XXX link 12mo?
)
%>
+<% include('/elements/tr-select-part_referral.html',
+ 'label' => 'Advertising source ',
+ 'disable_empty' => 0,
+ 'empty_label' => 'all',
+ )
+%>
+
<TR>
<TD ALIGN="right"><INPUT TYPE="checkbox" NAME="12mo" VALUE="1"></TD>
<TD>Show 12 month totals instead of monthly values</TD>
$search{'agentnum'} = $1;
}
+ if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ $search{'refnum'} = $1;
+ }
+
if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
$search{'custnum'} = $1;
}
$title = $agent->agent. " $title";
}
+if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ push @search, "refnum = $1";
+ my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );
+ die "unknown refnum $1" unless $part_referral;
+ $title = $part_referral->referral. " $title";
+}
+
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
push @search, "cust_bill._date >= $beginning ",
"cust_bill._date <= $ending";
$title = $agent->agent. " $title";
}
+if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ push @search, "refnum = $1";
+ my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );
+ die "unknown refnum $1" unless $part_referral;
+ $title = $part_referral->referral. " $title";
+}
+
if ( $unapplied ) {
push @search, FS::cust_credit->unapplied_sql . ' > 0';
}
$title = $agent->agent. " $title";
}
+if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ push @search, "refnum = $1";
+ my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );
+ die "unknown refnum $1" unless $part_referral;
+ $title = $part_referral->referral. " $title";
+}
+
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
push @search, "cust_bill._date >= $beginning ",
"cust_bill._date <= $ending";
$title = $agent->agent. " $title";
}
+if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ push @search, "refnum = $1";
+ my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );
+ die "unknown refnum $1" unless $part_referral;
+ $title = $part_referral->referral. " $title";
+}
+
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
push @search, "cust_credit._date >= $beginning ",
"cust_credit._date <= $ending";
$title = $agent->agent. " $title";
}
+ if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ push @search, "refnum = $1";
+ my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );
+ die "unknown refnum $1" unless $part_referral;
+ $title = $part_referral->referral. " $title";
+ }
+
if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
push @search, "custnum = $1";
}