CluPilotCloud/app/Services/Billing/SampleInvoice.php

100 lines
4.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Services\Billing;
use App\Support\CompanyProfile;
/**
* A specimen invoice, for looking at the layout before anything is issued.
*
* It uses the real company details where they have been entered and obvious
* placeholders where they have not, so the preview shows what is still missing
* rather than a page that looks finished and is not.
*
* The customer and the lines are invented on purpose and say so. A specimen
* that looks like a real document is a specimen somebody eventually files.
*/
final class SampleInvoice
{
/** @return array<string, mixed> */
public static function snapshot(): array
{
$issuer = CompanyProfile::all();
foreach (['name' => 'Ihr Firmenwortlaut e.U.', 'address' => 'Musterstraße 1', 'postcode' => '1010', 'city' => 'Wien', 'vat_id' => 'ATU00000000'] as $field => $placeholder) {
if (trim((string) ($issuer[$field] ?? '')) === '') {
$issuer[$field] = $placeholder;
}
}
$rate = (int) round(CompanyProfile::taxRate() * 100);
$lines = [
[
'description' => 'CluPilot Cloud — Paket Start',
'details' => ['Abrechnungszeitraum 01.08.2026 31.08.2026', '500 GB Speicher, 4 Kerne, 8 GB RAM'],
'quantity_milli' => 1000,
'unit' => '',
'unit_net_cents' => 1900,
],
[
'description' => 'Zusatzspeicher 250 GB',
'details' => ['Add-on, monatlich'],
'quantity_milli' => 2000,
'unit' => '',
'unit_net_cents' => 500,
],
[
'description' => 'Zusätzliches Datenvolumen',
'details' => ['Add-on, monatlich'],
'quantity_milli' => 1000,
'unit' => '',
'unit_net_cents' => 900,
],
[
'description' => 'Einrichtung und Datenübernahme',
'details' => ['einmalig, 2,5 Stunden'],
'quantity_milli' => 2500,
'unit' => 'Std.',
'unit_net_cents' => 9000,
],
];
// A discount on the specimen deliberately: it is the part of the layout
// most likely to be wrong, and the only way to find that out is to see
// it printed.
$adjustment = ['type' => InvoiceMath::PERCENT, 'value' => -1000];
$totals = InvoiceMath::totals($lines, $adjustment, $rate) + ['rate_basis_points' => $rate];
return [
'issuer' => $issuer,
'customer' => [
'name' => 'Muster GmbH (Beispiel)',
'address' => 'Beispielgasse 12/3',
'postcode' => '1030',
'city' => 'Wien',
'country' => 'Österreich',
'vat_id' => 'ATU11111111',
],
'meta' => [
'title' => __('invoice.title'),
'number' => 'RE-'.now()->format('Y').'-0001',
'customer_number' => 'KN-0001',
'issued_on' => now()->local()->format('d.m.Y'),
'due_on' => now()->local()->addDays((int) CompanyProfile::get('payment_days', 14))->format('d.m.Y'),
'currency' => 'EUR',
'salutation' => 'Sehr geehrte Damen und Herren,',
'intro' => 'wir erlauben uns, für die im Folgenden aufgeführten Leistungen in Rechnung zu stellen.',
'adjustment_label' => 'Rabatt 10 %',
'payment_terms' => trim((string) CompanyProfile::get('payment_terms')) !== ''
? (string) CompanyProfile::get('payment_terms')
: 'Zahlbar ohne Abzug innerhalb von '.CompanyProfile::get('payment_days', 14).' Tagen auf das unten angeführte Konto.',
'closing' => 'Dies ist ein Muster zur Ansicht des Layouts. Es ist keine Rechnung und keine Zahlungsaufforderung.',
],
'lines' => $lines,
'totals' => $totals,
];
}
}