1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Enable E-Invoice for client download

This commit is contained in:
Lars Kusch 2023-08-07 21:55:12 +02:00
parent d8a6578be2
commit dd17119fd6
4 changed files with 44 additions and 15 deletions

View File

@ -12,6 +12,7 @@
namespace App\Http\Livewire;
use App\Services\Invoice\GetInvoiceEInvoice;
use App\Utils\Number;
use Livewire\Component;
use App\Utils\HtmlEngine;
@ -38,7 +39,7 @@ class PdfSlot extends Component
public $pdf;
public $url;
private $settings;
private $html_variables;
@ -61,7 +62,7 @@ class PdfSlot extends Component
}
public function getPdf()
{
{
// $this->pdf = $this->entity->fullscreenPdfViewer($this->invitation);
$blob = [
@ -74,14 +75,14 @@ class PdfSlot extends Component
$hash = Str::random(64);
Cache::put($hash, $blob, now()->addMinutes(2));
$this->pdf = $hash;
}
public function downloadPdf()
{
$file_name = $this->entity->numberFormatter().'.pdf';
if($this->entity instanceof \App\Models\PurchaseOrder)
@ -95,11 +96,25 @@ class PdfSlot extends Component
echo $file;
}, $file_name, $headers);
}
public function downloadEInvoice()
{
$file_name = $this->entity->numberFormatter().'.xml';
$file = (new GetInvoiceEInvoice($this->entity))->run();
$headers = ['Content-Type' => 'application/xml'];
return response()->streamDownload(function () use ($file) {
echo $file;
}, $file_name, $headers);
}
public function render()
{
$this->entity_type = $this->resolveEntityType();
$this->settings = $this->entity->client ? $this->entity->client->getMergedSettings() : $this->entity->company->settings;
@ -146,7 +161,7 @@ class PdfSlot extends Component
private function getCompanyAddress()
{
$company_address = "";
foreach($this->settings->pdf_variables->company_address as $variable) {
@ -166,7 +181,7 @@ class PdfSlot extends Component
}
return $this->convertVariables($company_details);
}
private function getEntityDetails()
@ -174,9 +189,9 @@ class PdfSlot extends Component
$entity_details = "";
if($this->entity_type == 'invoice' || $this->entity_type == 'recurring_invoice') {
foreach($this->settings->pdf_variables->invoice_details as $variable)
foreach($this->settings->pdf_variables->invoice_details as $variable)
$entity_details .= "<div class='flex px-5 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-5 w-36 block entity-field'>{$variable}</p></div>";
}
elseif($this->entity_type == 'quote'){
foreach($this->settings->pdf_variables->quote_details as $variable)
@ -190,7 +205,7 @@ class PdfSlot extends Component
foreach($this->settings->pdf_variables->purchase_order_details as $variable)
$entity_details .= "<div class='flex px-5 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-5 w-36 block entity-field'>{$variable}</p></div>";
}
return $this->convertVariables($entity_details);
}
@ -206,7 +221,7 @@ class PdfSlot extends Component
$name = $this->settings->pdf_variables->client_details[0];
}
return $this->convertVariables($name);
}
@ -225,7 +240,7 @@ class PdfSlot extends Component
$user_details .= "<p>{$variable}</p>";
}
}
return $this->convertVariables($user_details);
}

View File

@ -12,6 +12,7 @@
namespace App\Jobs\Entity;
use App\Exceptions\FilePermissionsFailure;
use App\Jobs\Invoice\MergeEInvoice;
use App\Libraries\MultiDB;
use App\Models\Credit;
use App\Models\CreditInvitation;
@ -202,6 +203,9 @@ class CreateRawPdf implements ShouldQueue
if ($pdf) {
$maker =null;
$state = null;
if ($this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->entity == "invoice"){
(new \App\Services\Invoice\MergeEInvoice($this->invitation->invoice))->run();
};
return $pdf;
}

View File

@ -9,6 +9,15 @@
</svg>
</div>
</button>
<button wire:loading.attr="disabled" wire:click="downloadEInvoice" class="bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold px-2 rounded inline-flex" type="button">
<span>{{ ctrans('texts.download_xml') }}</span>
<div wire:loading wire:target="downloadEInvoice">
<svg class="animate-spin h-5 w-5 text-blue" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
</div>
</button>
</div>
<div class="hidden lg:block">
<div wire:init="getPdf()">
@ -86,7 +95,7 @@ function waitForElement(querySelector, timeout){
}
});
observer.observe(document.body, {
childList: true,
childList: true,
subtree: true
});
if(timeout) timer = setTimeout(()=>{
@ -97,4 +106,4 @@ function waitForElement(querySelector, timeout){
}
</script>
</script>

View File

@ -16,7 +16,8 @@
<form action="{{ route('client.invoices.bulk') }}" method="post" id="bulkActions">
@csrf
<button type="submit" onclick="setTimeout(() => this.disabled = true, 0); setTimeout(() => this.disabled = false, 5000); return true;" class="button button-primary bg-primary" name="action" value="download">{{ ctrans('texts.download') }}</button>
@csrf
<button type="submit" onclick="setTimeout(() => this.disabled = true, 0); setTimeout(() => this.disabled = false, 5000); return true;" class="button button-primary bg-secondary" name="action-xml" value="download">{{ ctrans('texts.download_xml') }}</button>
@if(!empty(auth()->user()->client->service()->getPaymentMethods(0)))
<button onclick="setTimeout(() => this.disabled = true, 0); return true;" type="submit" class="button button-primary bg-primary" name="action" value="payment">{{ ctrans('texts.pay_now') }}</button>
@endif