| @@ -3,9 +3,13 @@ | ||
| 3 | 3 | * Corporate Template - Business-Focused Design |
| 4 | 4 | * Professional, corporate, and business-oriented 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 | /* Corporate Template - Business-Focused Design */ |
| @@ -329,9 +333,9 @@ | ||
| 329 | 333 | font-weight: 600; |
| 330 | 334 | color: var(--text-primary); |
| 331 | 335 | } |
| 332 | 336 | |
| 333 | -.template-corporate .invoice-grand-total { | |
| 337 | +.template-corporate .invoice-totals .invoice-grand-total { | |
| 334 | 338 | font-size: var(--font-size-xl); |
| 335 | 339 | font-weight: 700; |
| 336 | 340 | color: var(--primary-color); |
| 337 | 341 | border-top: 2px solid var(--primary-color); |
| @@ -427,27 +431,81 @@ | ||
| 427 | 431 | .template-corporate .invoice-totals { |
| 428 | 432 | width: 100%; |
| 429 | 433 | } |
| 430 | 434 | } |
| 435 | + | |
| 436 | +/* Shared polish: numbers line up, numeric headings sit over their figures. */ | |
| 437 | +.template-corporate .invoice-items th + th { text-align: right; } | |
| 438 | +.template-corporate .invoice-items .item-quantity, | |
| 439 | +.template-corporate .invoice-items .item-price, | |
| 440 | +.template-corporate .invoice-items .item-adjust, | |
| 441 | +.template-corporate .invoice-items .item-total, | |
| 442 | +.template-corporate .invoice-total-value { font-variant-numeric: tabular-nums; white-space: nowrap; } | |
| 443 | +.template-corporate .meta-value { white-space: nowrap; } | |
| 444 | +.template-corporate .invoice-items .item-adjust { text-align: right; } | |
| 445 | +.template-corporate .client-contact { font-weight: 500; margin-bottom: 0.15em; } | |
| 446 | +.template-corporate .client-tax-number, | |
| 447 | +.template-corporate .company-tax-number { margin-top: 0.35em; } | |
| 448 | +.template-corporate .invoice-items .item-description { white-space: pre-line; } | |
| 449 | + | |
| 450 | +/* Corporate: a navy masthead across the full width of the sheet, rules below it. */ | |
| 451 | +.template-corporate { border-radius: 0; } | |
| 452 | +.template-corporate::before { display: none; } | |
| 453 | +.template-corporate .invoice-header { background: var(--primary-color); color: #ffffff; margin: calc(-1 * var(--spacing-8)) calc(-1 * var(--spacing-8)) var(--spacing-10); padding: var(--spacing-8); border-bottom: 0; align-items: start; } | |
| 454 | +.template-corporate .invoice-header::after { display: none; } | |
| 455 | +.template-corporate .company-name { color: #ffffff; } | |
| 456 | +.template-corporate .company-details { color: rgba(255, 255, 255, 0.78); } | |
| 457 | +.template-corporate .logo-image { filter: none; background: #ffffff; padding: 6px; border-radius: var(--radius-sm); } | |
| 458 | +.template-corporate .invoice-meta { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.22); box-shadow: none; border-radius: var(--radius-sm); padding: var(--spacing-5) var(--spacing-6); gap: 0; } | |
| 459 | +.template-corporate .invoice-title { color: #ffffff; text-align: left; letter-spacing: 0.1em; font-size: var(--font-size-xl); margin-bottom: var(--spacing-3); } | |
| 460 | +.template-corporate .meta-item { border-bottom: 1px solid rgba(255, 255, 255, 0.18); padding: var(--spacing-2) 0; } | |
| 461 | +.template-corporate .meta-item:last-child { border-bottom: 0; } | |
| 462 | +.template-corporate .meta-label { color: rgba(255, 255, 255, 0.72); } | |
| 463 | +.template-corporate .meta-value { color: #ffffff; } | |
| 464 | +.template-corporate .address-section { margin-bottom: var(--spacing-10); } | |
| 465 | +.template-corporate .address-block { background: transparent; border: 0; border-left: 3px solid var(--primary-color); border-radius: 0; padding: var(--spacing-1) var(--spacing-5); overflow: visible; } | |
| 466 | +.template-corporate .address-block::before { display: none; } | |
| 467 | +.template-corporate .address-block h2 { font-size: var(--font-size-xs); color: var(--text-muted); margin-bottom: var(--spacing-2); letter-spacing: 0.12em; } | |
| 468 | +.template-corporate .invoice-items { border-radius: 0; box-shadow: none; border: 0; border-top: 2px solid var(--primary-color); margin-bottom: var(--spacing-10); } | |
| 469 | +.template-corporate .invoice-items th { background: var(--background-accent); color: var(--text-primary); border-bottom: 1px solid var(--border-color); padding: var(--spacing-3) var(--spacing-5); font-size: var(--font-size-xs); letter-spacing: 0.08em; } | |
| 470 | +.template-corporate .invoice-items td { padding: var(--spacing-4) var(--spacing-5); } | |
| 471 | +.template-corporate .invoice-items tr:last-child td { border-bottom: 1px solid var(--border-light); } | |
| 472 | +.template-corporate .invoice-items tr:hover { background: transparent; } | |
| 473 | +.template-corporate .invoice-totals { border-radius: 0; box-shadow: none; background: transparent; border: 0; padding: 0; width: 380px; } | |
| 474 | +.template-corporate .invoice-total-row { padding: var(--spacing-2) var(--spacing-4); } | |
| 475 | +.template-corporate .invoice-totals .invoice-grand-total { background: var(--primary-color); margin-top: var(--spacing-3); padding: var(--spacing-3) var(--spacing-4); border: 0; } | |
| 476 | +.template-corporate .invoice-grand-total .invoice-total-label, .template-corporate .invoice-grand-total .invoice-total-value { color: #ffffff; } | |
| 477 | +.template-corporate .invoice-notes, .template-corporate .invoice-terms { border-radius: 0; background: transparent; border: 0; border-top: 1px solid var(--border-color); padding: var(--spacing-5) 0 0; margin-top: var(--spacing-6); } | |
| 478 | +.template-corporate .invoice-notes h3, .template-corporate .invoice-terms h3 { border: 0; padding: 0; font-size: var(--font-size-xs); text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-muted); margin-bottom: var(--spacing-2); } | |
| 479 | +.template-corporate .invoice-footer { border-top: 1px solid var(--border-color); } | |
| 480 | +@media (max-width: 768px) { | |
| 481 | + .template-corporate .invoice-header { margin: calc(-1 * var(--spacing-4)) calc(-1 * var(--spacing-4)) var(--spacing-8); padding: var(--spacing-5) var(--spacing-4); } | |
| 482 | +} | |
| 483 | +.template-corporate .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; } | |
| 484 | +.template-corporate .invoice-totals .invoice-paid-row .invoice-total-value { color: var(--success-color, #047857); } | |
| 485 | +.template-corporate .invoice-totals .invoice-balance-due { font-weight: 700; } | |
| 486 | +.template-corporate .invoice-totals .invoice-balance-due .invoice-total-label { color: inherit; font-weight: 700; } | |
| 487 | +.template-corporate .meta-amount-due .meta-value { font-weight: 700; font-size: 1.08em; } | |
| 488 | +.template-corporate .invoice-title .document-kind { color: rgba(255, 255, 255, 0.65); } | |
| 431 | 489 | </style> |
| 432 | 490 | |
| 433 | 491 | <div class="template template-corporate"> |
| 434 | - <!-- Header --> | |
| 435 | 492 | <div class="invoice-header"> |
| 436 | 493 | <div class="company-info"> |
| 494 | + <?php if (!empty($company_info['logo'])): ?> | |
| 437 | 495 | <div class="company-logo"> |
| 438 | - <?php if (!empty($company_info['logo'])): ?> | |
| 439 | - <img src="<?php echo esc_url($company_info['logo']); ?>" alt="<?php echo esc_attr($company_info['name']); ?>" class="logo-image"> | |
| 440 | - <?php endif; ?> | |
| 496 | + <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)"> | |
| 441 | 497 | </div> |
| 498 | + <?php endif; ?> | |
| 442 | 499 | <div class="company-name"><?php echo esc_html($company_info['name']); ?></div> |
| 443 | 500 | <div class="company-details"> |
| 444 | - <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only'); ?> | |
| 501 | + <?php echo wp_kses_post(\EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only')); ?> | |
| 445 | 502 | </div> |
| 446 | 503 | </div> |
| 447 | 504 | |
| 448 | 505 | <div class="invoice-meta"> |
| 449 | - <div class="invoice-title"><?php echo esc_html($invoice->getTitle() ?: __('Invoice', 'easy-invoice')); ?></div> | |
| 506 | + <?php $ei_kind = \EasyInvoice\Helpers\TemplateTextHelper::documentKind($invoice); $ei_title = trim((string) $invoice->getTitle()); ?> | |
| 507 | + <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> | |
| 450 | 508 | <div class="meta-item"> |
| 451 | 509 | <span class="meta-label"><?php echo esc_html($text_settings['invoice_number']); ?></span> |
| 452 | 510 | <span class="meta-value"><?php echo esc_html($invoice->getNumber()); ?></span> |
| 453 | 511 | </div> |
| @@ -454,32 +512,44 @@ | ||
| 454 | 512 | <div class="meta-item"> |
| 455 | 513 | <span class="meta-label"><?php echo esc_html($text_settings['invoice_date']); ?></span> |
| 456 | 514 | <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getIssueDate())); ?></span> |
| 457 | 515 | </div> |
| 516 | + <?php if (empty($ei_is_credit_note)) : ?> | |
| 458 | 517 | <div class="meta-item"> |
| 459 | 518 | <span class="meta-label"><?php echo esc_html($text_settings['due_date']); ?></span> |
| 460 | 519 | <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getDueDate())); ?></span> |
| 461 | 520 | </div> |
| 521 | + <?php endif; ?> | |
| 522 | + <?php if (empty($ei_is_credit_note)) : ?> | |
| 523 | + <div class="meta-item meta-amount-due"> | |
| 524 | + <span class="meta-label"><?php echo esc_html($text_settings['total_due']); ?></span> | |
| 525 | + <span class="meta-value"><?php echo esc_html($formatter->format(\EasyInvoice\Helpers\TemplateTextHelper::amountDue($invoice))); ?></span> | |
| 526 | + </div> | |
| 527 | + <?php endif; ?> | |
| 462 | 528 | </div> |
| 463 | 529 | </div> |
| 464 | 530 | |
| 465 | - <!-- Address Section --> | |
| 531 | + <?php $ei_client_html = \EasyInvoice\Helpers\TemplateTextHelper::generateClientBlock($invoice); if ('' !== $ei_client_html) : ?> | |
| 466 | 532 | <div class="address-section"> |
| 467 | 533 | <div class="address-block"> |
| 468 | 534 | <h2><?php echo esc_html($text_settings['to']); ?></h2> |
| 469 | 535 | <div class="address-content"> |
| 470 | - <div class="client-name"><?php echo esc_html($invoice->getCustomerName()); ?></div> | |
| 471 | - <?php if ($invoice->getCustomerAddress()): ?> | |
| 472 | - <?php echo nl2br(esc_html($invoice->getCustomerAddress())); ?><br> | |
| 473 | - <?php endif; ?> | |
| 474 | - <?php if ($invoice->getCustomerEmail()): ?> | |
| 475 | - <?php echo esc_html($invoice->getCustomerEmail()); ?><br> | |
| 476 | - <?php endif; ?> | |
| 536 | + <?php echo wp_kses_post($ei_client_html); ?> | |
| 477 | 537 | </div> |
| 478 | 538 | </div> |
| 479 | 539 | </div> |
| 540 | + <?php endif; ?> | |
| 480 | 541 | |
| 481 | - <!-- Invoice Items --> | |
| 542 | + <?php | |
| 543 | + // The adjustment column appears only when at least one line uses it. | |
| 544 | + $ei_show_adjust = \EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField(); | |
| 545 | + if ($ei_show_adjust) { | |
| 546 | + $ei_show_adjust = false; | |
| 547 | + foreach ($invoice->getItems() as $ei_item) { | |
| 548 | + if ((float) $ei_item->getAdjustPercentage() != 0.0) { $ei_show_adjust = true; break; } | |
| 549 | + } | |
| 550 | + } | |
| 551 | + ?> | |
| 482 | 552 | <table class="invoice-items"> |
| 483 | 553 | <thead> |
| 484 | 554 | <tr> |
| 485 | 555 | <th><?php echo esc_html($text_settings['service']); ?></th> |
| @@ -484,15 +554,18 @@ | ||
| 484 | 554 | <tr> |
| 485 | 555 | <th><?php echo esc_html($text_settings['service']); ?></th> |
| 486 | 556 | <th><?php echo esc_html($text_settings['qty']); ?></th> |
| 487 | 557 | <th><?php echo esc_html($text_settings['rate_price']); ?></th> |
| 488 | - <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowQuoteAdjustField()): ?> | |
| 558 | + <?php if ($ei_show_adjust): ?> | |
| 489 | 559 | <th><?php echo esc_html($text_settings['adjust']); ?> (%)</th> |
| 490 | 560 | <?php endif; ?> |
| 491 | - <th><?php echo esc_html($text_settings['total']); ?></th> | |
| 561 | + <th><?php echo esc_html($text_settings['line_total'] ?? $text_settings['total']); ?></th> | |
| 492 | 562 | </tr> |
| 493 | 563 | </thead> |
| 494 | 564 | <tbody> |
| 565 | + <?php if (!$invoice->getItems()) : ?> | |
| 566 | + <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> | |
| 567 | + <?php endif; ?> | |
| 495 | 568 | <?php foreach ($invoice->getItems() as $item): ?> |
| 496 | 569 | <tr> |
| 497 | 570 | <td class="item-name"> |
| 498 | 571 | <div class="item-title"><?php echo esc_html($item->getName()); ?></div> |
| @@ -501,9 +574,9 @@ | ||
| 501 | 574 | <?php endif; ?> |
| 502 | 575 | </td> |
| 503 | 576 | <td class="item-quantity"><?php echo esc_html($item->getQuantity() ?: '0'); ?></td> |
| 504 | 577 | <td class="item-price"><?php echo esc_html($formatter->format($item->getPrice())); ?></td> |
| 505 | - <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowQuoteAdjustField()): ?> | |
| 578 | + <?php if ($ei_show_adjust): ?> | |
| 506 | 579 | <td class="item-adjust"><?php |
| 507 | 580 | $adjust_percentage = $item->getAdjustPercentage(); |
| 508 | 581 | if ($adjust_percentage != 0) { |
| 509 | 582 | echo esc_html($adjust_percentage > 0 ? '+' : '') . esc_html($adjust_percentage) . '%'; |
| @@ -517,17 +590,15 @@ | ||
| 517 | 590 | <?php endforeach; ?> |
| 518 | 591 | </tbody> |
| 519 | 592 | </table> |
| 520 | 593 | |
| 521 | - <!-- Invoice Totals --> | |
| 522 | 594 | <div class="invoice-totals"> |
| 523 | - <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice'); ?> | |
| 595 | + <?php echo wp_kses_post(\EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice')); ?> | |
| 524 | 596 | </div> |
| 525 | 597 | |
| 526 | - <!-- Notes --> | |
| 527 | 598 | <?php if ($invoice->getNotes()): ?> |
| 528 | 599 | <div class="invoice-notes"> |
| 529 | - <h3><?php _e('Notes:', 'easy-invoice'); ?></h3> | |
| 600 | + <h3><?php esc_html_e('Notes', 'easy-invoice'); ?></h3> | |
| 530 | 601 | <div class="notes-content"> |
| 531 | 602 | <?php echo wp_kses_post($invoice->getNotes() ?: ''); ?> |
| 532 | 603 | </div> |
| 533 | 604 | </div> |
| @@ -532,15 +603,14 @@ | ||
| 532 | 603 | </div> |
| 533 | 604 | </div> |
| 534 | 605 | <?php endif; ?> |
| 535 | 606 | |
| 536 | - <!-- Terms and Conditions --> | |
| 537 | 607 | <?php |
| 538 | - $terms_conditions = $invoice->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions(); | |
| 608 | + $terms_conditions = empty($ei_is_credit_note) ? ($invoice->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions()) : ''; | |
| 539 | 609 | if ($terms_conditions): |
| 540 | 610 | ?> |
| 541 | 611 | <div class="invoice-terms"> |
| 542 | - <h3><?php _e('Terms & Conditions:', 'easy-invoice'); ?></h3> | |
| 612 | + <h3><?php esc_html_e('Terms & Conditions', 'easy-invoice'); ?></h3> | |
| 543 | 613 | <div class="terms-content"> |
| 544 | 614 | <?php echo wp_kses_post($terms_conditions); ?> |
| 545 | 615 | </div> |
| 546 | 616 | </div> |
| @@ -545,15 +615,23 @@ | ||
| 545 | 615 | </div> |
| 546 | 616 | </div> |
| 547 | 617 | <?php endif; ?> |
| 548 | 618 | |
| 549 | - <!-- Footer --> | |
| 619 | + <?php | |
| 620 | + /** | |
| 621 | + * Fires inside the document card, after notes and terms and before the | |
| 622 | + * footer text: attachments, the signature block, e-invoicing notes. Being | |
| 623 | + * inside the card, it is part of what "Download as PDF" captures. | |
| 624 | + * | |
| 625 | + * @param object $document The invoice model. | |
| 626 | + * @param string $type 'invoice'. | |
| 627 | + */ | |
| 628 | + do_action('easy_invoice_document_body_after', $invoice, 'invoice'); | |
| 629 | + | |
| 630 | + $ei_footer_text = \EasyInvoice\Helpers\TemplateTextHelper::footerText($invoice, 'invoice'); | |
| 631 | + if ('' !== trim(wp_strip_all_tags((string) $ei_footer_text))) : | |
| 632 | + ?> | |
| 550 | 633 | <div class="invoice-footer"> |
| 551 | - <?php | |
| 552 | - $invoice_footer_text = $invoice->getFooterText(); | |
| 553 | - if (!$invoice_footer_text) { | |
| 554 | - $invoice_footer_text = \EasyInvoice\Controllers\SettingsController::getInvoiceFooterText(); | |
| 555 | - } | |
| 556 | - ?> | |
| 557 | - <p><?php echo wp_kses_post($invoice_footer_text); ?></p> | |
| 634 | + <p><?php echo wp_kses_post($ei_footer_text); ?></p> | |
| 558 | 635 | </div> |
| 559 | -</div> | |
| 636 | + <?php endif; ?> | |
| 637 | +</div> | |