diff --git a/app/Console/Commands/SendRemindersCron.php b/app/Console/Commands/SendRemindersCron.php index 7319ec30f727..68da45d79e21 100644 --- a/app/Console/Commands/SendRemindersCron.php +++ b/app/Console/Commands/SendRemindersCron.php @@ -175,6 +175,9 @@ class SendRemindersCron extends Command $invoice->calc()->getInvoice()->save(); $invoice->fresh(); $invoice->service()->deletePdf()->save(); + if ($invoice->company->use_xinvoice){ + $invoice->service()->deleteXInvoice()->save(); + } /* Refresh the client here to ensure the balance is fresh */ $client = $invoice->client; diff --git a/app/Jobs/Invoice/CreateXInvoice.php b/app/Jobs/Invoice/CreateXInvoice.php index 1970aad1874f..69c9e49cb709 100644 --- a/app/Jobs/Invoice/CreateXInvoice.php +++ b/app/Jobs/Invoice/CreateXInvoice.php @@ -36,7 +36,34 @@ class CreateXInvoice implements ShouldQueue $invoice = $this->invoice; $company = $invoice->company; $client = $invoice->client; - $xrechnung = ZugferdDocumentBuilder::CreateNew(ZugferdProfiles::PROFILE_EN16931); + $profile = ""; + switch ($company->xinvoice_type){ + case "EN16931": + $profile = ZugferdProfiles::PROFILE_EN16931; + break; + case "XInvoice_2_2": + $profile = ZugferdProfiles::PROFILE_XRECHNUNG_2_2; + break; + case "XInvoice_2_1": + $profile = ZugferdProfiles::PROFILE_XRECHNUNG_2_1; + break; + case "XInvoice_2_0": + $profile = ZugferdProfiles::PROFILE_XRECHNUNG_2; + break; + case "XInvoice_1_0": + $profile = ZugferdProfiles::PROFILE_XRECHNUNG; + break; + case "XInvoice-Extended": + $profile = ZugferdProfiles::PROFILE_EXTENDED; + break; + case "XInvoice-BasicWL": + $profile = ZugferdProfiles::PROFILE_BASICWL; + break; + case "XInvoice-Basic": + $profile = ZugferdProfiles::PROFILE_BASIC; + break; + } + $xrechnung = ZugferdDocumentBuilder::CreateNew($profile); $xrechnung ->setDocumentInformation($invoice->number, "380", date_create($invoice->date), $invoice->client->getCurrencyCode()) diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index 4d6dca8fe63a..064d42f7f496 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -78,7 +78,7 @@ class ZipInvoices implements ShouldQueue $this->invoices->each(function ($invoice) { (new CreateEntityPdf($invoice->invitations()->first()))->handle(); - if ($this->company->getSetting("create_xinvoice")){ + if ($this->company->use_xinvoice){ (new CreateXInvoice($invoice))->handle(); } }); diff --git a/app/Models/Company.php b/app/Models/Company.php index 49531af286ce..c31b894c21ff 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -97,6 +97,8 @@ use Laracasts\Presenter\PresentableTrait; * @property int $stock_notification * @property string|null $matomo_url * @property int|null $matomo_id + * @property bool $use_xinvoice + * @property string $xinvoice_type * @property int $enabled_expense_tax_rates * @property int $invoice_task_project * @property int $report_include_deleted @@ -354,6 +356,8 @@ class Company extends BaseModel 'google_analytics_key', 'matomo_url', 'matomo_id', + 'use_xinvoice', + 'xinvoice_type', 'client_can_register', 'enable_shop_api', 'invoice_task_timelog', diff --git a/database/migrations/2023_03_13_156872_add_letiweg_id_to_clients_table.php b/database/migrations/2023_03_13_156872_add_leitweg_id_to_clients_table.php similarity index 72% rename from database/migrations/2023_03_13_156872_add_letiweg_id_to_clients_table.php rename to database/migrations/2023_03_13_156872_add_leitweg_id_to_clients_table.php index c176897dd993..4bc691615a47 100644 --- a/database/migrations/2023_03_13_156872_add_letiweg_id_to_clients_table.php +++ b/database/migrations/2023_03_13_156872_add_leitweg_id_to_clients_table.php @@ -17,6 +17,10 @@ return new class extends Migration Schema::table('clients', function (Blueprint $table) { $table->string('leitweg_idf')->default(null); }); + Schema::table('companies', function (Blueprint $table) { + $table->boolean('use_xinvoice')->default(false); + $table->string('xinvoice_type')->default("EN16931"); + }); } /**