diff options
author | Mark Wells <mark@freeside.biz> | 2015-09-18 10:18:43 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-09-18 10:18:43 -0700 |
commit | c0c5709fb022b83a482d0b35f7094505766d5868 (patch) | |
tree | 1cc652dad8a1280f4297c0ab12e8520e610fbd14 /httemplate | |
parent | 7bce756e86a4307d6cad49a690f22a321acc9981 (diff) |
send commission reports by email, #33101
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/elements/popup_link-send_report_batch.html | 28 | ||||
-rw-r--r-- | httemplate/misc/process/send-report.html | 7 | ||||
-rw-r--r-- | httemplate/misc/send-report.html | 166 | ||||
-rw-r--r-- | httemplate/search/cust_msg.html | 3 | ||||
-rw-r--r-- | httemplate/search/report_sales_commission_pkg.html | 10 | ||||
-rw-r--r-- | httemplate/search/sales_commission_pkg.html | 7 |
6 files changed, 220 insertions, 1 deletions
diff --git a/httemplate/elements/popup_link-send_report_batch.html b/httemplate/elements/popup_link-send_report_batch.html new file mode 100644 index 000000000..5f4471054 --- /dev/null +++ b/httemplate/elements/popup_link-send_report_batch.html @@ -0,0 +1,28 @@ +<%doc> + +Example: + +<& /elements/popup_link-send_report_batch.html, + reportname => 'sales_commission_pkg', + label => 'Click here to send reports by email', +&> +</%doc> +<& /elements/popup_link.html, $params &>\ +<%init> + +my $params = { 'closetext' => emt('Close') }; + +if (ref($_[0]) eq 'HASH') { + $params = { %$params, %{ $_[0] } }; +} else { + $params = { %$params, @_ }; +} + +$params->{'label'} ||= emt('Send reports by email'); +$params->{'actionlabel'} ||= emt('Send reports'); +#$params->{'width'} ||= 350; +$params->{'height'} ||= 650; + +$params->{'action'} = $fsurl. 'misc/send-report.html?reportname='. $params->{'reportname'}; + +</%init> diff --git a/httemplate/misc/process/send-report.html b/httemplate/misc/process/send-report.html new file mode 100644 index 000000000..3bceebc0c --- /dev/null +++ b/httemplate/misc/process/send-report.html @@ -0,0 +1,7 @@ +<%init> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Send reports to customers'); + +my $server = FS::UI::Web::JSRPC->new('FS::report_batch::process_send_report', $cgi); +</%init> +<% $server->process %> diff --git a/httemplate/misc/send-report.html b/httemplate/misc/send-report.html new file mode 100644 index 000000000..557767a57 --- /dev/null +++ b/httemplate/misc/send-report.html @@ -0,0 +1,166 @@ +<%doc> + +Parameters: + +- reportname: the report name (per FS::report_batch) + +</%doc> +<& /elements/header-popup.html, { title => $report_info->{name} } &> +<script type="text/javascript"> + +$().ready(function() { + var agent_info = <% encode_json(\%agent) %>; + + $('#agentnum').on('change', function() { + var agentnum = this.value; + if ( agent_info[agentnum] ) { + $('#msgnum').prop('value', agent_info[agentnum]['msgnum']); + $('#beginning_text').prop('value', agent_info[agentnum]['beginning']); + $('#ending_text').prop('value', agent_info[agentnum]['ending']); + } else { + $('#msgnum').prop('value', ''); + $('#beginning_text').prop('value', ''); + $('#ending_text').prop('value', ''); + } + }); + + $('#agentnum').trigger('change'); + +}); + +</script> +<FORM NAME="OneTrueForm" ACTION="process/send-report.html" METHOD="POST"> + +<table class="inv"> + <input type="hidden" name="reportname" value="<% $cgi->param('reportname') |h %>"> + + <& /elements/tr-select-agent.html &> + + <& /elements/tr-td-label.html, label => emt('Message template') &> + <TD> + <& /elements/select-msg_template.html, field => 'msgnum' &> + </TD> + </TR> + + <& /elements/tr-input-beginning_ending.html &> + + <& /elements/progress-init.html, + 'OneTrueForm', + [ qw( reportname msgnum agentnum beginning ending ) ], + $p.'misc/process/send-report.html', + { message => 'Reports sent', + url => $cgi->referer } + &> + +</table> + +<INPUT TYPE="button" onclick="process()" VALUE="<% emt('Send reports') %>" /> +</FORM> + +<style> +table.grid { + border-collapse: collapse; + margin-top: 1ex; + margin-left: auto; + margin-right: auto; +} +.grid caption { + font-weight: bold; + margin-bottom: 0.5ex; +} +.grid th,td { + padding-left: 3px; + padding-right: 3px; + padding-bottom: 2px; + border: none; + empty-cells: show; +} +.grid th { + border-bottom: 1px solid #999999; + font-size: 90%; + vertical-align: bottom; +} +</style> + +% if ( @report_history ) { +<hr> +<table class="grid"> +<caption><% emt('Report history') %></caption> +<thead> + <th>Agent</th> + <th>Sent on</th> + <th colspan=2>Date range</th> + <th>User</th> +</thead> +<tbody> +% my $row = 0; +% foreach my $report (@report_history) { +% my $agent = ($report->agentnum ? +% $report->agent->agent : 'All agents'); + <tr class="row<% $row % 2 %>"> + <td><% $agent %></td> + <td><% time2str($date_format, $report->send_date) %></td> + <td><% time2str($date_format, $report->sdate) %></td> + <td><% time2str($date_format, $report->edate) %></td> + <td><% $report->access_user->username %></td> + </tr> +% $row++; +% } +</tbody> +</table> +% } + +<& /elements/footer.html &> + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Send reports to customers'); + +$cgi->param('reportname') =~ /^(\w+)$/ + or die "bad reportname"; +my $reportname = $1; +my $report_info = $FS::report_batch::sendable_reports{$reportname} + or die "bad reportname"; + +my $date_format = FS::Conf->new->config('date_format') || '%x'; + +my @report_history = qsearch({ + table => 'report_batch', + hashref => { reportname => $reportname }, + order_by => ' ORDER BY send_date DESC', +}); + +# defaults per agent that could be selected for the report +my %agent; + +foreach my $report ( @report_history ) { + my $agentnum = $report->agentnum; + next if $agent{$agentnum}; + + # estimate the width of the report period, in months + my $last_sdate = DateTime->from_epoch( epoch => $report->sdate ); + my $last_edate = DateTime->from_epoch( epoch => $report->edate ); + + my $days = $last_sdate->delta_days( $last_edate )->delta_days; + my $months = sprintf('%.0f', $days / 6) / 5; + + my $next_sdate = $last_edate->clone->add(days => 1); + my $next_edate = $next_sdate->clone; + if ( $months >= 1 ) { # then treat as an interval in months + $next_edate->add( months => sprintf('%.0f', $months) ); + $next_edate->subtract(days => 1); + } else { # treat as a number of days + $next_edate->add( days => $days ); + } + + my $name = $agentnum ? FS::agent->by_key($agentnum)->agent : 'All agents'; + $agent{$agentnum} = { + name => $name, + beginning => $next_sdate->strftime($date_format), + ending => $next_edate->strftime($date_format), + msgnum => $report->msgnum, + }; +} + +</%init> diff --git a/httemplate/search/cust_msg.html b/httemplate/search/cust_msg.html index 401f52ebb..e9aece202 100644 --- a/httemplate/search/cust_msg.html +++ b/httemplate/search/cust_msg.html @@ -144,11 +144,12 @@ include('/elements/select.html', include('/elements/select.html', 'field' => 'msgtype', 'curr_value' => $cgi->param('msgtype') || '', - 'options' => [ '', 'invoice', 'receipt', 'admin' ], + 'options' => [ '', 'invoice', 'receipt', 'admin', 'report' ], 'labels' => { '' => '(any)', 'invoice' => 'Invoices', 'receipt' => 'Receipts', 'admin' => 'Admin notices', + 'report' => 'Reports', }, ) . '</TD> diff --git a/httemplate/search/report_sales_commission_pkg.html b/httemplate/search/report_sales_commission_pkg.html index 6adf090e9..27906e0c3 100644 --- a/httemplate/search/report_sales_commission_pkg.html +++ b/httemplate/search/report_sales_commission_pkg.html @@ -1,5 +1,15 @@ <& /elements/header.html, 'Sales commission report per package' &> +% if ($FS::CurrentUser::CurrentUser->access_right('Send reports to customers')) +% { +<P> +<& /elements/popup_link-send_report_batch.html, + reportname => 'sales_commission_pkg', + label => emt('Send these reports by email'), +&> +</P> +% } + <FORM ACTION="sales_commission_pkg.html"> <TABLE BGCOLOR="#cccccc" CELLSPACING=0> diff --git a/httemplate/search/sales_commission_pkg.html b/httemplate/search/sales_commission_pkg.html index 2b5f2bb0a..9fbe22eca 100644 --- a/httemplate/search/sales_commission_pkg.html +++ b/httemplate/search/sales_commission_pkg.html @@ -1,12 +1,17 @@ %# still not a good way to do rows grouped by some field in a search.html %# report +%# (there is now, but we're not yet sponsored to switch this over to it) % if ( $type eq 'xls' ) { <% $data %>\ % } else { +% if ( $type eq 'html-print' ) { +<& /elements/header-popup.html, $title &> +% } else { <& /elements/header.html, $title &> <P ALIGN="right" CLASS="noprint"> Download full results<BR> as <A HREF="<% $cgi->self_url %>;_type=xls">Excel spreadsheet</A></P> +% } <BR> <STYLE TYPE="text/css"> td.cust_head { @@ -22,12 +27,14 @@ td.money:before { content: '<% $money_char %>'; } .row1 { background-color: #ffffff; } </STYLE> <& /elements/table-grid.html &> +<THEAD> <TR STYLE="background-color: #cccccc"> <TH CLASS="grid">Package</TH> <TH CLASS="grid">Sales</TH> <TH CLASS="grid">Percentage</TH> <TH CLASS="grid">Commission</TH> </TR> +</THEAD> % my ($custnum, $sales, $commission, $row, $bgcolor) = (0, 0, 0, 0); % foreach my $cust_pkg ( @cust_pkg ) { % if ( $custnum ne $cust_pkg->custnum ) { |