Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Classes

  • EDD_API_Request_Log_Table
  • EDD_Customer_Reports_Table
  • EDD_Customers_Export
  • EDD_Download_History_Export
  • EDD_Download_Reports_Table
  • EDD_Export
  • EDD_File_Downloads_Log_Table
  • EDD_Gateway_Error_Log_Table
  • EDD_Payments_Export
  • EDD_Sales_Log_Table

Functions

  • edd_draw_chart_image
  • edd_estimated_monthly_stats
  • edd_generate_pdf
  • edd_get_report_dates
  • edd_log_default_views
  • edd_log_views
  • edd_logs_view_api_requests
  • edd_logs_view_file_downloads
  • edd_logs_view_gateway_errors
  • edd_logs_view_sales
  • edd_parse_report_dates
  • edd_report_views
  • edd_reporting_contextual_help
  • edd_reports_customers_table
  • edd_reports_default_views
  • edd_reports_downloads_table
  • edd_reports_earnings
  • edd_reports_graph
  • edd_reports_graph_controls
  • edd_reports_page
  • edd_reports_tab_export
  • edd_reports_tab_logs
  • edd_reports_tab_reports
  • edd_reports_taxes
  1 <?php
  2 /**
  3  * Admin Reports Page
  4  *
  5  * @package     EDD
  6  * @subpackage  Admin/Reports
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.0
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 /**
 16  * Reports Page
 17  *
 18  * Renders the reports page contents.
 19  *
 20  * @since 1.0
 21  * @global $edd_options Array of all the EDD Options
 22  * @return void
 23 */
 24 function edd_reports_page() {
 25     global $edd_options;
 26 
 27     $current_page = admin_url( 'edit.php?post_type=download&page=edd-reports' );
 28     $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'reports';
 29     ?>
 30     <div class="wrap">
 31         <h2 class="nav-tab-wrapper">
 32             <a href="<?php echo add_query_arg( array( 'tab' => 'reports', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'reports' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Reports', 'edd' ); ?></a>
 33             <?php if ( current_user_can( 'export_shop_reports' ) ) { ?>
 34                 <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'edd' ); ?></a>
 35             <?php } ?>
 36             <a href="<?php echo add_query_arg( array( 'tab' => 'logs', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'logs' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Logs', 'edd' ); ?></a>
 37             <?php do_action( 'edd_reports_tabs' ); ?>
 38         </h2>
 39 
 40         <?php
 41         do_action( 'edd_reports_page_top' );
 42         do_action( 'edd_reports_tab_' . $active_tab );
 43         do_action( 'edd_reports_page_bottom' );
 44         ?>
 45     </div><!-- .wrap -->
 46     <?php
 47 }
 48 
 49 /**
 50  * Default Report Views
 51  *
 52  * @since 1.4
 53  * @return array $views Report Views
 54  */
 55 function edd_reports_default_views() {
 56     $views = array(
 57         'earnings'  => __( 'Earnings', 'edd' ),
 58         'downloads' => edd_get_label_plural(),
 59         'customers' => __( 'Customers', 'edd' ),
 60         'taxes'     => __( 'Taxes', 'edd' )
 61     );
 62 
 63     $views = apply_filters( 'edd_report_views', $views );
 64 
 65     return $views;
 66 }
 67 
 68 /**
 69  * Renders the Reports page
 70  *
 71  * @since 1.3
 72  * @return void
 73  */
 74 function edd_reports_tab_reports() {
 75     $current_view = 'earnings';
 76     $views        = edd_reports_default_views();
 77 
 78     if ( isset( $_GET[ 'view' ] ) && array_key_exists( $_GET[ 'view' ], $views ) )
 79         $current_view = $_GET[ 'view' ];
 80 
 81     do_action( 'edd_reports_view_' . $current_view );
 82 }
 83 add_action( 'edd_reports_tab_reports', 'edd_reports_tab_reports' );
 84 
 85 /**
 86  * Renders the Reports Page Views Drop Downs
 87  *
 88  * @since 1.3
 89  * @return void
 90  */
 91 function edd_report_views() {
 92     $views        = edd_reports_default_views();
 93     $current_view = isset( $_GET[ 'view' ] ) ? $_GET[ 'view' ] : 'earnings';
 94     ?>
 95     <form id="edd-reports-filter" method="get">
 96         <select id="edd-reports-view" name="view">
 97             <option value="-1"><?php _e( 'Report Type', 'edd' ); ?></option>
 98             <?php foreach ( $views as $view_id => $label ) : ?>
 99                 <option value="<?php echo esc_attr( $view_id ); ?>" <?php selected( $view_id, $current_view ); ?>><?php echo $label; ?></option>
100             <?php endforeach; ?>
101         </select>
102 
103         <?php do_action( 'edd_report_view_actions' ); ?>
104 
105         <input type="hidden" name="post_type" value="download"/>
106         <input type="hidden" name="page" value="edd-reports"/>
107         <?php submit_button( __( 'Show', 'edd' ), 'secondary', 'submit', false ); ?>
108     </form>
109     <?php
110 }
111 
112 /**
113  * Renders the Reports Downloads Table
114  *
115  * @since 1.3
116  * @uses EDD_Download_Reports_Table::prepare_items()
117  * @uses EDD_Download_Reports_Table::display() 
118  * @return void
119  */
120 function edd_reports_downloads_table() {
121     include( dirname( __FILE__ ) . '/class-download-reports-table.php' );
122 
123     $downloads_table = new EDD_Download_Reports_Table();
124     $downloads_table->prepare_items();
125     $downloads_table->display();
126 }
127 add_action( 'edd_reports_view_downloads', 'edd_reports_downloads_table' );
128 
129 /**
130  * Renders the Reports Customers Table
131  *
132  * @since 1.3
133  * @uses EDD_Customer_Reports_Table::prepare_items()
134  * @uses EDD_Customer_Reports_Table::display()
135  * @return void
136  */
137 function edd_reports_customers_table() {
138     include( dirname( __FILE__ ) . '/class-customer-reports-table.php' );
139 
140     $downloads_table = new EDD_Customer_Reports_Table();
141     $downloads_table->prepare_items();
142     $downloads_table->display();
143 }
144 add_action( 'edd_reports_view_customers', 'edd_reports_customers_table' );
145 
146 /**
147  * Renders the Reports Earnings Graphs
148  *
149  * @since 1.3
150  * @return void
151  */
152 function edd_reports_earnings() {
153     ?>
154     <div class="tablenav top">
155         <div class="alignleft actions"><?php edd_report_views(); ?></div>
156     </div>
157     <?php
158     edd_reports_graph();
159 }
160 add_action( 'edd_reports_view_earnings', 'edd_reports_earnings' );
161 
162 /**
163  * Renders the Tax Reports
164  *
165  * @since 1.3.3
166  * @return void
167  */
168 function edd_reports_taxes() {
169     $year = isset( $_GET['year'] ) ? absint( $_GET['year'] ) : date( 'Y' );
170     ?>
171     <div class="tablenav top">
172         <div class="alignleft actions"><?php edd_report_views(); ?></div>
173     </div>
174 
175     <div class="metabox-holder" style="padding-top: 0;">
176         <div class="postbox">
177             <h3><span><?php _e('Tax Report', 'edd'); ?></span></h3>
178             <div class="inside">
179                 <p><?php _e( 'This report shows the total amount collected in sales tax for the given year.', 'edd' ); ?></p>
180                 <form method="get" action="<?php echo admin_url( 'edit.php' ); ?>">
181                     <span><?php echo $year; ?></span>: <strong><?php edd_sales_tax_for_year( $year ); ?></strong>&nbsp;&mdash;&nbsp;
182                     <select name="year">
183                         <?php for ( $i = 2009; $i <= date( 'Y' ); $i++ ) : ?>
184                         <option value="<?php echo $i; ?>"<?php selected( $year, $i ); ?>><?php echo $i; ?></option>
185                         <?php endfor; ?>
186                     </select>
187                     <input type="hidden" name="view" value="taxes" />
188                     <input type="hidden" name="post_type" value="download" />
189                     <input type="hidden" name="page" value="edd-reports" />
190                     <?php submit_button( __( 'Submit', 'edd' ), 'secondary', 'submit', false ); ?>
191                 </form>
192             </div><!-- .inside -->
193         </div><!-- .postbox -->
194     </div><!-- .metabox-holder -->
195     <?php
196 }
197 add_action( 'edd_reports_view_taxes', 'edd_reports_taxes' );
198 
199 /**
200  * Renders the 'Export' tab on the Reports Page
201  *
202  * @since 1.3
203  * @return void
204  */
205 function edd_reports_tab_export() {
206     ?>
207     <div class="metabox-holder">
208         <div id="post-body">
209             <div id="post-body-content">
210 
211                 <?php do_action( 'edd_reports_tab_export_content_top' ); ?>
212 
213                 <div class="postbox">
214                     <h3><span><?php _e( 'Export PDF of Sales and Earnings', 'edd' ); ?></span></h3>
215                     <div class="inside">
216                         <p><?php _e( 'Download a PDF of Sales and Earnings reports for all products for the current year.', 'edd' ); ?> <?php _e( 'Date range reports will be coming soon.', 'edd' ); ?></p>
217                         <p><a class="button" href="<?php echo wp_nonce_url( add_query_arg( array( 'edd-action' => 'generate_pdf' ) ), 'edd_generate_pdf' ); ?>"><?php _e( 'Generate PDF', 'edd' ); ?></a></p>
218                     </div><!-- .inside -->
219                 </div><!-- .postbox -->
220 
221                 <div class="postbox">
222                     <h3><span><?php _e('Export Payment History', 'edd'); ?></span></h3>
223                     <div class="inside">
224                         <p><?php _e( 'Download a CSV of all payments recorded.', 'edd' ); ?></p>
225                         <p>
226                             <form method="post">
227                                 <select name="edd_export_payment_status">
228                                     <option value="0"><?php _e( 'All Statuses', 'edd' ); ?></option>
229                                     <?php
230                                     $statuses = edd_get_payment_statuses();
231                                     foreach( $statuses as $status => $label ) {
232                                         echo '<option value="' . $status . '">' . $label . '</option>';
233                                     }
234                                     ?>
235                                 </select>
236                                 <input type="hidden" name="edd-action" value="payment_export"/>
237                                 <input type="submit" value="<?php _e( 'Generate CSV', 'edd' ); ?>" class="button-secondary"/>
238                             </form>
239                         </p>
240                     </div><!-- .inside -->
241                 </div><!-- .postbox -->
242 
243                 <div class="postbox">
244                     <h3><span><?php _e('Export Customers in CSV', 'edd'); ?></span></h3>
245                     <div class="inside">
246                         <p><?php _e( 'Download a CSV of all customer emails. Optionally export only customers that have purchased a particular product.', 'edd' ); ?></p>
247                         <p>
248                             <form method="post">
249                                 <select name="edd_export_download">
250                                     <option value="0"><?php _e( 'All', 'edd' ); ?></option>
251                                     <?php
252                                     $downloads = get_posts( array( 'post_type' => 'download', 'posts_per_page' => -1 ) );
253                                     if( $downloads ) {
254                                         foreach( $downloads as $download ) {
255                                             echo '<option value="' . $download->ID . '">' . get_the_title( $download->ID ) . '</option>';
256                                         }
257                                     }
258                                     ?>
259                                 </select>
260                                 <input type="hidden" name="edd-action" value="email_export"/>
261                                 <input type="submit" value="<?php _e( 'Generate CSV', 'edd' ); ?>" class="button-secondary"/>
262                             </form>
263                         </p>
264                     </div><!-- .inside -->
265                 </div><!-- .postbox -->
266 
267                 <div class="postbox">
268                     <h3><span><?php _e('Export Download History in CSV', 'edd'); ?></span></h3>
269                     <div class="inside">
270                         <p><?php _e( 'Download a CSV of all file downloads for the current month.', 'edd' ); ?></p>
271                         <p><a class="button" href="<?php echo wp_nonce_url( add_query_arg( array( 'edd-action' => 'downloads_history_export' ) ), 'edd_export_all_downloads_history' ); ?>"><?php _e( 'Generate CSV', 'edd' ) ; ?></a></p>
272                     </div><!-- .inside -->
273                 </div><!-- .postbox -->
274 
275                 <?php do_action( 'edd_reports_tab_export_content_bottom' ); ?>
276 
277             </div><!-- .post-body-content -->
278         </div><!-- .post-body -->
279     </div><!-- .metabox-holder -->
280     <?php
281 }
282 add_action( 'edd_reports_tab_export', 'edd_reports_tab_export' );
283 
284 /**
285  * Renders the Reports page
286  *
287  * @since 1.3
288  * @return void
289  */
290 function edd_reports_tab_logs() {
291     require( EDD_PLUGIN_DIR . 'includes/admin/reporting/logs.php' );
292 
293     $current_view = 'file_downloads';
294     $log_views    = edd_log_default_views();
295 
296     if ( isset( $_GET[ 'view' ] ) && array_key_exists( $_GET[ 'view' ], $log_views ) )
297         $current_view = $_GET[ 'view' ];
298 
299     do_action( 'edd_logs_view_' . $current_view );
300 }
301 add_action( 'edd_reports_tab_logs', 'edd_reports_tab_logs' );
302 
303 /**
304  * Retrieves estimated monthly earnings and sales
305  *
306  * @since 1.5
307  * @return array
308  */
309 function edd_estimated_monthly_stats() {
310     $estimated = get_transient( 'edd_estimated_monthly_stats' );
311 
312     if ( false === $estimated ) {
313         $estimated = array(
314             'earnings' => 0,
315             'sales'    => 0
316         );
317 
318         $products = get_posts( array( 'post_type' => 'download', 'posts_per_page' => -1, 'fields' => 'ids' ) );
319         if ( $products ) {
320             foreach ( $products as $download ) {
321                 $estimated['earnings'] += edd_get_average_monthly_download_earnings( $download );
322                 $estimated['sales']    += number_format( edd_get_average_monthly_download_sales( $download ), 0 );
323             }
324         }
325 
326         // Cache for one day
327         set_transient( 'edd_estimated_monthly_stats', serialize( $estimated ), 86400 );
328     }
329 
330     return maybe_unserialize( $estimated );
331 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0