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