PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.6.1
GiveWP – Donation Plugin and Fundraising Platform v2.6.1
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / tools / export / pdf-reports.php
give / includes / admin / tools / export Last commit date
class-batch-export-donors.php 7 years ago class-batch-export.php 6 years ago class-core-settings-export.php 7 years ago class-export-earnings.php 6 years ago class-export.php 6 years ago class-give-export-donations.php 6 years ago export-actions.php 6 years ago export-functions.php 6 years ago give-export-donations-exporter.php 6 years ago give-export-donations-functions.php 6 years ago pdf-reports.php 6 years ago
pdf-reports.php
362 lines
1 <?php
2 /**
3 * PDF Report Generation Functions.
4 *
5 * @package Give
6 * @subpackage Admin/Reports
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly..
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Generate PDF Reports.
19 *
20 * Generates PDF report on donations and income for all forms for the current year.
21 *
22 * @since 1.0
23 *
24 * @param string $data Data.
25 *
26 * @uses give_pdf
27 */
28 function give_generate_pdf( $data ) {
29
30 if ( ! current_user_can( 'view_give_reports' ) ) {
31 wp_die( __( 'You do not have permission to generate PDF sales reports.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
32 }
33
34 if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'give_generate_pdf' ) ) {
35 wp_die( __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
36 }
37
38 if ( ! file_exists( GIVE_PLUGIN_DIR . '/includes/libraries/give-pdf.php' ) ) {
39 wp_die( __( 'Dependency missing.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
40 }
41
42 require_once GIVE_PLUGIN_DIR . '/includes/libraries/give-pdf.php';
43
44 $daterange = utf8_decode(
45 sprintf(
46 /* translators: 1: start date 2: end date */
47 __( '%1$s to %2$s', 'give' ),
48 date_i18n( give_date_format(), mktime( 0, 0, 0, 1, 1, date( 'Y' ) ) ),
49 date_i18n( give_date_format() )
50 )
51 );
52
53 $categories_enabled = give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) );
54 $tags_enabled = give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) );
55
56 $pdf = new Give_PDF( 'L', 'mm', 'A', true, 'UTF-8', false );
57 $default_font = apply_filters( 'give_pdf_default_font', 'Helvetica' );
58 $custom_font = 'dejavusans';
59 $font_style = '';
60 $font_path = '';
61
62 if ( file_exists( GIVE_PLUGIN_DIR . 'vendor/autoload.php' ) ) {
63 $font_path = GIVE_PLUGIN_DIR . '/vendor/tecnickcom/tcpdf/fonts/CODE2000.TTF';
64 } else {
65 $font_path = GIVE_PLUGIN_DIR . '/includes/libraries/tcpdf/fonts/CODE2000.TTF';
66 }
67
68 if (
69 file_exists( $font_path ) &&
70
71 // RIAL exist for backward compatibility.
72 in_array( give_get_currency(), array( 'RIAL', 'RUB', 'IRR' ) )
73 ) {
74 TCPDF_FONTS::addTTFfont( $font_path, '' );
75 $custom_font = 'CODE2000';
76 $font_style = 'B';
77 }
78
79 $pdf->AddPage( 'L', 'A4' );
80 $pdf->setImageScale( 1.5 );
81 $pdf->SetTitle( utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ) );
82 $pdf->SetAuthor( utf8_decode( __( 'GiveWP - Democratizing Generosity', 'give' ) ) );
83 $pdf->SetCreator( utf8_decode( __( 'GiveWP - Democratizing Generosity', 'give' ) ) );
84
85 // Image URL should have absolute path. @see https://tcpdf.org/examples/example_009/.
86 $pdf->Image( apply_filters( 'give_pdf_export_logo', GIVE_PLUGIN_DIR . 'assets/dist/images/give-logo-small.png' ), 247, 8 );
87
88 $pdf->SetMargins( 8, 8, 8 );
89 $pdf->SetX( 8 );
90
91 $pdf->SetFont( $default_font, '', 16 );
92 $pdf->SetTextColor( 50, 50, 50 );
93 $pdf->Cell( 0, 3, utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ), 0, 2, 'L', false );
94
95 $pdf->SetFont( $default_font, '', 13 );
96 $pdf->SetTextColor( 150, 150, 150 );
97 $pdf->Ln( 1 );
98 $pdf->Cell( 0, 6, utf8_decode( __( 'Date Range: ', 'give' ) ) . $daterange, 0, 2, 'L', false );
99 $pdf->Ln();
100 $pdf->SetTextColor( 50, 50, 50 );
101 $pdf->SetFont( $default_font, '', 14 );
102 $pdf->Cell( 0, 10, utf8_decode( __( 'Table View', 'give' ) ), 0, 2, 'L', false );
103 $pdf->SetFont( $default_font, '', 12 );
104
105 $pdf->SetFillColor( 238, 238, 238 );
106 $pdf->SetTextColor( 0, 0, 0, 100 ); // Set Black color.
107 $pdf->Cell( 50, 6, utf8_decode( __( 'Form Name', 'give' ) ), 1, 0, 'L', true );
108 $pdf->Cell( 50, 6, utf8_decode( __( 'Price', 'give' ) ), 1, 0, 'L', true );
109
110 // Display Categories Heading only, if user has opted for it.
111 if ( $categories_enabled ) {
112 $pdf->Cell( 45, 6, utf8_decode( __( 'Categories', 'give' ) ), 1, 0, 'L', true );
113 }
114
115 // Display Tags Heading only, if user has opted for it.
116 if ( $tags_enabled ) {
117 $pdf->Cell( 45, 6, utf8_decode( __( 'Tags', 'give' ) ), 1, 0, 'L', true );
118 }
119
120 $pdf->Cell( 45, 6, utf8_decode( __( 'Number of Donations', 'give' ) ), 1, 0, 'L', true );
121 $pdf->Cell( 45, 6, utf8_decode( __( 'Income to Date', 'give' ) ), 1, 1, 'L', true );
122
123 // Set Custom Font to support various currencies.
124 $pdf->SetFont( apply_filters( 'give_pdf_custom_font', $custom_font ), $font_style, 12 );
125
126 // Object for getting stats.
127 $donation_stats = new Give_Payment_Stats();
128
129 $give_forms = get_posts(
130 array(
131 'post_type' => 'give_forms',
132 'posts_per_page' => - 1,
133 'suppress_filters' => false,
134 )
135 );
136
137 if ( $give_forms ) {
138 $pdf->SetWidths( array( 50, 50, 45, 45, 45, 45 ) );
139
140 foreach ( $give_forms as $form ) :
141 $pdf->SetFillColor( 255, 255, 255 );
142
143 $title = $form->post_title;
144
145 if ( give_has_variable_prices( $form->ID ) ) {
146 $price = html_entity_decode( give_price_range( $form->ID, false ), ENT_COMPAT, 'UTF-8' );
147 } else {
148 $price = give_currency_filter( give_get_form_price( $form->ID ), array( 'decode_currency' => true ) );
149 }
150
151 // Display Categories Data only, if user has opted for it.
152 $categories = array();
153 if ( $categories_enabled ) {
154 $categories = get_the_term_list( $form->ID, 'give_forms_category', '', ', ', '' );
155 $categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : '';
156 }
157
158 // Display Tags Data only, if user has opted for it.
159 $tags = array();
160 if ( $tags_enabled ) {
161 $tags = get_the_term_list( $form->ID, 'give_forms_tag', '', ', ', '' );
162 $tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : '';
163 }
164
165 $sales = $donation_stats->get_sales( $form->ID, 'this_year' );
166 $earnings = give_currency_filter( give_format_amount( $donation_stats->get_earnings( $form->ID, 'this_year' ), array( 'sanitize' => false ) ), array( 'decode_currency' => true ) );
167
168 // This will help filter data before appending it to PDF Receipt.
169 $prepare_pdf_data = array();
170 $prepare_pdf_data[] = $title;
171 $prepare_pdf_data[] = $price;
172
173 // Append Categories Data only, if user has opted for it.
174 if ( $categories_enabled ) {
175 $prepare_pdf_data[] = $categories;
176 }
177
178 // Append Tags Data only, if user has opted for it.
179 if ( $tags_enabled ) {
180 $prepare_pdf_data[] = $tags;
181 }
182
183 $prepare_pdf_data[] = $sales;
184 $prepare_pdf_data[] = $earnings;
185
186 $pdf->Row( $prepare_pdf_data );
187
188 endforeach;
189 } else {
190
191 // Fix: Minor Styling Alignment Issue for PDF.
192 if ( $categories_enabled && $tags_enabled ) {
193 $no_found_width = 280;
194 } elseif ( $categories_enabled || $tags_enabled ) {
195 $no_found_width = 235;
196 } else {
197 $no_found_width = 190;
198 }
199 $title = utf8_decode( __( 'No forms found.', 'give' ) );
200 $pdf->MultiCell( $no_found_width, 5, $title, 1, 'C', false, 1, '', '', true, 0, false, true, 0, 'T', false );
201 }// End if().
202 $pdf->Ln();
203 $pdf->SetTextColor( 50, 50, 50 );
204 $pdf->SetFont( $default_font, '', 14 );
205
206 // Output Graph on a new page.
207 $pdf->AddPage( 'L', 'A4' );
208 $pdf->Cell( 0, 10, utf8_decode( __( 'Graph View', 'give' ) ), 0, 2, 'L', false );
209 $pdf->SetFont( $default_font, '', 12 );
210
211 $image = html_entity_decode( urldecode( give_draw_chart_image() ) );
212 $image = str_replace( ' ', '%20', $image );
213
214 $pdf->SetX( 25 );
215 $pdf->Image( $image . '&file=.png' );
216 $pdf->Ln( 7 );
217 $pdf->Output( apply_filters( 'give_sales_earnings_pdf_export_filename', 'give-report-' . date_i18n( 'Y-m-d' ) ) . '.pdf', 'D' );
218 exit();
219 }
220
221 add_action( 'give_generate_pdf', 'give_generate_pdf' );
222
223 /**
224 * Draws Chart for PDF Report.
225 *
226 * Draws the sales and earnings chart for the PDF report and then retrieves the
227 * URL of that chart to display on the PDF Report.
228 *
229 * @since 1.1.4.0
230 * @uses GoogleChart
231 * @uses GoogleChartData
232 * @uses GoogleChartShapeMarker
233 * @uses GoogleChartTextMarker
234 * @uses GoogleChartAxis
235 * @return string $chart->getUrl() URL for the Google Chart
236 */
237 function give_draw_chart_image() {
238 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/GoogleChart.php';
239 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php';
240 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartTextMarker.php';
241
242 $chart = new GoogleChart( 'lc', 900, 330 );
243
244 $i = 1;
245 $earnings = '';
246 $sales = '';
247
248 while ( $i <= 12 ) :
249 $earnings .= give_get_earnings_by_date( null, $i, date( 'Y' ) ) . ',';
250 $sales .= give_get_sales_by_date( null, $i, date( 'Y' ) ) . ',';
251 $i ++;
252 endwhile;
253
254 $earnings_array = explode( ',', $earnings );
255 $sales_array = explode( ',', $sales );
256
257 $i = 0;
258 while ( $i <= 11 ) {
259 if ( empty( $sales_array[ $i ] ) ) {
260 $sales_array[ $i ] = 0;
261 }
262 $i ++;
263 }
264
265 $min_earnings = 0;
266 $max_earnings = max( $earnings_array );
267 $earnings_scale = round( $max_earnings, - 1 );
268
269 $data = new GoogleChartData(
270 array(
271 $earnings_array[0],
272 $earnings_array[1],
273 $earnings_array[2],
274 $earnings_array[3],
275 $earnings_array[4],
276 $earnings_array[5],
277 $earnings_array[6],
278 $earnings_array[7],
279 $earnings_array[8],
280 $earnings_array[9],
281 $earnings_array[10],
282 $earnings_array[11],
283 )
284 );
285
286 $data->setLegend( __( 'Income', 'give' ) );
287 $data->setColor( '1b58a3' );
288 $chart->addData( $data );
289
290 $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
291 $shape_marker->setColor( '000000' );
292 $shape_marker->setSize( 7 );
293 $shape_marker->setBorder( 2 );
294 $shape_marker->setData( $data );
295 $chart->addMarker( $shape_marker );
296
297 $value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE );
298 $value_marker->setColor( '000000' );
299 $value_marker->setData( $data );
300 $chart->addMarker( $value_marker );
301
302 $data = new GoogleChartData(
303 array(
304 $sales_array[0],
305 $sales_array[1],
306 $sales_array[2],
307 $sales_array[3],
308 $sales_array[4],
309 $sales_array[5],
310 $sales_array[6],
311 $sales_array[7],
312 $sales_array[8],
313 $sales_array[9],
314 $sales_array[10],
315 $sales_array[11],
316 )
317 );
318 $data->setLegend( __( 'Donations', 'give' ) );
319 $data->setColor( 'ff6c1c' );
320 $chart->addData( $data );
321
322 $chart->setTitle( __( 'Donations by Month for all GiveWP Forms', 'give' ), '336699', 18 );
323
324 $chart->setScale( 0, $max_earnings );
325
326 $y_axis = new GoogleChartAxis( 'y' );
327 $y_axis->setDrawTickMarks( true )->setLabels( array( 0, $max_earnings ) );
328 $chart->addAxis( $y_axis );
329
330 $x_axis = new GoogleChartAxis( 'x' );
331 $x_axis->setTickMarks( 5 );
332 $x_axis->setLabels(
333 array(
334 __( 'Jan', 'give' ),
335 __( 'Feb', 'give' ),
336 __( 'Mar', 'give' ),
337 __( 'Apr', 'give' ),
338 __( 'May', 'give' ),
339 __( 'June', 'give' ),
340 __( 'July', 'give' ),
341 __( 'Aug', 'give' ),
342 __( 'Sept', 'give' ),
343 __( 'Oct', 'give' ),
344 __( 'Nov', 'give' ),
345 __( 'Dec', 'give' ),
346 )
347 );
348 $chart->addAxis( $x_axis );
349
350 $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
351 $shape_marker->setSize( 6 );
352 $shape_marker->setBorder( 2 );
353 $shape_marker->setData( $data );
354 $chart->addMarker( $shape_marker );
355
356 $value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE );
357 $value_marker->setData( $data );
358 $chart->addMarker( $value_marker );
359
360 return $chart->getUrl();
361 }
362