mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 15:54:31 -04:00
Add Xinvoice to E-Mail
This commit is contained in:
parent
55bb506d4e
commit
f2c38bb948
3
.gitignore
vendored
3
.gitignore
vendored
@ -37,4 +37,5 @@ public/test.pdf
|
||||
public/storage/test.pdf
|
||||
/Modules
|
||||
_ide_helper_models.php
|
||||
_ide_helper.php
|
||||
_ide_helper.php
|
||||
/composer.phar
|
||||
|
@ -21,9 +21,10 @@ class CreateXInvoice implements ShouldQueue
|
||||
|
||||
public Invoice $invoice;
|
||||
|
||||
public function __construct(Invoice $invoice)
|
||||
public function __construct(Invoice $invoice, bool $alterPDF)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
$this->alterpdf = $alterPDF;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,12 +295,13 @@ class CreateXInvoice implements ShouldQueue
|
||||
$xrechnung->writeFile(Storage::disk($disk)->path($client->xinvoice_filepath($invoice->invitations->first()) . $invoice->getFileName("xml")));
|
||||
$filepath_pdf = $client->invoice_filepath($invoice->invitations->first()).$invoice->getFileName();
|
||||
|
||||
|
||||
$file = Storage::disk($disk)->exists($filepath_pdf);
|
||||
if ($file) {
|
||||
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, Storage::disk($disk)->path($filepath_pdf));
|
||||
$pdfBuilder->generateDocument();
|
||||
$pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf));
|
||||
if ($this->alterpdf){
|
||||
$file = Storage::disk($disk)->exists($filepath_pdf);
|
||||
if ($file) {
|
||||
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, Storage::disk($disk)->path($filepath_pdf));
|
||||
$pdfBuilder->generateDocument();
|
||||
$pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf));
|
||||
}
|
||||
}
|
||||
return $client->invoice_filepath($invoice->invitations->first()).$invoice->getFileName("xml");
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class ZipInvoices implements ShouldQueue
|
||||
$this->invoices->each(function ($invoice) {
|
||||
(new CreateEntityPdf($invoice->invitations()->first()))->handle();
|
||||
if ($this->company->use_xinvoice){
|
||||
(new CreateXInvoice($invoice))->handle();
|
||||
(new CreateXInvoice($invoice, false))->handle();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Services\Email;
|
||||
|
||||
use App\Jobs\Invoice\CreateXInvoice;
|
||||
use App\Models\Task;
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Quote;
|
||||
@ -55,7 +56,7 @@ class EmailDefaults
|
||||
public function __construct(protected Email $email)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Entry point for generating
|
||||
* the defaults for the email object
|
||||
@ -66,7 +67,7 @@ class EmailDefaults
|
||||
{
|
||||
$this->settings = $this->email->email_object->settings;
|
||||
|
||||
$this->setLocale()
|
||||
$this->setLocale()
|
||||
->setFrom()
|
||||
->setTo()
|
||||
->setTemplate()
|
||||
@ -76,7 +77,7 @@ class EmailDefaults
|
||||
->setBcc()
|
||||
->setAttachments()
|
||||
->setVariables();
|
||||
|
||||
|
||||
return $this->email->email_object;
|
||||
}
|
||||
|
||||
@ -169,7 +170,7 @@ class EmailDefaults
|
||||
// Default template to be used
|
||||
$this->email->email_object->body = EmailTemplateDefaults::getDefaultTemplate($this->email->email_object->email_template_body, $this->locale);
|
||||
}
|
||||
|
||||
|
||||
if ($this->template == 'email.template.custom') {
|
||||
$this->email->email_object->body = (str_replace('$body', $this->email->email_object->body, $this->email->email_object->settings->email_style_custom));
|
||||
}
|
||||
@ -214,7 +215,7 @@ class EmailDefaults
|
||||
public function setVariables(): self
|
||||
{
|
||||
$this->email->email_object->body = strtr($this->email->email_object->body, $this->email->email_object->variables);
|
||||
|
||||
|
||||
$this->email->email_object->subject = strtr($this->email->email_object->subject, $this->email->email_object->variables);
|
||||
|
||||
if ($this->template != 'custom') {
|
||||
@ -243,7 +244,7 @@ class EmailDefaults
|
||||
foreach ($bccs as $bcc) {
|
||||
$bcc_array[] = new Address($bcc);
|
||||
}
|
||||
|
||||
|
||||
$this->email->email_object->bcc = array_merge($this->email->email_object->bcc, $bcc_array);
|
||||
|
||||
return $this;
|
||||
@ -256,7 +257,7 @@ class EmailDefaults
|
||||
private function buildCc()
|
||||
{
|
||||
return [
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@ -289,6 +290,7 @@ class EmailDefaults
|
||||
$this->email->email_object->entity instanceof Quote ||
|
||||
$this->email->email_object->entity instanceof Credit)) {
|
||||
|
||||
// TODO: Alter this to include XInvoice
|
||||
$pdf = ((new CreateRawPdf($this->email->email_object->invitation, $this->email->company->db))->handle());
|
||||
|
||||
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($pdf), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]);
|
||||
@ -303,6 +305,11 @@ class EmailDefaults
|
||||
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($ubl_string), 'name' => $this->email->email_object->entity->getFileName('xml')]]);
|
||||
}
|
||||
}
|
||||
/** XInvoice xml file */
|
||||
if ($this->email->email_object->company->use_xinvoice && $this->email->email_object->entity instanceof Invoice) {
|
||||
$xinvoice_path = (new CreateXInvoice($this->email->email_object->entity, false))->handle();
|
||||
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode(file_get_contents($xinvoice_path)), 'name' => explode(".", $this->email->email_object->entity->getFileName('xml'))[0]."-xinvoice.xml"]]);
|
||||
}
|
||||
|
||||
if(!$this->email->email_object->settings->document_email_attachment)
|
||||
return $this;
|
||||
@ -324,7 +331,7 @@ class EmailDefaults
|
||||
if ($this->email->email_object->entity instanceof Invoice) {
|
||||
$expense_ids = [];
|
||||
$task_ids = [];
|
||||
|
||||
|
||||
foreach ($this->email->email_object->entity->line_items as $item) {
|
||||
if (property_exists($item, 'expense_id')) {
|
||||
$expense_ids[] = $item->expense_id;
|
||||
|
@ -46,7 +46,7 @@ class GetInvoiceXInvoice extends AbstractService
|
||||
$file = Storage::disk($disk)->exists($file_path);
|
||||
|
||||
if (! $file) {
|
||||
$file_path = (new CreateXInvoice($this->invoice))->handle();
|
||||
$file_path = (new CreateXInvoice($this->invoice, false))->handle();
|
||||
}
|
||||
|
||||
return $file_path;
|
||||
|
@ -451,7 +451,7 @@ class InvoiceService
|
||||
(new CreateEntityPdf($invitation))->handle();
|
||||
if ($invitation instanceof InvoiceInvitation)
|
||||
{
|
||||
(new CreateXInvoice($invitation->invoice))->handle();
|
||||
(new CreateXInvoice($invitation->invoice, true))->handle();
|
||||
}
|
||||
});
|
||||
|
||||
@ -462,7 +462,7 @@ class InvoiceService
|
||||
CreateEntityPdf::dispatch($invitation);
|
||||
if ($invitation instanceof InvoiceInvitation)
|
||||
{
|
||||
CreateXInvoice::dispatch($invitation->invoice);
|
||||
CreateXInvoice::dispatch($invitation->invoice, true);
|
||||
}
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user