| @@ -3,9 +3,13 @@ | ||
| 3 | 3 | * Creative Template - Artistic Design |
| 4 | 4 | * Creative, artistic, and innovative 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 | /* Creative Template - Artistic Design */ |
| @@ -10,9 +14,9 @@ | ||
| 10 | 14 | <style> |
| 11 | 15 | /* Creative Template - Artistic Design */ |
| 12 | 16 | :root { |
| 13 | 17 | --primary-color: #8b5cf6; |
| 14 | - --primary-light: #a855f7; | |
| 18 | + --primary-light: #d946ef; | |
| 15 | 19 | --primary-dark: #7c3aed; |
| 16 | 20 | --secondary-color: #06b6d4; |
| 17 | 21 | --accent-color: #f59e0b; |
| 18 | 22 | --success-color: #10b981; |
| @@ -353,9 +357,9 @@ | ||
| 353 | 357 | font-weight: 600; |
| 354 | 358 | color: var(--text-primary); |
| 355 | 359 | } |
| 356 | 360 | |
| 357 | -.template-creative .invoice-grand-total { | |
| 361 | +.template-creative .invoice-totals .invoice-grand-total { | |
| 358 | 362 | font-size: var(--font-size-xl); |
| 359 | 363 | font-weight: 700; |
| 360 | 364 | color: var(--primary-color); |
| 361 | 365 | border-top: 2px solid var(--primary-color); |
| @@ -444,27 +448,76 @@ | ||
| 444 | 448 | .template-creative .invoice-totals { |
| 445 | 449 | width: 100%; |
| 446 | 450 | } |
| 447 | 451 | } |
| 452 | + | |
| 453 | +/* Shared polish: numbers line up, numeric headings sit over their figures. */ | |
| 454 | +.template-creative .invoice-items th + th { text-align: right; } | |
| 455 | +.template-creative .invoice-items .item-quantity, | |
| 456 | +.template-creative .invoice-items .item-price, | |
| 457 | +.template-creative .invoice-items .item-adjust, | |
| 458 | +.template-creative .invoice-items .item-total, | |
| 459 | +.template-creative .invoice-total-value { font-variant-numeric: tabular-nums; white-space: nowrap; } | |
| 460 | +.template-creative .meta-value { white-space: nowrap; } | |
| 461 | +.template-creative .invoice-items .item-adjust { text-align: right; } | |
| 462 | +.template-creative .client-contact { font-weight: 500; margin-bottom: 0.15em; } | |
| 463 | +.template-creative .client-tax-number, | |
| 464 | +.template-creative .company-tax-number { margin-top: 0.35em; } | |
| 465 | +.template-creative .invoice-items .item-description { white-space: pre-line; } | |
| 466 | + | |
| 467 | +/* Creative: one bold gradient carries the character; everything else stays quiet. */ | |
| 468 | +.template-creative::before { height: 10px; background: linear-gradient(90deg, var(--primary-color), var(--primary-light)); } | |
| 469 | +.template-creative .invoice-header::after { background: linear-gradient(90deg, var(--primary-color), var(--primary-light)); } | |
| 470 | +.template-creative .invoice-meta { border-radius: var(--radius-xl); } | |
| 471 | +.template-creative .invoice-title { color: var(--primary-dark); } | |
| 472 | +.template-creative .address-block { border-radius: var(--radius-xl); } | |
| 473 | +.template-creative .address-block::before { background: linear-gradient(90deg, var(--primary-color), var(--primary-light)); } | |
| 474 | +.template-creative .invoice-items { border-radius: var(--radius-xl); } | |
| 475 | +.template-creative .invoice-items thead { background: linear-gradient(90deg, var(--primary-color), var(--primary-light)); } | |
| 476 | +.template-creative .invoice-items th { background: transparent; } | |
| 477 | +.template-creative .invoice-items tbody tr:nth-child(even) td { background: var(--background-accent); } | |
| 478 | +.template-creative .invoice-items tr:hover { background: transparent; } | |
| 479 | +.template-creative .invoice-totals { border-radius: var(--radius-xl); } | |
| 480 | +.template-creative .invoice-totals .invoice-grand-total { color: var(--primary-dark); border-top: 2px solid var(--primary-light); } | |
| 481 | +.template-creative .invoice-notes, .template-creative .invoice-terms { border-radius: var(--radius-xl); } | |
| 482 | +.template-creative .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; } | |
| 483 | +.template-creative .invoice-totals .invoice-paid-row .invoice-total-value { color: var(--success-color, #047857); } | |
| 484 | +.template-creative .invoice-totals .invoice-balance-due { font-weight: 700; } | |
| 485 | +.template-creative .invoice-totals .invoice-balance-due .invoice-total-label { color: inherit; font-weight: 700; } | |
| 486 | +.template-creative .meta-amount-due .meta-value { font-weight: 700; font-size: 1.08em; } | |
| 487 | + | |
| 488 | +/* The sheet this design draws on is A4. Every other design fits a short | |
| 489 | + invoice inside it; this one ran ~200px past the bottom on its spacing | |
| 490 | + alone, so the page it produced — and the PDF captured from it — always | |
| 491 | + spilled onto a second sheet. The scale is redeclared on the card, which | |
| 492 | + its descendants inherit, so the proportions hold and the gaps shrink. */ | |
| 493 | +.template-creative { | |
| 494 | + --spacing-6: 1rem; | |
| 495 | + --spacing-8: 1.25rem; | |
| 496 | + --spacing-10: 1.5rem; | |
| 497 | + --spacing-12: 1.5rem; | |
| 498 | + --spacing-16: 2rem; | |
| 499 | + --spacing-20: 2.25rem; | |
| 500 | +} | |
| 448 | 501 | </style> |
| 449 | 502 | |
| 450 | 503 | <div class="template template-creative"> |
| 451 | - <!-- Header --> | |
| 452 | 504 | <div class="invoice-header"> |
| 453 | 505 | <div class="company-info"> |
| 506 | + <?php if (!empty($company_info['logo'])): ?> | |
| 454 | 507 | <div class="company-logo"> |
| 455 | - <?php if (!empty($company_info['logo'])): ?> | |
| 456 | - <img src="<?php echo esc_url($company_info['logo']); ?>" alt="<?php echo esc_attr($company_info['name']); ?>" class="logo-image"> | |
| 457 | - <?php endif; ?> | |
| 508 | + <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)"> | |
| 458 | 509 | </div> |
| 510 | + <?php endif; ?> | |
| 459 | 511 | <div class="company-name"><?php echo esc_html($company_info['name']); ?></div> |
| 460 | 512 | <div class="company-details"> |
| 461 | - <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only'); ?> | |
| 513 | + <?php echo wp_kses_post(\EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only')); ?> | |
| 462 | 514 | </div> |
| 463 | 515 | </div> |
| 464 | 516 | |
| 465 | 517 | <div class="invoice-meta"> |
| 466 | - <div class="invoice-title"><?php echo esc_html($invoice->getTitle() ?: __('Invoice', 'easy-invoice')); ?></div> | |
| 518 | + <?php $ei_kind = \EasyInvoice\Helpers\TemplateTextHelper::documentKind($invoice); $ei_title = trim((string) $invoice->getTitle()); ?> | |
| 519 | + <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> | |
| 467 | 520 | <div class="meta-item"> |
| 468 | 521 | <span class="meta-label"><?php echo esc_html($text_settings['invoice_number']); ?></span> |
| 469 | 522 | <span class="meta-value"><?php echo esc_html($invoice->getNumber()); ?></span> |
| 470 | 523 | </div> |
| @@ -471,32 +524,44 @@ | ||
| 471 | 524 | <div class="meta-item"> |
| 472 | 525 | <span class="meta-label"><?php echo esc_html($text_settings['invoice_date']); ?></span> |
| 473 | 526 | <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getIssueDate())); ?></span> |
| 474 | 527 | </div> |
| 528 | + <?php if (empty($ei_is_credit_note)) : ?> | |
| 475 | 529 | <div class="meta-item"> |
| 476 | 530 | <span class="meta-label"><?php echo esc_html($text_settings['due_date']); ?></span> |
| 477 | 531 | <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getDueDate())); ?></span> |
| 478 | 532 | </div> |
| 533 | + <?php endif; ?> | |
| 534 | + <?php if (empty($ei_is_credit_note)) : ?> | |
| 535 | + <div class="meta-item meta-amount-due"> | |
| 536 | + <span class="meta-label"><?php echo esc_html($text_settings['total_due']); ?></span> | |
| 537 | + <span class="meta-value"><?php echo esc_html($formatter->format(\EasyInvoice\Helpers\TemplateTextHelper::amountDue($invoice))); ?></span> | |
| 538 | + </div> | |
| 539 | + <?php endif; ?> | |
| 479 | 540 | </div> |
| 480 | 541 | </div> |
| 481 | 542 | |
| 482 | - <!-- Address Section --> | |
| 543 | + <?php $ei_client_html = \EasyInvoice\Helpers\TemplateTextHelper::generateClientBlock($invoice); if ('' !== $ei_client_html) : ?> | |
| 483 | 544 | <div class="address-section"> |
| 484 | 545 | <div class="address-block"> |
| 485 | 546 | <h2><?php echo esc_html($text_settings['to']); ?></h2> |
| 486 | 547 | <div class="address-content"> |
| 487 | - <div class="client-name"><?php echo esc_html($invoice->getCustomerName()); ?></div> | |
| 488 | - <?php if ($invoice->getCustomerAddress()): ?> | |
| 489 | - <?php echo nl2br(esc_html($invoice->getCustomerAddress())); ?><br> | |
| 490 | - <?php endif; ?> | |
| 491 | - <?php if ($invoice->getCustomerEmail()): ?> | |
| 492 | - <?php echo esc_html($invoice->getCustomerEmail()); ?><br> | |
| 493 | - <?php endif; ?> | |
| 548 | + <?php echo wp_kses_post($ei_client_html); ?> | |
| 494 | 549 | </div> |
| 495 | 550 | </div> |
| 496 | 551 | </div> |
| 552 | + <?php endif; ?> | |
| 497 | 553 | |
| 498 | - <!-- Invoice Items --> | |
| 554 | + <?php | |
| 555 | + // The adjustment column appears only when at least one line uses it. | |
| 556 | + $ei_show_adjust = \EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField(); | |
| 557 | + if ($ei_show_adjust) { | |
| 558 | + $ei_show_adjust = false; | |
| 559 | + foreach ($invoice->getItems() as $ei_item) { | |
| 560 | + if ((float) $ei_item->getAdjustPercentage() != 0.0) { $ei_show_adjust = true; break; } | |
| 561 | + } | |
| 562 | + } | |
| 563 | + ?> | |
| 499 | 564 | <table class="invoice-items"> |
| 500 | 565 | <thead> |
| 501 | 566 | <tr> |
| 502 | 567 | <th><?php echo esc_html($text_settings['service']); ?></th> |
| @@ -501,15 +566,18 @@ | ||
| 501 | 566 | <tr> |
| 502 | 567 | <th><?php echo esc_html($text_settings['service']); ?></th> |
| 503 | 568 | <th><?php echo esc_html($text_settings['qty']); ?></th> |
| 504 | 569 | <th><?php echo esc_html($text_settings['rate_price']); ?></th> |
| 505 | - <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowQuoteAdjustField()): ?> | |
| 570 | + <?php if ($ei_show_adjust): ?> | |
| 506 | 571 | <th><?php echo esc_html($text_settings['adjust']); ?> (%)</th> |
| 507 | 572 | <?php endif; ?> |
| 508 | - <th><?php echo esc_html($text_settings['total']); ?></th> | |
| 573 | + <th><?php echo esc_html($text_settings['line_total'] ?? $text_settings['total']); ?></th> | |
| 509 | 574 | </tr> |
| 510 | 575 | </thead> |
| 511 | 576 | <tbody> |
| 577 | + <?php if (!$invoice->getItems()) : ?> | |
| 578 | + <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> | |
| 579 | + <?php endif; ?> | |
| 512 | 580 | <?php foreach ($invoice->getItems() as $item): ?> |
| 513 | 581 | <tr> |
| 514 | 582 | <td class="item-name"> |
| 515 | 583 | <div class="item-title"><?php echo esc_html($item->getName()); ?></div> |
| @@ -516,11 +584,11 @@ | ||
| 516 | 584 | <?php if ($item->getDescription()): ?> |
| 517 | 585 | <div class="item-description"><?php echo esc_html($item->getDescription()); ?></div> |
| 518 | 586 | <?php endif; ?> |
| 519 | 587 | </td> |
| 520 | - <td class="item-quantity"><?php echo esc_html($item->getQuantity()); ?></td> | |
| 588 | + <td class="item-quantity"><?php echo esc_html($item->getQuantity() ?: '0'); ?></td> | |
| 521 | 589 | <td class="item-price"><?php echo esc_html($formatter->format($item->getPrice())); ?></td> |
| 522 | - <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowQuoteAdjustField()): ?> | |
| 590 | + <?php if ($ei_show_adjust): ?> | |
| 523 | 591 | <td class="item-adjust"><?php |
| 524 | 592 | $adjust_percentage = $item->getAdjustPercentage(); |
| 525 | 593 | if ($adjust_percentage != 0) { |
| 526 | 594 | echo esc_html($adjust_percentage > 0 ? '+' : '') . esc_html($adjust_percentage) . '%'; |
| @@ -534,17 +602,15 @@ | ||
| 534 | 602 | <?php endforeach; ?> |
| 535 | 603 | </tbody> |
| 536 | 604 | </table> |
| 537 | 605 | |
| 538 | - <!-- Invoice Totals --> | |
| 539 | 606 | <div class="invoice-totals"> |
| 540 | - <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice'); ?> | |
| 607 | + <?php echo wp_kses_post(\EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice')); ?> | |
| 541 | 608 | </div> |
| 542 | 609 | |
| 543 | - <!-- Notes --> | |
| 544 | 610 | <?php if ($invoice->getNotes()): ?> |
| 545 | 611 | <div class="invoice-notes"> |
| 546 | - <h3><?php _e('Notes:', 'easy-invoice'); ?></h3> | |
| 612 | + <h3><?php esc_html_e('Notes', 'easy-invoice'); ?></h3> | |
| 547 | 613 | <div class="notes-content"> |
| 548 | 614 | <?php echo wp_kses_post($invoice->getNotes() ?: ''); ?> |
| 549 | 615 | </div> |
| 550 | 616 | </div> |
| @@ -549,15 +615,14 @@ | ||
| 549 | 615 | </div> |
| 550 | 616 | </div> |
| 551 | 617 | <?php endif; ?> |
| 552 | 618 | |
| 553 | - <!-- Terms and Conditions --> | |
| 554 | 619 | <?php |
| 555 | - $terms_conditions = $invoice->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions(); | |
| 620 | + $terms_conditions = empty($ei_is_credit_note) ? ($invoice->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions()) : ''; | |
| 556 | 621 | if ($terms_conditions): |
| 557 | 622 | ?> |
| 558 | 623 | <div class="invoice-terms"> |
| 559 | - <h3><?php _e('Terms & Conditions:', 'easy-invoice'); ?></h3> | |
| 624 | + <h3><?php esc_html_e('Terms & Conditions', 'easy-invoice'); ?></h3> | |
| 560 | 625 | <div class="terms-content"> |
| 561 | 626 | <?php echo wp_kses_post($terms_conditions); ?> |
| 562 | 627 | </div> |
| 563 | 628 | </div> |
| @@ -562,15 +627,23 @@ | ||
| 562 | 627 | </div> |
| 563 | 628 | </div> |
| 564 | 629 | <?php endif; ?> |
| 565 | 630 | |
| 566 | - <!-- Footer --> | |
| 631 | + <?php | |
| 632 | + /** | |
| 633 | + * Fires inside the document card, after notes and terms and before the | |
| 634 | + * footer text: attachments, the signature block, e-invoicing notes. Being | |
| 635 | + * inside the card, it is part of what "Download as PDF" captures. | |
| 636 | + * | |
| 637 | + * @param object $document The invoice model. | |
| 638 | + * @param string $type 'invoice'. | |
| 639 | + */ | |
| 640 | + do_action('easy_invoice_document_body_after', $invoice, 'invoice'); | |
| 641 | + | |
| 642 | + $ei_footer_text = \EasyInvoice\Helpers\TemplateTextHelper::footerText($invoice, 'invoice'); | |
| 643 | + if ('' !== trim(wp_strip_all_tags((string) $ei_footer_text))) : | |
| 644 | + ?> | |
| 567 | 645 | <div class="invoice-footer"> |
| 568 | - <?php | |
| 569 | - $invoice_footer_text = $invoice->getFooterText(); | |
| 570 | - if (!$invoice_footer_text) { | |
| 571 | - $invoice_footer_text = \EasyInvoice\Controllers\SettingsController::getInvoiceFooterText(); | |
| 572 | - } | |
| 573 | - ?> | |
| 574 | - <p><?php echo wp_kses_post($invoice_footer_text); ?></p> | |
| 646 | + <p><?php echo wp_kses_post($ei_footer_text); ?></p> | |
| 575 | 647 | </div> |
| 576 | -</div> | |
| 648 | + <?php endif; ?> | |
| 649 | +</div> | |