| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Assets Class |
| 4 |
* |
| 5 |
* @package Easy_Invoice |
| 6 |
* @subpackage Admin |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace EasyInvoice\Admin; |
| 10 |
|
| 11 |
use EasyInvoice\Constants\PagesSlugs; |
| 12 |
|
| 13 |
/** |
| 14 |
* AdminAssets Class |
| 15 |
* |
| 16 |
* Handles registration and enqueuing of admin CSS and JS assets. |
| 17 |
*/ |
| 18 |
class AdminAssets { |
| 19 |
/** |
| 20 |
* Register hooks |
| 21 |
*/ |
| 22 |
public function register() { |
| 23 |
add_action('admin_enqueue_scripts', array($this, 'enqueueAdminAssets')); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Enqueue admin assets |
| 28 |
* |
| 29 |
* @param string $hook The current admin page |
| 30 |
*/ |
| 31 |
public function enqueueAdminAssets($hook) { |
| 32 |
// Only load on our plugin pages |
| 33 |
if (empty($hook) || strpos($hook, 'easy-invoice') === false) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
// Enqueue styles |
| 38 |
$this->enqueueStyles(); |
| 39 |
|
| 40 |
// Enqueue scripts |
| 41 |
$this->enqueueScripts($hook); |
| 42 |
|
| 43 |
// Localize script data |
| 44 |
$this->localizeScripts($hook); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Enqueue stylesheets |
| 49 |
*/ |
| 50 |
private function enqueueStyles() { |
| 51 |
|
| 52 |
wp_enqueue_style( |
| 53 |
'easy-invoice-tailwind', |
| 54 |
EASY_INVOICE_PLUGIN_URL . 'assets/lib/tailwind/tailwind.min.css', |
| 55 |
array(), |
| 56 |
EASY_INVOICE_VERSION |
| 57 |
); |
| 58 |
|
| 59 |
$page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
| 60 |
|
| 61 |
// Main plugin layout + header strip alignment (always on Easy Invoice admin screens). |
| 62 |
wp_enqueue_style( |
| 63 |
'easy-invoice-main', |
| 64 |
EASY_INVOICE_PLUGIN_URL . 'assets/css/easy-invoice.css', |
| 65 |
array(), |
| 66 |
EASY_INVOICE_VERSION |
| 67 |
); |
| 68 |
|
| 69 |
if($page === 'easy-invoice-builder') { |
| 70 |
// Main admin styles |
| 71 |
|
| 72 |
wp_enqueue_style( |
| 73 |
'easy-invoice-preview', |
| 74 |
EASY_INVOICE_PLUGIN_URL . 'assets/css/invoice-preview.css', |
| 75 |
array(), |
| 76 |
EASY_INVOICE_VERSION |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
wp_enqueue_style( |
| 81 |
'font-awesome', |
| 82 |
EASY_INVOICE_PLUGIN_URL . 'assets/lib/font-awesome/css/all.min.css', |
| 83 |
array(), |
| 84 |
EASY_INVOICE_VERSION |
| 85 |
); |
| 86 |
|
| 87 |
|
| 88 |
// Add RTL support |
| 89 |
wp_style_add_data('easy-invoice-admin', 'rtl', 'replace'); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Enqueue scripts |
| 94 |
* |
| 95 |
* @param string $hook The current admin page |
| 96 |
*/ |
| 97 |
private function enqueueScripts($hook) { |
| 98 |
// Only load on Easy Invoice pages |
| 99 |
if (empty($hook) || strpos($hook, 'easy-invoice') === false) { |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
// Common admin scripts |
| 104 |
wp_enqueue_script('jquery'); |
| 105 |
wp_enqueue_script('jquery-ui-core'); |
| 106 |
wp_enqueue_script('jquery-ui-datepicker'); |
| 107 |
wp_enqueue_script('wp-util'); |
| 108 |
|
| 109 |
// Add WordPress core dependencies that provide the 'wp' object |
| 110 |
wp_enqueue_script('wp-api-fetch'); |
| 111 |
wp_enqueue_script('wp-i18n'); |
| 112 |
wp_enqueue_script('wp-a11y'); |
| 113 |
wp_enqueue_script('wp-hooks'); |
| 114 |
|
| 115 |
// Settings page script |
| 116 |
if (isset($_GET['page']) && $_GET['page'] === 'easy-invoice-settings') { |
| 117 |
wp_enqueue_script( |
| 118 |
'easy-invoice-settings', |
| 119 |
EASY_INVOICE_PLUGIN_URL . 'assets/js/settings.js', |
| 120 |
array('jquery', 'wp-util', 'wp-api-fetch', 'wp-i18n'), |
| 121 |
EASY_INVOICE_VERSION, |
| 122 |
true |
| 123 |
); |
| 124 |
|
| 125 |
// Localize the script with necessary data |
| 126 |
wp_localize_script('easy-invoice-settings', 'easyInvoiceSettings', array( |
| 127 |
'nonce' => wp_create_nonce('easy_invoice_settings'), |
| 128 |
'ajaxurl' => admin_url('admin-ajax.php') |
| 129 |
)); |
| 130 |
return; // Don't load other scripts on settings page |
| 131 |
} |
| 132 |
|
| 133 |
// Load dependencies |
| 134 |
wp_enqueue_script('jquery-ui-sortable'); |
| 135 |
|
| 136 |
// Main admin script |
| 137 |
wp_enqueue_script('jquery'); |
| 138 |
|
| 139 |
// Register and enqueue our scripts |
| 140 |
wp_register_script('easy-invoice-scripts', EASY_INVOICE_PLUGIN_URL . 'assets/js/easy-invoice.js', array('jquery', 'wp-api-fetch', 'wp-i18n', 'wp-a11y'), EASY_INVOICE_VERSION, true); |
| 141 |
wp_enqueue_script('easy-invoice-scripts'); |
| 142 |
|
| 143 |
// Conditionally load client manager only on invoice pages (not quote pages or invoice builder) |
| 144 |
if (!(isset($_GET['page']) && ($_GET['page'] === 'easy-invoice-quote-builder' || $_GET['page'] === 'easy-invoice-builder'))) { |
| 145 |
wp_register_script('easy-invoice-client-manager', EASY_INVOICE_PLUGIN_URL . 'assets/js/client-manager.js', array('jquery', 'easy-invoice-scripts', 'wp-api-fetch', 'wp-i18n'), EASY_INVOICE_VERSION, true); |
| 146 |
wp_enqueue_script('easy-invoice-client-manager'); |
| 147 |
} |
| 148 |
|
| 149 |
// Load clients.js on the clients page |
| 150 |
if (isset($_GET['page']) && $_GET['page'] === PagesSlugs::CLIENTS) { |
| 151 |
wp_register_script('easy-invoice-clients', EASY_INVOICE_PLUGIN_URL . 'assets/js/clients.js', array('jquery', 'easy-invoice-scripts', 'easy-invoice-confirmation-modal', 'easy-invoice-toast', 'wp-api-fetch', 'wp-i18n'), EASY_INVOICE_VERSION, true); |
| 152 |
wp_enqueue_script('easy-invoice-clients'); |
| 153 |
} |
| 154 |
|
| 155 |
wp_register_script('easy-invoice-payment-manager', EASY_INVOICE_PLUGIN_URL . 'assets/js/payment-manager.js', array('jquery', 'easy-invoice-scripts', 'wp-api-fetch', 'wp-i18n'), EASY_INVOICE_VERSION, true); |
| 156 |
wp_enqueue_script('easy-invoice-payment-manager'); |
| 157 |
|
| 158 |
// Tooltip manager - reusable across the plugin |
| 159 |
wp_register_script('easy-invoice-tooltip', EASY_INVOICE_PLUGIN_URL . 'assets/js/tooltip-manager.js', array('jquery', 'wp-api-fetch', 'wp-i18n'), EASY_INVOICE_VERSION, true); |
| 160 |
wp_enqueue_script('easy-invoice-tooltip'); |
| 161 |
|
| 162 |
// Confirmation modal - reusable across the plugin |
| 163 |
wp_register_script('easy-invoice-confirmation-modal', EASY_INVOICE_PLUGIN_URL . 'assets/js/confirmation-modal.js', array('jquery', 'wp-api-fetch', 'wp-i18n'), EASY_INVOICE_VERSION, true); |
| 164 |
wp_enqueue_script('easy-invoice-confirmation-modal'); |
| 165 |
|
| 166 |
// Toast notification system - global across the plugin |
| 167 |
wp_register_script('easy-invoice-toast', EASY_INVOICE_PLUGIN_URL . 'assets/js/easy-invoice-toast.js', array('jquery', 'wp-api-fetch', 'wp-i18n'), EASY_INVOICE_VERSION, true); |
| 168 |
wp_enqueue_script('easy-invoice-toast'); |
| 169 |
|
| 170 |
// Bulk "Send Email" teaser — only on the invoice / quote listings. |
| 171 |
// Always injects the option (even without Pro) so users discover the |
| 172 |
// feature; when Pro is inactive, clicking Apply opens the upgrade |
| 173 |
// dialog instead of doing the work. |
| 174 |
$current_page = isset($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
| 175 |
if (in_array($current_page, ['easy-invoice-all', 'easy-quote-all'], true)) { |
| 176 |
wp_register_script( |
| 177 |
'easy-invoice-bulk-send-email-teaser', |
| 178 |
EASY_INVOICE_PLUGIN_URL . 'assets/js/bulk-send-email-teaser.js', |
| 179 |
array('jquery', 'easy-invoice-confirmation-modal', 'easy-invoice-toast'), |
| 180 |
EASY_INVOICE_VERSION, |
| 181 |
true |
| 182 |
); |
| 183 |
wp_localize_script('easy-invoice-bulk-send-email-teaser', 'easyInvoiceBulkSendTeaser', array( |
| 184 |
'hasPro' => function_exists('easy_invoice_has_pro') && easy_invoice_has_pro(), |
| 185 |
'upgradeUrl' => 'https://matrixaddons.com/plugins/easy-invoice/#pricing', |
| 186 |
'i18n' => array( |
| 187 |
// Send Email |
| 188 |
'send_email_label' => __('Send Email (Pro)', 'easy-invoice'), |
| 189 |
'send_email_feature_name' => __('Bulk Send Email', 'easy-invoice'), |
| 190 |
'send_email_feature_description'=> __('Select multiple invoices or quotes and send the configured "Available" email to every selected document\'s client in a single click. Includes a per-row success / failure report so you can spot deliverability problems immediately.', 'easy-invoice'), |
| 191 |
// Export |
| 192 |
'export_feature_name' => __('Bulk Export Selected', 'easy-invoice'), |
| 193 |
'export_feature_description' => __('Export your selected invoices or quotes to a clean, accounting-ready CSV — perfect for QuickBooks, Xero, audit trails, or migrating to a new system.', 'easy-invoice'), |
| 194 |
// Generic |
| 195 |
'upgrade_required' => __('This action requires Easy Invoice Pro.', 'easy-invoice'), |
| 196 |
), |
| 197 |
)); |
| 198 |
wp_enqueue_script('easy-invoice-bulk-send-email-teaser'); |
| 199 |
} |
| 200 |
|
| 201 |
// jsPDF for PDF generation - available on all Easy Invoice pages |
| 202 |
wp_register_script('jspdf', 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js', array(), '2.5.1', true); |
| 203 |
wp_enqueue_script('jspdf'); |
| 204 |
|
| 205 |
|
| 206 |
// Conditionally load invoice-specific scripts only on invoice pages |
| 207 |
if (isset($_GET['page']) && ($_GET['page'] === 'easy-invoice-new' || $_GET['page'] === 'easy-invoice-builder')) { |
| 208 |
// Invoice builder scripts |
| 209 |
wp_register_script('easy-invoice-builder', EASY_INVOICE_PLUGIN_URL . 'assets/js/invoice-builder.js', array('jquery', 'easy-invoice-scripts', 'easy-invoice-payment-manager', 'wp-api-fetch', 'wp-i18n'), EASY_INVOICE_VERSION, true); |
| 210 |
wp_enqueue_script('easy-invoice-builder'); |
| 211 |
|
| 212 |
// Use invoice-save.js for comprehensive save functionality |
| 213 |
wp_register_script('easy-invoice-save', EASY_INVOICE_PLUGIN_URL . 'assets/js/invoice-save.js', array('jquery', 'easy-invoice-scripts', 'easy-invoice-payment-manager', 'wp-api-fetch', 'wp-i18n'), EASY_INVOICE_VERSION, true); |
| 214 |
wp_enqueue_script('easy-invoice-save'); |
| 215 |
} |
| 216 |
|
| 217 |
// Quote builder (full-screen editor) |
| 218 |
if (isset($_GET['page']) && $_GET['page'] === 'easy-invoice-quote-builder') { |
| 219 |
wp_register_script( |
| 220 |
'easy-quote-save', |
| 221 |
EASY_INVOICE_PLUGIN_URL . 'assets/js/quote-save.js', |
| 222 |
array('jquery', 'easy-invoice-scripts', 'easy-invoice-payment-manager', 'wp-api-fetch', 'wp-i18n'), |
| 223 |
EASY_INVOICE_VERSION, |
| 224 |
true |
| 225 |
); |
| 226 |
wp_enqueue_script('easy-quote-save'); |
| 227 |
} |
| 228 |
|
| 229 |
if (isset($_GET['page']) && in_array($_GET['page'], array('easy-invoice-builder', 'easy-invoice-quote-builder'), true)) { |
| 230 |
wp_enqueue_script( |
| 231 |
'easy-invoice-builder-mobile-tabs', |
| 232 |
EASY_INVOICE_PLUGIN_URL . 'assets/js/builder-mobile-tabs.js', |
| 233 |
array('jquery'), |
| 234 |
EASY_INVOICE_VERSION, |
| 235 |
true |
| 236 |
); |
| 237 |
wp_enqueue_script( |
| 238 |
'easy-invoice-builder-ux', |
| 239 |
EASY_INVOICE_PLUGIN_URL . 'assets/js/builder-ux.js', |
| 240 |
array('jquery', 'easy-invoice-scripts'), |
| 241 |
EASY_INVOICE_VERSION, |
| 242 |
true |
| 243 |
); |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* Localize script data |
| 249 |
* |
| 250 |
* @param string $hook The current admin page |
| 251 |
*/ |
| 252 |
private function localizeScripts($hook) { |
| 253 |
global $pagenow, $post; |
| 254 |
|
| 255 |
// Get currency settings |
| 256 |
$settings_controller = new \EasyInvoice\Controllers\SettingsController(); |
| 257 |
$settings = $settings_controller->getSettings(); |
| 258 |
$currency_code = $settings['easy_invoice_currency_code'] ?? 'USD'; |
| 259 |
$currency_position = $settings['easy_invoice_currency_position'] ?? 'left'; |
| 260 |
$currency_symbol = easy_invoice_get_currency_symbol(); |
| 261 |
|
| 262 |
$current_admin_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; |
| 263 |
|
| 264 |
// Default data |
| 265 |
$script_data = array( |
| 266 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 267 |
'nonce' => wp_create_nonce('easy_invoice_nonce'), |
| 268 |
'i18n' => array( |
| 269 |
'confirm_delete' => __('Are you sure you want to delete this invoice?', 'easy-invoice'), |
| 270 |
'invoice_deleted' => __('Invoice deleted successfully', 'easy-invoice'), |
| 271 |
'client_deleted' => __('Client deleted successfully', 'easy-invoice'), |
| 272 |
'confirm_delete_client' => __('Are you sure you want to delete this client?', 'easy-invoice'), |
| 273 |
'edit_invoice' => __('Edit Invoice', 'easy-invoice'), |
| 274 |
'create_invoice' => __('Create Invoice', 'easy-invoice'), |
| 275 |
'save' => __('Save', 'easy-invoice'), |
| 276 |
'cancel' => __('Cancel', 'easy-invoice'), |
| 277 |
'add_item' => __('Add Item', 'easy-invoice'), |
| 278 |
'delete_item' => __('Delete Item', 'easy-invoice'), |
| 279 |
'error' => __('An error occurred', 'easy-invoice'), |
| 280 |
), |
| 281 |
); |
| 282 |
|
| 283 |
if (in_array($current_admin_page, array('easy-invoice-builder', 'easy-invoice-quote-builder'), true)) { |
| 284 |
$script_data['i18n'] = array_merge( |
| 285 |
$script_data['i18n'], |
| 286 |
array( |
| 287 |
'saving' => __('Saving…', 'easy-invoice'), |
| 288 |
'sending' => __('Sending…', 'easy-invoice'), |
| 289 |
'save_invoice' => __('Save Invoice', 'easy-invoice'), |
| 290 |
'update_invoice' => __('Update Invoice', 'easy-invoice'), |
| 291 |
'save_quote' => __('Save Quote', 'easy-invoice'), |
| 292 |
'update_quote' => __('Update Quote', 'easy-invoice'), |
| 293 |
'send_invoice' => __('Send Invoice', 'easy-invoice'), |
| 294 |
'send_quote' => __('Send Quote', 'easy-invoice'), |
| 295 |
'save_first_invoice' => __('Please save the invoice before sending.', 'easy-invoice'), |
| 296 |
'save_first_quote' => __('Please save the quote before sending.', 'easy-invoice'), |
| 297 |
'email_sent_invoice' => __('Invoice email sent successfully.', 'easy-invoice'), |
| 298 |
'email_sent_quote' => __('Quote email sent successfully.', 'easy-invoice'), |
| 299 |
'email_error' => __('Error sending email.', 'easy-invoice'), |
| 300 |
'network_error' => __('Error connecting to server.', 'easy-invoice'), |
| 301 |
'tab_editor' => __('Editor', 'easy-invoice'), |
| 302 |
'tab_preview' => __('Preview', 'easy-invoice'), |
| 303 |
'confirm_send_invoice_title' => __('Send invoice by email?', 'easy-invoice'), |
| 304 |
'confirm_send_invoice_message' => __('This will email the invoice to the client using your configured template.', 'easy-invoice'), |
| 305 |
'confirm_send_quote_title' => __('Send quote by email?', 'easy-invoice'), |
| 306 |
'confirm_send_quote_message' => __('This will email the quote to the client using your configured template.', 'easy-invoice'), |
| 307 |
'confirm_send_confirm' => __('Send', 'easy-invoice'), |
| 308 |
'confirm_cancel' => __('Cancel', 'easy-invoice'), |
| 309 |
'builder_unsaved_warning' => __('You have unsaved changes. If you leave this page, your changes may be lost.', 'easy-invoice'), |
| 310 |
'builder_title_hint' => __('The title above matches the document title field in the editor.', 'easy-invoice'), |
| 311 |
'builder_shell_hint' => __('On smaller screens, use the tabs to switch between the editor and the live preview.', 'easy-invoice'), |
| 312 |
'builder_shell_hint_dismiss' => __('Got it', 'easy-invoice'), |
| 313 |
'send_invoice_confirm_browser' => __('Send this invoice by email?', 'easy-invoice'), |
| 314 |
'send_quote_confirm_browser' => __('Send this quote by email?', 'easy-invoice'), |
| 315 |
) |
| 316 |
); |
| 317 |
} |
| 318 |
|
| 319 |
$script_data = array_merge( |
| 320 |
$script_data, |
| 321 |
array( |
| 322 |
'urls' => array( |
| 323 |
'preview' => admin_url('admin.php?action=easy_invoice_preview&invoice_id='), |
| 324 |
'edit' => admin_url('admin.php?page=easy-invoice-new&id='), |
| 325 |
), |
| 326 |
'settings' => array( |
| 327 |
'currency_symbol' => $currency_symbol, |
| 328 |
'currency_position' => $currency_position, |
| 329 |
'currency_code' => $currency_code, |
| 330 |
'decimal_separator' => $settings['easy_invoice_decimal_separator'] ?? '.', |
| 331 |
'thousand_separator' => $settings['easy_invoice_thousands_separator'] ?? ',', |
| 332 |
'decimal_places' => $settings['easy_invoice_decimal_precision'] ?? 2, |
| 333 |
'date_format' => get_option('date_format', 'F j, Y'), |
| 334 |
), |
| 335 |
'showAdjustField' => \EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField(), |
| 336 |
) |
| 337 |
); |
| 338 |
|
| 339 |
// Localize common scripts |
| 340 |
wp_localize_script('easy-invoice-scripts', 'easyInvoice', $script_data); |
| 341 |
|
| 342 |
// Conditionally localize client manager only when it's loaded |
| 343 |
if (!(isset($_GET['page']) && ($_GET['page'] === 'easy-invoice-quote-builder' || $_GET['page'] === 'easy-invoice-builder'))) { |
| 344 |
wp_localize_script('easy-invoice-client-manager', 'easyInvoice', $script_data); |
| 345 |
} |
| 346 |
|
| 347 |
wp_localize_script('easy-invoice-payment-manager', 'easyInvoice', $script_data); |
| 348 |
wp_localize_script('easy-invoice-tooltip', 'easyInvoice', $script_data); |
| 349 |
|
| 350 |
// Conditionally localize invoice-specific scripts |
| 351 |
if (isset($_GET['page']) && ($_GET['page'] === 'easy-invoice-new' || $_GET['page'] === 'easy-invoice-builder')) { |
| 352 |
// Add invoice-specific field configuration |
| 353 |
$form_manager = new \EasyInvoice\Forms\Invoice\InvoiceFormManager(); |
| 354 |
$script_data['fieldConfig'] = $form_manager->getFieldConfigForJavaScript(); |
| 355 |
|
| 356 |
// Add additional data for the invoice edit page |
| 357 |
$invoice_id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
| 358 |
$invoice_items_json = ''; |
| 359 |
|
| 360 |
if ($invoice_id > 0) { |
| 361 |
// Existing invoice - get its data |
| 362 |
$repository = \EasyInvoice\Providers\InvoiceServiceProvider::getInvoiceRepository(); |
| 363 |
$invoice = $repository->find($invoice_id); |
| 364 |
|
| 365 |
if ($invoice) { |
| 366 |
$script_data['invoice_id'] = $invoice_id; |
| 367 |
$script_data['editMode'] = true; |
| 368 |
|
| 369 |
// Get invoice data for JavaScript |
| 370 |
$invoice_data = $invoice->toArray(); |
| 371 |
$script_data['invoiceData'] = $invoice_data; |
| 372 |
|
| 373 |
// Get invoice items |
| 374 |
$items = $invoice->getItems(); |
| 375 |
$items_data = []; |
| 376 |
foreach ($items as $item) { |
| 377 |
$items_data[] = [ |
| 378 |
'id' => $item->getId(), |
| 379 |
'name' => $item->getName(), |
| 380 |
'description' => $item->getDescription(), |
| 381 |
'quantity' => $item->getQuantity(), |
| 382 |
'price' => $item->getPrice(), |
| 383 |
'taxable' => $item->isTaxable(), |
| 384 |
'total' => $item->getAmount() |
| 385 |
]; |
| 386 |
} |
| 387 |
$script_data['invoiceItems'] = $items_data; |
| 388 |
|
| 389 |
// Get client data if available |
| 390 |
if ($invoice->getClientId()) { |
| 391 |
$client_repository = \EasyInvoice\Providers\ClientServiceProvider::getClientRepository(); |
| 392 |
$client = $client_repository->find($invoice->getClientId()); |
| 393 |
if ($client) { |
| 394 |
$script_data['clientData'] = [ |
| 395 |
'id' => $client->getId(), |
| 396 |
'name' => $client->getBusinessClientName() ?: ($client->getFirstName() . ' ' . $client->getLastName()), |
| 397 |
'email' => $client->getEmail(), |
| 398 |
'phone' => $client->getExtraInfo(), |
| 399 |
'address' => $client->getAddress(), |
| 400 |
'company' => $client->getBusinessClientName() |
| 401 |
]; |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
} else { |
| 406 |
// New invoice - set default items |
| 407 |
$script_data['editMode'] = false; |
| 408 |
$script_data['invoice_id'] = 0; |
| 409 |
$default_items = [ |
| 410 |
[ |
| 411 |
'name' => '', |
| 412 |
'description' => '', |
| 413 |
'quantity' => 0, |
| 414 |
'price' => 0, |
| 415 |
'taxable' => true |
| 416 |
] |
| 417 |
]; |
| 418 |
$script_data['default_items'] = $default_items; |
| 419 |
} |
| 420 |
|
| 421 |
// Localize invoice-specific scripts |
| 422 |
wp_localize_script('easy-invoice-builder', 'easyInvoice', $script_data); |
| 423 |
wp_localize_script('easy-invoice-save', 'easyInvoice', $script_data); |
| 424 |
} |
| 425 |
|
| 426 |
if (isset($_GET['page']) && $_GET['page'] === 'easy-invoice-quote-builder') { |
| 427 |
// Override showAdjustField for quote pages |
| 428 |
$script_data['showAdjustField'] = \EasyInvoice\Controllers\SettingsController::shouldShowQuoteAdjustField(); |
| 429 |
wp_localize_script('easy-quote-save', 'easyInvoice', $script_data); |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
|