mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-01 12:48:08 +09:00
* Attach PDF invoices to invoice emails (#1724) Adds generic file-attachment support to the email pipeline (Mail, QueuedEmail, Email\Service) and wires it into invoice notifications via a new "Attach PDF Copy to Invoice Emails" setting, so clients who pay by bank transfer can view the invoice without logging in. Also carries the same attachment into the sent-email activity log so a later "resend" (client or admin) reattaches the PDF instead of dropping it. * Address PR review: avoid blob hydration in email history list, fix checkbox uncheck - ActivityClientEmailRepository::getSearchQueryBuilder() now selects a partial entity that excludes attachment_content, so the paginated admin/client email history list no longer hydrates every PDF into memory just to render has_attachment. Verified against a real Doctrine EntityManager that the DQL parses, the generated SQL excludes the blob column, and toApiArray() still works correctly on the partial entity. - mod_invoice_settings.html.twig: add the hidden-input-before-checkbox pattern already used elsewhere in this codebase (e.g. mod_client_new_form.html.twig), so unchecking "Attach PDF Copy to Invoice Emails" actually persists as disabled instead of being silently dropped from the form submission.
200 lines
5.0 KiB
PHP
200 lines
5.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/**
|
|
* Copyright 2022-2026 FOSSBilling
|
|
* SPDX-License-Identifier: Apache-2.0.
|
|
*
|
|
* @copyright FOSSBilling (https://www.fossbilling.org)
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
|
|
*/
|
|
|
|
namespace Box\Mod\Email\Entity;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use FOSSBilling\Doctrine\TimestampTrait;
|
|
use FOSSBilling\Interfaces\ApiArrayInterface;
|
|
use FOSSBilling\Interfaces\TimestampInterface;
|
|
use FOSSBilling\Tools;
|
|
|
|
/**
|
|
* One row per email that FOSSBilling sent to a client.
|
|
*
|
|
* Used as a delivery log and to power the "resend" action on the
|
|
* client-facing email history view.
|
|
*/
|
|
#[ORM\Entity(repositoryClass: \Box\Mod\Email\Repository\ActivityClientEmailRepository::class)]
|
|
#[ORM\Table(name: 'activity_client_email')]
|
|
#[ORM\HasLifecycleCallbacks]
|
|
class ActivityClientEmail implements ApiArrayInterface, TimestampInterface
|
|
{
|
|
use TimestampTrait;
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column(type: Types::INTEGER)]
|
|
/** @phpstan-ignore property.unusedType (Doctrine entity ID is auto-generated by the database) */
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(name: 'client_id', type: Types::INTEGER, nullable: true)]
|
|
private ?int $clientId = null;
|
|
|
|
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
|
private ?string $sender = null;
|
|
|
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
|
private ?string $recipients = null;
|
|
|
|
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
|
private ?string $subject = null;
|
|
|
|
#[ORM\Column(name: 'content_html', type: Types::TEXT, nullable: true)]
|
|
private ?string $contentHtml = null;
|
|
|
|
#[ORM\Column(name: 'content_text', type: Types::TEXT, nullable: true)]
|
|
private ?string $contentText = null;
|
|
|
|
#[ORM\Column(name: 'attachment_name', type: Types::STRING, length: 255, nullable: true)]
|
|
private ?string $attachmentName = null;
|
|
|
|
#[ORM\Column(name: 'attachment_content', type: Types::BLOB, nullable: true)]
|
|
private mixed $attachmentContent = null;
|
|
|
|
#[ORM\Column(name: 'attachment_mime', type: Types::STRING, length: 100, nullable: true)]
|
|
private ?string $attachmentMime = null;
|
|
|
|
public function toApiArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'client_id' => $this->clientId,
|
|
'sender' => $this->sender,
|
|
'recipients' => $this->recipients,
|
|
'subject' => $this->subject,
|
|
'content_html' => Tools::sanitizeContent($this->contentHtml ?? ''),
|
|
'content_text' => $this->contentText,
|
|
'has_attachment' => $this->attachmentName !== null,
|
|
'created_at' => $this->getCreatedAt()?->format('Y-m-d H:i:s'),
|
|
'updated_at' => $this->getUpdatedAt()?->format('Y-m-d H:i:s'),
|
|
];
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getClientId(): ?int
|
|
{
|
|
return $this->clientId;
|
|
}
|
|
|
|
public function setClientId(?int $clientId): self
|
|
{
|
|
$this->clientId = $clientId;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSender(): ?string
|
|
{
|
|
return $this->sender;
|
|
}
|
|
|
|
public function setSender(?string $sender): self
|
|
{
|
|
$this->sender = $sender;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getRecipients(): ?string
|
|
{
|
|
return $this->recipients;
|
|
}
|
|
|
|
public function setRecipients(?string $recipients): self
|
|
{
|
|
$this->recipients = $recipients;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSubject(): ?string
|
|
{
|
|
return $this->subject;
|
|
}
|
|
|
|
public function setSubject(?string $subject): self
|
|
{
|
|
$this->subject = $subject;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getContentHtml(): ?string
|
|
{
|
|
return $this->contentHtml;
|
|
}
|
|
|
|
public function setContentHtml(?string $contentHtml): self
|
|
{
|
|
$this->contentHtml = $contentHtml;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getContentText(): ?string
|
|
{
|
|
return $this->contentText;
|
|
}
|
|
|
|
public function setContentText(?string $contentText): self
|
|
{
|
|
$this->contentText = $contentText;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAttachmentName(): ?string
|
|
{
|
|
return $this->attachmentName;
|
|
}
|
|
|
|
public function setAttachmentName(?string $attachmentName): self
|
|
{
|
|
$this->attachmentName = $attachmentName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAttachmentContent(): ?string
|
|
{
|
|
if (is_resource($this->attachmentContent)) {
|
|
return stream_get_contents($this->attachmentContent) ?: null;
|
|
}
|
|
|
|
return $this->attachmentContent;
|
|
}
|
|
|
|
public function setAttachmentContent(?string $attachmentContent): self
|
|
{
|
|
$this->attachmentContent = $attachmentContent;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAttachmentMime(): ?string
|
|
{
|
|
return $this->attachmentMime;
|
|
}
|
|
|
|
public function setAttachmentMime(?string $attachmentMime): self
|
|
{
|
|
$this->attachmentMime = $attachmentMime;
|
|
|
|
return $this;
|
|
}
|
|
}
|