Merge pull request #8466 from turbo124/v5-develop

Handle e-invoices when creating zip files
This commit is contained in:
David Bomba 2023-04-24 08:29:21 +10:00 committed by GitHub
commit b51eb5e23c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 21 deletions

View File

@ -118,7 +118,7 @@ class BaseRule implements RuleInterface
protected ?Response $tax_data;
public ?Invoice $invoice;
public mixed $invoice;
public function __construct()
{
@ -129,7 +129,7 @@ class BaseRule implements RuleInterface
return $this;
}
public function setInvoice(Invoice $invoice): self
public function setInvoice(mixed $invoice): self
{
$this->invoice = $invoice;

View File

@ -62,11 +62,8 @@ class ZipInvoices implements ShouldQueue
* Execute the job.
*
* @return void
* @throws \ZipStream\Exception\FileNotFoundException
* @throws \ZipStream\Exception\FileNotReadableException
* @throws \ZipStream\Exception\OverflowException
*/
public function handle()
public function handle(): void
{
MultiDB::setDb($this->company->db);
@ -78,22 +75,25 @@ class ZipInvoices implements ShouldQueue
$this->invoices->each(function ($invoice) {
(new CreateEntityPdf($invoice->invitations()->first()))->handle();
if ($this->company->use_xinvoice){
if ($this->company->enable_e_invoice){
(new CreateEInvoice($invoice, false))->handle();
}
});
try {
foreach ($this->invoices as $invoice) {
$file = $invoice->service()->getInvoicePdf();
$xinvoice = $invoice->service()->getXInvoice();
$zip_file_name = basename($file);
$xinvoice_zip_file_name = basename($xinvoice);
$zipFile->addFromString($zip_file_name, Storage::get($file))
->addDir($xinvoice_zip_file_name, Storage::get($xinvoice));
$zipFile->addFromString($zip_file_name, Storage::get($file));
}
//$download_file = file_get_contents($invoice->pdf_file_path($invitation, 'url', true));
//$zipFile->addFromString(basename($invoice->pdf_file_path($invitation)), $download_file);
if($this->company->enable_e_invoice){
foreach ($this->invoices as $invoice) {
$xinvoice = $invoice->service()->getEInvoice();
$xinvoice_zip_file_name = basename($xinvoice);
$zipFile->addFromString($xinvoice_zip_file_name, Storage::get($xinvoice));
}
}
Storage::put($path.$file_name, $zipFile->outputAsString());

View File

@ -153,8 +153,8 @@ class TemplateEmail extends Mailable
$this->attachData($ubl_string, $this->invitation->invoice->getFileName('xml'));
}
}
if ($this->invitation && $this->invitation->invoice && $company->use_xinvoice && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) {
$this->invitation->invoice->service()->getXInvoice($this->invitation->contact);
if ($this->invitation && $this->invitation->invoice && $company->enable_e_invoice && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) {
$this->invitation->invoice->service()->getEInvoice($this->invitation->contact);
$disk = config('filesystems.default');
$this->attach(Storage::disk($disk)->path($this->invitation->invoice->client->xinvoice_filepath($this->invitation->invoice->invitations->first()) . $this->invitation->invoice->getFileName("xml")));
}

View File

@ -641,7 +641,7 @@ use Laracasts\Presenter\PresentableTrait;
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Vendor> $vendors
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Webhook> $webhooks
* @property int $tax_all_products
* @property int $use_xinvoice
* @property int $enable_e_invoice
* @property string $xinvoice_type
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $all_activities

View File

@ -158,15 +158,21 @@ class ZugferdEInvoice extends AbstractService
$xrechnung->setDocumentSummation($this->invoice->amount, $this->invoice->balance, $invoicing_data->getSubTotal(), $invoicing_data->getTotalSurcharges(), $invoicing_data->getTotalDiscount(), $invoicing_data->getSubTotal(), $invoicing_data->getItemTotalTaxes(), null, 0.0);
}
foreach ($invoicing_data->getTaxMap() as $item) {
$tax = explode(" ", $item["name"]);
$xrechnung->addDocumentTax($this->getTaxType(""), "VAT", $item["total"] / (explode("%", end($tax))[0] / 100), $item["total"], explode("%", end($tax))[0]);
$tax_name = explode(" ", $item["name"]);
$tax_rate = (explode("%", end($tax_name))[0] / 100);
$total_tax = $tax_rate == 0 ? 0 : $item["total"] / $tax_rate;
$xrechnung->addDocumentTax($this->getTaxType(""), "VAT", $total_tax, $item["total"], explode("%", end($tax_name))[0]);
// TODO: Add correct tax type within getTaxType
}
if (!empty($globaltax && isset($invoicing_data->getTotalTaxMap()[$globaltax]["name"]))) {
$tax = explode(" ", $invoicing_data->getTotalTaxMap()[$globaltax]["name"]);
$xrechnung->addDocumentTax($this->getTaxType(""), "VAT", $invoicing_data->getTotalTaxMap()[$globaltax]["total"] / (explode("%", end($tax))[0] / 100), $invoicing_data->getTotalTaxMap()[$globaltax]["total"], explode("%", end($tax))[0]);
$tax_name = explode(" ", $invoicing_data->getTotalTaxMap()[$globaltax]["name"]);
$xrechnung->addDocumentTax($this->getTaxType(""), "VAT", $invoicing_data->getTotalTaxMap()[$globaltax]["total"] / (explode("%", end($tax_name))[0] / 100), $invoicing_data->getTotalTaxMap()[$globaltax]["total"], explode("%", end($tax_name))[0]);
// TODO: Add correct tax type within getTaxType
}

View File

@ -19,7 +19,7 @@ use Illuminate\Support\Facades\Storage;
class GetInvoiceXInvoice extends AbstractService
{
public function __construct(public Invoice $invoice, public ClientContact $contact = null)
public function __construct(public Invoice $invoice, public ?ClientContact $contact = null)
{
}