PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.5
GiveWP – Donation Plugin and Fundraising Platform v2.0.5
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 8 years ago class-batch-export-forms.php 9 years ago class-batch-export-payments.php 8 years ago class-batch-export.php 8 years ago class-core-settings-export.php 8 years ago class-export-earnings.php 8 years ago class-export.php 8 years ago export-actions.php 8 years ago export-functions.php 8 years ago pdf-reports.php 8 years ago
pdf-reports.php
346 lines
1 <?php
2 /**
3 * PDF Report Generation Functions.
4 *
5 * @package Give
6 * @subpackage Admin/Reports
7 * @copyright Copyright (c) 2016, WordImpress
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
61 if (
62 file_exists( GIVE_PLUGIN_DIR . '/includes/libraries/tcpdf/fonts/CODE2000.TTF' ) &&
63
64 // RIAL exist for backward compatibility.
65 in_array( give_get_currency(), array( 'RIAL', 'RUB', 'IRR' ) )
66 ) {
67 TCPDF_FONTS::addTTFfont( GIVE_PLUGIN_DIR . '/includes/libraries/tcpdf/fonts/CODE2000.TTF', '' );
68 $custom_font = 'CODE2000';
69 $font_style = 'B';
70 }
71
72 $pdf->AddPage( 'L', 'A4' );
73 $pdf->setImageScale( 1.5 );
74 $pdf->SetTitle( utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ) );
75 $pdf->SetAuthor( utf8_decode( __( 'Give - Democratizing Generosity', 'give' ) ) );
76 $pdf->SetCreator( utf8_decode( __( 'Give - Democratizing Generosity', 'give' ) ) );
77
78 // Image URL should have absolute path. @see https://tcpdf.org/examples/example_009/.
79 $pdf->Image( apply_filters( 'give_pdf_export_logo', GIVE_PLUGIN_DIR . 'assets/images/give-logo-small.png' ), 247, 8 );
80
81 $pdf->SetMargins( 8, 8, 8 );
82 $pdf->SetX( 8 );
83
84 $pdf->SetFont( $default_font, '', 16 );
85 $pdf->SetTextColor( 50, 50, 50 );
86 $pdf->Cell( 0, 3, utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ), 0, 2, 'L', false );
87
88 $pdf->SetFont( $default_font, '', 13 );
89 $pdf->SetTextColor( 150, 150, 150 );
90 $pdf->Ln( 1 );
91 $pdf->Cell( 0, 6, utf8_decode( __( 'Date Range: ', 'give' ) ) . $daterange, 0, 2, 'L', false );
92 $pdf->Ln();
93 $pdf->SetTextColor( 50, 50, 50 );
94 $pdf->SetFont( $default_font, '', 14 );
95 $pdf->Cell( 0, 10, utf8_decode( __( 'Table View', 'give' ) ), 0, 2, 'L', false );
96 $pdf->SetFont( $default_font, '', 12 );
97
98 $pdf->SetFillColor( 238, 238, 238 );
99 $pdf->SetTextColor( 0, 0, 0, 100 ); // Set Black color.
100 $pdf->Cell( 50, 6, utf8_decode( __( 'Form Name', 'give' ) ), 1, 0, 'L', true );
101 $pdf->Cell( 50, 6, utf8_decode( __( 'Price', 'give' ) ), 1, 0, 'L', true );
102
103 // Display Categories Heading only, if user has opted for it.
104 if ( $categories_enabled ) {
105 $pdf->Cell( 45, 6, utf8_decode( __( 'Categories', 'give' ) ), 1, 0, 'L', true );
106 }
107
108 // Display Tags Heading only, if user has opted for it.
109 if ( $tags_enabled ) {
110 $pdf->Cell( 45, 6, utf8_decode( __( 'Tags', 'give' ) ), 1, 0, 'L', true );
111 }
112
113 $pdf->Cell( 45, 6, utf8_decode( __( 'Number of Donations', 'give' ) ), 1, 0, 'L', true );
114 $pdf->Cell( 45, 6, utf8_decode( __( 'Income to Date', 'give' ) ), 1, 1, 'L', true );
115
116 // Set Custom Font to support various currencies.
117 $pdf->SetFont( apply_filters( 'give_pdf_custom_font', $custom_font ), $font_style, 12 );
118
119 $year = date( 'Y' );
120 $give_forms = get_posts( array(
121 'post_type' => 'give_forms',
122 'year' => $year,
123 'posts_per_page' => - 1,
124 'supply_filter' => false,
125 ) );
126
127 if ( $give_forms ) {
128 $pdf->SetWidths( array( 50, 50, 45, 45, 45, 45 ) );
129
130 foreach ( $give_forms as $form ):
131 $pdf->SetFillColor( 255, 255, 255 );
132
133 $title = $form->post_title;
134
135 if ( give_has_variable_prices( $form->ID ) ) {
136 $price = html_entity_decode( give_price_range( $form->ID, false ), ENT_COMPAT, 'UTF-8' );
137 } else {
138 $price = give_currency_filter( give_get_form_price( $form->ID ), array( 'decode_currency' => true ) );
139 }
140
141 // Display Categories Data only, if user has opted for it.
142 $categories = array();
143 if ( $categories_enabled ) {
144 $categories = get_the_term_list( $form->ID, 'give_forms_category', '', ', ', '' );
145 $categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : '';
146 }
147
148 // Display Tags Data only, if user has opted for it.
149 $tags = array();
150 if ( $tags_enabled ) {
151 $tags = get_the_term_list( $form->ID, 'give_forms_tag', '', ', ', '' );
152 $tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : '';
153 }
154
155 $sales = give_get_form_sales_stats( $form->ID );
156 $earnings = give_currency_filter( give_format_amount( give_get_form_earnings_stats( $form->ID ), array( 'sanitize' => false, ) ), array( 'decode_currency' => true ) );
157
158 // This will help filter data before appending it to PDF Receipt.
159 $prepare_pdf_data = array();
160 $prepare_pdf_data[] = $title;
161 $prepare_pdf_data[] = $price;
162
163 // Append Categories Data only, if user has opted for it.
164 if ( $categories_enabled ) {
165 $prepare_pdf_data[] = $categories;
166 }
167
168 // Append Tags Data only, if user has opted for it.
169 if ( $tags_enabled ) {
170 $prepare_pdf_data[] = $tags;
171 }
172
173 $prepare_pdf_data[] = $sales;
174 $prepare_pdf_data[] = $earnings;
175
176 $pdf->Row( $prepare_pdf_data );
177
178 endforeach;
179 } else {
180
181 // Fix: Minor Styling Alignment Issue for PDF.
182 if ( $categories_enabled && $tags_enabled ) {
183 $no_found_width = 280;
184 } elseif ( $categories_enabled || $tags_enabled ) {
185 $no_found_width = 235;
186 } else {
187 $no_found_width = 190;
188 }
189 $title = utf8_decode( __( 'No forms found.', 'give' ) );
190 $pdf->MultiCell( $no_found_width, 5, $title, 1, 'C', false, 1, '', '', true, 0, false, true, 0, 'T', false );
191 }// End if().
192 $pdf->Ln();
193 $pdf->SetTextColor( 50, 50, 50 );
194 $pdf->SetFont( $default_font, '', 14 );
195
196 // Output Graph on a new page.
197 $pdf->AddPage( 'L', 'A4' );
198 $pdf->Cell( 0, 10, utf8_decode( __( 'Graph View', 'give' ) ), 0, 2, 'L', false );
199 $pdf->SetFont( $default_font, '', 12 );
200
201 $image = html_entity_decode( urldecode( give_draw_chart_image() ) );
202 $image = str_replace( ' ', '%20', $image );
203
204 $pdf->SetX( 25 );
205 $pdf->Image( $image . '&file=.png' );
206 $pdf->Ln( 7 );
207 $pdf->Output( apply_filters( 'give_sales_earnings_pdf_export_filename', 'give-report-' . date_i18n( 'Y-m-d' ) ) . '.pdf', 'D' );
208 exit();
209 }
210
211 add_action( 'give_generate_pdf', 'give_generate_pdf' );
212
213 /**
214 * Draws Chart for PDF Report.
215 *
216 * Draws the sales and earnings chart for the PDF report and then retrieves the
217 * URL of that chart to display on the PDF Report.
218 *
219 * @since 1.1.4.0
220 * @uses GoogleChart
221 * @uses GoogleChartData
222 * @uses GoogleChartShapeMarker
223 * @uses GoogleChartTextMarker
224 * @uses GoogleChartAxis
225 * @return string $chart->getUrl() URL for the Google Chart
226 */
227 function give_draw_chart_image() {
228 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/GoogleChart.php';
229 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php';
230 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartTextMarker.php';
231
232 $chart = new GoogleChart( 'lc', 900, 330 );
233
234 $i = 1;
235 $earnings = "";
236 $sales = "";
237
238 while ( $i <= 12 ) :
239 $earnings .= give_get_earnings_by_date( null, $i, date( 'Y' ) ) . ",";
240 $sales .= give_get_sales_by_date( null, $i, date( 'Y' ) ) . ",";
241 $i ++;
242 endwhile;
243
244 $earnings_array = explode( ",", $earnings );
245 $sales_array = explode( ",", $sales );
246
247 $i = 0;
248 while ( $i <= 11 ) {
249 if ( empty( $sales_array[ $i ] ) ) {
250 $sales_array[ $i ] = 0;
251 }
252 $i ++;
253 }
254
255 $min_earnings = 0;
256 $max_earnings = max( $earnings_array );
257 $earnings_scale = round( $max_earnings, - 1 );
258
259 $data = new GoogleChartData( array(
260 $earnings_array[0],
261 $earnings_array[1],
262 $earnings_array[2],
263 $earnings_array[3],
264 $earnings_array[4],
265 $earnings_array[5],
266 $earnings_array[6],
267 $earnings_array[7],
268 $earnings_array[8],
269 $earnings_array[9],
270 $earnings_array[10],
271 $earnings_array[11],
272 ) );
273
274 $data->setLegend( __( 'Income', 'give' ) );
275 $data->setColor( '1b58a3' );
276 $chart->addData( $data );
277
278 $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
279 $shape_marker->setColor( '000000' );
280 $shape_marker->setSize( 7 );
281 $shape_marker->setBorder( 2 );
282 $shape_marker->setData( $data );
283 $chart->addMarker( $shape_marker );
284
285 $value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE );
286 $value_marker->setColor( '000000' );
287 $value_marker->setData( $data );
288 $chart->addMarker( $value_marker );
289
290 $data = new GoogleChartData( array(
291 $sales_array[0],
292 $sales_array[1],
293 $sales_array[2],
294 $sales_array[3],
295 $sales_array[4],
296 $sales_array[5],
297 $sales_array[6],
298 $sales_array[7],
299 $sales_array[8],
300 $sales_array[9],
301 $sales_array[10],
302 $sales_array[11],
303 ) );
304 $data->setLegend( __( 'Donations', 'give' ) );
305 $data->setColor( 'ff6c1c' );
306 $chart->addData( $data );
307
308 $chart->setTitle( __( 'Donations by Month for all Give Forms', 'give' ), '336699', 18 );
309
310 $chart->setScale( 0, $max_earnings );
311
312 $y_axis = new GoogleChartAxis( 'y' );
313 $y_axis->setDrawTickMarks( true )->setLabels( array( 0, $max_earnings ) );
314 $chart->addAxis( $y_axis );
315
316 $x_axis = new GoogleChartAxis( 'x' );
317 $x_axis->setTickMarks( 5 );
318 $x_axis->setLabels( array(
319 __( 'Jan', 'give' ),
320 __( 'Feb', 'give' ),
321 __( 'Mar', 'give' ),
322 __( 'Apr', 'give' ),
323 __( 'May', 'give' ),
324 __( 'June', 'give' ),
325 __( 'July', 'give' ),
326 __( 'Aug', 'give' ),
327 __( 'Sept', 'give' ),
328 __( 'Oct', 'give' ),
329 __( 'Nov', 'give' ),
330 __( 'Dec', 'give' ),
331 ) );
332 $chart->addAxis( $x_axis );
333
334 $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
335 $shape_marker->setSize( 6 );
336 $shape_marker->setBorder( 2 );
337 $shape_marker->setData( $data );
338 $chart->addMarker( $shape_marker );
339
340 $value_marker = new GoogleChartTextMarker( GoogleChartTextMarker::VALUE );
341 $value_marker->setData( $data );
342 $chart->addMarker( $value_marker );
343
344 return $chart->getUrl();
345 }
346