37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Integrations\Whmcs\Extractors;
|
|
|
|
use App\Integrations\Whmcs\Support\SyncedLegacyIds;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\LazyCollection;
|
|
|
|
class InvoiceExtractor
|
|
{
|
|
public function extract(bool $missingOnly = false): LazyCollection
|
|
{
|
|
$rows = DB::connection('whmcs')->table('tblinvoices')->orderBy('id')->cursor();
|
|
if (! $missingOnly) {
|
|
return $rows;
|
|
}
|
|
|
|
$synced = SyncedLegacyIds::of('invoices');
|
|
|
|
return $rows->reject(fn ($row) => isset($synced[$row->id]));
|
|
}
|
|
|
|
/**
|
|
* Line items for a single invoice (tblinvoiceitems has no per-invoice cursor of its own,
|
|
* items are pulled per-invoice while its job runs).
|
|
*/
|
|
public function items(int $invoiceId): \Illuminate\Support\Collection
|
|
{
|
|
return DB::connection('whmcs')->table('tblinvoiceitems')->where('invoiceid', $invoiceId)->get();
|
|
}
|
|
|
|
public function orderIdFor(int $invoiceId): ?int
|
|
{
|
|
return DB::connection('whmcs')->table('tblorders')->where('invoiceid', $invoiceId)->value('id');
|
|
}
|
|
}
|