2 <% $cgi->redirect($sales_link->[0] . $salesnum) %>
4 <& elements/search.html,
6 'name_singular' => 'sales person',
7 'header' => [ 'Sales person', 'One-Time Sales', 'Recurring Sales', 'Commission', ],
8 'fields' => [ 'salesperson',
9 $sales_sub_maker->('setup'),
10 $sales_sub_maker->('recur'),
13 'links' => [ '', $sales_link, $sales_link, $commission_link ],
16 'count_query' => $count_query,
23 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
25 my $conf = new FS::Conf;
27 my $money_char = $conf->config('money_char') || '$';
29 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
31 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
33 my %query = ( 'table' => 'sales' );
34 my $count_query = "SELECT COUNT(*) FROM sales";
36 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
37 $query{hashref}->{agentnum} = $1;
38 $count_query .= " WHERE agentnum = $1";
42 if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) {
45 $cgi->delete('salesnum');
48 my $title = 'Sales person commission';
49 $title .= ': '. time2str($date_format, $beginning). ' to '.
50 time2str($date_format, $ending)
53 my $paid = $cgi->param('paid') ? 1 : 0;
54 $title .= ' - paid sales only' if $paid;
56 my $cust_main_sales = $cgi->param('cust_main_sales') eq 'Y' ? 'Y' : '';
58 my $sales_link = [ 'sales_pkg_class.html?'.
59 # pass all of our parameters along
60 $cgi->query_string. ';salesnum=',
64 my $sales_sub_maker = sub {
69 #efficiency improvement: ask the db for a sum instead of all the records
71 my @cust_bill_pkg = $sales->cust_bill_pkg(
74 'cust_main_sales' => $cust_main_sales,
77 $total += $_->get($field) foreach @cust_bill_pkg;
79 $money_char. sprintf('%.2f', $total);
83 my $commission_sub = sub {
86 #efficiency improvement: ask the db for a sum instead of all the records
88 my @cust_credit = $sales->cust_credit( $beginning, $ending );
89 $total_credit += $_->amount foreach @cust_credit;
91 $money_char. sprintf('%.2f', $total_credit);
94 my $commission_link = [ 'cust_credit.html?'.
97 "cust_main_sales=$cust_main_sales;".
98 'commission_salesnum=',