1<?php
2
3use WHMCS\Carbon;
4use WHMCS\Database\Capsule;
5use WHMCS\Invoices;
6use WHMCS\Module\GatewaySetting;
7
8if (!defined("WHMCS")) {
9 die("This file cannot be accessed directly");
10}
11
12$reportdata['isPrintable'] = false;
13$reportdata['canCsvExport'] = false;
14
15$reportdata["title"] = "Batch PDF Invoice Export";
16$reportdata["description"] = <<<DESCRIPTION
17This tool can be used to generate and download a batch export of invoices in PDF format (one per page).<br />
18Typical uses for this include producing hard paper copies for mailing to clients or record keeping.
19DESCRIPTION;
20
21require("../includes/gatewayfunctions.php");
22
23if ($noresults) {
24 infoBox("No Invoices Match Criteria", "No invoices were found matching the criteria you specified");
25 $reportdata["description"] .= $infobox;
26}
27
28$range = App::getFromRequest('range');
29if (!$range) {
30 $today = Carbon::today()->endOfDay();
31 $lastMonth = Carbon::today()->subDays(29)->startOfDay();
32 $range = $lastMonth->toAdminDateFormat() . ' - ' . $today->toAdminDateFormat();
33}
34
35$clientsDropDown = $aInt->clientsDropDown($userid, false, 'userid', true);
36
37$gatewayOptions = '';
38
39foreach (GatewaySetting::getActiveGatewayFriendlyNames() as $gateway => $friendlyName) {
40 $gatewayOptions .= "<option value=\"{$gateway}\" selected>{$friendlyName}</option>";
41}
42
43$statusOptions = '';
44foreach (Invoices::getInvoiceStatusValues() as $invoiceStatusOption) {
45 if ($invoiceStatusOption == 'Unpaid') {
46 $isSelected = 'selected';
47 } else {
48 $isSelected = '';
49 }
50 $optionName = $aInt->lang('status', strtolower(str_replace(' ', '', $invoiceStatusOption)));
51 $statusOptions .= "<option value=\"{$invoiceStatusOption}\" {$isSelected}>{$optionName}</option>";
52}
53
54$reportdata["headertext"] = <<<HTML
55<form method="post" action="csvdownload.php?type=pdfbatch">
56 <table class="form" width="100%" border="0" cellspacing="2" cellpadding="3">
57 <tr>
58 <td width="20%" class="fieldlabel">
59 Client Name
60 </td>
61 <td class="fieldarea">
62 {$clientsDropDown}
63 </td>
64 </tr>
65 <tr>
66 <td class="fieldlabel">
67 Filter By
68 </td>
69 <td class="fieldarea">
70 <select name="filterby" class="form-control select-inline">
71 <option>Date Created</option>
72 <option>Due Date</option>
73 <option>Date Paid</option>
74 </select>
75 </td>
76 </tr>
77 <tr>
78 <td class="fieldlabel">
79 Date Range
80 </td>
81 <td class="fieldarea">
82 <div class="form-group date-picker-prepend-icon">
83 <label for="inputFilterDate" class="field-icon">
84 <i class="fal fa-calendar-alt"></i>
85 </label>
86 <input id="inputFilterDate"
87 type="text"
88 name="range"
89 value="{$range}"
90 class="form-control date-picker-search input-inline"
91 />
92 </div>
93 </td>
94 </tr>
95 <tr>
96 <td class="fieldlabel">
97 Payment Methods
98 </td>
99 <td class="fieldarea">
100 <select name="paymentmethods[]" class="form-control input-250" size="8" multiple="true">
101 {$gatewayOptions}
102 </select>
103 </td>
104 </tr>
105 <tr>
106 <td class="fieldlabel">
107 Statuses
108 </td>
109 <td class="fieldarea">
110 <select name="statuses[]" class="form-control input-150" size="6" multiple="true">
111 {$statusOptions}
112 </select>
113 </td>
114 </tr>
115 <tr>
116 <td class="fieldlabel">
117 Sort Order
118 </td>
119 <td class="fieldarea">
120 <select name="sortorder" class="form-control select-inline">
121 <option>Invoice ID</option>
122 <option>Invoice Number</option>
123 <option>Date Paid</option>
124 <option>Due Date</option>
125 <option>Client ID</option>
126 <option>Client Name</option>
127 </select>
128 </td>
129 </tr>
130 </table>
131 <p align=center>
132 <input type="submit" value="Download File" class="btn btn-default">
133 </p>
134</form>
135HTML;
136
137$report = '';
138
139