Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom date ranges to the sales and revenue report #3257

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions adminpages/reports/sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ function pmpro_report_sales_page()
$startdate = date( 'Y-m-01', strtotime( current_time( 'mysql' ) . ' -12 month' ) );
// Set the end date to the last day of the previous month.
$enddate = date('Y-m-t', strtotime( current_time( 'mysql' ) . ' -1 month' ) );
} else if ( $period === 'custom' ) {
// Set up the report unit to use.
$report_unit = 'DAY';
$axis_date_format = 'd';
$tooltip_date_format = get_option( 'date_format' );
// Set up the start and end dates.
$startdate = sanitize_text_field( $_REQUEST['custom_start_date'] );
$enddate = sanitize_text_field( $_REQUEST['custom_end_date'] );
} else {
// Set up the report unit to use.
$report_unit = 'YEAR';
Expand Down Expand Up @@ -607,6 +615,7 @@ function pmpro_report_sales_page()
<option value='7days' <?php selected( $period, '7days' ); ?>><?php esc_html_e( 'Last 7 Days', 'paid-memberships-pro' ); ?></option>
<option value='30days' <?php selected( $period, '30days' ); ?>><?php esc_html_e( 'Last 30 Days', 'paid-memberships-pro' ); ?></option>
<option value='12months' <?php selected( $period, '12months' ); ?>><?php esc_html_e( 'Last 12 Months', 'paid-memberships-pro' ); ?></option>
<option value='custom' <?php selected( $period, 'custom' ); ?>><?php esc_html_e( 'Custom Range', 'paid-memberships-pro' ); ?></option>
</select>
<label for="type" class="screen-reader-text"><?php esc_html_e( 'Select report type', 'paid-memberships-pro' ); ?></label>
<select id="type" name="type">
Expand All @@ -626,6 +635,12 @@ function pmpro_report_sales_page()
<option value="<?php echo esc_attr( $i );?>" <?php selected($year, $i);?>><?php echo esc_html( $i );?></option>
<?php } ?>
</select>
<span class="pmpro-sales-report-custom"><?php esc_html_e('from', 'paid-memberships-pro' )?></span>
<label for="custom_start_date" class="screen-reader-text pmpro-sales-report-custo"><?php esc_html_e( 'Select report start date', 'paid-memberships-pro' ); ?></label>
<input type="date" id="custom_start_date" name="custom_start_date" class="pmpro-sales-report-custom" value="<?php echo esc_attr( $startdate ); ?>" />
<span class="pmpro-sales-report-custom"><?php esc_html_e('to', 'paid-memberships-pro' )?></span>
<label for="custom_end_date" class="screen-reader-text pmpro-sales-report-custo"><?php esc_html_e( 'Select report end date', 'paid-memberships-pro' ); ?></label>
<input type="date" id="custom_end_date" name="custom_end_date" class="pmpro-sales-report-custom" value="<?php echo esc_attr( $enddate ); ?>" />
<span id="for"><?php esc_html_e('for', 'paid-memberships-pro' )?></span>
<label for="level" class="screen-reader-text"><?php esc_html_e( 'Filter report by membership level', 'paid-memberships-pro' ); ?></label>
<select id="level" name="level">
Expand Down Expand Up @@ -686,18 +701,27 @@ function pmpro_ShowMonthOrYear()
jQuery('#for').show();
jQuery('#month').show();
jQuery('#year').show();
jQuery('.pmpro-sales-report-custom').hide();
}
else if(period == 'monthly')
{
jQuery('#for').show();
jQuery('#month').hide();
jQuery('#year').show();
jQuery('.pmpro-sales-report-custom').hide();
}
else if ( period == 'custom' ) {
jQuery('.pmpro-sales-report-custom').show();
jQuery('#for').hide();
jQuery('#month').hide();
jQuery('#year').hide();
}
else
{
jQuery('#for').hide();
jQuery('#month').hide();
jQuery('#year').hide();
jQuery('.pmpro-sales-report-custom').hide();
}
}

Expand Down