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";
37 if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) {
40 $cgi->delete('salesnum');
43 my $title = 'Sales person commission';
44 $title .= ': '. time2str($date_format, $beginning). ' to '.
45 time2str($date_format, $ending)
48 my $paid = $cgi->param('paid') ? 1 : 0;
49 $title .= ' - paid sales only' if $paid;
51 my $cust_main_sales = $cgi->param('cust_main_sales') eq 'Y' ? 'Y' : '';
53 my $sales_link = [ 'sales_pkg_class.html?'.
54 # pass all of our parameters along
55 $cgi->query_string. ';salesnum=',
59 my $sales_sub_maker = sub {
64 #efficiency improvement: ask the db for a sum instead of all the records
66 my @cust_bill_pkg = $sales->cust_bill_pkg(
69 'cust_main_sales' => $cust_main_sales,
72 $total += $_->get($field) foreach @cust_bill_pkg;
74 $money_char. sprintf('%.2f', $total);
78 my $commission_sub = sub {
81 #efficiency improvement: ask the db for a sum instead of all the records
83 my @cust_credit = $sales->cust_credit( $beginning, $ending );
84 $total_credit += $_->amount foreach @cust_credit;
86 $money_char. sprintf('%.2f', $total_credit);
89 my $commission_link = [ 'cust_credit.html?'.
92 "cust_main_sales=$cust_main_sales;".
93 'commission_salesnum=',