1 <& search.html, %opt &>
3 <& elements/commission.html,
4 name_singular => 'sales person', # or 'agent', 'employee', etc.
5 header => [ 'Sales person' ], # 'One-Time Sales', 'Recurring Sales',
6 # 'Commission' will be appended
7 fields => [ 'salesperson' ], # ditto
8 links => [ [ '/view/sales.html?', 'salesnum' ] ], # usual conventions
9 sales_detail_link => [ 'sales_commission_pkg.html?', 'salesnum' ],
10 credit_detail_link => [ 'cust_credit.html?commission_salesnum=', 'salesnum' ],
12 query => { table => 'sales', # must be a Commission_Mixin
13 #other params as appropriate
15 count_query => 'SELECT COUNT(*) FROM sales ...',
17 # all other elements/search.html stuff will be passed through
20 The hash passed as 'query' will be passed through to the cust_bill_pkg_search
21 and cust_credit_search methods, and so can contain type-specific options.
25 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
28 my $conf = new FS::Conf;
30 my $money_char = $conf->config('money_char') || '$';
32 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
34 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
36 my $query = $opt{'query'};
38 my $paid = $cgi->param('paid') ? 1 : 0;
40 $opt{'title'} .= ': ' . time2str($date_format, $beginning) . ' to ' .
41 time2str($date_format, $ending);
44 $opt{'title'} .= ' - paid sales only';
47 my $sales_sub_maker = sub {
51 my $search = $object->cust_bill_pkg_search(
57 $search->{select} = "SUM(cust_bill_pkg.$field) AS total_amount";
58 my $result = qsearchs($search);
59 my $total = $result->get('total_amount') || 0;
61 return $money_char. sprintf('%.2f', $total);
65 my $commission_sub = sub {
68 my $search = $object->cust_credit_search(
73 $search->{select} = 'SUM(cust_credit.amount) AS total_amount';
74 my $result = qsearchs($search);
75 my $total = $result->get('total_amount') || 0;
77 return $money_char. sprintf('%.2f', $total);
80 my $sales_link = $opt{'sales_detail_link'};
82 my ($pre, $post) = split('\?', $sales_link->[0], 2);
83 $sales_link->[0] = $pre . "?begin=$beginning;end=$ending;" . $post;
86 my $commission_link = $opt{'credit_detail_link'};
87 if ($commission_link) {
88 my ($pre, $post) = split('\?', $commission_link->[0], 2);
89 $commission_link->[0] = $pre . "?begin=$beginning;end=$ending;" . $post;
92 # merge our new stuff into %opt
93 my $header = $opt{'header'};
100 my $fields = $opt{'fields'};
102 $sales_sub_maker->('setup'),
103 $sales_sub_maker->('recur'),
107 push @{$opt{'links'}}, $sales_link, $sales_link, $commission_link;
108 $opt{'align'} .= 'rrr';