| @@ -3,9 +3,13 @@ | ||
| 3 | 3 | * Classic Template - Traditional Design |
| 4 | 4 | * Classic, traditional, and timeless invoice template |
| 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 | <style> |
| 11 | 15 | /* Classic Template - Traditional Design */ |
| @@ -279,9 +283,9 @@ | ||
| 279 | 283 | font-weight: 700; |
| 280 | 284 | color: var(--text-primary); |
| 281 | 285 | } |
| 282 | 286 | |
| 283 | -.template-classic .invoice-grand-total { | |
| 287 | +.template-classic .invoice-totals .invoice-grand-total { | |
| 284 | 288 | font-size: var(--font-size-lg); |
| 285 | 289 | font-weight: 700; |
| 286 | 290 | color: var(--primary-color); |
| 287 | 291 | border-top: 2px solid var(--primary-color); |
| @@ -386,27 +390,62 @@ | ||
| 386 | 390 | .template-classic .invoice-totals { |
| 387 | 391 | width: 100%; |
| 388 | 392 | } |
| 389 | 393 | } |
| 394 | + | |
| 395 | +/* Shared polish: numbers line up, numeric headings sit over their figures. */ | |
| 396 | +.template-classic .invoice-items th + th { text-align: right; } | |
| 397 | +.template-classic .invoice-items .item-quantity, | |
| 398 | +.template-classic .invoice-items .item-price, | |
| 399 | +.template-classic .invoice-items .item-adjust, | |
| 400 | +.template-classic .invoice-items .item-total, | |
| 401 | +.template-classic .invoice-total-value { font-variant-numeric: tabular-nums; white-space: nowrap; } | |
| 402 | +.template-classic .meta-value { white-space: nowrap; } | |
| 403 | +.template-classic .invoice-items .item-adjust { text-align: right; } | |
| 404 | +.template-classic .client-contact { font-weight: 500; margin-bottom: 0.15em; } | |
| 405 | +.template-classic .client-tax-number, | |
| 406 | +.template-classic .company-tax-number { margin-top: 0.35em; } | |
| 407 | +.template-classic .invoice-items .item-description { white-space: pre-line; } | |
| 408 | +.template-classic .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; } | |
| 409 | + | |
| 410 | +/* Classic: the ledger look — serif, a dark header row, rules instead of cell grids. */ | |
| 411 | +.template-classic .invoice-items th, .template-classic .invoice-items td { border-left: 0; border-right: 0; } | |
| 412 | +.template-classic .invoice-items { border-left: 0; border-right: 0; border-top: 0; } | |
| 413 | +.template-classic .invoice-items th { padding: var(--spacing-3) var(--spacing-4); letter-spacing: 0.1em; font-size: var(--font-size-xs); } | |
| 414 | +.template-classic .invoice-items td { padding: var(--spacing-4); } | |
| 415 | +.template-classic .address-block { background: transparent; border: 0; padding: 0; } | |
| 416 | +.template-classic .address-block h2 { font-size: var(--font-size-xs); letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--border-color); padding-bottom: var(--spacing-2); margin-bottom: var(--spacing-3); } | |
| 417 | +.template-classic .invoice-meta { background: transparent; border: 0; padding: 0; } | |
| 418 | +.template-classic .invoice-title { border-bottom: 2px solid var(--text-primary); } | |
| 419 | +.template-classic .invoice-totals { background: transparent; border: 0; padding: 0; width: 340px; } | |
| 420 | +.template-classic .invoice-total-row { border-bottom: 1px solid var(--border-light); padding: var(--spacing-2) 0; } | |
| 421 | +.template-classic .invoice-totals .invoice-grand-total { border-top: 2px solid var(--text-primary); border-bottom: 3px double var(--text-primary); color: var(--text-primary); padding: var(--spacing-3) 0; } | |
| 422 | +.template-classic .invoice-notes, .template-classic .invoice-terms { background: transparent; border: 0; border-top: 1px solid var(--border-color); border-radius: 0; padding: var(--spacing-5) 0 0; margin-top: var(--spacing-6); } | |
| 423 | +.template-classic .invoice-notes h3, .template-classic .invoice-terms h3 { border: 0; padding: 0; font-size: var(--font-size-base); margin-bottom: var(--spacing-2); } | |
| 424 | +.template-classic .invoice-footer { background: transparent; color: var(--text-secondary); border: 0; border-top: 1px solid var(--border-color); padding: var(--spacing-5) 0 0; margin-top: var(--spacing-8); font-style: italic; } | |
| 425 | +.template-classic .invoice-totals .invoice-paid-row .invoice-total-value { color: var(--success-color, #047857); } | |
| 426 | +.template-classic .invoice-totals .invoice-balance-due { font-weight: 700; } | |
| 427 | +.template-classic .invoice-totals .invoice-balance-due .invoice-total-label { color: inherit; font-weight: 700; } | |
| 428 | +.template-classic .meta-amount-due .meta-value { font-weight: 700; font-size: 1.08em; } | |
| 390 | 429 | </style> |
| 391 | 430 | |
| 392 | 431 | <div class="template template-classic"> |
| 393 | - <!-- Header --> | |
| 394 | 432 | <div class="invoice-header"> |
| 395 | 433 | <div class="company-info"> |
| 434 | + <?php if (!empty($company_info['logo'])): ?> | |
| 396 | 435 | <div class="company-logo"> |
| 397 | - <?php if (!empty($company_info['logo'])): ?> | |
| 398 | - <img src="<?php echo esc_url($company_info['logo']); ?>" alt="<?php echo esc_attr($company_info['name']); ?>" class="logo-image"> | |
| 399 | - <?php endif; ?> | |
| 436 | + <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)"> | |
| 400 | 437 | </div> |
| 438 | + <?php endif; ?> | |
| 401 | 439 | <div class="company-name"><?php echo esc_html($company_info['name']); ?></div> |
| 402 | 440 | <div class="company-details"> |
| 403 | - <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only'); ?> | |
| 441 | + <?php echo wp_kses_post(\EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only')); ?> | |
| 404 | 442 | </div> |
| 405 | 443 | </div> |
| 406 | 444 | |
| 407 | 445 | <div class="invoice-meta"> |
| 408 | - <div class="invoice-title"><?php echo esc_html($invoice->getTitle() ?: __('Invoice', 'easy-invoice')); ?></div> | |
| 446 | + <?php $ei_kind = \EasyInvoice\Helpers\TemplateTextHelper::documentKind($invoice); $ei_title = trim((string) $invoice->getTitle()); ?> | |
| 447 | + <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> | |
| 409 | 448 | <div class="meta-item"> |
| 410 | 449 | <span class="meta-label"><?php echo esc_html($text_settings['invoice_number']); ?></span> |
| 411 | 450 | <span class="meta-value"><?php echo esc_html($invoice->getNumber()); ?></span> |
| 412 | 451 | </div> |
| @@ -413,32 +452,44 @@ | ||
| 413 | 452 | <div class="meta-item"> |
| 414 | 453 | <span class="meta-label"><?php echo esc_html($text_settings['invoice_date']); ?></span> |
| 415 | 454 | <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getIssueDate())); ?></span> |
| 416 | 455 | </div> |
| 456 | + <?php if (empty($ei_is_credit_note)) : ?> | |
| 417 | 457 | <div class="meta-item"> |
| 418 | 458 | <span class="meta-label"><?php echo esc_html($text_settings['due_date']); ?></span> |
| 419 | 459 | <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getDueDate())); ?></span> |
| 420 | 460 | </div> |
| 461 | + <?php endif; ?> | |
| 462 | + <?php if (empty($ei_is_credit_note)) : ?> | |
| 463 | + <div class="meta-item meta-amount-due"> | |
| 464 | + <span class="meta-label"><?php echo esc_html($text_settings['total_due']); ?></span> | |
| 465 | + <span class="meta-value"><?php echo esc_html($formatter->format(\EasyInvoice\Helpers\TemplateTextHelper::amountDue($invoice))); ?></span> | |
| 466 | + </div> | |
| 467 | + <?php endif; ?> | |
| 421 | 468 | </div> |
| 422 | 469 | </div> |
| 423 | 470 | |
| 424 | - <!-- Address Section --> | |
| 471 | + <?php $ei_client_html = \EasyInvoice\Helpers\TemplateTextHelper::generateClientBlock($invoice); if ('' !== $ei_client_html) : ?> | |
| 425 | 472 | <div class="address-section"> |
| 426 | 473 | <div class="address-block"> |
| 427 | 474 | <h2><?php echo esc_html($text_settings['to']); ?></h2> |
| 428 | 475 | <div class="address-content"> |
| 429 | - <div class="client-name"><?php echo esc_html($invoice->getCustomerName()); ?></div> | |
| 430 | - <?php if ($invoice->getCustomerAddress()): ?> | |
| 431 | - <?php echo nl2br(esc_html($invoice->getCustomerAddress())); ?><br> | |
| 432 | - <?php endif; ?> | |
| 433 | - <?php if ($invoice->getCustomerEmail()): ?> | |
| 434 | - <?php echo esc_html($invoice->getCustomerEmail()); ?><br> | |
| 435 | - <?php endif; ?> | |
| 476 | + <?php echo wp_kses_post($ei_client_html); ?> | |
| 436 | 477 | </div> |
| 437 | 478 | </div> |
| 438 | 479 | </div> |
| 480 | + <?php endif; ?> | |
| 439 | 481 | |
| 440 | - <!-- Invoice Items --> | |
| 482 | + <?php | |
| 483 | + // The adjustment column appears only when at least one line uses it. | |
| 484 | + $ei_show_adjust = \EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField(); | |
| 485 | + if ($ei_show_adjust) { | |
| 486 | + $ei_show_adjust = false; | |
| 487 | + foreach ($invoice->getItems() as $ei_item) { | |
| 488 | + if ((float) $ei_item->getAdjustPercentage() != 0.0) { $ei_show_adjust = true; break; } | |
| 489 | + } | |
| 490 | + } | |
| 491 | + ?> | |
| 441 | 492 | <table class="invoice-items"> |
| 442 | 493 | <thead> |
| 443 | 494 | <tr> |
| 444 | 495 | <th><?php echo esc_html($text_settings['service']); ?></th> |
| @@ -443,15 +494,18 @@ | ||
| 443 | 494 | <tr> |
| 444 | 495 | <th><?php echo esc_html($text_settings['service']); ?></th> |
| 445 | 496 | <th><?php echo esc_html($text_settings['qty']); ?></th> |
| 446 | 497 | <th><?php echo esc_html($text_settings['rate_price']); ?></th> |
| 447 | - <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowQuoteAdjustField()): ?> | |
| 498 | + <?php if ($ei_show_adjust): ?> | |
| 448 | 499 | <th><?php echo esc_html($text_settings['adjust']); ?> (%)</th> |
| 449 | 500 | <?php endif; ?> |
| 450 | - <th><?php echo esc_html($text_settings['total']); ?></th> | |
| 501 | + <th><?php echo esc_html($text_settings['line_total'] ?? $text_settings['total']); ?></th> | |
| 451 | 502 | </tr> |
| 452 | 503 | </thead> |
| 453 | 504 | <tbody> |
| 505 | + <?php if (!$invoice->getItems()) : ?> | |
| 506 | + <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> | |
| 507 | + <?php endif; ?> | |
| 454 | 508 | <?php foreach ($invoice->getItems() as $item): ?> |
| 455 | 509 | <tr> |
| 456 | 510 | <td class="item-name"> |
| 457 | 511 | <div class="item-title"><?php echo esc_html($item->getName()); ?></div> |
| @@ -460,9 +514,9 @@ | ||
| 460 | 514 | <?php endif; ?> |
| 461 | 515 | </td> |
| 462 | 516 | <td class="item-quantity"><?php echo esc_html($item->getQuantity() ?: '0'); ?></td> |
| 463 | 517 | <td class="item-price"><?php echo esc_html($formatter->format($item->getPrice())); ?></td> |
| 464 | - <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowQuoteAdjustField()): ?> | |
| 518 | + <?php if ($ei_show_adjust): ?> | |
| 465 | 519 | <td class="item-adjust"><?php |
| 466 | 520 | $adjust_percentage = $item->getAdjustPercentage(); |
| 467 | 521 | if ($adjust_percentage != 0) { |
| 468 | 522 | echo esc_html($adjust_percentage > 0 ? '+' : '') . esc_html($adjust_percentage) . '%'; |
| @@ -476,17 +530,15 @@ | ||
| 476 | 530 | <?php endforeach; ?> |
| 477 | 531 | </tbody> |
| 478 | 532 | </table> |
| 479 | 533 | |
| 480 | - <!-- Invoice Totals --> | |
| 481 | 534 | <div class="invoice-totals"> |
| 482 | - <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice'); ?> | |
| 535 | + <?php echo wp_kses_post(\EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice')); ?> | |
| 483 | 536 | </div> |
| 484 | 537 | |
| 485 | - <!-- Notes --> | |
| 486 | 538 | <?php if ($invoice->getNotes()): ?> |
| 487 | 539 | <div class="invoice-notes"> |
| 488 | - <h3><?php _e('Notes:', 'easy-invoice'); ?></h3> | |
| 540 | + <h3><?php esc_html_e('Notes', 'easy-invoice'); ?></h3> | |
| 489 | 541 | <div class="notes-content"> |
| 490 | 542 | <?php echo wp_kses_post($invoice->getNotes() ?: ''); ?> |
| 491 | 543 | </div> |
| 492 | 544 | </div> |
| @@ -491,15 +543,14 @@ | ||
| 491 | 543 | </div> |
| 492 | 544 | </div> |
| 493 | 545 | <?php endif; ?> |
| 494 | 546 | |
| 495 | - <!-- Terms and Conditions --> | |
| 496 | 547 | <?php |
| 497 | - $terms_conditions = $invoice->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions(); | |
| 548 | + $terms_conditions = empty($ei_is_credit_note) ? ($invoice->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions()) : ''; | |
| 498 | 549 | if ($terms_conditions): |
| 499 | 550 | ?> |
| 500 | 551 | <div class="invoice-terms"> |
| 501 | - <h3><?php _e('Terms & Conditions:', 'easy-invoice'); ?></h3> | |
| 552 | + <h3><?php esc_html_e('Terms & Conditions', 'easy-invoice'); ?></h3> | |
| 502 | 553 | <div class="terms-content"> |
| 503 | 554 | <?php echo wp_kses_post($terms_conditions); ?> |
| 504 | 555 | </div> |
| 505 | 556 | </div> |
| @@ -504,15 +555,23 @@ | ||
| 504 | 555 | </div> |
| 505 | 556 | </div> |
| 506 | 557 | <?php endif; ?> |
| 507 | 558 | |
| 508 | - <!-- Footer --> | |
| 559 | + <?php | |
| 560 | + /** | |
| 561 | + * Fires inside the document card, after notes and terms and before the | |
| 562 | + * footer text: attachments, the signature block, e-invoicing notes. Being | |
| 563 | + * inside the card, it is part of what "Download as PDF" captures. | |
| 564 | + * | |
| 565 | + * @param object $document The invoice model. | |
| 566 | + * @param string $type 'invoice'. | |
| 567 | + */ | |
| 568 | + do_action('easy_invoice_document_body_after', $invoice, 'invoice'); | |
| 569 | + | |
| 570 | + $ei_footer_text = \EasyInvoice\Helpers\TemplateTextHelper::footerText($invoice, 'invoice'); | |
| 571 | + if ('' !== trim(wp_strip_all_tags((string) $ei_footer_text))) : | |
| 572 | + ?> | |
| 509 | 573 | <div class="invoice-footer"> |
| 510 | - <?php | |
| 511 | - $invoice_footer_text = $invoice->getFooterText(); | |
| 512 | - if (!$invoice_footer_text) { | |
| 513 | - $invoice_footer_text = \EasyInvoice\Controllers\SettingsController::getInvoiceFooterText(); | |
| 514 | - } | |
| 515 | - ?> | |
| 516 | - <p><?php echo wp_kses_post($invoice_footer_text); ?></p> | |
| 574 | + <p><?php echo wp_kses_post($ei_footer_text); ?></p> | |
| 517 | 575 | </div> |
| 518 | -</div> | |
| 576 | + <?php endif; ?> | |
| 577 | +</div> | |