PHP code example of philharmonie / lexware-office-laravel
1. Go to this page and download the library: Download philharmonie/lexware-office-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
philharmonie / lexware-office-laravel example snippets
PhilHarmonie\LexOffice\ServiceProvider::class,
use PhilHarmonie\LexOffice\Facades\Contact;
// Find a contact by ID
$contact = Contact::find('contact-id');
// List contacts with optional filters
$contacts = Contact::list(['email' => '[email protected]']);
use PhilHarmonie\LexOffice\Facades\Article;
// Find an article by ID
$article = Article::find('article-id');
// List articles (paged: content, totalPages, totalElements, number, size, ...)
$page = Article::list(['page' => 0, 'size' => 100]);
// Filter by articleNumber, gtin or type (PRODUCT|SERVICE); filters are AND-ed
$services = Article::list(['type' => 'SERVICE']);
$article = Article::list(['articleNumber' => 'LXW-BUCH-001'])['content'][0] ?? null;
// Create an article (returns id, resourceUri, createdDate, updatedDate, version)
$created = Article::create([
'title' => 'Lexware buch',
'type' => 'PRODUCT', // or SERVICE
'unitName' => 'Stück',
'articleNumber' => 'LXW-BUCH-001',
'price' => ['netPrice' => 61.90, 'leadingPrice' => 'NET', 'taxRate' => 19],
]);
// Update an article: the current version is fetched (uncached) and sent
// automatically. Pass 'version' yourself to skip that extra request.
Article::update($created['id'], [
'title' => 'Lexware buch (2. Auflage)',
'type' => 'PRODUCT',
'unitName' => 'Stück',
'price' => ['netPrice' => 64.90, 'leadingPrice' => 'NET', 'taxRate' => 19],
]);
use PhilHarmonie\LexOffice\Facades\Invoice;
// Create an invoice
$invoice = Invoice::create($data, $finalize = false);
// Find an invoice by ID
$invoice = Invoice::find('invoice-id');
use PhilHarmonie\LexOffice\Facades\Dunning;
// Create a dunning
$dunning = Dunning::create($data);
// Find a dunning
$dunning = Dunning::find('dunning-id');
// Pursue a dunning
$result = Dunning::pursue('dunning-id');
// Render dunning document
$document = Dunning::render('dunning-id');
// Download dunning file
$file = Dunning::download('dunning-id');
// Get deeplink
$link = Dunning::deeplink('dunning-id');
use PhilHarmonie\LexOffice\Builders\InvoiceBuilder;
use PhilHarmonie\LexOffice\Builders\AddressBuilder;
use PhilHarmonie\LexOffice\Builders\LineItemBuilder;
$invoice = InvoiceBuilder::make()
->timezone('Europe/Berlin')
->voucherDate(now())
->address(
AddressBuilder::make()
->name('Company Name')
->supplement('c/o John Doe')
->street('Street 123')
->city('City')
->zip('12345')
->countryCode('DE')
)
->addLineItem(
LineItemBuilder::custom()
->name('Product')
->description('Detailed description of the product')
->quantity(1)
->unitName('piece')
->unitPrice('EUR', 99.99, 19.0)
)
->addLineItem(
LineItemBuilder::text()
->name('Note')
->description('Additional context for the invoice')
)
->taxConditions('net')
->paymentConditions(
label: '10 days - 3%',
duration: 30,
discountPercentage: 3.0,
discountRange: 10
)
->shippingConditions(
date: now()->addDays(5),
type: 'delivery'
)
->title('Invoice')
->introduction('Introduction text for the invoice')
->remark('Thank you for your business!')
->toArray(); // Automatically validates the invoice data
use PhilHarmonie\LexOffice\Services\ContactService;
use PhilHarmonie\LexOffice\Services\InvoiceService;
class MyController
{
public function __construct(
private ContactService $contactService,
private InvoiceService $invoiceService
) {}
public function createInvoice()
{
$contact = $this->contactService->find('contact-id');
$invoice = $this->invoiceService->create($data);
}
}
use Illuminate\Cache\CacheManager;
use Illuminate\Http\Client\Factory as Http;
use PhilHarmonie\LexOffice\Client;
use PhilHarmonie\LexOffice\Services\ArticleService;
use PhilHarmonie\LexOffice\Services\ContactService;
use PhilHarmonie\LexOffice\Services\InvoiceService;
$client = new Client(apiKey: $tenant->lexware_api_key, http: app(Http::class), cache: app(CacheManager::class));
$articles = new ArticleService($client);
$contacts = new ContactService($client);
$invoices = new InvoiceService($client);