Minor cleanup?

This commit is contained in:
David Bomba 2023-04-17 18:23:07 +10:00
parent 3bec2ab1d9
commit a365d11661
4 changed files with 29 additions and 37 deletions

View File

@ -30,15 +30,11 @@ use App\Http\Requests\Invoice\UpdateReminderRequest;
use App\Http\Requests\Invoice\UploadInvoiceRequest;
use App\Jobs\Cron\AutoBill;
use App\Jobs\Invoice\BulkInvoiceJob;
use App\Jobs\Invoice\StoreInvoice;
use App\Jobs\Invoice\UpdateReminders;
use App\Jobs\Invoice\ZipInvoices;
use App\Jobs\Ninja\TransactionLog;
use App\Models\Account;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Quote;
use App\Models\TransactionEvent;
use App\Repositories\InvoiceRepository;
use App\Services\PdfMaker\PdfMerge;
use App\Transformers\InvoiceTransformer;
@ -46,7 +42,6 @@ use App\Transformers\QuoteTransformer;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Storage;
@ -862,7 +857,7 @@ class InvoiceController extends BaseController
/**
* @OA\Get(
* path="/api/v1/invoice/{invitation_key}/download_xinvoice",
* path="/api/v1/invoice/{invitation_key}/download_e_invoice",
* operationId="downloadXInvoice",
* tags={"invoices"},
* summary="Download a specific x-invoice by invitation key",

View File

@ -20,15 +20,8 @@ class CreateXInvoice implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private Invoice $invoice;
private bool $alterpdf;
private string $custompdfpath;
public function __construct(Invoice $invoice, bool $alterPDF, string $custompdfpath = "")
public function __construct(private Invoice $invoice, private bool $alterPDF, private string $custom_pdf_path = "")
{
$this->invoice = $invoice;
$this->alterpdf = $alterPDF;
$this->custompdfpath = $custompdfpath;
}
/**
@ -100,7 +93,7 @@ class CreateXInvoice implements ShouldQueue
$xrechnung->addDocumentSellerTaxRegistration("VA", $company->getSetting('vat_number'));
}
$invoicingdata = $invoice->calc();
$invoicing_data = $invoice->calc();
$globaltax = null;
//Create line items and calculate taxes
@ -153,19 +146,19 @@ class CreateXInvoice implements ShouldQueue
if ($invoice->isPartial()) {
$xrechnung->setDocumentSummation($invoice->amount, $invoice->balance, $invoicingdata->getSubTotal(), $invoicingdata->getTotalSurcharges(), $invoicingdata->getTotalDiscount(), $invoicingdata->getSubTotal(), $invoicingdata->getItemTotalTaxes(), null, $invoice->partial);
$xrechnung->setDocumentSummation($invoice->amount, $invoice->balance, $invoicing_data->getSubTotal(), $invoicing_data->getTotalSurcharges(), $invoicing_data->getTotalDiscount(), $invoicing_data->getSubTotal(), $invoicing_data->getItemTotalTaxes(), null, $invoice->partial);
} else {
$xrechnung->setDocumentSummation($invoice->amount, $invoice->balance, $invoicingdata->getSubTotal(), $invoicingdata->getTotalSurcharges(), $invoicingdata->getTotalDiscount(), $invoicingdata->getSubTotal(), $invoicingdata->getItemTotalTaxes(), null, 0.0);
$xrechnung->setDocumentSummation($invoice->amount, $invoice->balance, $invoicing_data->getSubTotal(), $invoicing_data->getTotalSurcharges(), $invoicing_data->getTotalDiscount(), $invoicing_data->getSubTotal(), $invoicing_data->getItemTotalTaxes(), null, 0.0);
}
foreach ($invoicingdata->getTaxMap() as $item) {
foreach ($invoicing_data->getTaxMap() as $item) {
$tax = explode(" ", $item["name"]);
$xrechnung->addDocumentTax($this->getTaxType("", $invoice), "VAT", $item["total"] / (explode("%", end($tax))[0] / 100), $item["total"], explode("%", end($tax))[0]);
// TODO: Add correct tax type within getTaxType
}
if (!empty($globaltax)){
$tax = explode(" ", $invoicingdata->getTotalTaxMap()[$globaltax]["name"]);
$xrechnung->addDocumentTax($this->getTaxType("", $invoice), "VAT", $invoicingdata->getTotalTaxMap()[$globaltax]["total"] / (explode("%", end($tax))[0] / 100), $invoicingdata->getTotalTaxMap()[$globaltax]["total"], explode("%", end($tax))[0]);
$tax = explode(" ", $invoicing_data->getTotalTaxMap()[$globaltax]["name"]);
$xrechnung->addDocumentTax($this->getTaxType("", $invoice), "VAT", $invoicing_data->getTotalTaxMap()[$globaltax]["total"] / (explode("%", end($tax))[0] / 100), $invoicing_data->getTotalTaxMap()[$globaltax]["total"], explode("%", end($tax))[0]);
// TODO: Add correct tax type within getTaxType
}
@ -176,11 +169,11 @@ class CreateXInvoice implements ShouldQueue
$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
if ($this->alterpdf) {
if ($this->custompdfpath != "") {
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, $this->custompdfpath);
if ($this->alterPDF) {
if ($this->custom_pdf_path != "") {
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, $this->custom_pdf_path);
$pdfBuilder->generateDocument();
$pdfBuilder->saveDocument($this->custompdfpath);
$pdfBuilder->saveDocument($this->custom_pdf_path);
} else {
$filepath_pdf = $client->invoice_filepath($invoice->invitations->first()) . $invoice->getFileName();
$file = Storage::disk($disk)->exists($filepath_pdf);

View File

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

View File

@ -9,13 +9,14 @@
* @license https://www.elastic.co/licensing/elastic-license
*/
use Tests\TestCase;
use Tests\MockAccountData;
use App\Jobs\Entity\CreateEntityPdf;
use App\Jobs\Invoice\CreateXInvoice;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\MockAccountData;
use Tests\TestCase;
use Illuminate\Support\Facades\Storage;
use horstoeko\zugferd\ZugferdDocumentReader;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
/**
* @test
@ -38,9 +39,11 @@ class EInvoiceTest extends TestCase
public function testEInvoiceGenerates()
{
$this->invoice->client->routing_id = 'DE123456789';
$this->invoice->client->save();
$xinvoice = (new CreateXInvoice($this->invoice, false))->handle();
$this->assertNotNull($xinvoice);
$this->assertFileExists($xinvoice);
$this->assertTrue(Storage::exists($xinvoice));
}
/**
@ -48,9 +51,13 @@ class EInvoiceTest extends TestCase
*/
public function testValidityofXMLFile()
{
$this->invoice->client->routing_id = 'DE123456789';
$this->invoice->client->save();
$xinvoice = (new CreateXInvoice($this->invoice, false))->handle();
$document = ZugferdDocumentReader::readAndGuessFromFile($xinvoice);
$document ->getDocumentInformation($documentno);
nlog(Storage::path($xinvoice));
$document = ZugferdDocumentReader::readAndGuessFromFile(Storage::path($xinvoice));
$document->getDocumentInformation($documentno);
$this->assertEquals($this->invoice->number, $documentno);
}
@ -59,10 +66,10 @@ class EInvoiceTest extends TestCase
*/
public function checkEmbededPDFFile()
{
$pdf = (new CreateEntityPdf($this->invoice->invitations()->first()));
$pdf = (new CreateEntityPdf($this->invoice->invitations()->first()))->handle();
(new CreateXInvoice($this->invoice, true, $pdf))->handle();
$document = ZugferdDocumentReader::readAndGuessFromFile($pdf);
$document ->getDocumentInformation($documentno);
$document->getDocumentInformation($documentno);
$this->assertEquals($this->invoice->number, $documentno);
}
}