mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add Xinvoice to E-Mail
This commit is contained in:
parent
f2c38bb948
commit
073fee4c5b
@ -21,10 +21,11 @@ class CreateXInvoice implements ShouldQueue
|
||||
|
||||
public Invoice $invoice;
|
||||
|
||||
public function __construct(Invoice $invoice, bool $alterPDF)
|
||||
public function __construct(Invoice $invoice, bool $alterPDF, string $custompdfpath = "")
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
$this->alterpdf = $alterPDF;
|
||||
$this->custompdfpath = $custompdfpath;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,14 +294,21 @@ class CreateXInvoice implements ShouldQueue
|
||||
Storage::makeDirectory($client->xinvoice_filepath($invoice->invitations->first()));
|
||||
}
|
||||
$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();
|
||||
|
||||
if ($this->alterpdf){
|
||||
$file = Storage::disk($disk)->exists($filepath_pdf);
|
||||
if ($file) {
|
||||
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, Storage::disk($disk)->path($filepath_pdf));
|
||||
if ($this->custompdfpath != ""){
|
||||
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, $this->custompdfpath);
|
||||
$pdfBuilder->generateDocument();
|
||||
$pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf));
|
||||
$pdfBuilder->saveDocument($this->custompdfpath);
|
||||
}
|
||||
else {
|
||||
$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));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $client->invoice_filepath($invoice->invitations->first()).$invoice->getFileName("xml");
|
||||
|
@ -13,6 +13,7 @@ namespace App\Services\Email;
|
||||
|
||||
use App\Jobs\Invoice\CreateXInvoice;
|
||||
use App\Models\Task;
|
||||
use App\Services\Invoice\GetInvoiceXInvoice;
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Credit;
|
||||
@ -292,8 +293,17 @@ class EmailDefaults
|
||||
|
||||
// TODO: Alter this to include XInvoice
|
||||
$pdf = ((new CreateRawPdf($this->email->email_object->invitation, $this->email->company->db))->handle());
|
||||
if ($this->email->email_object->company->use_xinvoice && $this->email->email_object->entity instanceof Invoice) {
|
||||
$tempfile = tmpfile();
|
||||
file_put_contents(stream_get_meta_data($tempfile)['uri'], $pdf);
|
||||
$xinvoice_path = (new CreateXInvoice($this->email->email_object->entity, true, stream_get_meta_data($tempfile)['uri']))->handle();
|
||||
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode(file_get_contents(stream_get_meta_data($tempfile)['uri'])), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]);
|
||||
$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"]]);
|
||||
}
|
||||
else {
|
||||
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($pdf), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]);
|
||||
}
|
||||
|
||||
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($pdf), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]);
|
||||
|
||||
}
|
||||
|
||||
@ -307,7 +317,7 @@ class EmailDefaults
|
||||
}
|
||||
/** 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();
|
||||
$xinvoice_path = (new GetInvoiceXInvoice($this->email->email_object->entity))->run();
|
||||
$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"]]);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user