| @@ -3,9 +3,13 @@ | ||
| 3 | 3 | * Legacy Invoice Template |
| 4 | 4 | * Clean, minimalist design with traditional business layout |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -$text_settings = \EasyInvoice\Helpers\TemplateTextHelper::getInvoiceTextSettings(); | |
| 7 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 8 | + exit; | |
| 9 | +} | |
| 10 | +$text_settings = \EasyInvoice\Helpers\TemplateTextHelper::forDocument(\EasyInvoice\Helpers\TemplateTextHelper::getInvoiceTextSettings(), $invoice); | |
| 11 | +$ei_is_credit_note = \EasyInvoice\Helpers\TemplateTextHelper::isCreditNote($invoice); | |
| 8 | 12 | $company_info = \EasyInvoice\Helpers\TemplateTextHelper::getCompanyInfo(); |
| 9 | 13 | ?> |
| 10 | 14 | |
| 11 | 15 | <style> |
| @@ -256,9 +260,9 @@ | ||
| 256 | 260 | color: #111827; |
| 257 | 261 | font-size: 14px; |
| 258 | 262 | } |
| 259 | 263 | |
| 260 | -.template-legacy .invoice-grand-total { | |
| 264 | +.template-legacy .invoice-totals .invoice-grand-total { | |
| 261 | 265 | background: #f9fafb; |
| 262 | 266 | border-top: 1px solid #e5e7eb; |
| 263 | 267 | margin-top: 0; |
| 264 | 268 | padding-top: 12px; |
| @@ -264,9 +268,9 @@ | ||
| 264 | 268 | padding-top: 12px; |
| 265 | 269 | } |
| 266 | 270 | |
| 267 | 271 | .template-legacy .invoice-grand-total .invoice-total-label, |
| 268 | -.template-legacy .invoice-grand-total .invoice-total-value { | |
| 272 | +.template-legacy .invoice-totals .invoice-grand-total .invoice-total-value { | |
| 269 | 273 | font-weight: 700; |
| 270 | 274 | font-size: 16px; |
| 271 | 275 | color: #111827; |
| 272 | 276 | } |
| @@ -287,26 +291,78 @@ | ||
| 287 | 291 | .template-legacy .footer-company { |
| 288 | 292 | color: #9ca3af; |
| 289 | 293 | font-size: 13px; |
| 290 | 294 | } |
| 295 | + | |
| 296 | +.template-legacy .terms-section { | |
| 297 | + margin-top: 20px; | |
| 298 | + padding: 20px; | |
| 299 | + background: #f9fafb; | |
| 300 | + border-radius: 8px; | |
| 301 | + border-left: 4px solid #e5e7eb; | |
| 302 | +} | |
| 303 | + | |
| 304 | +.template-legacy .terms-section h3 { | |
| 305 | + font-size: 16px; | |
| 306 | + font-weight: 600; | |
| 307 | + color: #374151; | |
| 308 | + margin-bottom: 12px; | |
| 309 | + text-transform: uppercase; | |
| 310 | + letter-spacing: 0.5px; | |
| 311 | +} | |
| 312 | + | |
| 313 | +.template-legacy .terms-content { | |
| 314 | + color: #6b7280; | |
| 315 | + font-size: 14px; | |
| 316 | + line-height: 1.6; | |
| 317 | +} | |
| 318 | + | |
| 319 | +/* Shared polish: numbers line up, numeric headings sit over their figures. */ | |
| 320 | +.template-legacy .invoice-items th + th { text-align: right; } | |
| 321 | +.template-legacy .invoice-items .item-quantity, | |
| 322 | +.template-legacy .invoice-items .item-price, | |
| 323 | +.template-legacy .invoice-items .item-adjust, | |
| 324 | +.template-legacy .invoice-items .item-total, | |
| 325 | +.template-legacy .invoice-total-value { font-variant-numeric: tabular-nums; white-space: nowrap; } | |
| 326 | +.template-legacy .meta-value { white-space: nowrap; } | |
| 327 | +.template-legacy .invoice-items .item-adjust { text-align: right; } | |
| 328 | +.template-legacy .client-contact { font-weight: 500; margin-bottom: 0.15em; } | |
| 329 | +.template-legacy .client-tax-number, | |
| 330 | +.template-legacy .company-tax-number { margin-top: 0.35em; } | |
| 331 | +.template-legacy .invoice-items .item-description { white-space: pre-line; } | |
| 332 | +.template-legacy .document-kind { display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-muted, #8a8a8a); font-family: var(--font-family-body, inherit); font-style: normal; margin-bottom: 0.3em; line-height: 1.2; } | |
| 333 | + | |
| 334 | +/* Legacy: keeps its ruled grid, with softer rules and the same type size as the other designs. */ | |
| 335 | +.template-legacy .invoice-items th, .template-legacy .invoice-items td { border-color: #e5e7eb !important; } | |
| 336 | +.template-legacy .invoice-items th { background: #f9fafb; font-size: 12px; letter-spacing: 0.08em; color: #374151; } | |
| 337 | +.template-legacy .invoice-meta, .template-legacy .meta-item { border-color: #e5e7eb !important; } | |
| 338 | +.template-legacy .company-name { color: #111827; } | |
| 339 | +.template-legacy .address-block h2 { font-size: 12px; letter-spacing: 0.12em; color: #6b7280; text-transform: uppercase; } | |
| 340 | +.template-legacy .terms-section, .template-legacy .description-section { background: transparent; border: 0; border-top: 1px solid #e5e7eb; border-radius: 0; padding: 16px 0 0; } | |
| 341 | +.template-legacy .terms-section h3 { font-size: 12px; letter-spacing: 0.12em; color: #6b7280; } | |
| 342 | +.template-legacy .invoice-header { margin-bottom: 24px; } | |
| 343 | +.template-legacy .invoice-totals .invoice-paid-row .invoice-total-value { color: var(--success-color, #047857); } | |
| 344 | +.template-legacy .invoice-totals .invoice-balance-due { font-weight: 700; } | |
| 345 | +.template-legacy .invoice-totals .invoice-balance-due .invoice-total-label { color: inherit; font-weight: 700; } | |
| 291 | 346 | </style> |
| 292 | 347 | |
| 293 | 348 | <div class="template-legacy"> |
| 294 | 349 | <div class="invoice-header"> |
| 295 | 350 | <div class="company-info"> |
| 351 | + <?php if (!empty($company_info['logo'])): ?> | |
| 296 | 352 | <div class="company-logo"> |
| 297 | - <?php if (!empty($company_info['logo'])): ?> | |
| 298 | - <img src="<?php echo esc_url($company_info['logo']); ?>" alt="<?php echo esc_attr($company_info['name']); ?>" class="logo-image"> | |
| 299 | - <?php endif; ?> | |
| 353 | + <img src="<?php echo esc_url($company_info['logo']); ?>" alt="<?php echo esc_attr($company_info['name']); ?>" class="logo-image" onerror="this.parentNode.parentNode.removeChild(this.parentNode)"> | |
| 300 | 354 | </div> |
| 355 | + <?php endif; ?> | |
| 301 | 356 | <div class="company-name"><?php echo esc_html($company_info['name']); ?></div> |
| 302 | 357 | <div class="company-details"> |
| 303 | - <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only'); ?> | |
| 358 | + <?php echo wp_kses_post(\EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only')); ?> | |
| 304 | 359 | </div> |
| 305 | 360 | </div> |
| 306 | 361 | |
| 307 | 362 | <div class="invoice-title-section"> |
| 308 | - <div class="invoice-title"><?php echo esc_html($invoice->getTitle() ?: __('Invoice', 'easy-invoice')); ?></div> | |
| 363 | + <?php $ei_kind = \EasyInvoice\Helpers\TemplateTextHelper::documentKind($invoice); $ei_title = trim((string) $invoice->getTitle()); ?> | |
| 364 | + <div class="invoice-title"><?php if ('' !== $ei_title && 0 !== strcasecmp($ei_title, $ei_kind)) : ?><span class="document-kind"><?php echo esc_html($ei_kind); ?></span><?php endif; ?><?php echo esc_html('' !== $ei_title ? $ei_title : $ei_kind); ?></div> | |
| 309 | 365 | <div class="invoice-meta"> |
| 310 | 366 | <div class="meta-item"> |
| 311 | 367 | <span class="meta-label"><?php echo esc_html($text_settings['invoice_number']); ?></span> |
| 312 | 368 | <span class="meta-value"><?php echo esc_html($invoice->getNumber()); ?></span> |
| @@ -314,34 +370,34 @@ | ||
| 314 | 370 | <div class="meta-item"> |
| 315 | 371 | <span class="meta-label"><?php echo esc_html($text_settings['invoice_date']); ?></span> |
| 316 | 372 | <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getIssueDate())); ?></span> |
| 317 | 373 | </div> |
| 374 | + <?php if (empty($ei_is_credit_note)) : ?> | |
| 318 | 375 | <div class="meta-item"> |
| 319 | 376 | <span class="meta-label"><?php echo esc_html($text_settings['due_date']); ?></span> |
| 320 | 377 | <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getDueDate())); ?></span> |
| 321 | 378 | </div> |
| 379 | + <?php endif; ?> | |
| 380 | + <?php if (empty($ei_is_credit_note)) : ?> | |
| 322 | 381 | <div class="meta-item"> |
| 323 | 382 | <span class="meta-label"><?php echo esc_html($text_settings['total_due']); ?></span> |
| 324 | - <span class="meta-value total-due"><?php echo esc_html($formatter->format($invoice->getTotal())); ?></span> | |
| 383 | + <span class="meta-value total-due"><?php echo esc_html($formatter->format(\EasyInvoice\Helpers\TemplateTextHelper::amountDue($invoice))); ?></span> | |
| 325 | 384 | </div> |
| 385 | + <?php endif; ?> | |
| 326 | 386 | </div> |
| 327 | 387 | </div> |
| 328 | 388 | </div> |
| 329 | 389 | |
| 390 | + <?php $ei_client_html = \EasyInvoice\Helpers\TemplateTextHelper::generateClientBlock($invoice); if ('' !== $ei_client_html) : ?> | |
| 330 | 391 | <div class="address-section"> |
| 331 | 392 | <div class="address-block"> |
| 332 | 393 | <h2><?php echo esc_html($text_settings['to']); ?></h2> |
| 333 | 394 | <div class="address-content"> |
| 334 | - <div class="client-name"><?php echo esc_html($invoice->getCustomerName()); ?></div> | |
| 335 | - <?php if ($invoice->getCustomerAddress()): ?> | |
| 336 | - <?php echo nl2br(esc_html($invoice->getCustomerAddress())); ?><br> | |
| 337 | - <?php endif; ?> | |
| 338 | - <?php if ($invoice->getCustomerEmail()): ?> | |
| 339 | - <?php echo esc_html($invoice->getCustomerEmail()); ?><br> | |
| 340 | - <?php endif; ?> | |
| 395 | + <?php echo wp_kses_post($ei_client_html); ?> | |
| 341 | 396 | </div> |
| 342 | 397 | </div> |
| 343 | 398 | </div> |
| 399 | + <?php endif; ?> | |
| 344 | 400 | |
| 345 | 401 | <?php if ($invoice->getNotes()): ?> |
| 346 | 402 | <div class="description-section"> |
| 347 | 403 | <div class="description-content"> |
| @@ -349,8 +405,18 @@ | ||
| 349 | 405 | </div> |
| 350 | 406 | </div> |
| 351 | 407 | <?php endif; ?> |
| 352 | 408 | |
| 409 | + <?php | |
| 410 | + // The adjustment column appears only when at least one line uses it. | |
| 411 | + $ei_show_adjust = \EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField(); | |
| 412 | + if ($ei_show_adjust) { | |
| 413 | + $ei_show_adjust = false; | |
| 414 | + foreach ($invoice->getItems() as $ei_item) { | |
| 415 | + if ((float) $ei_item->getAdjustPercentage() != 0.0) { $ei_show_adjust = true; break; } | |
| 416 | + } | |
| 417 | + } | |
| 418 | + ?> | |
| 353 | 419 | <table class="invoice-items"> |
| 354 | 420 | <thead> |
| 355 | 421 | <tr> |
| 356 | 422 | <th><?php echo esc_html($text_settings['service']); ?></th> |
| @@ -355,15 +421,18 @@ | ||
| 355 | 421 | <tr> |
| 356 | 422 | <th><?php echo esc_html($text_settings['service']); ?></th> |
| 357 | 423 | <th><?php echo esc_html($text_settings['qty']); ?></th> |
| 358 | 424 | <th><?php echo esc_html($text_settings['rate_price']); ?></th> |
| 359 | - <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField()): ?> | |
| 425 | + <?php if ($ei_show_adjust): ?> | |
| 360 | 426 | <th><?php echo esc_html($text_settings['adjust']); ?> (%)</th> |
| 361 | 427 | <?php endif; ?> |
| 362 | - <th><?php echo esc_html($text_settings['total']); ?></th> | |
| 428 | + <th><?php echo esc_html($text_settings['line_total'] ?? $text_settings['total']); ?></th> | |
| 363 | 429 | </tr> |
| 364 | 430 | </thead> |
| 365 | 431 | <tbody> |
| 432 | + <?php if (!$invoice->getItems()) : ?> | |
| 433 | + <tr class="no-items"><td colspan="<?php echo $ei_show_adjust ? 5 : 4; ?>" style="text-align:center;color:#9ca3af;padding:18px;"><?php esc_html_e('No items yet.', 'easy-invoice'); ?></td></tr> | |
| 434 | + <?php endif; ?> | |
| 366 | 435 | <?php foreach ($invoice->getItems() as $item): ?> |
| 367 | 436 | <tr> |
| 368 | 437 | <td class="item-name"> |
| 369 | 438 | <div class="item-title"><?php echo esc_html($item->getName()); ?></div> |
| @@ -372,9 +441,9 @@ | ||
| 372 | 441 | <?php endif; ?> |
| 373 | 442 | </td> |
| 374 | 443 | <td class="item-quantity"><?php echo esc_html($item->getQuantity() ?: '0'); ?></td> |
| 375 | 444 | <td class="item-price"><?php echo esc_html($formatter->format($item->getPrice())); ?></td> |
| 376 | - <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField()): ?> | |
| 445 | + <?php if ($ei_show_adjust): ?> | |
| 377 | 446 | <td class="item-adjust"><?php |
| 378 | 447 | $adjust_percentage = $item->getAdjustPercentage(); |
| 379 | 448 | if ($adjust_percentage != 0) { |
| 380 | 449 | echo esc_html($adjust_percentage > 0 ? '+' : '') . esc_html($adjust_percentage) . '%'; |
| @@ -389,14 +458,38 @@ | ||
| 389 | 458 | </tbody> |
| 390 | 459 | </table> |
| 391 | 460 | |
| 392 | 461 | <div class="invoice-totals"> |
| 393 | - <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice'); ?> | |
| 462 | + <?php echo wp_kses_post(\EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice')); ?> | |
| 394 | 463 | </div> |
| 395 | 464 | |
| 465 | + <?php | |
| 466 | + $terms_conditions = empty($ei_is_credit_note) ? ($invoice->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions()) : ''; | |
| 467 | + if ($terms_conditions): | |
| 468 | + ?> | |
| 469 | + <div class="terms-section"> | |
| 470 | + <h3><?php esc_html_e('Terms & Conditions', 'easy-invoice'); ?></h3> | |
| 471 | + <div class="terms-content"> | |
| 472 | + <?php echo wp_kses_post($terms_conditions); ?> | |
| 473 | + </div> | |
| 474 | + </div> | |
| 475 | + <?php endif; ?> | |
| 476 | + | |
| 477 | + <?php | |
| 478 | + /** | |
| 479 | + * Fires inside the document card, after notes and terms and before the | |
| 480 | + * footer text: attachments, the signature block, e-invoicing notes. Being | |
| 481 | + * inside the card, it is part of what "Download as PDF" captures. | |
| 482 | + * | |
| 483 | + * @param object $document The invoice model. | |
| 484 | + * @param string $type 'invoice'. | |
| 485 | + */ | |
| 486 | + do_action('easy_invoice_document_body_after', $invoice, 'invoice'); | |
| 487 | + | |
| 488 | + $ei_footer_text = \EasyInvoice\Helpers\TemplateTextHelper::footerText($invoice, 'invoice'); | |
| 489 | + if ('' !== trim(wp_strip_all_tags((string) $ei_footer_text))) : | |
| 490 | + ?> | |
| 396 | 491 | <div class="invoice-footer"> |
| 397 | - <p>Payment is due within <?php echo esc_html($invoice->getDueDays() ?: 30); ?> days from date of invoice.</p> | |
| 398 | - <div class="footer-company"> | |
| 399 | - Thanks for choosing <?php echo esc_html($company_info['name']); ?> | <?php echo esc_html($company_info['email'] ?? '[email protected]'); ?> | |
| 400 | - </div> | |
| 492 | + <p><?php echo wp_kses_post($ei_footer_text); ?></p> | |
| 401 | 493 | </div> |
| 494 | + <?php endif; ?> | |
| 402 | 495 | </div> |