Fixes for e-invoices

This commit is contained in:
David Bomba 2023-04-28 17:04:49 +10:00
parent cf6cd98eec
commit cd9c7d9237
2 changed files with 25 additions and 19 deletions

View File

@ -801,7 +801,6 @@ class Invoice extends BaseModel
public function entityEmailEvent($invitation, $reminder_template, $template = '')
{
nlog($template);
switch ($reminder_template) {
case 'invoice':

View File

@ -11,24 +11,25 @@
namespace App\Services\Email;
use App\Jobs\Invoice\CreateEInvoice;
use App\Services\Invoice\GetInvoiceXInvoice;
use App\DataMapper\EmailTemplateDefaults;
use App\Jobs\Entity\CreateRawPdf;
use App\Jobs\Invoice\CreateUbl;
use App\Jobs\Vendor\CreatePurchaseOrderPdf;
use App\Models\Account;
use App\Models\Task;
use App\Utils\Ninja;
use App\Models\Quote;
use App\Models\Credit;
use App\Models\Account;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\PurchaseOrder;
use App\Models\Quote;
use App\Models\Task;
use App\Utils\Ninja;
use App\Jobs\Invoice\CreateUbl;
use App\Utils\Traits\MakesHash;
use Illuminate\Mail\Mailables\Address;
use App\Jobs\Entity\CreateRawPdf;
use Illuminate\Support\Facades\App;
use App\Jobs\Invoice\CreateEInvoice;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Support\Facades\Storage;
use App\DataMapper\EmailTemplateDefaults;
use League\CommonMark\CommonMarkConverter;
use App\Jobs\Vendor\CreatePurchaseOrderPdf;
use App\Services\Invoice\GetInvoiceXInvoice;
class EmailDefaults
{
@ -299,11 +300,15 @@ class EmailDefaults
$this->email->email_object->entity instanceof Credit)) {
$pdf = ((new CreateRawPdf($this->email->email_object->invitation, $this->email->company->db))->handle());
if ($this->email->email_object->settings->enable_e_invoice && $this->email->email_object->entity instanceof Invoice) {
$tempfile = tmpfile();
file_put_contents(stream_get_meta_data($tempfile)['uri'], $pdf);
$xinvoice_path = (new CreateEInvoice($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"]]);
$xinvoice_path = $this->email->email_object->entity->service()->getEInvoice();
// $xinvoice_path = (new CreateEInvoice($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($pdf), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]);
if(Storage::disk(config('filesystems.default'))->exists($xinvoice_path))
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode(Storage::get($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']]);
@ -321,8 +326,10 @@ class EmailDefaults
}
/** E-Invoice xml file */
if ($this->email->email_object->settings->enable_e_invoice && $this->email->email_object->entity instanceof Invoice) {
$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]."-e_invoice.xml"]]);
$xinvoice_path = $this->email->email_object->entity->service()->getEInvoice();
if(Storage::disk(config('filesystems.default'))->exists($xinvoice_path))
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode(Storage::get($xinvoice_path)), 'name' => explode(".", $this->email->email_object->entity->getFileName('xml'))[0]."-e_invoice.xml"]]);
}
if (!$this->email->email_object->settings->document_email_attachment || !$this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) {