PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.4.3
GiveWP – Donation Plugin and Fundraising Platform v2.4.3
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 7 years ago class-core-settings-export.php 7 years ago class-export-earnings.php 7 years ago class-export.php 7 years ago class-give-export-donations.php 7 years ago export-actions.php 7 years ago export-functions.php 7 years ago give-export-donations-exporter.php 7 years ago give-export-donations-functions.php 7 years ago pdf-reports.php 7 years ago
pdf-reports.php
354 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( __( 'Nonce verification failed.', '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( __( 'Give - Democratizing Generosity', 'give' ) ) );
83 $pdf->SetCreator( utf8_decode( __( 'Give - 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( array(
130 'post_type' => 'give_forms',
131 'posts_per_page' => - 1,
132 'suppress_filters' => false,
133 ) );
134
135 if ( $give_forms ) {
136 $pdf->SetWidths( array( 50, 50, 45, 45, 45, 45 ) );
137
138 foreach ( $give_forms as $form ):
139 $pdf->SetFillColor( 255, 255, 255 );
140
141 $title = $form->post_title;
142
143 if ( give_has_variable_prices( $form->ID ) ) {
144 $price = html_entity_decode( give_price_range( $form->ID, false ), ENT_COMPAT, 'UTF-8' );
145 } else {
146 $price = give_currency_filter( give_get_form_price( $form->ID ), array( 'decode_currency' => true ) );
147 }
148
149 // Display Categories Data only, if user has opted for it.
150 $categories = array();
151 if ( $categories_enabled ) {
152 $categories = get_the_term_list( $form->ID, 'give_forms_category', '', ', ', '' );
153 $categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : '';
154 }
155
156 // Display Tags Data only, if user has opted for it.
157 $tags = array();
158 if ( $tags_enabled ) {
159 $tags = get_the_term_list( $form->ID, 'give_forms_tag', '', ', ', '' );
160 $tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : '';
161 }
162
163 $sales = $donation_stats->get_sales( $form->ID, 'this_year' );
164 $earnings = give_currency_filter( give_format_amount( $donation_stats->get_earnings( $form->ID, 'this_year' ), array( 'sanitize' => false, ) ), array( 'decode_currency' => true ) );
165
166 // This will help filter data before appending it to PDF Receipt.
167 $prepare_pdf_data = array();
168 $prepare_pdf_data[] = $title;
169 $prepare_pdf_data[] = $price;
170
171 // Append Categories Data only, if user has opted for it.
172 if ( $categories_enabled ) {
173 $prepare_pdf_data[] = $categories;
174 }
175
176 // Append Tags Data only, if user has opted for it.
177 if ( $tags_enabled ) {
178 $prepare_pdf_data[] = $tags;
179 }
180
181 $prepare_pdf_data[] = $sales;
182 $prepare_pdf_data[] = $earnings;
183
184 $pdf->Row( $prepare_pdf_data );
185
186 endforeach;
187 } else {
188
189 // Fix: Minor Styling Alignment Issue for PDF.
190 if ( $categories_enabled && $tags_enabled ) {
191 $no_found_width = 280;
192 } elseif ( $categories_enabled || $tags_enabled ) {
193 $no_found_width = 235;
194 } else {
195 $no_found_width = 190;
196 }
197 $title = utf8_decode( __( 'No forms found.', 'give' ) );
198 $pdf->MultiCell( $no_found_width, 5, $title, 1, 'C', false, 1, '', '', true, 0, false, true, 0, 'T', false );
199 }// End if().
200 $pdf->Ln();
201 $pdf->SetTextColor( 50, 50, 50 );
202 $pdf->SetFont( $default_font, '', 14 );
203
204 // Output Graph on a new page.
205 $pdf->AddPage( 'L', 'A4' );
206 $pdf->Cell( 0, 10, utf8_decode( __( 'Graph View', 'give' ) ), 0, 2, 'L', false );
207 $pdf->SetFont( $default_font, '', 12 );
208
209 $image = html_entity_decode( urldecode( give_draw_chart_image() ) );
210 $image = str_replace( ' ', '%20', $image );
211
212 $pdf->SetX( 25 );
213 $pdf->Image( $image . '&file=.png' );
214 $pdf->Ln( 7 );
215 $pdf->Output( apply_filters( 'give_sales_earnings_pdf_export_filename', 'give-report-' . date_i18n( 'Y-m-d' ) ) . '.pdf', 'D' );
216 exit();
217 }
218
219 add_action( 'give_generate_pdf', 'give_generate_pdf' );
220
221 /**
222 * Draws Chart for PDF Report.
223 *
224 * Draws the sales and earnings chart for the PDF report and then retrieves the
225 * URL of that chart to display on the PDF Report.
226 *
227 * @since 1.1.4.0
228 * @uses GoogleChart
229 * @uses GoogleChartData
230 * @uses GoogleChartShapeMarker
231 * @uses GoogleChartTextMarker
232 * @uses GoogleChartAxis
233 * @return string $chart->getUrl() URL for the Google Chart
234 */
235 function give_draw_chart_image() {
236 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/GoogleChart.php';
237 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php';
238 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartTextMarker.php';
239
240 $chart = new GoogleChart( 'lc', 900, 330 );
241
242 $i = 1;
243 $earnings = "";
244 $sales = "";
245
246 while ( $i <= 12 ) :
247 $earnings .= give_get_earnings_by_date( null, $i, date( 'Y' ) ) . ",";
248 $sales .= give_get_sales_by_date( null, $i, date( 'Y' ) ) . ",";
249 $i ++;
250 endwhile;
251
252 $earnings_array = explode( ",", $earnings );
253 $sales_array = explode( ",", $sales );
254
255 $i = 0;
256 while ( $i <= 11 ) {
257 if ( empty( $sales_array[ $i ] ) ) {
258 $sales_array[ $i ] = 0;
259 }
260 $i ++;
261 }
262
263 $min_earnings = 0;
264 $max_earnings = max( $earnings_array );
265 $earnings_scale = round( $max_earnings, - 1 );
266
267 $data = new GoogleChartData( array(
268 $earnings_array[0],
269 $earnings_array[1],
270 $earnings_array[2],
271 $earnings_array[3],
272 $earnings_array[4],
273 $earnings_array[5],
274 $earnings_array[6],
275 $earnings_array[7],
276 $earnings_array[8],
277 $earnings_array[9],
278 $earnings_array[10],
279 $earnings_array[11],
280 ) );
281
282 $data->setLegend( __( 'Income', 'give' ) );
283 $data->setColor( '1b58a3' );
284 $chart->addData( $data );
285
286 $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
287 $shape_marker->setColor( '000000' );
288 $shape_marker->setSize( 7 );
289 $shape_marker->setBorder( 2 );
290 $shape_marker->setData( $data );
291 $chart->addMarker( $shape_marker );
292
293 $value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE );
294 $value_marker->setColor( '000000' );
295 $value_marker->setData( $data );
296 $chart->addMarker( $value_marker );
297
298 $data = new GoogleChartData( array(
299 $sales_array[0],
300 $sales_array[1],
301 $sales_array[2],
302 $sales_array[3],
303 $sales_array[4],
304 $sales_array[5],
305 $sales_array[6],
306 $sales_array[7],
307 $sales_array[8],
308 $sales_array[9],
309 $sales_array[10],
310 $sales_array[11],
311 ) );
312 $data->setLegend( __( 'Donations', 'give' ) );
313 $data->setColor( 'ff6c1c' );
314 $chart->addData( $data );
315
316 $chart->setTitle( __( 'Donations by Month for all Give Forms', 'give' ), '336699', 18 );
317
318 $chart->setScale( 0, $max_earnings );
319
320 $y_axis = new GoogleChartAxis( 'y' );
321 $y_axis->setDrawTickMarks( true )->setLabels( array( 0, $max_earnings ) );
322 $chart->addAxis( $y_axis );
323
324 $x_axis = new GoogleChartAxis( 'x' );
325 $x_axis->setTickMarks( 5 );
326 $x_axis->setLabels( array(
327 __( 'Jan', 'give' ),
328 __( 'Feb', 'give' ),
329 __( 'Mar', 'give' ),
330 __( 'Apr', 'give' ),
331 __( 'May', 'give' ),
332 __( 'June', 'give' ),
333 __( 'July', 'give' ),
334 __( 'Aug', 'give' ),
335 __( 'Sept', 'give' ),
336 __( 'Oct', 'give' ),
337 __( 'Nov', 'give' ),
338 __( 'Dec', 'give' ),
339 ) );
340 $chart->addAxis( $x_axis );
341
342 $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
343 $shape_marker->setSize( 6 );
344 $shape_marker->setBorder( 2 );
345 $shape_marker->setData( $data );
346 $chart->addMarker( $shape_marker );
347
348 $value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE );
349 $value_marker->setData( $data );
350 $chart->addMarker( $value_marker );
351
352 return $chart->getUrl();
353 }
354