summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/elements/menu.html9
-rw-r--r--httemplate/misc/delete-cust_pkg_discount.html4
-rw-r--r--httemplate/search/cust_bill_pkg_discount.html151
-rw-r--r--httemplate/search/cust_pkg_discount.html122
-rw-r--r--httemplate/search/report_cust_bill_pkg_discount.html47
-rw-r--r--httemplate/search/report_cust_pkg_discount.html50
6 files changed, 382 insertions, 1 deletions
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index 5090abc73..1694a5927 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -102,6 +102,13 @@ tie my %report_invoices, 'Tie::IxHash',
'Advanced invoice reports' => [ $fsurl.'search/report_cust_bill.html', 'by agent, date range, etc.' ],
;
+tie my %report_discounts, 'Tie::IxHash',
+ 'Discount graph' => [ $fsurl. 'graph/report_cust_bill_pkg_discount.html', 'Discount overview per month' ],
+ 'Discount detail' => [ $fsurl.'search/report_cust_bill_pkg_discount.html', 'Discount report (by employee and/or date range)' ],
+ #awful name
+ 'Package discounts' => [ $fsurl.'search/report_cust_pkg_discount.html', 'Active/inactive discounts by package' ],
+;
+
tie my %report_services, 'Tie::IxHash';
if ( $curuser->access_right('Configuration') ) {
$report_services{'Service definitions'} = [ $fsurl.'browse/part_svc.cgi?orderby=active', 'Service definitions by number of active packages' ];
@@ -262,6 +269,8 @@ $report_menu{'Customers'} = [ \%report_customers, 'Customer reports' ]
if $curuser->access_right('List customers');
$report_menu{'Invoices'} = [ \%report_invoices, 'Invoice reports' ]
if $curuser->access_right('List invoices');
+$report_menu{'Discounts'} = [ \%report_discounts, 'Discount reports' ]
+ if $curuser->access_right('Financial reports');
$report_menu{'Payments'} = [ \%report_payments, 'Payment reports' ]
if $curuser->access_right('Financial reports');
$report_menu{'Packages'} = [ \%report_packages, 'Package reports' ]
diff --git a/httemplate/misc/delete-cust_pkg_discount.html b/httemplate/misc/delete-cust_pkg_discount.html
index 69168af3b..0bdaa13b3 100644
--- a/httemplate/misc/delete-cust_pkg_discount.html
+++ b/httemplate/misc/delete-cust_pkg_discount.html
@@ -25,6 +25,8 @@ my $cust_pkg_discount =
my $cust_pkg = $cust_pkg_discount->cust_pkg;
my $custnum = $cust_pkg->custnum;
-my $error = $cust_pkg_discount->delete;
+$cust_pkg_discount->disabled('Y');
+
+my $error = $cust_pkg_discount->replace;
</%init>
diff --git a/httemplate/search/cust_bill_pkg_discount.html b/httemplate/search/cust_bill_pkg_discount.html
new file mode 100644
index 000000000..088b29115
--- /dev/null
+++ b/httemplate/search/cust_bill_pkg_discount.html
@@ -0,0 +1,151 @@
+<% include( 'elements/search.html',
+ 'title' => 'Discounts',
+ 'name' => 'discounts',
+ 'query' => $query,
+ 'count_query' => $count_query,
+ 'count_addl' => [ $money_char. '%.2f total', ],
+ 'header' => [
+ #'#',
+ 'Discount',
+ 'Amount',
+ 'Months',
+ 'Package',
+ 'Invoice',
+ 'Date',
+ FS::UI::Web::cust_header(),
+ ],
+ 'fields' => [
+ #'billpkgdiscountnum',
+ sub { $_[0]->cust_pkg_discount->discount->description },
+ sub { sprintf($money_char.'%.2f', shift->amount ) },
+ sub { my $m = shift->months;
+ $m =~ /\./ ? sprintf('%.2f', $m) : $m;
+ },
+ 'pkg',#sub { $_[0]->cust_bill_pkg->cust_pkg->part_pkg->pkg },
+ 'invnum',
+ sub { time2str('%b %d %Y', shift->_date ) },
+ \&FS::UI::Web::cust_fields,
+ ],
+ 'links' => [
+ #'',
+ '', #link to customer discount???
+ '',
+ '',
+ '',
+ $ilink,
+ $ilink,
+ ( map { $_ ne 'Cust. Status' ? $clink : '' }
+ FS::UI::Web::cust_header()
+ ),
+ ],
+ #'align' => 'rlrrrc'.FS::UI::Web::cust_aligns(),
+ 'align' => 'lrrlrr'.FS::UI::Web::cust_aligns(),
+ 'color' => [
+ #'',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ FS::UI::Web::cust_colors(),
+ ],
+ 'style' => [
+ #'',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ FS::UI::Web::cust_styles(),
+ ],
+ )
+%>
+<%init>
+
+#a little false laziness below w/cust_bill_pkg.cgi
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my $conf = new FS::Conf;
+
+#here is the agent virtualization
+my $agentnums_sql =
+ $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
+
+my @where = ( $agentnums_sql );
+
+my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
+push @where, "_date >= $beginning",
+ "_date <= $ending";
+
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+ push @where, "cust_main.agentnum = $1";
+}
+
+# #classnum
+# # not specified: all classes
+# # 0: empty class
+# # N: classnum
+# my $use_override = $cgi->param('use_override');
+# if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
+# my $comparison = '';
+# if ( $1 == 0 ) {
+# $comparison = "IS NULL";
+# } else {
+# $comparison = "= $1";
+# }
+#
+# if ( $use_override ) {
+# push @where, "(
+# part_pkg.classnum $comparison AND pkgpart_override IS NULL OR
+# override.classnum $comparison AND pkgpart_override IS NOT NULL
+# )";
+# } else {
+# push @where, "part_pkg.classnum $comparison";
+# }
+# }
+
+my $count_query = "SELECT COUNT(*), SUM(amount)";
+
+my $join_cust = ' JOIN cust_bill_pkg USING ( billpkgnum )
+ JOIN cust_bill USING ( invnum )
+ LEFT JOIN cust_main USING ( custnum ) ';
+
+my $join_pkg = ' LEFT JOIN cust_pkg USING ( pkgnum )
+ LEFT JOIN part_pkg USING ( pkgpart ) ';
+ #LEFT JOIN part_pkg AS override
+ # ON pkgpart_override = override.pkgpart ';
+
+my $where = ' WHERE '. join(' AND ', @where);
+
+$count_query .= " FROM cust_bill_pkg_discount $join_cust $join_pkg $where";
+
+my @select = (
+ 'cust_bill_pkg_discount.*',
+ #'cust_bill_pkg.*',
+ 'cust_bill.invnum',
+ 'cust_bill._date',
+ );
+push @select, 'part_pkg.pkg';
+push @select, 'cust_main.custnum',
+ FS::UI::Web::cust_sql_fields();
+
+my $query = {
+ 'table' => 'cust_bill_pkg_discount',
+ 'addl_from' => "$join_cust $join_pkg",
+ 'hashref' => {},
+ 'select' => join(', ', @select ),
+ 'extra_sql' => $where,
+ 'order_by' => 'ORDER BY _date, billpkgdiscountnum',
+};
+
+my $ilink = [ "${p}view/cust_bill.cgi?", 'invnum' ];
+my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
+
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
+
+</%init>
diff --git a/httemplate/search/cust_pkg_discount.html b/httemplate/search/cust_pkg_discount.html
new file mode 100644
index 000000000..233345e1c
--- /dev/null
+++ b/httemplate/search/cust_pkg_discount.html
@@ -0,0 +1,122 @@
+<% include( 'elements/search.html',
+ 'title' => 'Package discounts',
+ 'name' => 'discounts',
+ 'query' => $query,
+ 'count_query' => $count_query,
+ #'redirect' => $link,
+ 'header' => [ 'Status',
+ 'Discount',
+ 'Months used',
+ 'Employee',
+ 'Package',
+ FS::UI::Web::cust_header(
+ # $cgi->param('cust_fields')
+ ),
+ ],
+ 'fields' => [
+ sub { ucfirst( shift->status ) },
+ sub { shift->discount->description },
+ sub { my $m = shift->months_used;
+ $m =~ /\./ ? sprintf('%.2f',$m) : $m;
+ },
+ 'otaker',
+ 'pkg',
+ \&FS::UI::Web::cust_fields,
+ ],
+ 'links' => [
+ '',
+ '',
+ '',
+ '',
+ '',
+ ( map { $_ ne 'Cust. Status' ? $clink : ''}
+ FS::UI::Web::cust_header()
+ ),
+ ],
+ 'align' => 'clrll'. FS::UI::Web::cust_aligns(),
+ 'color' => [
+ '',
+ '',
+ '',
+ '',
+ '',
+ FS::UI::Web::cust_colors(),
+ ],
+ 'style' => [
+ '',
+ '',
+ '',
+ '',
+ '',
+ FS::UI::Web::cust_styles(),
+ ],
+ )
+%>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+#my $conf = new FS::Conf;
+
+#here is the agent virtualization
+my $agentnums_sql =
+ $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
+
+my @where = ( $agentnums_sql );
+
+#status
+if ( $cgi->param('status') eq 'active' ) {
+ push @where, " ( cust_pkg_discount.disabled IS NULL
+ OR cust_pkg_discount.disabled != 'Y' )
+ AND ( months IS NULL OR months_used < months ) ";
+ #XXX also end date
+} elsif ( $cgi->param('status') eq 'expired' ) {
+ push @where, " ( cust_pkg_discount.disabled IS NOT NULL
+ AND cust_pkg_discount.disabled = 'Y' )
+ OR ( months IS NOT NULL AND months_used >= months )
+ "; #XXX also end date
+}
+
+#otaker
+if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
+ push @where, "cust_pkg_discount.otaker = '$1'";
+}
+
+#agent
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+ push @where, "cust_main.agentnum = $1";
+}
+
+my $count_query = "SELECT COUNT(*), SUM(amount)";
+
+my $join = ' LEFT JOIN discount USING ( discountnum )
+ LEFT JOIN cust_pkg USING ( pkgnum )
+ LEFT JOIN part_pkg USING ( pkgpart )
+ LEFT JOIN cust_main USING ( custnum ) ';
+
+my $where = ' WHERE '. join(' AND ', @where);
+
+$count_query .= " FROM cust_pkg_discount $join $where";
+
+my @select = (
+ 'cust_pkg_discount.*',
+ 'part_pkg.pkg',
+ );
+push @select, 'cust_main.custnum',
+ FS::UI::Web::cust_sql_fields();
+
+my $query = {
+ 'table' => 'cust_pkg_discount',
+ 'addl_from' => $join,
+ 'hashref' => {},
+ 'select' => join(', ', @select ),
+ 'extra_sql' => $where,
+ 'order_by' => 'ORDER BY pkgdiscountnum',
+};
+
+my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
+
+my $conf = new FS::Conf;
+
+</%init>
diff --git a/httemplate/search/report_cust_bill_pkg_discount.html b/httemplate/search/report_cust_bill_pkg_discount.html
new file mode 100644
index 000000000..f1879d4a9
--- /dev/null
+++ b/httemplate/search/report_cust_bill_pkg_discount.html
@@ -0,0 +1,47 @@
+<% include('/elements/header.html', 'Discount report' ) %>
+
+<FORM ACTION="cust_bill_pkg_discount.html" METHOD="GET">
+
+
+<TABLE>
+
+ <% include( '/elements/tr-select-otaker.html',
+ 'label' => 'Discounts by employee: ',
+ 'otakers' => \@otakers,
+ )
+ %>
+
+ <% include( '/elements/tr-select-agent.html',
+ 'curr_value' => scalar( $cgi->param('agentnum') ),
+ 'label' => 'for agent: ',
+ 'disable_empty' => 0,
+ )
+ %>
+
+ <% include( '/elements/tr-input-beginning_ending.html' ) %>
+
+ <% include( '/elements/tr-input-lessthan_greaterthan.html',
+ 'label' => 'Amount',
+ 'field' => 'amount',
+ )
+ %>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="Get Report">
+
+</FORM>
+
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my $sth = dbh->prepare("SELECT DISTINCT otaker FROM cust_pkg_discount")
+ or die dbh->errstr;
+$sth->execute or die $sth->errstr;
+my @otakers = map { $_->[0] } @{$sth->fetchall_arrayref};
+
+</%init>
diff --git a/httemplate/search/report_cust_pkg_discount.html b/httemplate/search/report_cust_pkg_discount.html
new file mode 100644
index 000000000..7ebd44f75
--- /dev/null
+++ b/httemplate/search/report_cust_pkg_discount.html
@@ -0,0 +1,50 @@
+<% include('/elements/header.html', 'Package discount report' ) %>
+
+<FORM ACTION="cust_pkg_discount.html" METHOD="GET">
+
+
+<TABLE>
+
+ <TR>
+ <TD>Discount status</TD>
+ <TD>
+ <SELECT NAME="status">
+ <OPTION VALUE="active">Active
+ <OPTION VALUE="expired">Expired
+ <OPTION VALUE="">(all)
+ </SELECT>
+ </TD>
+ </TR>
+
+ <% include( '/elements/tr-select-otaker.html',
+ 'label' => 'Discounts by employee: ',
+ 'otakers' => \@otakers,
+ )
+ %>
+
+ <% include( '/elements/tr-select-agent.html',
+ 'curr_value' => scalar( $cgi->param('agentnum') ),
+ 'label' => 'for agent: ',
+ 'disable_empty' => 0,
+ )
+ %>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="Get Report">
+
+</FORM>
+
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my $sth = dbh->prepare("SELECT DISTINCT otaker FROM cust_pkg_discount")
+ or die dbh->errstr;
+$sth->execute or die $sth->errstr;
+my @otakers = map { $_->[0] } @{$sth->fetchall_arrayref};
+
+</%init>