1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<& elements/search.html,
'title' => $title,
'name_singular' => 'sales person',
# 'redirect' => sub { #my( $sales, $cgi ) = @);
# $saleslink;
# },
'header' => [ 'Sales person', 'Sales', 'Commission', ],
'fields' => [ 'salesperson', $sales_sub, $commission_sub, ],
'links' => [ '', $sales_link, $commission_link ],
'align' => 'lrr',
'query' => { 'table' => 'sales', },
'count_query' => 'SELECT COUNT(*) FROM sales',
'disableable' => 1,
&>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
my $date_format = $conf->config('date_format') || '%m/%d/%Y';
my $title = 'Sales person commission';
$title .= ': '. time2str($date_format, $beginning). ' to '.
time2str($date_format, $ending)
if $beginning;
my $cust_main_sales = $cgi->param('cust_main_sales') eq 'Y' ? 'Y' : '';
my $sales_link = [ 'sales_pkg_class.html?'.
"begin=$beginning;".
"end=$ending;".
"cust_main_sales=$cust_main_sales;".
"salesnum=",
'salesnum'
];
my $sales_sub = sub {
my $sales = shift;
#efficiency improvement: ask the db for a sum instead of all the records
my $total_recur = 0;
my @cust_bill_pkg = $sales->cust_bill_pkg(
$beginning,
$ending,
'cust_main_sales' => $cust_main_sales,
);
$total_recur += $_->recur foreach @cust_bill_pkg;
$money_char. sprintf('%.2f', $total_recur);
};
my $commission_sub = sub {
my $sales = shift;
#efficiency improvement: ask the db for a sum instead of all the records
my $total_credit = 0;
my @cust_credit = $sales->cust_credit( $beginning, $ending );
$total_credit += $_->amount foreach @cust_credit;
$money_char. sprintf('%.2f', $total_credit);
};
my $commission_link = [ 'cust_credit.html?'.
"begin=$beginning;".
"end=$ending;".
"cust_main_sales=$cust_main_sales;".
'commission_salesnum=',
'salesnum'
];
</%init>
|