Renamed to e_invoice

This commit is contained in:
Lars Kusch 2023-04-17 09:24:16 +02:00
parent 24b2993198
commit 81b5c8783e
13 changed files with 49 additions and 42 deletions

View File

@ -175,8 +175,8 @@ class SendRemindersCron extends Command
$invoice->calc()->getInvoice()->save(); $invoice->calc()->getInvoice()->save();
$invoice->fresh(); $invoice->fresh();
$invoice->service()->deletePdf()->save(); $invoice->service()->deletePdf()->save();
if ($invoice->company->use_xinvoice){ if ($invoice->company->enable_e_invoice){
$invoice->service()->deleteXInvoice()->save(); $invoice->service()->deleteEInvoice()->save();
} }
/* Refresh the client here to ensure the balance is fresh */ /* Refresh the client here to ensure the balance is fresh */

View File

@ -903,7 +903,7 @@ class InvoiceController extends BaseController
* @param $invitation_key * @param $invitation_key
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/ */
public function downloadXInvoice($invitation_key) public function downloadEInvoice($invitation_key)
{ {
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key); $invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
@ -914,7 +914,7 @@ class InvoiceController extends BaseController
$contact = $invitation->contact; $contact = $invitation->contact;
$invoice = $invitation->invoice; $invoice = $invitation->invoice;
$file = $invoice->service()->getXInvoice($contact); $file = $invoice->service()->getEInvoice($contact);
$headers = ['Content-Type' => 'application/xml']; $headers = ['Content-Type' => 'application/xml'];

View File

@ -212,7 +212,7 @@ class CreateEntityPdf implements ShouldQueue
throw new FilePermissionsFailure($e->getMessage()); throw new FilePermissionsFailure($e->getMessage());
} }
} }
if ($this->entity_string == "invoice" && $this->company->use_xinvoice){ if ($this->entity_string == "invoice" && $this->company->enable_e_invoice){
(new CreateXInvoice($this->entity, true))->handle(); (new CreateXInvoice($this->entity, true))->handle();
} }
$this->invitation = null; $this->invitation = null;

View File

@ -43,7 +43,7 @@ class CreateXInvoice implements ShouldQueue
$company = $invoice->company; $company = $invoice->company;
$client = $invoice->client; $client = $invoice->client;
$profile = ""; $profile = "";
switch ($company->xinvoice_type) { switch ($company->e_invoice_type) {
case "EN16931": case "EN16931":
$profile = ZugferdProfiles::PROFILE_EN16931; $profile = ZugferdProfiles::PROFILE_EN16931;
break; break;
@ -79,7 +79,7 @@ class CreateXInvoice implements ShouldQueue
->setDocumentSellerContact($invoice->user->first_name." ".$invoice->user->last_name, "", $invoice->user->phone, "", $invoice->user->email) ->setDocumentSellerContact($invoice->user->first_name." ".$invoice->user->last_name, "", $invoice->user->phone, "", $invoice->user->email)
->setDocumentBuyer($client->name, $client->number) ->setDocumentBuyer($client->name, $client->number)
->setDocumentBuyerAddress($client->address1, "", "", $client->postal_code, $client->city, $client->country->iso_3166_2) ->setDocumentBuyerAddress($client->address1, "", "", $client->postal_code, $client->city, $client->country->iso_3166_2)
->setDocumentBuyerReference($client->leitweg_id) ->setDocumentBuyerReference($client->routing_id)
->setDocumentBuyerContact($client->primary_contact()->first()->first_name . " " . $client->primary_contact()->first()->last_name, "", $client->primary_contact()->first()->phone, "", $client->primary_contact()->first()->email) ->setDocumentBuyerContact($client->primary_contact()->first()->first_name . " " . $client->primary_contact()->first()->last_name, "", $client->primary_contact()->first()->phone, "", $client->primary_contact()->first()->email)
->setDocumentShipToAddress($client->shipping_address1, $client->shipping_address2, "", $client->shipping_postal_code, $client->shipping_city, $client->shipping_country->iso_3166_2, $client->shipping_state) ->setDocumentShipToAddress($client->shipping_address1, $client->shipping_address2, "", $client->shipping_postal_code, $client->shipping_city, $client->shipping_country->iso_3166_2, $client->shipping_state)
->addDocumentPaymentTerm(ctrans("texts.xinvoice_payable", ['payeddue' => date_create($invoice->date)->diff(date_create($invoice->due_date))->format("%d"), 'paydate' => $invoice->due_date])); ->addDocumentPaymentTerm(ctrans("texts.xinvoice_payable", ['payeddue' => date_create($invoice->date)->diff(date_create($invoice->due_date))->format("%d"), 'paydate' => $invoice->due_date]));
@ -89,7 +89,7 @@ class CreateXInvoice implements ShouldQueue
if (!empty($invoice->po_number)) { if (!empty($invoice->po_number)) {
$xrechnung->setDocumentBuyerOrderReferencedDocument($invoice->po_number); $xrechnung->setDocumentBuyerOrderReferencedDocument($invoice->po_number);
} }
if (empty($client->leitweg_id)){ if (empty($client->routing_id)){
$xrechnung->setDocumentBuyerReference(ctrans("texts.xinvoice_no_buyers_reference")); $xrechnung->setDocumentBuyerReference(ctrans("texts.xinvoice_no_buyers_reference"));
} }
$xrechnung->addDocumentPaymentMean(68, ctrans("texts.xinvoice_online_payment")); $xrechnung->addDocumentPaymentMean(68, ctrans("texts.xinvoice_online_payment"));
@ -170,10 +170,10 @@ class CreateXInvoice implements ShouldQueue
} }
$disk = config('filesystems.default'); $disk = config('filesystems.default');
if (!Storage::exists($client->xinvoice_filepath($invoice->invitations->first()))) { if (!Storage::exists($client->e_invoice_filepath($invoice->invitations->first()))) {
Storage::makeDirectory($client->xinvoice_filepath($invoice->invitations->first())); Storage::makeDirectory($client->e_invoice_filepath($invoice->invitations->first()));
} }
$xrechnung->writeFile(Storage::disk($disk)->path($client->xinvoice_filepath($invoice->invitations->first()) . $invoice->getFileName("xml"))); $xrechnung->writeFile(Storage::disk($disk)->path($client->e_invoice_filepath($invoice->invitations->first()) . $invoice->getFileName("xml")));
// The validity can be checked using https://portal3.gefeg.com/invoice/validation // The validity can be checked using https://portal3.gefeg.com/invoice/validation
if ($this->alterpdf) { if ($this->alterpdf) {
@ -192,7 +192,7 @@ class CreateXInvoice implements ShouldQueue
} }
} }
return $client->xinvoice_filepath($invoice->invitations->first()) . $invoice->getFileName("xml"); return $client->e_invoice_filepath($invoice->invitations->first()) . $invoice->getFileName("xml");
} }
private function getTaxType($name, Invoice $invoice): string private function getTaxType($name, Invoice $invoice): string

View File

@ -41,7 +41,7 @@ use Laracasts\Presenter\PresentableTrait;
* @property string|null $client_hash * @property string|null $client_hash
* @property string|null $logo * @property string|null $logo
* @property string|null $phone * @property string|null $phone
* @property string|null leitweg_id * @property string|null routing_id
* @property string $balance * @property string $balance
* @property string $paid_to_date * @property string $paid_to_date
* @property string $credit_balance * @property string $credit_balance
@ -363,7 +363,7 @@ class Client extends BaseModel implements HasLocalePreference
'public_notes', 'public_notes',
'phone', 'phone',
'number', 'number',
'leitweg_id', 'routing_id',
]; ];
protected $with = [ protected $with = [
@ -413,7 +413,7 @@ class Client extends BaseModel implements HasLocalePreference
'id_number', 'id_number',
'public_notes', 'public_notes',
'phone', 'phone',
'leitweg_id', 'routing_id',
]; ];
// public function scopeExclude($query) // public function scopeExclude($query)
@ -875,11 +875,11 @@ class Client extends BaseModel implements HasLocalePreference
return $this->company->company_key.'/'.$this->client_hash.'/'.$contact_key.'/invoices/'; return $this->company->company_key.'/'.$this->client_hash.'/'.$contact_key.'/invoices/';
} }
public function xinvoice_filepath($invitation) public function e_invoice_filepath($invitation)
{ {
$contact_key = $invitation->contact->contact_key; $contact_key = $invitation->contact->contact_key;
return $this->company->company_key.'/'.$this->client_hash.'/'.$contact_key.'/xinvoice/'; return $this->company->company_key.'/'.$this->client_hash.'/'.$contact_key.'/e_invoice/';
} }
public function quote_filepath($invitation) public function quote_filepath($invitation)

View File

@ -97,8 +97,8 @@ use Laracasts\Presenter\PresentableTrait;
* @property int $stock_notification * @property int $stock_notification
* @property string|null $matomo_url * @property string|null $matomo_url
* @property int|null $matomo_id * @property int|null $matomo_id
* @property bool $use_xinvoice * @property bool $enable_e_invoice
* @property string $xinvoice_type * @property string $e_invoice_type
* @property int $enabled_expense_tax_rates * @property int $enabled_expense_tax_rates
* @property int $invoice_task_project * @property int $invoice_task_project
* @property int $report_include_deleted * @property int $report_include_deleted
@ -746,8 +746,8 @@ class Company extends BaseModel
'google_analytics_key', 'google_analytics_key',
'matomo_url', 'matomo_url',
'matomo_id', 'matomo_id',
'use_xinvoice', 'enable_e_invoice',
'xinvoice_type', 'e_invoice_type',
'client_can_register', 'client_can_register',
'enable_shop_api', 'enable_shop_api',
'invoice_task_timelog', 'invoice_task_timelog',
@ -825,7 +825,7 @@ class Company extends BaseModel
public function refreshTaxData() public function refreshTaxData()
{ {
} }
public function documents() public function documents()

View File

@ -267,7 +267,7 @@ class EmailDefaults
return $this; return $this;
// return $this->email->email_object->cc; // return $this->email->email_object->cc;
// return [ // return [
// ]; // ];
} }
@ -298,7 +298,7 @@ class EmailDefaults
$this->email->email_object->entity instanceof Quote || $this->email->email_object->entity instanceof Quote ||
$this->email->email_object->entity instanceof Credit)) { $this->email->email_object->entity instanceof Credit)) {
$pdf = ((new CreateRawPdf($this->email->email_object->invitation, $this->email->company->db))->handle()); $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) { if ($this->email->email_object->company->enable_e_invoice && $this->email->email_object->entity instanceof Invoice) {
$tempfile = tmpfile(); $tempfile = tmpfile();
file_put_contents(stream_get_meta_data($tempfile)['uri'], $pdf); 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(); $xinvoice_path = (new CreateXInvoice($this->email->email_object->entity, true, stream_get_meta_data($tempfile)['uri']))->handle();
@ -319,10 +319,10 @@ class EmailDefaults
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($ubl_string), 'name' => $this->email->email_object->entity->getFileName('xml')]]); $this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($ubl_string), 'name' => $this->email->email_object->entity->getFileName('xml')]]);
} }
} }
/** XInvoice xml file */ /** E-Invoice xml file */
if ($this->email->email_object->company->use_xinvoice && $this->email->email_object->entity instanceof Invoice) { if ($this->email->email_object->company->enable_e_invoice && $this->email->email_object->entity instanceof Invoice) {
$xinvoice_path = (new GetInvoiceXInvoice($this->email->email_object->entity))->run(); $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"]]); $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"]]);
} }
if (!$this->email->email_object->settings->document_email_attachment || !$this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { if (!$this->email->email_object->settings->document_email_attachment || !$this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) {

View File

@ -38,7 +38,7 @@ class GetInvoiceXInvoice extends AbstractService
$invitation = $this->invoice->invitations->first(); $invitation = $this->invoice->invitations->first();
} }
$file_path = $this->invoice->client->xinvoice_filepath($this->invoice->invitations->first()). $this->invoice->getFileName("xml"); $file_path = $this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()). $this->invoice->getFileName("xml");
// $disk = 'public'; // $disk = 'public';
$disk = config('filesystems.default'); $disk = config('filesystems.default');

View File

@ -186,7 +186,7 @@ class InvoiceService
return (new GenerateDeliveryNote($invoice, $contact))->run(); return (new GenerateDeliveryNote($invoice, $contact))->run();
} }
public function getXInvoice($contact = null) public function getEInvoice($contact = null)
{ {
return (new GetInvoiceXInvoice($this->invoice, $contact))->run(); return (new GetInvoiceXInvoice($this->invoice, $contact))->run();
} }
@ -358,18 +358,18 @@ class InvoiceService
return $this; return $this;
} }
public function deleteXInvoice() public function deleteEInvoice()
{ {
$this->invoice->load('invitations'); $this->invoice->load('invitations');
$this->invoice->invitations->each(function ($invitation) { $this->invoice->invitations->each(function ($invitation) {
try { try {
if (Storage::disk(config('filesystems.default'))->exists($this->invoice->client->xinvoice_filepath($invitation).$this->invoice->getFileName("xml"))) { if (Storage::disk(config('filesystems.default'))->exists($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"))) {
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->xinvoice_filepath($invitation).$this->invoice->getFileName("xml")); Storage::disk(config('filesystems.default'))->delete($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"));
} }
if (Ninja::isHosted() && Storage::disk('public')->exists($this->invoice->client->invoice_filepath($invitation).$this->invoice->getFileName("xml"))) { if (Ninja::isHosted() && Storage::disk('public')->exists($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"))) {
Storage::disk('public')->delete($this->invoice->client->invoice_filepath($invitation).$this->invoice->getFileName("xml")); Storage::disk('public')->delete($this->invoice->client->e_invoice_filepath($invitation).$this->invoice->getFileName("xml"));
} }
} catch (\Exception $e) { } catch (\Exception $e) {
nlog($e->getMessage()); nlog($e->getMessage());

View File

@ -15,11 +15,11 @@ return new class extends Migration
{ {
Schema::table('clients', function (Blueprint $table) { Schema::table('clients', function (Blueprint $table) {
$table->string('leitweg_id')->default(null); $table->string('routing_id')->default(null)->nullable();
}); });
Schema::table('companies', function (Blueprint $table) { Schema::table('companies', function (Blueprint $table) {
$table->boolean('use_xinvoice')->default(false); $table->boolean('enable_e_invoice')->default(false);
$table->string('xinvoice_type')->default("EN16931"); $table->string('e_invoice_type')->default("EN16931");
}); });
} }

View File

@ -205,7 +205,7 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale']
Route::get('invoices/{invoice}/{action}', [InvoiceController::class, 'action'])->name('invoices.action'); Route::get('invoices/{invoice}/{action}', [InvoiceController::class, 'action'])->name('invoices.action');
Route::put('invoices/{invoice}/upload', [InvoiceController::class, 'upload'])->name('invoices.upload'); Route::put('invoices/{invoice}/upload', [InvoiceController::class, 'upload'])->name('invoices.upload');
Route::get('invoice/{invitation_key}/download', [InvoiceController::class, 'downloadPdf'])->name('invoices.downloadPdf'); Route::get('invoice/{invitation_key}/download', [InvoiceController::class, 'downloadPdf'])->name('invoices.downloadPdf');
Route::get('invoice/{invitation_key}/download_xinvoice', [InvoiceController::class, 'downloadXInvoice_pdf'])->name('invoices.downloadXInvoice'); Route::get('invoice/{invitation_key}/download_e_invoice', [InvoiceController::class, 'downloadEInvoice'])->name('invoices.downloadEInvoice');
Route::post('invoices/bulk', [InvoiceController::class, 'bulk'])->name('invoices.bulk'); Route::post('invoices/bulk', [InvoiceController::class, 'bulk'])->name('invoices.bulk');
Route::post('invoices/update_reminders', [InvoiceController::class, 'update_reminders'])->name('invoices.update_reminders'); Route::post('invoices/update_reminders', [InvoiceController::class, 'update_reminders'])->name('invoices.update_reminders');

View File

@ -128,7 +128,7 @@ Route::group(['middleware' => ['invite_db'], 'prefix' => 'client', 'as' => 'clie
Route::get('credit/{invitation_key}', [App\Http\Controllers\ClientPortal\InvitationController::class, 'creditRouter']); Route::get('credit/{invitation_key}', [App\Http\Controllers\ClientPortal\InvitationController::class, 'creditRouter']);
Route::get('recurring_invoice/{invitation_key}/download_pdf', [RecurringInvoiceController::class, 'downloadPdf'])->name('recurring_invoice.download_invitation_key'); Route::get('recurring_invoice/{invitation_key}/download_pdf', [RecurringInvoiceController::class, 'downloadPdf'])->name('recurring_invoice.download_invitation_key');
Route::get('invoice/{invitation_key}/download_pdf', [InvoiceController::class, 'downloadPdf'])->name('invoice.download_invitation_key'); Route::get('invoice/{invitation_key}/download_pdf', [InvoiceController::class, 'downloadPdf'])->name('invoice.download_invitation_key');
Route::get('invoice/{invitation_key}/download_xinvoice', [InvoiceController::class, 'downloadXInvoice'])->name('invoice.download_xinvoice'); Route::get('invoice/{invitation_key}/download_e_invoice', [InvoiceController::class, 'downloadEInvoice'])->name('invoice.download_e_invoice');
Route::get('quote/{invitation_key}/download_pdf', [QuoteController::class, 'downloadPdf'])->name('quote.download_invitation_key'); Route::get('quote/{invitation_key}/download_pdf', [QuoteController::class, 'downloadPdf'])->name('quote.download_invitation_key');
Route::get('credit/{invitation_key}/download_pdf', [CreditController::class, 'downloadPdf'])->name('credit.download_invitation_key'); Route::get('credit/{invitation_key}/download_pdf', [CreditController::class, 'downloadPdf'])->name('credit.download_invitation_key');
Route::get('{entity}/{invitation_key}/download', [App\Http\Controllers\ClientPortal\InvitationController::class, 'routerForDownload']); Route::get('{entity}/{invitation_key}/download', [App\Http\Controllers\ClientPortal\InvitationController::class, 'routerForDownload']);

View File

@ -19,9 +19,9 @@ use horstoeko\zugferd\ZugferdDocumentReader;
/** /**
* @test * @test
* @covers App\Jobs\Invoice\CreateUbl * @covers App\Jobs\Invoice\CreateXInvoice
*/ */
class XInvoiceTest extends TestCase class EInvoiceTest extends TestCase
{ {
use MockAccountData; use MockAccountData;
use DatabaseTransactions; use DatabaseTransactions;
@ -36,13 +36,16 @@ class XInvoiceTest extends TestCase
$this->makeTestData(); $this->makeTestData();
} }
public function testXInvoiceGenerates() public function testEInvoiceGenerates()
{ {
$xinvoice = (new CreateXInvoice($this->invoice, false))->handle(); $xinvoice = (new CreateXInvoice($this->invoice, false))->handle();
$this->assertNotNull($xinvoice); $this->assertNotNull($xinvoice);
$this->assertFileExists($xinvoice); $this->assertFileExists($xinvoice);
} }
/**
* @throws Exception
*/
public function testValidityofXMLFile() public function testValidityofXMLFile()
{ {
$xinvoice = (new CreateXInvoice($this->invoice, false))->handle(); $xinvoice = (new CreateXInvoice($this->invoice, false))->handle();
@ -50,6 +53,10 @@ class XInvoiceTest extends TestCase
$document ->getDocumentInformation($documentno); $document ->getDocumentInformation($documentno);
$this->assertEquals($this->invoice->number, $documentno); $this->assertEquals($this->invoice->number, $documentno);
} }
/**
* @throws Exception
*/
public function checkEmbededPDFFile() public function checkEmbededPDFFile()
{ {
$pdf = (new CreateEntityPdf($this->invoice->invitations()->first())); $pdf = (new CreateEntityPdf($this->invoice->invitations()->first()));